Fix crash when running quantized models through torch.compile#52
Fix crash when running quantized models through torch.compile#52jtreminio wants to merge 3 commits into
Conversation
|
✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged. |
|
I have read and agree to the Contributor License Agreement |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughQuantizedTensor now threads ChangesDynamic outer stride rebuilds
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_unflatten_dynamic_shapes.py`:
- Around line 56-62: The `_dummy_qt` helper is registering the "Dummy" layout on
every call via register_layout_class, which repeatedly mutates the global
LAYOUTS registry across tests. Move the register_layout_class("Dummy",
self._DummyLayout) call out of _dummy_qt and into module scope so the layout is
registered once when the test module loads, while leaving _dummy_qt only
responsible for constructing the QuantizedTensor with _DummyLayout and
_DummyParams.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 38c59d67-74a6-44d9-9c76-3680e42b8ba5
📒 Files selected for processing (2)
comfy_kitchen/tensor/base.pytests/test_unflatten_dynamic_shapes.py
Quantized models could crash during
torch.compilewhenever the input size changes between runs, for example an image model where the prompt length varies, because the quantized tensor wasn't reporting its shape the way PyTorch's compiler expects when it rebuilds the tensor.This change makes that step pass the requested shape and stride through correctly, so compiling quantized models (including mxfp8) now works instead of erroring out, with no change to normal non-compiled use. Includes a regression test that reproduces the original failure.
An example model that crashed is https://huggingface.co/Comfy-Org/Krea-2/blob/main/diffusion_models/krea2_turbo_mxfp8.safetensors
Full disclosure: I am a software engineer but Torch internals are a mystery to me. This PR was heavily assisted with Claude, but I did the code review, I did the testing, I verified this works as intended, and minimized the area of impact for the fix.