mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-26 22:30:19 +08:00
fix(quant_ops): implement __torch_function__ to support torch.empty_like for mock QuantizedTensor
Signed-off-by: Macpaul Lin <macpaul@gmail.com>
This commit is contained in:
parent
96803b16c0
commit
ea3ec049bd
@ -118,6 +118,18 @@ except ImportError as e:
|
|||||||
return self._layout_params
|
return self._layout_params
|
||||||
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __torch_function__(cls, func, types, args=(), kwargs=None):
|
||||||
|
if kwargs is None:
|
||||||
|
kwargs = {}
|
||||||
|
if func is torch.empty_like:
|
||||||
|
input_t = args[0]
|
||||||
|
if isinstance(input_t, cls):
|
||||||
|
dtype = kwargs.get("dtype", input_t.dtype)
|
||||||
|
device = kwargs.get("device", input_t.device)
|
||||||
|
return torch.empty(input_t.shape, dtype=dtype, device=device)
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
def __torch_dispatch__(self, func, types, args=(), kwargs=None):
|
def __torch_dispatch__(self, func, types, args=(), kwargs=None):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user