Skip to content

[BugFix] Treat FlattenAction NestedKey tuples as one key - #4476

Open
YeonwooSung wants to merge 3 commits into
pytorch:mainfrom
YeonwooSung:bugfix/4464-flatten-action-nestedkey
Open

YeonwooSung wants to merge 3 commits into
pytorch:mainfrom
YeonwooSung:bugfix/4464-flatten-action-nestedkey

Conversation

@YeonwooSung

Copy link
Copy Markdown
Contributor

Description

ActionScaling and FlattenAction wrapped in_keys_inv with isinstance(..., (list, tuple)). A NestedKey ("agent", "action") is a tuple, so it was treated as two keys "agent" and "action".

ActionScaling then raised (single action key per instance). FlattenAction defaulted in_keys / out_keys / out_keys_inv from list(in_keys_inv) and registered the two strings.

Both constructors now wrap with isinstance(..., (str, tuple)), matching LastAction and Transform. Existing tests that pass a list of NestedKeys still work. in_keys, out_keys, and out_keys_inv were already handled by the Transform setters.

Code example

from torchrl.envs.transforms import ActionScaling, FlattenAction

t = ActionScaling(in_keys_inv=("agent", "action"))
assert t.in_keys_inv == [("agent", "action")]

t = FlattenAction(first_dim=-2, last_dim=-1, in_keys_inv=("agent", "action"))
assert t.in_keys_inv == [("agent", "action")]
assert t.in_keys == [("agent", "action")]

Motivation and Context

close #4464

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@pytorch-bot

pytorch-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4476

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 16 Awaiting Approval

As of commit 58945fb with merge base de28012 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 22, 2026
@vmoens

vmoens commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

What about insinstance(key, NestedKey)?

@YeonwooSung
YeonwooSung force-pushed the bugfix/4464-flatten-action-nestedkey branch from 569feb0 to 58945fb Compare September 23, 2026 01:37
@YeonwooSung

Copy link
Copy Markdown
Contributor Author

isinstance(key, NestedKey) is a runtime check: a string or nested tuple is a NestedKey, a list of keys is not. ActionScaling and FlattenAction now wrap in_keys_inv with that.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BugFix CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ActionScaling and FlattenAction treat NestedKey tuples as sequences of keys

2 participants