Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions tests/jax/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,15 @@ def test_forward_with_fp8(self, data_shape, dtype, attrs, fp8_recipe):
"""Test forward with fp8 enabled"""
# Empty MeshResource is used as we are running on a single device
with autocast(enabled=True, recipe=fp8_recipe, mesh_resource=MeshResource()):
self.runner(attrs).test_forward(data_shape, dtype, rtol=1e-4, atol=1e-3)
self.runner(attrs).test_forward(data_shape, dtype)

@pytest.mark.skipif(not is_fp8_supported, reason=reason)
@pytest.mark.parametrize("fp8_recipe", QUANTIZE_RECIPES)
def test_backward_with_fp8(self, data_shape, dtype, attrs, fp8_recipe):
"""Test backward with fp8 enabled"""
# Empty MeshResource is used as we are running on a single device
with autocast(enabled=True, recipe=fp8_recipe, mesh_resource=MeshResource()):
self.runner(attrs).test_backward(data_shape, dtype, rtol=1e-4, atol=1e-3)
self.runner(attrs).test_backward(data_shape, dtype)


class TestEncoderLayer(BaseTester):
Expand Down
6 changes: 3 additions & 3 deletions tests/jax/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,21 +1531,21 @@ def dtype_tols(

# Estimate floating-point error
finfo = jnp.finfo(dtype)
eps_relaxed = math.pow(finfo.eps, 2 / 3)
eps_relaxed = float(finfo.eps)
with jax.default_device(jax.devices("cpu")[0]):
if isinstance(reference_value, (float, int)):
reference_value = jnp.array(reference_value, dtype=dtype)
else:
reference_value = reference_value.astype(dtype)
spacing_high = jnp.nextafter(reference_value, finfo.max) - reference_value
spacing_low = reference_value - jnp.nextafter(reference_value, finfo.min)
ulp = max(spacing_high.item(), spacing_low.item())
ulp = float(max(spacing_high.item(), spacing_low.item()))
if rtol is None:
rtol = eps_relaxed
if atol is None:
atol = max(ulp, eps_relaxed)

# Manually set tols for nvfp4
# Manually set tols for nvfp4 as we expect enhanced precision with additional scaling factors
if dtype == jnp.float4_e2m1fn:
atol = 0.05
rtol = 0.1
Expand Down
Loading