Skip to content

Commit ee5fd87

Browse files
Update CPU 4bit test tolerance
1 parent 5129c59 commit ee5fd87

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/test_functional.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,7 @@ def test_4bit_quant(self, device, dtype, quant_type, blocksize):
11231123

11241124
assert A2.dtype == dtype
11251125

1126-
# With larger block sizes, we can expect this to blow up.
1127-
# At blocksize>=1024, don't even bother looking at relerr.
1128-
#
1129-
# Actually, the above is not true anymore after fixing the integer packing bug.
1130-
# The following values were taken from averaging 1k samples per test configuration after fixing the bug.
1126+
# The following values were taken from averaging 1k samples per test configuration
11311127
error_dict = dict()
11321128
error_dict["fp4"] = dict()
11331129
error_dict["nf4"] = dict()
@@ -1169,8 +1165,12 @@ def test_4bit_quant(self, device, dtype, quant_type, blocksize):
11691165
4096: 0.262457,
11701166
}
11711167

1172-
assert err < error_dict[quant_type]["err"][blocksize] + 1e-3
1173-
assert relerr < error_dict[quant_type]["rel_err"][blocksize] + 1e-3
1168+
# We need a higher tolerance for fp32 on CPU with blocksize >= 128.
1169+
# TODO: See if we can reduce this.
1170+
tolerance = 2.7e-3 if device == "cpu" and dtype == torch.float32 and blocksize >= 128 else 1e-3
1171+
1172+
assert err < error_dict[quant_type]["err"][blocksize] + tolerance
1173+
assert relerr < error_dict[quant_type]["rel_err"][blocksize] + tolerance
11741174

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

0 commit comments

Comments
 (0)