Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions tests/pytorch/test_onnx_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ def create_ort_input_dict(session, inputs):
)


def get_atol(precision: torch.dtype, default: float = 1e-3) -> float:
# ORT runs on CPU while TE runs on GPU; fp16 accumulation differences reach a few ULPs.
return 2e-2 if precision is torch.float16 else default


def dtype2str(dtype: torch.dtype, fake_bf16_io=False):
if fake_bf16_io:
assert dtype == torch.bfloat16
Expand Down Expand Up @@ -458,7 +463,7 @@ def forward(self, inp):
if precision in (torch.bfloat16,):
return
if fp8_recipe is None:
validate_result(fname, inp, model, atol=1e-3, te_outputs=te_outputs)
validate_result(fname, inp, model, atol=get_atol(precision), te_outputs=te_outputs)
else:
validate_result(
fname, inp, model, atol=1e-2, is_fp8=fp8_recipe is not None, te_outputs=te_outputs
Expand Down Expand Up @@ -587,15 +592,19 @@ def _test_export_layernorm_linear(
if precision in (torch.bfloat16,):
return
if fp8_recipe is None:
validate_result(fname, inp, model, atol=1e-3, te_outputs=te_outputs)
validate_result(fname, inp, model, atol=get_atol(precision), te_outputs=te_outputs)
elif precision != torch.bfloat16:
validate_result(
fname,
inp,
model,
# For current scaling we use Float8Quantizer in tests + amax computed by hand,
# which has slightly different numerics than Float8CurrentScalingQuantizer.
atol=1e-3 if fp8_recipe.__class__ is not recipe.Float8CurrentScaling else 2e-2,
atol=(
get_atol(precision)
if fp8_recipe.__class__ is not recipe.Float8CurrentScaling
else 2e-2
),
is_fp8=fp8_recipe is not None,
te_outputs=te_outputs,
)
Expand Down Expand Up @@ -673,7 +682,9 @@ def _test_export_layernorm_mlp(
if precision in (torch.bfloat16,):
return
atol = (
2e-2 if fp8_recipe is not None else (5e-1 if activation == "swiglu" else 1e-3)
2e-2
if fp8_recipe is not None
else (5e-1 if activation == "swiglu" else get_atol(precision))
) # TODO(pgadzinski) - check 2e-2
validate_result(
fname, inp, model, atol=atol, is_fp8=fp8_recipe is not None, te_outputs=te_outputs
Expand Down
Loading