aigc-apps/videox-fun/integrating-models
Claude Code and agent skill by aigc-apps/videox-fun
- community
Checking that the SKILL.md file is still in the repository.
Guides adding, porting, or onboarding a diffusion model (transformer/VAE/encoder, inference pipeline, training script, config) into the VideoX-Fun repository by mirroring the closest existing model family and maximizing reuse of the repository's existing code and shared infrastructure. Use when integrating a new model/architecture, or when creating predict_*.py inference scripts, scripts/*/train*.py training scripts, pipeline_*.py, config/*.yaml, or model definitions under videox_fun/models/.
Install
npx vskill@latest install aigc-apps/videox-fun/integrating-modelsSKILL.md
The same SKILL.md was published earlier as aigc-apps/videox-fun/integrating-models.
Integrating Models into VideoX-Fun
Core rule: maximize reuse of existing repo code — mirror, extend, never reinvent
Prime directive: reuse this repository's existing code to the maximum. Nearly every building block you need already exists in videox_fun/ or in a sibling model family. Your job is to find it, import it, and extend it — not to write a parallel implementation. A new file should be mostly reused structure plus the genuinely model-specific delta; the less new code you write, the better.
Reuse-first protocol — before writing ANY new function / class / util:
- Search the repo first. Grep
videox_fun/and the closest family for an existing equivalent (weight loader, scheduler, sampler, offload, attention, LoRA, fp8, dataset, dist helper, save/metric util). If one exists → import and reuse it. If it is 80% right → extend / parameterize it, do not fork it. - Only if nothing exists may you add new code — and then put it in the shared layer (
videox_fun/utils,videox_fun/data,videox_fun/dist) so the next model reuses it too, instead of burying it in a family folder. - Never copy-paste a util into a new file (that creates drift); import the single source of truth.
Mirror the closest family. Every model follows the same layered template. Integrating a model means finding the closest existing family and mirroring its structure, changing only what genuinely differs:
- Pick the closest existing family by task type (t2v / i2v / v2v-control / s2v / t2i / edit / distill):
wan2.1,wan2.1_fun,wan2.2,qwenimage,flux2,minimax_h3,ltx2,longcatvideo,cogvideox_fun,z_image, etc. - Read that family end-to-end across all layers:
examples/<family>/predict_*.py(inference entry)scripts/<family>/train*.py+*.sh+README_TRAIN*.md(training)videox_fun/pipeline/pipeline_<family>*.py(pipeline)videox_fun/models/<family>_*.py(model definitions)config/<family>/*.yaml(config)
- Copy that structure and adapt. Keep names, argument sets, control flow, and reuse points identical in shape.
Writing a bespoke pipeline, weight loader, trainer, sampler, dataset, or offload scheme from scratch is a failure mode. If you are tempted to, stop and check the Reuse inventory below first.
Repository layout (where each layer lives)
| Layer | Location | What it is | |
|---|---|---|---|
| Model definitions | videox_fun/models/<family>_*.py | Transformer / VAE / text-audio-image encoders. Diffusers ModelMixin+ConfigMixin, @register_to_config, custom from_pretrained. | |
| Model registry | videox_fun/models/__init__.py | Imports every model class. Must be updated for a new model. | |
| Inference pipelines | videox_fun/pipeline/pipeline_<family>*.py | <Family>Pipeline(DiffusionPipeline) with __call__. | |
| Pipeline registry | videox_fun/pipeline/__init__.py | Imports every pipeline + aliases. Must be updated. | |
| Configs (optional) | config/<family>/*.yaml | OmegaConf YAML for civitai/custom layouts; a standard diffusers-layout checkpoint can load without one. | |
| Inference entry scripts | examples/<family>/predict_*.py | User-facing, config-block-at-top runnable scripts. | |
| Inference services | examples/<family>/{app.py,launch_api.py,post_infer*.py} | Gradio UI / API server / batch inference. | |
| Training scripts | scripts/<family>/train*.py | train.py, train_lora.py, train_control.py, train_distill.py, ... | |
| Training launchers | scripts/<family>/train*.sh | accelerate launch / DeepSpeed command with full arg list. | |
| Training docs | scripts/<family>/README_TRAIN*.md | Bilingual pairs: README_TRAIN.md + README_TRAIN_zh-CN.md. | |
| Shared: schedulers/utils | videox_fun/utils/ | fm_solvers, fm_solvers_unipc, lora_utils, fp8_optimization, group_offload, utils.py. | |
| Shared: distributed | videox_fun/dist/ | fsdp.shard_model, fuser.set_multi_gpus_devices, <family>_xfuser sequence-parallel attention. | |
| Shared: data | videox_fun/data/ | Datasets (ImageVideoDataset, VideoDataset, ...) + bucket/aspect-ratio samplers. | |
| Demo / test datasets | datasets/X-Fun-*-Demo/ | Ready-made smoke-test data, downloaded via modelscope download --dataset PAI/<name>; each ships several metadata*.json variants. The only test data to use (see reference.md §8). | |
| Preprocessing (data gen) | scripts/<family>/generate_*.py / train_preprocess.py (+ .sh) | Offline multi-GPU generation of cached training data (latents / ODE pairs / embeddings) → per-sample .safetensors + outputs.json, loaded by ImageVideoSafetensorsDataset. | |
| ComfyUI nodes | comfyui/<family>/nodes.py | Optional node integration mirroring the pipeline. |
Integration workflow
Copy this checklist and track progress:
Step 0 — Choose the mirror. Match by task and architecture. A new control model mirrors an existing *_fun/*_control family; a new audio/talking model mirrors minimax_h3/longcatvideo/infinitetalk; a new image model mirrors qwenimage/flux2/z_image.
Step 1 — Model. Create videox_fun/models/<family>_transformer3d.py (or 2d), <family>_vae.py, encoders as needed. Mirror the class shape: class <Family>Transformer3DModel(ModelMixin, ConfigMixin, FromOriginalModelMixin), _supports_gradient_checkpointing = True, @register_to_config __init__, and a from_pretrained that supports transformer_additional_kwargs, dict_mapping, low_cpu_mem_usage, and missing-key init. Add imports to videox_fun/models/__init__.py.
Step 2 — Pipeline. Create videox_fun/pipeline/pipeline_<family>.py. Mirror pipeline_wan.py: module-level retrieve_timesteps, a <Family>PipelineOutput(BaseOutput) dataclass, <Family>Pipeline(DiffusionPipeline) with model_cpu_offload_seq, _callback_tensor_inputs, __init__(vae, tokenizer, text_encoder, transformer, scheduler, ...), encode_prompt, and __call__. Add imports/aliases to videox_fun/pipeline/__init__.py.
Step 3 — Config (optional). A YAML under config/<family>/ is not always required. It is needed mainly for civitai-format / custom single-file layouts — to supply transformer_additional_kwargs, dict_mapping (civitai key → __init__ kwarg), component subpaths, and vae_kwargs/text_encoder_kwargs/scheduler_kwargs/image_encoder_kwargs. For a standard diffusers-layout checkpoint (model_index.json + per-subfolder config.json), load directly via from_pretrained(model_name, subfolder=...) with no YAML — mirror examples/minimax_h3_fun/predict_v2v_control.py, which guards if config_path is not None:. When you do add a YAML, load it via OmegaConf.load(config_path) and spread into from_pretrained instead of hardcoding those values.
Step 4 — Inference script. Create examples/<family>/predict_<task>.py following the exact template (config block at top → component loading → scheduler dict → pipeline construction → multi-GPU/FSDP/compile → GPU_memory_mode branching → TeaCache → LoRA merge → inference → save_results). See examples.md.
Step 5 — Training script. Create scripts/<family>/train.py (+ train_lora.py etc.). Mirror the shared structure: license header, sys.path bootstrap, imports from videox_fun, log_validation() that reuses the inference Pipeline, parse_args() (reuse the existing shared argument set), main(). Add a train.sh launcher. Reuse videox_fun.data datasets/samplers — do not write a new dataset.
Step 6 — Docs. Write README_TRAIN.md and README_TRAIN_zh-CN.md as an aligned bilingual pair (same structure, same commands/params, matching section order).
Step 7 — Reuse audit + verification. Confirm you reused shared infra (below), smoke-test the new train/predict path on the matching official demo dataset under datasets/X-Fun-*-Demo/ (pick by task and metadata variant — see reference.md §8), then run the verification checklist. Never invent an ad-hoc test set and never leave datasets/internal_datasets/ placeholders in shipped scripts/docs.
Reuse inventory (use these, do not reimplement)
Reuse-first catalog: import from here instead of reimplementing. If a helper you need is not listed, grep `videox_fun/` and the closest family before writing your own.
- Schedulers:
FlowMatchEulerDiscreteScheduler,videox_fun.utils.fm_solvers.FlowDPMSolverMultistepScheduler,fm_solvers_unipc.FlowUniPCMultistepScheduler. Selected via asampler_namedict. - LoRA:
videox_fun.utils.lora_utils—merge_lora,unmerge_lora,create_network,convert_peft_lora_to_kohya_lora. - FP8 / quantization:
videox_fun.utils.fp8_optimization—convert_model_weight_to_float8,convert_weight_dtype_wrapper,replace_parameters_by_name. - Offloading:
videox_fun.utils.group_offload—register_auto_device_hook,safe_enable_group_offload; plus pipelineenable_sequential_cpu_offload/enable_model_cpu_offload/.to(device). - Distributed:
videox_fun.dist—set_multi_gpus_devices,shard_model(FSDP),<family>_xfusersequence-parallel attention processors,enable_multi_gpus_inference(). - IO / helpers:
videox_fun.utils.utils—save_videos_grid,save_videos_with_audio_grid,get_image_to_video_latent,get_video_to_video_latent,get_image_latent,filter_kwargs,calculate_dimensions. - Data:
videox_fun.data—ImageVideoDataset,VideoDataset,ImageVideoControlDataset,VideoSpeechDataset, bucket/aspect-ratio samplers,get_closest_ratio,get_random_mask. - Caching / speedups: TeaCache (
models/cache_utils,get_teacache_coefficients,transformer.enable_teacache),enable_cfg_skip, Riflex (enable_riflex),torch.compileontransformer.blocks. - Preprocessing (data gen, multi-GPU): mirror
scripts/wan2.1_self_forcing/generate_ode_pairs.py—accelerate launch+Accelerator(interleaved rank sharding), config-drivenfrom_pretrainedfor the teacher/VAE/text-encoder,safetensors.torch.save_fileper sample +outputs.jsonindex, consumed byvideox_fun.data.ImageVideoSafetensorsDataset. Store as safetensors only — never LMDB or `.pt` (see reference.md §10).
Non-negotiable conventions
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 repositoryChecking.skills/integrating-models/SKILL.md
Popularity
- Repository stars
- 2,250
- Repository forks
- 189
- 7-day trend score
- 39
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/aigc-apps/videox-fun/integrating-models)