Skip to content

Commit d731fc4

Browse files
Adjust 4bit test tolerance on CPU for larger blocksizes (#1749)
1 parent 27549fb commit d731fc4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/test_functional.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,12 @@ def test_4bit_quant(self, device, dtype, quant_type, blocksize):
11691169
4096: 0.262457,
11701170
}
11711171

1172-
assert err < error_dict[quant_type]["err"][blocksize] + 1e-3
1173-
assert relerr < error_dict[quant_type]["rel_err"][blocksize] + 1e-3
1172+
# Allow higher tolerance for fp32 on CPU with larger block sizes
1173+
reltol = 2.8e-3 if dtype == torch.float32 and blocksize >= 128 and device == "cpu" else 1e-3
1174+
errtol = 1.2e-3 if dtype == torch.float32 and blocksize >= 1024 and device == "cpu" else 1e-3
1175+
1176+
assert err < error_dict[quant_type]["err"][blocksize] + errtol
1177+
assert relerr < error_dict[quant_type]["rel_err"][blocksize] + reltol
11741178

11751179
@pytest.mark.parametrize("device", get_available_devices())
11761180
@pytest.mark.parametrize("quant_type", ["fp4", "nf4"])

0 commit comments

Comments
 (0)