-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
overwrite to() for QTensor and QBitsTensor #88
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,14 @@ | |
from quanto import QTensor, absmax_scale, qfloat8_e4m3fn, qfloat8_e5m2, qint8, qint16, qint32 | ||
|
||
|
||
def test_qtensor_move(device): | ||
input_shape = (2, 4, 8) | ||
qa = random_qtensor(input_shape, dtype=torch.float32) | ||
qa = qa.to(device) | ||
assert qa._data.device.type == device.type | ||
assert qa._scale.device.type == device.type | ||
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following works even before this PR. This is why you never had this specific issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a test for this here: https://github.com/huggingface/quanto/blob/6302171b7569a3fd86f31e1731d01d390d1eb557/test/tensor/ops/test_quantized_dispatch.py#L8 |
||
|
||
|
||
@pytest.mark.parametrize("input_shape", [(10,), (1, 10), (10, 32, 32)]) | ||
@pytest.mark.parametrize("dtype", [torch.float16, torch.float32], ids=["fp16", "fp32"]) | ||
@pytest.mark.parametrize("qtype", [qint8], ids=["qint8"]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to return
super().to(*args, **kwargs)
but it was causing weird behavior with tests usingQBitsTensor
and it was calling__torch_function__
after . To reproduce, returnsuper().to(*args, **kwargs)
and runpython -m pytest -sv test/nn/test_qlinear.py::test_move_qlinear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tensor subclasses are a very special beasts: you should not override the base Tensor methods that way, and instead do it through the dispatch.