Lightning-AI / Lightning-AI/lightning-thunder

[reporting] `check_consistency` to use double precision computation as reference and verify that thunder result is closer.

Open
#1,935 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement reporting
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.

https://github.com/Lightning-AI/lightning-thunder/blob/31594068e7df8ae9cbd1dbe27b17cbf76aea0400/thunder/dynamo/report.py#L460-L462

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

https://github.com/Lightning-AI/lightning-thunder/blob/31594068e7df8ae9cbd1dbe27b17cbf76aea0400/thunder/tests/test_grad.py#L1387-L1393

cc: @kiya00 @mruberry

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.