model_patcher.py: AttributeError on RMS_norm modules (missing .weight attribute)
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
## Bug Description
`get_key_weight()` in `model_patcher.py` crashes when encountering `RMS_norm` modules because it assumes all modules have a `.weight` attribute. WAN 2.1/2.2 VAE uses `RMS_norm` which has a `gamma` parameter instead of `weight`.
## Error
```
Exception during processing!
Traceback (most recent call last):
File "comfy/model_patcher.py", line 166, in get_key_weight
weight = getattr(op, op_keys[1])
AttributeError: 'RMS_norm' object has no attribute 'weight'
```
## Environment
- ComfyUI: Latest master
- PyTorch: 2.9.1+cu128
- Model: WAN 2.2 I2V 14B GGUF with DisTorch2 multi-GPU distribution
## Root Cause
In `get_key_weight()`, the code does:
```python
op_keys = key.split(".")
if len(op_keys) >= 2:
weight = getattr(op, op_keys[1]) # Crashes if op_keys[1] doesn't exist
```
This assumes all normalization layers have a `.weight` attribute, but `RMS_norm` uses `.gamma` instead.
## Suggested Fix
Add a `hasattr()` check before the `getattr()` call:
```python
if len(op_keys) >= 2:
if not hasattr(op, op_keys[1]):
return None, None, None
weight = getattr(op, op_keys[1])
```
This gracefully handles modules with non-standard parameter names.
Contributor guide
Assessment
This issue has not been assessed yet.