raise exected exception when attempting to change dtype

This commit is contained in:
David Burnett
2025-04-22 11:05:20 +01:00
committed by psychedelicious
parent 93d4b00082
commit a07fac6180

View File

@@ -123,6 +123,12 @@ class GGMLTensor(torch.Tensor):
def to(self, *args, **kwargs) -> torch.Tensor: ...
def to(self, *args, **kwargs):
for func_arg in args:
if isinstance(func_arg, torch.dtype) and func_arg != self.quantized_data.dtype:
raise ValueError("Operation changed the dtype of GGMLTensor unexpectedly.")
if 'dtype' in kwargs.keys():
if kwargs['dtype'] != self.quantized_data.dtype:
raise ValueError("Operation changed the dtype of GGMLTensor unexpectedly."
self.quantized_data = self.quantized_data.to(*args, **kwargs)
return self