fix: auto-adapt LeRobot state dimension instead of raising ValueError#82
Open
cagataycali wants to merge 3 commits intostrands-labs:mainfrom
Open
fix: auto-adapt LeRobot state dimension instead of raising ValueError#82cagataycali wants to merge 3 commits intostrands-labs:mainfrom
cagataycali wants to merge 3 commits intostrands-labs:mainfrom
Conversation
When a robot exposes more joints than the policy was trained on (e.g. aloha has 16 joints but ACT expects 14), the policy raised a hard ValueError during inference, making sim-to-real transfer fragile. Fix: truncate excess joints or zero-pad if fewer, with debug logging. This is the standard approach in robotics — LeRobot's own teleoperation code does the same.
This was referenced Apr 1, 2026
Address review feedback: state dimension truncation/padding should be visible to operators since it can affect device behavior.
yinsong1986
reviewed
Apr 1, 2026
| f"robot_state_keys but model expects {expected_dim}. " | ||
| f"Check that robot_state_keys matches your robot's actual joint count." | ||
| if len(state_values) > expected_dim: | ||
| logger.warning( |
There was a problem hiding this comment.
The warning logs dimension counts but not key names. When a user sees State dim 16 > model expects 14 — truncating, they can't tell which joints are dropped. Consider adding key names to the message so users can verify the mapping is intentional vs. a genuine misconfiguration:
logger.warning(
"State dim %d > model expects %d — truncating to first %d values. "
"Check that robot_state_keys matches your robot's actual joint count.",
len(state_values), expected_dim, expected_dim,
)
Member
Author
There was a problem hiding this comment.
Fixed in 669735d — warning now includes actionable hint about robot_state_keys:
logger.warning(
"State dim %d > model expects %d — truncating to first %d values. "
"Check that robot_state_keys matches your robot's actual joint count.",
len(state_values), expected_dim, expected_dim,
)Same pattern applied to the zero-padding path.
Address review: include robot_state_keys hint in truncation/padding warnings so users can diagnose joint count mismatches.
yinsong1986
approved these changes
Apr 1, 2026
yinsong1986
left a comment
There was a problem hiding this comment.
All review comments addressed. LGTM.
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.
TL;DR
When a robot exposes more joints than the policy was trained on (e.g. aloha has 16 joints but ACT expects 14), the policy raised a hard
ValueErrorduring inference. This fix auto-adapts state dimensions — truncate excess or zero-pad if fewer — with debug logging.What changed
strands_robots/policies/lerobot_local/policy.pyValueErrorwith truncate/zero-pad + debug loggingtests/test_lerobot_local.pyraisesWhy
This is the standard approach in robotics — LeRobot's own teleoperation code does the same. Hard crashing on dimension mismatch makes sim↔real transfer fragile and prevents running policies trained on one embodiment on another with different joint counts.
Testing
test_state_padded_to_expected_dimto verify auto-pad behaviorruff check+ruff format --check)Part 1 of 6 in the MuJoCo simulation PR decomposition (see PR_TASKS.md)