fix(qwenimage): support index_timestep_zero for Qwen-Image-Edit#790
fix(qwenimage): support index_timestep_zero for Qwen-Image-Edit#790avan06 wants to merge 2 commits intonunchaku-ai:devfrom
Conversation
|
Could you include a test as in contribution guide? |
|
Hi, since the Contribution Guide is written for Linux, I ran into some difficulties running it on Windows. I’ll find some time to check how to run it properly. For now, I’ve just run pre-commit. Thank you. |
fd73baf to
47c4cd8
Compare
|
Not sure what I'm doing, but I'm getting an AttributeError: function 'EmptyProcessWorkingSet' not found during the test. (venv) G:\src\test-workspace>pytest -v tests/ -x -vv -k "nunchaku-qwen-image-edit-2509" tests/test_workflows.py::test[nunchaku-qwen-image-edit-2509_0] FAILED [ 50%] ========================================================================================= FAILURES ========================================================================================== case = <tests.case.Case object at 0x0000021F18B11160>, client = <comfy.client.embedded_comfy_client.Comfy object at 0x0000021F1ACD3E90>
tests\test_workflows.py:53: tests\utils.py:24: in compute_metrics model_name_or_path = 'openai/clip-vit-large-patch14'
{ prompts_list = ['Good photo.', 'Bad photo.'], device = device(type='cpu')
E AttributeError: 'BaseModelOutputWithPooling' object has no attribute 'norm' ..\ComfyUI-nunchaku-avan\venv\Lib\site-packages\torchmetrics\functional\multimodal\clip_iqa.py:178: AttributeError 2026-01-26 22:45:29 [INFO] [tests.test_workflows] [test_workflows.py:51] Generated image path: G:\src\test-workspace\output\ComfyUI_00002_.png Notes:
INFO tests.test_workflows:test_workflows.py:51 Generated image path: G:\src\test-workspace\output\ComfyUI_00002_.png :488 :488 :488 tests/test_workflows.py::test[nunchaku-qwen-image-edit-2509_0] tests/test_workflows.py::test[nunchaku-qwen-image-edit-2509_0] tests/test_workflows.py::test[nunchaku-qwen-image-edit-2509_0] tests/test_workflows.py::test[nunchaku-qwen-image-edit-2509_0] tests/test_workflows.py::test[nunchaku-qwen-image-edit-2509_0] tests/test_workflows.py::test[nunchaku-qwen-image-edit-2509_0] -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html |
- Implement timestep_zero_index handling in NunchakuQwenImageTransformerBlock. - Update _modulate to correctly split modulation parameters for doubled batches. - Ensure residual connections use split gates when Kontext reference method is used. - Fixes RuntimeError: 'shape is invalid for input of size...' during inference.
- Trim trailing whitespace - Reformat qwenimage.py with black-jupyter
47c4cd8 to
ea6f272
Compare
|
Could we please get this PR merged? I've been using it for over 2 weeks without any issues, and it fixes a serious problem that is a showstopper preventing the use of Qwen-Image-Edit-2511 with Nunchaku. |
|
确实可以用,感谢 |
Motivation
When using editing-based models (specifically Qwen-Image-Edit-2511), the index_timestep_zero reference method is required for positive conditioning to maintain high output quality. Without this specialized handling, the model fails to correctly anchor the reference image at the zero-noise state, leading to significantly degraded output quality or artifacts.
Currently, the qwenimage.py implementation in ComfyUI-nunchaku lacks the internal logic to handle this method. When index_timestep_zero is enabled, ComfyUI doubles the batch size of the timestep embeddings (temb), but the Nunchaku transformer blocks do not account for this batch doubling. This results in:
This 'Shape is invalid' issue has also been reported by others in the Hugging Face community. You can refer to this discussion for more context: Shape '[1, 52, 78, 16, 2, 2]' is invalid for input of size 519168 when using index_timestep_zero to fix image quality
Modifications
fix(qwenimage): support index_timestep_zero for Qwen-Image-Edit
Testing
This modification has been verified in ComfyUI with the FluxKontextMultiReferenceLatentMethod node set to index_timestep_zero. The image generation task now completes successfully as expected.
Checklist
pre-commit run --all-files).tests/workflowsdirectory following the guidance in the Contribution Guide.test_cases.json.test_data/inputs.yaml.scripts/download_models.pyandtest_data/models.yaml..github/workflows/pr-test.yaml.