Comfy-Org / Comfy-Org/ComfyUI

[Bug] ModelSamplingFlux affects globally the workflow, bypassing it won't disable its effect (Krea2 testing)

Open
#14,754 3 comments 0 reactions 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 7h
Merged PRs (30d)
158

Description

### Custom Node Testing

- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)

### Expected Behavior

Here's the Krea2 test workflow, simplified to only use native nodes and native models.

[krea2_modelsamplingflux_bug-test.json](https://github.com/user-attachments/files/29647582/krea2_modelsamplingflux_bug-test.json)

The workflow has two branches:
- **1st branch** splits the generation in half: **raw** -> **raw+turbo lora**;
- **2nd branch** is just **raw+turbo**

**ModelSamplingFlux** is only connected to the raw stage of the 1st branch (currently with `max_shift=3.0` for testing purposes)

**Expectation**: The shift should only take effect on the 1st branch.

### Actual Behavior

If the generation starts with the 1st branch, the 2nd branch generates an unfinished/broken image, even thought the node is not connected to it.

The shift keeps influencing globally after it takes effect.

**Just bypassing the node won't fix the issue.**

To temporary fix it, you have to clear node+model cache (or restart ComfyUI).

If the cache is cleared, you can also keep the node enabled and only run the 2nd branch: the generation is not influenced by it.

## Testing workflow (screenshot)

Image

## Generation comparison (same seed)

Image

### Steps to Reproduce

- Run the testing workflow with ModelSamplingFlux bypassed as a baseline
- Restart ComfyUI to clear cache
- Enable ModelSamplingFlux
- Only run 1st branch
- Then run 2nd branch
- Notice how the shift has affected both 1st and 2nd branch images
- Bypass the node, change the seed and run the workflow again
- The shift still affects both generations

### Final proof:
- Clear node+model cache
- Re-enable the node _(optional)_
- Only run 2nd branch
- The shift effect is gone

### Debug Logs

```powershell
E:\ComfyUI>.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-build --disable-api-nodes --disable-all-custom-nodes
[INFO] setup plugin alembic.autogenerate.schemas
[INFO] setup plugin alembic.autogenerate.tables
[INFO] setup plugin alembic.autogenerate.types
[INFO] setup plugin alembic.autogenerate.constraints
[INFO] setup plugin alembic.autogenerate.defaults
[INFO] setup plugin alembic.autogenerate.comments
[INFO] Found comfy_kitchen backend cuda: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'dequantize_int8_convrot_weight', 'dequantize_int8_convrot_weight_dtype', 'dequantize_int8_simple', 'dequantize_int8_simple_dtype', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'gemv_awq_w4a16', 'int8_linear', 'quantize_and_rotate_rowwise', 'quantize_int8_convrot_weight', 'quantize_int8_rowwise', 'quantize_int8_tensorwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8', 'quantize_svdquant_w4a4', 'scaled_mm_nvfp4', 'scaled_mm_svdquant_w4a4', 'stochastic_rounding_fp8']}
[INFO] Found comfy_kitchen backend triton: {'available': True, 'disabled': True, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'int8_linear', 'quantize_and_rotate_rowwise', 'quantize_int8_rowwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8']}
[INFO] Found comfy_kitchen backend eager: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'dequantize_int8_convrot_weight', 'dequantize_int8_convrot_weight_dtype', 'dequantize_int8_simple', 'dequantize_int8_simple_dtype', 'dequantize_mxfp8', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'gemv_awq_w4a16', 'int8_linear', 'quantize_and_rotate_rowwise', 'quantize_int8_convrot_weight', 'quantize_int8_rowwise', 'quantize_int8_tensorwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8', 'quantize_svdquant_w4a4', 'scaled_mm_mxfp8', 'scaled_mm_nvfp4', 'scaled_mm_svdquant_w4a4', 'stochastic_rounding_fp8']}
[INFO] Checkpoint files will always be loaded safely.
[INFO] Total VRAM 8192 MB, total RAM 65277 MB
[INFO] pytorch version: 2.12.0+cu130
[INFO] Set vram state to: NORMAL_VRAM
[INFO] Device: cuda:0 NVIDIA GeForce RTX 3070 Ti Laptop GPU : cudaMallocAsync
[INFO] Using async weight offloading with 2 streams
[INFO] Enabled pinned memory 26110.0
[INFO] Using pytorch attention
aimdo: src-win/cuda-detour.c:38:INFO:aimdo_setup_hooks: installing 6 hooks
aimdo: src-win/cuda-detour.c:28:DEBUG:install_hook_entries: hooks successfully installed
aimdo: src-win/shmem-detect.c:80:INFO:comfy-aimdo WDDM adapter match: NVIDIA GeForce RTX 3070 Ti Laptop GPU runtime_luid=00000000:00011c6d dxgi_luid=00000000:00011c6d
aimdo: src/control.c:248:INFO:comfy-aimdo inited for GPU: NVIDIA GeForce RTX 3070 Ti Laptop GPU (VRAM: 8191 MB)
[INFO] DynamicVRAM support detected and enabled
[INFO] Python version: 3.12.7 (tags/v3.12.7:0b05ead, Oct 1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)]
[INFO] ComfyUI version: 0.27.0
[INFO] comfy-aimdo version: 0.4.10
[INFO] comfy-kitchen version: 0.2.16
[INFO] comfyui-frontend-package version: 1.45.20
[INFO] comfyui-workflow-templates version: 0.11.2
[INFO] comfyui-embedded-docs version: 0.5.6
[INFO] comfy-kitchen version: 0.2.16
[INFO] comfy-aimdo version: 0.4.10
[INFO] [Prompt Server] web root: E:\ComfyUI\python_embeded\Lib\site-packages\comfyui_frontend_package\static
[INFO] Asset seeder disabled
[INFO] No OpenGL_accelerate module loaded: Acceleration disabled
[INFO] Skipping loading of custom nodes
[INFO] Context impl SQLiteImpl.
[INFO] Will assume non-transactional DDL.
[INFO] Using RAM pressure cache.
[INFO] Starting server

[INFO] To see the GUI go to: http://127.0.0.1:8188
[INFO] got prompt
[INFO] Using pytorch attention in VAE
[INFO] Using pytorch attention in VAE
[INFO] VAE load device: cuda:0, offload device: cpu, dtype: torch.bfloat16
[INFO] Found quantization metadata version 1
[INFO] Detected mixed precision quantization
[INFO] Using mixed precision operations
[INFO] Native ops: int8_tensorwise , emulated ops: mxfp8, nvfp4, float8_e5m2, float8_e4m3fn
[INFO] model weight dtype torch.bfloat16, manual cast: torch.bfloat16
[INFO] model_type FLUX
[INFO] CLIP/text encoder model load device: cuda:0, offload device: cpu, current: cpu, dtype: torch.float16
[INFO] Requested to load Krea2TEModel_
[INFO] Model Krea2TEModel_ prepared for dynamic VRAM loading. 8463MB Staged. 0 patches attached. Force pre-loaded 249 weights: 627 KB.
[INFO] got prompt
[INFO] 0 models unloaded.
[INFO] Model Krea2TEModel_ prepared for dynamic VRAM loading. 8463MB Staged. 0 patches attached. Force pre-loaded 249 weights: 627 KB.
[INFO] Requested to load Krea2
[INFO] 0 models unloaded.
[INFO] Model Krea2 prepared for dynamic VRAM loading. 12864MB Staged. 0 patches attached. Force pre-loaded 160 weights: 2824 KB.
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [01:09<00:00, 8.70s/it]
[INFO] Requested to load Krea2
[INFO] Model Krea2 prepared for dynamic VRAM loading. 12864MB Staged. 270 patches attached. Force pre-loaded 160 weights: 2824 KB.
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:39<00:00, 4.95s/it]
[INFO] Requested to load WanVAE
[INFO] 0 models unloaded.
[INFO] Model WanVAE prepared for dynamic VRAM loading. 241MB Staged. 0 patches attached. Force pre-loaded 60 weights: 61 KB.
[INFO] Prompt executed in 115.34 seconds
[INFO] Model Krea2 prepared for dynamic VRAM loading. 12864MB Staged. 270 patches attached. Force pre-loaded 160 weights: 2824 KB.
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:39<00:00, 4.99s/it]
[INFO] 0 models unloaded.
[INFO] Model WanVAE prepared for dynamic VRAM loading. 241MB Staged. 0 patches attached. Force pre-loaded 60 weights: 61 KB.
[INFO] Prompt executed in 41.16 seconds
```

### Other

I spent the entire day debugging to find the cause of this issue. Very painful day.

Seems like this issue is only present in that note, tried ModelSamplingSD3 and ModelSamplingAuraFlow and they work fine.

Contributor guide

Open the contributing guide

Research direction

Start by running the attached krea2_modelsamplingflux_bug-test.json workflow with custom nodes disabled, following the stated branch order and cache-clearing steps. Trace ModelSamplingFlux and the node/model cache behavior; done means the shift affects only the connected first branch, and bypassing it no longer leaves a residual effect on the second branch.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
backend, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.