TypeError: QuantizedTensor.is_contiguous() got an unexpected keyword argument 'memory_format' when utilizing torch.compile (Wan2.2)
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
### Expected Behavior
When running the Wan2.2 video generation workflow with the `TorchCompileModelWanVideoV2` node enabled, the model should compile successfully via torch.compile/dynamo and generate video without errors.
This feature was working correctly in ComfyUI version v0.3.68.
### Actual Behavior
The workflow crashes immediately during the model forward pass when `torch.compile` is engaged.
The error indicates that `QuantizedTensor.is_contiguous` in the core ComfyUI code is receiving a `memory_format` argument from PyTorch's dynamo compiler, but the method is not defined to accept any arguments.
Workaround: Bypassing/Disabling the `TorchCompileModelWanVideoV2` node allows the workflow to function correctly (albeit slower).
### Steps to Reproduce
1. Update ComfyUI to the latest version.
2. Load a standard Wan2.2 Video generation workflow.
3. Ensure the `TorchCompileModelWanVideoV2` node is connected and enabled (or any node that triggers `torch.compile` on the model).
4. Queue the prompt.
5. Observed `InternalTorchDynamoError`.
### Debug Logs
```powershell
torch._dynamo.exc.InternalTorchDynamoError: TypeError: QuantizedTensor.is_contiguous() got an unexpected keyword argument 'memory_format'
from user code:
File "...\comfy\ldm\wan\model.py", line 236, in forward
y = self.self_attn(
File "...\comfy\ldm\wan\model.py", line 78, in forward
q = qkv_fn_q(x)
File "...\comfy\ldm\wan\model.py", line 68, in qkv_fn_q
q = self.norm_q(self.q(x)).view(b, s, n, d)
File "...\comfy\ops.py", line 164, in forward
return self.forward_comfy_cast_weights(*args, **kwargs)
File "...\comfy\ops.py", line 489, in forward_comfy_cast_weights
out = fp8_linear(self, input)
File "...\comfy\ops.py", line 433, in fp8_linear
quantized_input = QuantizedTensor.from_float(input, "TensorCoreFP8Layout", scale=scale_input, dtype=dtype)
File "...\comfy\quant_ops.py", line 194, in from_float
return cls(qdata, layout_type, layout_params)
```
### Other
### Issue Description
**Description**
I encountered a `TypeError` when attempting to run the Wan2.1 video generation workflow using the latest version of ComfyUI. The error occurs specifically when the `TorchCompileModelWanVideoV2` node is active (referencing `torch.compile`).
The error seems to stem from `QuantizedTensor` not accepting the `memory_format` argument, which `torch._dynamo` passes during the compilation process of fp8 layers.
**Regression**
* **Current Version:** Latest (Error occurs here)
* **Last Working Version:** `v0.3.68` (This workflow worked correctly without error in this version).
**Workaround**
Bypassing/Disabling the `TorchCompileModelWanVideoV2` node allows the workflow to run successfully (at the cost of speed).
Contributor guide
Assessment
This issue has not been assessed yet.