Skip to content

Fix AttributeError in RayCollisionFunction.backward#182

Open
Mr-Neutr0n wants to merge 1 commit intoopenai:mainfrom
Mr-Neutr0n:fix/ray-collision-backward-saved-tensors
Open

Fix AttributeError in RayCollisionFunction.backward#182
Mr-Neutr0n wants to merge 1 commit intoopenai:mainfrom
Mr-Neutr0n:fix/ray-collision-backward-saved-tensors

Conversation

@Mr-Neutr0n
Copy link

Summary

  • RayCollisionFunction.backward uses ctx.input_tensors to retrieve tensors saved during the forward pass, but ctx.input_tensors does not exist in the PyTorch autograd.Function API. The correct attribute is ctx.saved_tensors (populated by ctx.save_for_backward() in forward).
  • This causes an AttributeError whenever gradients flow through checkpointed ray casting (cast_rays with checkpoint=True), which is the default path when ray_batch_size < total_rays.

Fix

Replace ctx.input_tensors with ctx.saved_tensors on line 114 of shap_e/rendering/raycast/cast.py.

Test plan

  • Verified forward uses ctx.save_for_backward(origins, directions, faces, vertices)
  • Verified backward now unpacks via ctx.saved_tensors to match
  • Run differentiable mesh rendering with checkpoint=True and confirm gradients propagate without error

RayCollisionFunction.forward correctly saves tensors via
ctx.save_for_backward(), but backward() retrieves them using the
non-existent attribute ctx.input_tensors instead of the correct
ctx.saved_tensors. This causes an AttributeError whenever gradients
are backpropagated through checkpointed ray casting (i.e., when
cast_rays is called with checkpoint=True).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments