forked from intel/neural-compressor
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (intel#1854)
* Add UT and remove unused code for torch MX quant --------- Change-Id: I2727aa716fa99467fa2d63b966de4d88470e4bb3 Signed-off-by: Mengni Wang <[email protected]>
- Loading branch information
1 parent
647905a
commit 31d8bb9
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