fix: add try-except block for Isaac Lab compatibility (#9)#10
fix: add try-except block for Isaac Lab compatibility (#9)#10zbbright233 wants to merge 2 commits into
Conversation
| try: | ||
| # Works for older Isaac Lab versions where buffers are wrapped | ||
| self.forwards = math_utils.quat_apply(self.robot.data.root_link_quat_w.torch, self.robot.data.FORWARD_VEC_B.torch) | ||
| except AttributeError: | ||
| # Works for recent Isaac Lab (0.54.4+) where buffers natively return standard PyTorch Tensors | ||
| self.forwards = math_utils.quat_apply(self.robot.data.root_link_quat_w, self.robot.data.FORWARD_VEC_B) |
There was a problem hiding this comment.
Exception thrown on every training step on new Isaac Lab
On Isaac Lab 0.54.4+, the try branch always raises AttributeError (because .torch no longer exists), which is then caught by except. Since _get_observations is called every environment step during training — potentially millions of times — this results in millions of exceptions being raised and swallowed silently. Python exception handling has non-trivial overhead compared to a conditional check, and the pattern also risks masking unrelated AttributeErrors raised inside quat_apply itself.
Prefer detecting the API shape once (e.g., with hasattr) rather than relying on exception control flow in a hot loop.
| try: | |
| # Works for older Isaac Lab versions where buffers are wrapped | |
| self.forwards = math_utils.quat_apply(self.robot.data.root_link_quat_w.torch, self.robot.data.FORWARD_VEC_B.torch) | |
| except AttributeError: | |
| # Works for recent Isaac Lab (0.54.4+) where buffers natively return standard PyTorch Tensors | |
| self.forwards = math_utils.quat_apply(self.robot.data.root_link_quat_w, self.robot.data.FORWARD_VEC_B) | |
| # Support both older Isaac Lab (wrapped buffers with .torch accessor) and | |
| # newer Isaac Lab 0.54.4+ (native PyTorch Tensors returned directly). | |
| quat = self.robot.data.root_link_quat_w | |
| fwd_vec = self.robot.data.FORWARD_VEC_B | |
| if hasattr(quat, "torch"): | |
| quat = quat.torch | |
| fwd_vec = fwd_vec.torch | |
| self.forwards = math_utils.quat_apply(quat, fwd_vec) |
|
Thanks for the great feedback regarding the performance overhead in the hot loop! I have refactored the compatibility logic using hasattr as suggested to keep the execution fast and clean. |
What does this PR do?
Fixes an
AttributeError: 'Tensor' object has no attribute 'torch'when running training scripts with recent Isaac Lab updates (Extension version 0.54.4+), where physics buffers now natively return standard PyTorch Tensors.How is it resolved?
To maintain backward compatibility for users still on older versions of Isaac Lab, I wrapped the data fetching in a
try-exceptblock. This ensures the code runs flawlessly on both old and new versions of Isaac Lab.Fixes #9