rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-add-model
Claude Code and agent skill by rh-runninghub/minimax-h3-multigpu-lightning
- community
Checking that the SKILL.md file is still in the repository.
Use when adding a new diffusion model or Diffusers pipeline to SGLang.
Install
npx vskill@latest install rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-add-modelSKILL.md
The same SKILL.md was published earlier as rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-add-model.
Add a Diffusion Model to SGLang
Use this skill when adding a new diffusion model or pipeline variant to sglang.multimodal_gen.
Three Pipeline Styles
Style A: Hybrid Monolithic Pipeline (Recommended)
The recommended default for most new models. Uses a three-stage structure:
- BeforeDenoisingStage: A single, model-specific stage that consolidates all pre-processing logic: input validation, text encoding, image encoding, latent preparation, timestep setup. This stage is unique per model.
- DenoisingStage: Framework-standard stage for the denoising loop (DiT/UNet forward passes). Shared across models.
- DecodingStage: Framework-standard stage for VAE decoding. Shared across models.
Why recommended? Modern diffusion models have highly heterogeneous pre-processing requirements (different text encoders, different latent formats, different conditioning mechanisms). The Hybrid approach keeps pre-processing isolated per model, avoids fragile shared stages with excessive conditional logic, and lets developers port Diffusers reference code quickly.
Style B: Modular Composition Style
Uses the framework's fine-grained standard stages (TextEncodingStage, LatentPreparationStage, TimestepPreparationStage, etc.) to build the pipeline by composition.
This style is appropriate when:
- The new model's pre-processing can largely reuse existing stages — e.g., a model that uses standard CLIP/T5 text encoding + standard latent preparation with minimal customization. In this case,
add_standard_t2i_stages()oradd_standard_ti2i_stages()may be all you need. - A model-specific optimization needs to be extracted as a standalone stage — e.g., a specialized encoding or conditioning step that benefits from being a separate stage for profiling, parallelism control, or reuse across multiple pipeline variants.
See existing Modular examples: QwenImagePipeline (uses add_standard_t2i_stages), FluxPipeline, WanPipeline, SanaPipeline, StableDiffusion3Pipeline, and ZImagePipeline.
Style C: Native Task-Contract Pipeline
Use this only when one checkpoint exposes multiple tightly coupled modalities or request profiles that cannot be represented safely by generic image/video sampling fields. MiniMax-H3 is the reference: it selects FL2VA or Ref2VA weights from one root model ID, validates canonical task / conditions / target requests before queueing, packs text/video/audio tokens into one denoise sequence, and returns synchronized video plus audio.
This style still uses ComposedPipelineBase, but owns a model-specific chain under stages/model_specific_stages/<model>/. Keep request validation, media materialization, packed-sequence construction, per-modality encode/decode, and presentation as explicit stages. Do not force coupled state into the standard DenoisingStage / DecodingStage contract just to resemble a simpler model.
Choose this style only with source evidence that the public API, scheduler, or joint latent state needs it. Preserve one canonical request object from API admission through offline generation and server execution so the two entry points cannot silently diverge.
How to Choose
| Situation | Recommended Style | |
|---|---|---|
| Model has unique/complex pre-processing (VLM captioning, AR token generation, custom latent packing, etc.) | Hybrid — consolidate into a BeforeDenoisingStage | |
| Model jointly denoises multiple modalities or exposes partitioned task contracts from one root checkpoint | Native task contract — use MiniMax-H3 as the reference and keep model-specific stages explicit | |
| Model fits neatly into standard text-to-image or text+image-to-image pattern | Modular — use add_standard_t2i_stages() / add_standard_ti2i_stages() | |
| Porting a Diffusers pipeline with many custom steps | Hybrid — copy the __call__ logic into a single stage | |
| Adding a variant of an existing model that shares most logic | Modular — reuse existing stages, customize via PipelineConfig callbacks | |
| A specific pre-processing step needs special parallelism or profiling isolation | Modular — extract that step as a dedicated stage |
Key principle (standard-denoise styles): For Hybrid and Modular pipelines, the stage(s) before DenoisingStage must produce a Req batch object with all the standard tensor fields that DenoisingStage expects (latents, timesteps, prompt embeds, and model-specific conditioning). Native task-contract pipelines may own a different denoise/decode contract; keep that divergence explicit and covered by request-contract tests.
Key Files and Directories
| Purpose | Path | |
|---|---|---|
| Pipeline classes | python/sglang/multimodal_gen/runtime/pipelines/ | |
| Model-specific stages | python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/ | |
| PipelineStage base class | python/sglang/multimodal_gen/runtime/pipelines_core/stages/base.py | |
| Pipeline base class | python/sglang/multimodal_gen/runtime/pipelines_core/composed_pipeline_base.py | |
| Standard stages (Denoising, Decoding) | python/sglang/multimodal_gen/runtime/pipelines_core/stages/ | |
| Pipeline configs | python/sglang/multimodal_gen/configs/pipeline_configs/ | |
| Sampling params | python/sglang/multimodal_gen/configs/sample/ | |
| DiT model implementations | python/sglang/multimodal_gen/runtime/models/dits/ | |
| VAE implementations | python/sglang/multimodal_gen/runtime/models/vaes/ | |
| Encoder implementations | python/sglang/multimodal_gen/runtime/models/encoders/ | |
| Scheduler implementations | python/sglang/multimodal_gen/runtime/models/schedulers/ | |
| Model/VAE/DiT configs | python/sglang/multimodal_gen/configs/models/dits/, vaes/, encoders/ | |
| Central registry | python/sglang/multimodal_gen/registry.py | |
| Model component registry | python/sglang/multimodal_gen/runtime/models/registry.py | |
| Current support list | docs/docs/sglang-diffusion/compatibility_matrix.mdx |
Step-by-Step Implementation
Step 1: Obtain and Study the Reference Implementation
Before writing any code, obtain the model's reference implementation or Diffusers pipeline code. You need the actual source code to work from — do not guess or assume the model's architecture. If the user already gave a HuggingFace model ID or repo, inspect that yourself first. Ask the user only when the reference implementation is private, ambiguous, or otherwise unavailable. Typical sources are:
- The model's Diffusers pipeline source (e.g., the
pipeline_*.pyfile from thediffuserslibrary or HuggingFace repo) - Or the model's official reference implementation (e.g., from the model author's GitHub repo)
- Or the HuggingFace model ID so you can look up
model_index.jsonand the associated pipeline class
Once you have the reference code, study it thoroughly:
- Find the model's
model_index.jsonto identify required modules (text_encoder, vae, transformer, scheduler, etc.) - Read the Diffusers pipeline's
__call__method end-to-end. Identify:
- How text prompts are encoded
- How latents are prepared (shape, dtype, scaling)
- How timesteps/sigmas are computed
- What conditioning kwargs the DiT/UNet expects
- How the denoising loop works (classifier-free guidance, etc.)
- How VAE decoding is done (scaling factors, tiling, etc.)
Step 2: Evaluate Reuse of Existing Pipelines and Stages
Before creating any new files, check whether an existing pipeline or stage can be reused or extended. Only create new pipelines/stages when the existing ones would require extensive modifications or when no similar implementation exists.
Specifically:
- Compare the new model's architecture against existing pipelines before creating files. Current native families include MiniMax-H3, Krea-2, LTX-2/2.3/2.5, HunyuanVideo/FastHunyuan, Wan/FastWan/TurboWan/LingBot World/LingBot Video MoE, MOVA, FLUX/FLUX.2/Klein, LongCat-Image, Z-Image, Qwen-Image/edit/layered, GLM-Image, SD3, Hunyuan3D, Helios, Cosmos3 Nano/Super/Edge/distilled, SANA/SANA-Video/SANA-WM, FireRed, ERNIE-Image, JoyAI, and Ideogram4. If the new model shares most of its structure with an existing one (e.g., same text encoders, similar latent format, compatible denoising loop), prefer:
- Adding a new config variant to the existing pipeline rather than creating a new pipeline class
- Reusing the existing
BeforeDenoisingStagewith minor parameter differences - Using
add_standard_t2i_stages()/add_standard_ti2i_stages()/add_standard_ti2v_stages()if the model fits standard patterns
- Check existing stages in
runtime/pipelines_core/stages/andstages/model_specific_stages/. If an existing stage handles 80%+ of what the new model needs, extend it rather than duplicating it. - Check existing model components — many models share VAEs (e.g.,
AutoencoderKL), text encoders (CLIP, T5), and schedulers. Reuse these directly instead of re-implementing.
Rule of thumb: Only create a new file when the existing implementation would need substantial structural changes to accommodate the new model, or when no architecturally similar implementation exists.
Step 3: Implement Model Components
Adapt or implement the model's core components in the appropriate directories.
DiT/Transformer (runtime/models/dits/{model_name}.py):
Tensor Parallel (TP) and Sequence Parallel (SP): For multi-GPU deployment, it is recommended to add TP/SP support to the DiT model. This can be done incrementally after the single-GPU implementation is verified. Reference existing implementations and adapt to your model's architecture:
- Wan model (
runtime/models/dits/wanvideo.py) — Full TP + SP reference: - TP: Uses
ColumnParallelLinearfor Q/K/V projections,RowParallelLinearfor output projections, attention heads divided bytp_size - SP: Sequence dimension sharding via
get_sp_world_size(), padding for alignment,sequence_model_parallel_all_gatherfor aggregation - Cross-attention skips SP (
skip_sequence_parallel=is_cross_attention) - Qwen-Image model (
runtime/models/dits/qwen_image.py) — SP + USPAttention reference: - SP: Uses
USPAttention(Ulysses + Ring Attention), configured via--ulysses-degree/--ring-degree - TP: Uses
MergedColumnParallelLinearfor QKV (with Nunchaku quantization),ReplicatedLinearotherwise
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingsglang/python/sglang/multimodal_gen/.claude/skills/sglang-diffusion-add-model/SKILL.md
Popularity
- Repository stars
- 99
- Repository forks
- 13
- 7-day trend score
- 23
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rh-runninghub/minimax-h3-multigpu-lightning/sglang-diffusion-add-model)