-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UT and remove unused code for torch MX quant (#1854)
* Add UT and remove unused code for torch MX quant --------- Signed-off-by: Mengni Wang <[email protected]>
- Loading branch information
1 parent
647905a
commit 455f1e1
Showing
3 changed files
with
48 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
import torch | ||
|
||
from neural_compressor.torch.algorithms.mx_quant import utils | ||
|
||
|
||
def test_mx_quant_utility(): | ||
tensor = torch.rand((1, 30)) | ||
assert torch.equal(tensor, utils.quantize_mx_op(tensor, None, "nearest", 32)) | ||
assert torch.equal(tensor, utils._quantize_fp(tensor)) | ||
assert torch.equal(tensor, utils._quantize_bfloat(tensor, 0)) | ||
assert torch.equal(tensor, utils._quantize_mx(tensor, 8, None)) | ||
|
||
assert not torch.equal(utils._shared_exponents(tensor, "none"), utils._shared_exponents(tensor)) | ||
with pytest.raises(Exception): | ||
utils._shared_exponents(tensor, None) | ||
with pytest.raises(Exception): | ||
utils._reshape_to_blocks(tensor, None, 32) | ||
with pytest.raises(Exception): | ||
utils.quantize_elemwise_op(tensor, "test") | ||
with pytest.raises(Exception): | ||
utils._round_mantissa(tensor, 3, "test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters