Skip to content

Commit 6ad54ba

Browse files
authored
Relax tolerance for apex xentropy for float16 (#2411)
`test_apex_torch_consistency` has been observed to be flakey for float16. This PR relaxes the tolerances for comparing apex xentropy to torch xentropy on float16.
1 parent 748c0d6 commit 6ad54ba

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

thunder/tests/test_apex_cross_entropy_executor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def fn(logits, labels):
3636
assert any(bsym.sym.name == "apex_cross_entropy" for bsym in extrace.bound_symbols)
3737

3838

39-
def snippet_torch_consistency(op, torch_op, sample):
39+
def snippet_torch_consistency(op, torch_op, sample, comparator):
4040
thunder_result = op(*sample.args, **sample.kwargs)
4141
torch_result = torch_op(*sample.args, **sample.kwargs)
42-
assert_close(thunder_result, torch_result, equal_nan=True, atol=1e-3, rtol=1e-4)
42+
comparator(thunder_result, torch_result)
4343

4444
last_trace = thunder.last_traces(op)[-1]
4545
assert any(bsym.sym.name == "apex_cross_entropy" for bsym in last_trace.bound_symbols)
@@ -65,6 +65,10 @@ def fn(*args, **kwargs):
6565
if not _cross_entropy_checker(*sample.args, **sample.kwargs):
6666
continue
6767

68+
# relax tolerances for lower precision dtypes
69+
atol, rtol = (1e-2, 1e-3) if dtype == torch.float16 else (1e-3, 1e-4)
70+
comparator = partial(assert_close, equal_nan=True, atol=atol, rtol=rtol)
71+
6872
at_least_one_supported_input = True
6973
result = run_snippet(
7074
snippet_torch_consistency,
@@ -74,6 +78,7 @@ def fn(*args, **kwargs):
7478
cfn,
7579
op.torch_reference,
7680
sample,
81+
comparator,
7782
)
7883

7984
if result is not None:

0 commit comments

Comments
 (0)