Skip to content

Commit

Permalink
fix(qtensor): prevent shallow copies
Browse files Browse the repository at this point in the history
By overriding a native tensor method, we prevent torch from blindly assigning
the content of a QTensor to another using Tensor.data.
  • Loading branch information
dacorvo committed Feb 20, 2024
1 parent 66126d5 commit da0315f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions quanto/tensor/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def get_qtensor_func(func):
return _QTENSOR_FUNC_TABLE.get(func, None)


@register_qtensor_func([torch._has_compatible_shallow_copy_type])
def has_compatible_shallow_copy_type(func, input: torch.Tensor, from_: torch.Tensor):
# Prevent torch from trying to shallow copy one QTensor to another
return False


@register_qtensor_func(
[
torch.nn.functional.cross_entropy,
Expand Down

0 comments on commit da0315f

Please sign in to comment.