Skip to content

[diffusion] comfyui: start the SGLD worker without re-running ComfyUI's main.py - #43872

Closed
OnePunchMonk wants to merge 1 commit into
sgl-project:mainfrom
OnePunchMonk:fix/comfyui-spawn-main
Closed

OnePunchMonk wants to merge 1 commit into
sgl-project:mainfrom
OnePunchMonk:fix/comfyui-spawn-main

Conversation

@OnePunchMonk

@OnePunchMonk OnePunchMonk commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #43873

Motivation

On ComfyUI v0.39.2, every integrated-mode model (SGLDUNETLoader) fails to load. The node raises "The SGLD worker exited while loading the model", and the worker log shows:

File "ComfyUI/main.py", line 25, in <module>
  from app.database.db import ...
File "ComfyUI/app/database/db.py", line 9, in <module>
  from utils.install_util import get_missing_requirements_message
ModuleNotFoundError: No module named 'utils.install_util'; 'utils' is not a package

The worker is started with multiprocessing spawn, so the child re-imports the parent's __main__, which under ComfyUI is main.py. ComfyUI's nodes.py puts ComfyUI/comfy first on sys.path, so in the child import utils.install_util finds comfy/utils.py instead of ComfyUI's utils/ package.

Modifications

  • Hide __main__.__file__ / __spec__ only while DiffGenerator.from_pretrained starts the workers, then restore them. The worker never runs ComfyUI's entry script; it only needs sglang modules.
  • Regression test that spawns a real worker through init_generator from a host script that fails when re-imported, like ComfyUI's main.py.

Accuracy Tests

No change to model outputs. End to end check with ComfyUI v0.39.2 started the normal way (python main.py) and a Flux.1-dev SGLDUNETLoader workflow (1024x1024, 25 steps):

  • main, T4: the worker dies with the 'utils' is not a package error above.
  • This branch, L40S: the worker starts and the workflow completes.

Flux.1-dev via SGLD on this branch

Speed Tests and Profiling

N/A

Checklist


CI States

Latest PR Test (Base): ❌ Run #38280102285
Latest PR Test (Extra): ❌ Run #38280101950
Latest PR Test (AMD ROCm 10): ❌ Run #38280102570

…'s main.py

Spawn re-imports __main__ in every worker. Under ComfyUI v0.39.2 that is
main.py, which fails in the child because comfy/ is first on sys.path and
comfy/utils.py shadows the utils package, so every integrated-mode model
failed to load.
@niehen6174

Copy link
Copy Markdown
Collaborator

Thanks! This is already fixed in #43504 (same approach, _spawn_without_launcher_main). Mind closing this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [diffusion] ComfyUI integrated mode: SGLD worker crashes at startup on ComfyUI v0.39.2

2 participants