Lightning-AI / Lightning-AI/lightning-thunder
Further improve`test_grad.py::check_vjp_correctness`
@mattteochen is already working on this.
Since Oct 15, 2025.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
PR https://github.com/Lightning-AI/lightning-thunder/pull/2618 is not a perfect patch to temporarily speed up CI jobs targeting `check_vjp_correctness` tests. This work maintained this mathematical [identity](https://github.com/Lightning-AI/lightning-thunder/blob/72a9d866b38e8ec0c3a29b1e6544c4787754236c/thunder/tests/test_grad.py#L424) to perform correctness checks; instead of relying on a finite difference method to compute the Jacobian vector product, it employed `torch.func.jvp`, which turned out to be much faster.
This is a valid approach, but we could improve the total test time by asserting different mathematical concepts. For example [this](https://github.com/Lightning-AI/lightning-thunder/pull/2618#discussion_r2428347427) with [this](https://github.com/Lightning-AI/lightning-thunder/pull/2618#discussion_r2428349737).
Some issues persist after this work:
- Most of the tests are run with the faster `torch.func.jvp`, but in some cases, we discovered relevant numerical discrepancies between the function that Thunder runs and the one Torch runs (eager), especially when executors are involved. Those are [whitelisted](https://github.com/Lightning-AI/lightning-thunder/blob/72a9d866b38e8ec0c3a29b1e6544c4787754236c/thunder/tests/test_grad.py#L124) and run with by using fdm.
- To make `torch.func.jvp` work on some test cases, we had to clone the input tensor inside the sample generators, but this will produce contiguous tensors [changing the original striders](https://github.com/Lightning-AI/lightning-thunder/pull/2618#discussion_r2428341356)
- Complete types are not differentiable within Torch, but they [are for Thunder](https://github.com/Lightning-AI/lightning-thunder/blob/72a9d866b38e8ec0c3a29b1e6544c4787754236c/thunder/tests/test_grad.py#L474). If the input has a complete type, then fdm is employed instead of the Torch API.
cc @borda @mruberry
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.