Skip to content

Commit ce06a14

Browse files
authored
[Diffusion] migrate the whole _register_configs from registry.py to the model own config file (#40612)
1 parent c6565c1 commit ce06a14

32 files changed

Lines changed: 936 additions & 857 deletions

‎docs/docs/sglang-diffusion/support_new_models.mdx‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ though the runtime is split into separate folders.
1212
The files are split by runtime responsibility. For a new model, read the
1313
request path first:
1414

15-
1. `registry.py` chooses the model family, sampling params, and pipeline config.
16-
2. `configs/pipeline_configs/{model}.py` defines model-specific denoising and
15+
1. `configs/pipeline_configs/{model}.py` defines model-specific denoising and
1716
decoding behavior.
18-
3. `runtime/pipelines/{model}.py` wires modules into stages.
19-
4. `runtime/pipelines_core/stages/` runs the shared stage logic.
20-
5. `runtime/models/` contains native model components only when the architecture
17+
2. `runtime/pipelines/{model}.py` wires modules into stages.
18+
3. `runtime/pipelines_core/stages/` runs the shared stage logic.
19+
4. `runtime/models/` contains native model components only when the architecture
2120
cannot be reused.
2221

2322
That is the dependency direction. Avoid making a model PR that requires readers
@@ -124,7 +123,6 @@ behavior.
124123

125124
| Area | Add or edit when | Typical file |
126125
| --- | --- | --- |
127-
| Registry | Always, unless extending an already registered family | `python/sglang/multimodal_gen/registry.py` |
128126
| Runtime parameters | The request schema differs from existing models | `configs/sample/{model}.py` |
129127
| Pipeline config | Denoising, decoding, precision, position encoding, or CFG hooks differ | `configs/pipeline_configs/{model}.py` |
130128
| Pipeline wiring | The model needs a new stage layout or module list | `runtime/pipelines/{model}.py` |
@@ -137,11 +135,10 @@ behavior.
137135

138136
For a new native architecture, the common minimum is:
139137

140-
1. `registry.py`
141-
2. `configs/sample/{model}.py`
142-
3. `configs/pipeline_configs/{model}.py`
143-
4. `runtime/pipelines/{model}.py`
144-
5. `runtime/models/dits/{model}.py`
138+
1. `configs/sample/{model}.py`
139+
2. `configs/pipeline_configs/{model}.py`
140+
3. `runtime/pipelines/{model}.py`
141+
4. `runtime/models/dits/{model}.py`
145142

146143
Every extra file should map to model behavior that existing code cannot express
147144
clearly.
@@ -499,19 +496,27 @@ native integration contract.
499496

500497
### 6. Registry
501498

502-
Register the family once the sampling params and pipeline config exist.
499+
Define a `register()` function in `configs/pipeline_configs/{model}.py`. The
500+
runtime auto-discovers it on startup and calls it to register the sampling
501+
params and pipeline config.
503502

504503
```python
505-
register_configs(
506-
model_family="my_model",
507-
sampling_param_cls=MyModelSamplingParams,
508-
pipeline_config_cls=MyModelPipelineConfig,
509-
hf_model_paths=["org/my-model"],
510-
)
504+
# python/sglang/multimodal_gen/configs/pipeline_configs/my_model.py
505+
def register():
506+
from sglang.multimodal_gen.registry import register_configs
507+
508+
register_configs(
509+
sampling_param_cls=MyModelSamplingParams,
510+
pipeline_config_cls=MyModelPipelineConfig,
511+
hf_model_paths=["org/my-model"],
512+
model_detectors=[lambda hf_id: "my-model" in hf_id.lower()],
513+
)
511514
```
512515

513-
The pipeline file is discovered through its `EntryClass`; do not add a second
514-
pipeline registry unless the existing registry requires it.
516+
`model_detectors` matches a model path or `model_index.json` `_class_name` when
517+
the Hugging Face path varies; see `wan.py` or `qwen_image21.py` for real
518+
examples. The pipeline file is discovered through its `EntryClass`; do not add
519+
a second pipeline registry unless the existing registry requires it.
515520

516521
## Verify the Port
517522

‎python/sglang/multimodal_gen/configs/pipeline_configs/cosmos3.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,24 @@ def get_model_deployment_config(self) -> ModelDeploymentConfig:
202202
keep_resident_min_available_gb=threshold_gb,
203203
keep_resident_components=("dit", "vae"),
204204
)
205+
206+
207+
def register():
208+
from sglang.multimodal_gen.configs.sample.cosmos3 import (
209+
Cosmos3SamplingParams,
210+
)
211+
from sglang.multimodal_gen.registry import register_configs
212+
213+
register_configs(
214+
sampling_param_cls=Cosmos3SamplingParams,
215+
pipeline_config_cls=Cosmos3Config,
216+
hf_model_paths=[
217+
"nvidia/Cosmos3-Nano",
218+
"nvidia/Cosmos3-Nano-Policy-DROID",
219+
"nvidia/Cosmos3-Super",
220+
"nvidia/Cosmos3-Super-Text2Image",
221+
"nvidia/Cosmos3-Super-Image2Video",
222+
"nvidia/Cosmos3-Edge",
223+
],
224+
model_detectors=[lambda hf_id: "cosmos3omni" in hf_id.lower()],
225+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/ernie_image.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,22 @@ def preprocess_decoding(self, latents, server_args=None, vae=None):
258258

259259
def post_denoising_loop(self, latents, batch):
260260
return latents
261+
262+
263+
def register():
264+
from sglang.multimodal_gen.configs.sample.ernie_image import (
265+
ErnieImageSamplingParams,
266+
)
267+
from sglang.multimodal_gen.registry import register_configs
268+
269+
register_configs(
270+
sampling_param_cls=ErnieImageSamplingParams,
271+
pipeline_config_cls=ErnieImagePipelineConfig,
272+
hf_model_paths=[
273+
"baidu/ERNIE-Image",
274+
"baidu/ERNIE-Image-Turbo",
275+
],
276+
model_detectors=[
277+
lambda hf_id: "ernie-image" in hf_id.lower(),
278+
],
279+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/flux.py‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,61 @@ def prepare_neg_cond_kwargs(self, batch, device, rotary_emb, dtype):
823823
txt_seq_lens,
824824
)
825825
}
826+
827+
828+
def register():
829+
from sglang.multimodal_gen.configs.sample.flux import (
830+
Flux2KleinBaseSamplingParams,
831+
Flux2KleinSamplingParams,
832+
Flux2SamplingParams,
833+
FluxSamplingParams,
834+
)
835+
from sglang.multimodal_gen.registry import register_configs
836+
837+
register_configs(
838+
sampling_param_cls=FluxSamplingParams,
839+
pipeline_config_cls=FluxPipelineConfig,
840+
hf_model_paths=[
841+
"black-forest-labs/FLUX.1-dev",
842+
],
843+
model_detectors=[lambda hf_id: "flux.1" in hf_id.lower()],
844+
)
845+
register_configs(
846+
sampling_param_cls=Flux2KleinSamplingParams,
847+
pipeline_config_cls=Flux2KleinPipelineConfig,
848+
hf_model_paths=[
849+
"black-forest-labs/FLUX.2-klein-4B",
850+
"black-forest-labs/FLUX.2-klein-9B",
851+
],
852+
model_detectors=[
853+
lambda hf_id: (
854+
("flux.2-klein" in hf_id.lower() or "flux2-klein" in hf_id.lower())
855+
and "base" not in hf_id.lower()
856+
)
857+
],
858+
)
859+
register_configs(
860+
sampling_param_cls=Flux2KleinBaseSamplingParams,
861+
pipeline_config_cls=Flux2KleinBasePipelineConfig,
862+
hf_model_paths=[
863+
"black-forest-labs/FLUX.2-klein-base-4B",
864+
"black-forest-labs/FLUX.2-klein-base-9B",
865+
],
866+
model_detectors=[
867+
lambda hf_id: (
868+
("flux.2-klein" in hf_id.lower() or "flux2-klein" in hf_id.lower())
869+
and "base" in hf_id.lower()
870+
)
871+
],
872+
)
873+
register_configs(
874+
sampling_param_cls=Flux2SamplingParams,
875+
pipeline_config_cls=Flux2PipelineConfig,
876+
hf_model_paths=[
877+
"black-forest-labs/FLUX.2-dev",
878+
"black-forest-labs/FLUX.2-dev-NVFP4",
879+
],
880+
model_detectors=[
881+
lambda hf_id: "flux.2" in hf_id.lower() and "klein" not in hf_id.lower()
882+
],
883+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/glm_image.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,16 @@ def post_denoising_loop(self, latents, batch):
118118

119119
def post_decoding(self, frames, server_args):
120120
return self.image_processor.postprocess(frames, output_type="latent")
121+
122+
123+
def register():
124+
from sglang.multimodal_gen.configs.sample.glmimage import (
125+
GlmImageSamplingParams,
126+
)
127+
from sglang.multimodal_gen.registry import register_configs
128+
129+
register_configs(
130+
sampling_param_cls=GlmImageSamplingParams,
131+
pipeline_config_cls=GlmImagePipelineConfig,
132+
model_detectors=[lambda hf_id: "glm-image" in hf_id.lower()],
133+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/helios.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,41 @@ class HeliosDistilledConfig(HeliosT2VConfig):
128128
pyramid_num_inference_steps_list: list[int] = field(
129129
default_factory=lambda: [10, 10, 10]
130130
)
131+
132+
133+
def register():
134+
from sglang.multimodal_gen.configs.sample.helios import (
135+
HeliosDistilledSamplingParams,
136+
HeliosMidSamplingParams,
137+
HeliosT2VSamplingParams,
138+
)
139+
from sglang.multimodal_gen.registry import register_configs
140+
141+
register_configs(
142+
sampling_param_cls=HeliosT2VSamplingParams,
143+
pipeline_config_cls=HeliosT2VConfig,
144+
hf_model_paths=[
145+
"BestWishYsh/Helios-Base",
146+
],
147+
model_detectors=[
148+
lambda hf_id: (
149+
"helios" in hf_id.lower()
150+
and "mid" not in hf_id.lower()
151+
and "distill" not in hf_id.lower()
152+
)
153+
],
154+
)
155+
register_configs(
156+
sampling_param_cls=HeliosMidSamplingParams,
157+
pipeline_config_cls=HeliosMidConfig,
158+
hf_model_paths=[
159+
"BestWishYsh/Helios-Mid",
160+
],
161+
)
162+
register_configs(
163+
sampling_param_cls=HeliosDistilledSamplingParams,
164+
pipeline_config_cls=HeliosDistilledConfig,
165+
hf_model_paths=[
166+
"BestWishYsh/Helios-Distilled",
167+
],
168+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/hunyuan.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,27 @@ def get_model_deployment_config(self) -> ModelDeploymentConfig:
169169
keep_resident_min_available_gb=60,
170170
keep_resident_components=("dit", "vae"),
171171
)
172+
173+
174+
def register():
175+
from sglang.multimodal_gen.configs.sample.hunyuan import (
176+
FastHunyuanSamplingParam,
177+
HunyuanSamplingParams,
178+
)
179+
from sglang.multimodal_gen.registry import register_configs
180+
181+
register_configs(
182+
sampling_param_cls=HunyuanSamplingParams,
183+
pipeline_config_cls=HunyuanConfig,
184+
hf_model_paths=[
185+
"hunyuanvideo-community/HunyuanVideo",
186+
],
187+
model_detectors=[lambda hf_id: "hunyuanvideo" in hf_id.lower()],
188+
)
189+
register_configs(
190+
sampling_param_cls=FastHunyuanSamplingParam,
191+
pipeline_config_cls=FastHunyuanConfig,
192+
hf_model_paths=[
193+
"FastVideo/FastHunyuan-diffusers",
194+
],
195+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/hunyuan3d.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,19 @@ def prepare_latent_shape(self, batch, batch_size, num_frames):
7878
latent_shape = self.vae_config.arch_config.latent_shape
7979
shape = (batch_size, *latent_shape)
8080
return shape
81+
82+
83+
def register():
84+
from sglang.multimodal_gen.configs.sample.hunyuan3d import (
85+
Hunyuan3DSamplingParams,
86+
)
87+
from sglang.multimodal_gen.registry import register_configs
88+
89+
register_configs(
90+
sampling_param_cls=Hunyuan3DSamplingParams,
91+
pipeline_config_cls=Hunyuan3D2PipelineConfig,
92+
hf_model_paths=[
93+
"tencent/Hunyuan3D-2",
94+
],
95+
model_detectors=[lambda hf_id: "hunyuan3d" in hf_id.lower()],
96+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/ideogram.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,39 @@ def prepare_latent_shape(self, batch, batch_size, num_frames):
308308
@dataclass
309309
class Ideogram4DistilledPipelineConfig(Ideogram4PipelineConfig):
310310
dit_config: DiTConfig = field(default_factory=Ideogram4DistilledDiTConfig)
311+
312+
313+
def register():
314+
from sglang.multimodal_gen.configs.sample.ideogram import (
315+
Ideogram4FastSamplingParams,
316+
Ideogram4InstantSamplingParams,
317+
Ideogram4SamplingParams,
318+
)
319+
from sglang.multimodal_gen.registry import register_configs
320+
321+
register_configs(
322+
sampling_param_cls=Ideogram4FastSamplingParams,
323+
pipeline_config_cls=Ideogram4DistilledPipelineConfig,
324+
hf_model_paths=["fal/ideogram-v4-fast"],
325+
)
326+
register_configs(
327+
sampling_param_cls=Ideogram4InstantSamplingParams,
328+
pipeline_config_cls=Ideogram4DistilledPipelineConfig,
329+
hf_model_paths=["fal/ideogram-v4-instant"],
330+
)
331+
register_configs(
332+
sampling_param_cls=Ideogram4SamplingParams,
333+
pipeline_config_cls=Ideogram4PipelineConfig,
334+
hf_model_paths=[
335+
"ideogram-ai/ideogram-4-fp8",
336+
"ideogram-ai/ideogram-4-nf4",
337+
"Comfy-Org/Ideogram-4",
338+
],
339+
model_detectors=[
340+
lambda hf_id: "ideogram4pipeline" in hf_id.lower(),
341+
lambda hf_id: "ideogram-4-fp8" in hf_id.lower(),
342+
lambda hf_id: "ideogram-4-nf4" in hf_id.lower(),
343+
lambda hf_id: "comfy-org/ideogram-4" in hf_id.lower(),
344+
lambda hf_id: "comfy-org--ideogram-4" in hf_id.lower(),
345+
],
346+
)

‎python/sglang/multimodal_gen/configs/pipeline_configs/joy_echo.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,24 @@ class JoyEchoPipelineConfig(LTX2PipelineConfig):
5858
video_memory_frame_selection_mode: str = "center"
5959

6060
late_layer_ratio: float = 0.7
61+
62+
63+
def register():
64+
from sglang.multimodal_gen.configs.sample.joy_echo import (
65+
JoyEchoSamplingParams,
66+
)
67+
from sglang.multimodal_gen.registry import register_configs
68+
69+
register_configs(
70+
sampling_param_cls=JoyEchoSamplingParams,
71+
pipeline_config_cls=JoyEchoPipelineConfig,
72+
hf_model_paths=[
73+
"jdopensource/JoyAI-Echo",
74+
],
75+
model_detectors=[
76+
lambda hf_id: (
77+
("joy-echo" in hf_id.lower() or "joyai-echo" in hf_id.lower())
78+
and "image-edit" not in hf_id.lower()
79+
),
80+
],
81+
)

0 commit comments

Comments
 (0)