Skip to content

fix: clearer error when wrt arg is a plain R literal#308

Merged
sebffischer merged 4 commits into
mainfrom
better-grad-error
May 18, 2026
Merged

fix: clearer error when wrt arg is a plain R literal#308
sebffischer merged 4 commits into
mainfrom
better-grad-error

Conversation

@sebffischer
Copy link
Copy Markdown
Contributor

TODOs:

  • properly handle trees in error message

When a `wrt` argument is passed as a plain R numeric (e.g.
`gradient(nv_log, wrt = "operand")(1)`), it is inlined as a constant
during tracing rather than registered as a graph input. The gradient
transform then produced zero outputs while `out_tree` still expected one
leaf, surfacing as a cryptic `subscript out of bounds` from
`unflatten.LeafNode`. Detect this in `compute_requirements()` and abort
with a message naming the offending argument(s) and pointing to
`nv_array()`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sebffischer sebffischer merged commit ef9f93a into main May 18, 2026
10 of 11 checks passed
@sebffischer sebffischer deleted the better-grad-error branch May 18, 2026 18:15
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