Main tensor-like class for storing quantized weights
| 42 | torch_compiler_disable = get_torch_compiler_disable_decorator() |
| 43 | |
| 44 | class GGMLTensor(torch.Tensor): |
| 45 | """ |
| 46 | Main tensor-like class for storing quantized weights |
| 47 | """ |
| 48 | def __init__(self, *args, tensor_type, tensor_shape, patches=[], **kwargs): |
| 49 | super().__init__() |
| 50 | self.tensor_type = tensor_type |
| 51 | self.tensor_shape = tensor_shape |
| 52 | self.patches = patches |
| 53 | |
| 54 | def __new__(cls, *args, tensor_type, tensor_shape, patches=[], **kwargs): |
| 55 | return super().__new__(cls, *args, **kwargs) |
| 56 | |
| 57 | def to(self, *args, **kwargs): |
| 58 | new = super().to(*args, **kwargs) |
| 59 | new.tensor_type = getattr(self, "tensor_type", None) |
| 60 | new.tensor_shape = getattr(self, "tensor_shape", new.data.shape) |
| 61 | new.patches = getattr(self, "patches", []).copy() |
| 62 | return new |
| 63 | |
| 64 | def clone(self, *args, **kwargs): |
| 65 | return self |
| 66 | |
| 67 | def detach(self, *args, **kwargs): |
| 68 | return self |
| 69 | |
| 70 | def copy_(self, *args, **kwargs): |
| 71 | # fixes .weight.copy_ in comfy/clip_model/CLIPTextModel |
| 72 | try: |
| 73 | return super().copy_(*args, **kwargs) |
| 74 | except Exception as e: |
| 75 | logging.warning(f"ignoring 'copy_' on tensor: {e}") |
| 76 | |
| 77 | def new_empty(self, size, *args, **kwargs): |
| 78 | # Intel Arc fix, ref#50 |
| 79 | new_tensor = super().new_empty(size, *args, **kwargs) |
| 80 | return GGMLTensor( |
| 81 | new_tensor, |
| 82 | tensor_type = getattr(self, "tensor_type", None), |
| 83 | tensor_shape = size, |
| 84 | patches = getattr(self, "patches", []).copy() |
| 85 | ) |
| 86 | |
| 87 | @property |
| 88 | def shape(self): |
| 89 | if not hasattr(self, "tensor_shape"): |
| 90 | self.tensor_shape = self.size() |
| 91 | return self.tensor_shape |
| 92 | |
| 93 | class GGMLLayer(torch.nn.Module): |
| 94 | """ |
no outgoing calls
no test coverage detected