[BugFix] Fix MultiOneHot.to_numpy() returning scalar instead of array#3589
Merged
vmoens merged 1 commit intopytorch:mainfrom Apr 4, 2026
Merged
[BugFix] Fix MultiOneHot.to_numpy() returning scalar instead of array#3589vmoens merged 1 commit intopytorch:mainfrom
vmoens merged 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3589
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 1 Cancelled JobAs of commit 5c52391 with merge base e2c8a8d ( NEW FAILURES - The following jobs have failed:
CANCELLED JOB - The following job was cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
vmoens
reviewed
Apr 4, 2026
Collaborator
vmoens
left a comment
There was a problem hiding this comment.
Wondering if getting a categorical value out of a one-hot when calling to_numpy() is the expected behavior?
Is it documented as such?
What happens for OneHot for instance, do we get a numpy scalar?
vmoens
approved these changes
Apr 4, 2026
Collaborator
vmoens
left a comment
There was a problem hiding this comment.
Ok read your comment on the PR, LGTM then!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MultiOneHot.to_numpy()inherits fromOneHot.to_numpy(), which callsargmax(-1)over the entire concatenated one-hot vector. For aMultiOneHot((11, 3))spec with a 14-element vector like[0,0,1,0,0,0,0,0,0,0,0,1,0,0], this returns a single scalar2instead of the correct array[2, 0].This also breaks gym
MultiDiscreteenvironment interaction sinceGymWrappermaps those toMultiOneHot.Changes
to_numpyoverride toMultiOneHotthat delegates toto_categorical(which already correctly splits bynvecand applies per-segmentargmax)nvecconfigs and batch shapesFixes #2633