Lightning-AI / Lightning-AI/lightning-thunder
[reporting] `check_consistency` to use double precision computation as reference and verify that thunder result is closer.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
Problem:
Currently with check_consistency, the result is compared against PyTorch eager with computation in same dtype.
However, for low precision dtype, there could be a numerical mismatch due to the difference in upcasts and downcasts during the computation. The discrepancy happens as fusion region lead to only one upcast and one down cast during the computation (which is better). While for eager, upcast and downcast occurs for every arithmetic operation.
For eg see - https://github.com/Lightning-AI/lightning-thunder/issues/1889
Proposed Solution:
Compare against the double precision result and verify that thunder is closer to reference than eager. Something along the lines of the snippet below -
try:
torch.testing.assert_close(result, eager_result)
except:
double_result = double_computation_fn(double_inputs)
from thunder.tests.framework import assert_closer
assert_closer(reference=double_result, candidate=result, competitor=eager_result, comparator=torch.testing.assert_close)
NOTE: This approach is also used in test_phantom_grad_vs_torch_consistency
cc: @kiya00 @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.
Research direction
Start at thunder/dynamo/report.py lines 460-462, where check_consistency compares the Thunder and PyTorch eager results. Review test_phantom_grad_vs_torch_consistency in thunder/tests/test_grad.py, especially lines 1387-1393, for the existing assert_closer pattern. Done means low-precision mismatches compare both results with a double-precision reference and verify that Thunder is closer than eager.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- devtools, testing-qa
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100