ワンクリックで
mflux-model-porting
Port ML models into mflux/MLX with correctness-first validation, then refactor toward mflux style.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Port ML models into mflux/MLX with correctness-first validation, then refactor toward mflux style.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Debug MLX ports by comparing against a PyTorch/diffusers reference via exported tensors/images (export-then-compare).
Manually validate mflux CLIs by exercising the changed paths and reviewing output images/artifacts.
Make a clean PR in mflux (inspect diff, quick verification, commit, push, open PR) using repo conventions.
Run tests in mflux (fast/slow/full), preserve image outputs, and handle golden image diffs safely.
Navigate MFLUX CLI capabilities, locate commands by area, and summarize supported features.
Set up and work in the mflux dev environment (arm64 expectation, uv, Makefile targets, lint/format/test).
| name | mflux-model-porting |
| description | Port ML models into mflux/MLX with correctness-first validation, then refactor toward mflux style. |
Provide a repeatable, MLX-focused workflow for porting ML models (typically from diffusers repo located near mflux repo in the system) into mflux with correctness first, then refactor to mflux style.
mx.compile, kernel fusion tweaks, scheduler micro-optimizations); add optimizations only after correctness is locked.z_image_turbo and flux2_klein for structure and naming.mx.compile and other speed-focused changes until deterministic parity is passing.mx.save/mx.load at critical points; it is OK to add these to the reference (without changing logic) to export latents.prompt → text_encoder → transformer_loop → VAE → image.MFLUX_PRESERVE_TEST_OUTPUT=1 uv run <test command>.CallbackManager.register_callbacks(...) so shared features like --stepwise-image-output-dir work; pass a latent_creator that supports unpack_latents(...).flux2_klein, z_image): prompt_cache, merged _predict, RoPE setup inside predict path, _decode_latents helper, no verbose comments/docstrings (see repo RULE.md).mflux-debugging latent injection if outputs disagree but you need to validate transformer/VAE.mflux-testing).models/<your_model>/; justify shared changes (memory_saver tiling guard, shared VAE tiling_config, training runner wiring). Drop unrelated edits (e.g. personal .gitignore entries).du on HF cache and/or mflux-save + du -sh for quantized sizes.models/common/training/_example/, un-ignore in .gitignore, fast unit tests for training-adapter preview defaults.make lint, make test-fast, then slow golden tests before merge.ModelConfig entry + aliasesflux2)Use src/mflux/models/flux2/ as the canonical tree. Do not invent flat mlx-vlm-style roots (config.py, scheduler.py, fp8.py, layout.py, monolithic model/transformer.py). Aliases and defaults live in ModelConfig; checkpoint validation belongs in the initializer and/or *WeightDefinition, not a separate layout module.
{model}/
{model}_initializer.py
__init__.py # export variant + initializer
README.md
cli/
{model}_generate.py # (+ edit/turbo CLIs when applicable)
latent_creator/
{model}_latent_creator.py
model/
{model}_text_encoder/ # prompt_encoder.py, tokenizer pieces, text_encoder.py
{model}_transformer/ # attention, blocks, rope, transformer.py (split files)
{model}_vae/ # or reuse shared VAE (e.g. flux2_vae) — document in README
{model}_scheduler/ # only when not covered by models/common/schedulers
variants/
__init__.py # re-export public variant class(es)
txt2img/
__init__.py
{model}.py # e.g. flux2_klein.py, ideogram4.py
edit/ # when the model supports image-conditioned generation
__init__.py
{model}_edit.py
weights/
__init__.py
{model}_weight_definition.py # components, download patterns, tokenizers
{model}_weight_mapping.py # WeightTarget list / key transforms for base weights
{model}_lora_mapping.py # LoRA key aliases (diffusers, PEFT, kohya) — when LoRA is supported
training_adapter/ # when mflux-train is supported
{model}_training_adapter.py
Variants: always place txt2img classes under variants/txt2img/ (even for single-mode models). Use variants/edit/ for edit/img2img variants. Import from the full path in save.py and CLIs, e.g. variants.txt2img.flux2_klein.
Weights: *WeightDefinition is required for every port. Add *WeightMapping when diffusers/HF key names need explicit targets. Add *LoRAMapping when inference or training supports LoRA — wire --lora-paths / --lora-scales through the shared parser and add fast tests that community LoRA filenames map to non-zero keys (see integration checklist below).
Variant class style (post-refactor): match flux2_klein / z_image — prompt_cache, _predict / _decode_latents, thin generate_image, prompt encoding in {model}_text_encoder/prompt_encoder.py.
Skip when not applicable: variants/edit/, training_adapter/, {model}_lora_mapping.py, local VAE package (if reusing another model family’s VAE). Document omitted features in the model README.
Past closed PRs show the same wiring gaps recurring on every new model. Use this as a tick list alongside the workflow above — not every row applies to every model (e.g. skip vision-encoder rows for txt2img-only), but scan it before opening a port PR.
| Surface | What to do |
|---|---|
pyproject.toml | Register mflux-generate-<model> (and edit/turbo variants if separate) |
ModelConfig | Entry in AVAILABLE_MODELS: aliases, HF repo id, num_train_steps, guidance support, sigma shift, transformer_overrides, distilled vs base step defaults |
cli/defaults/defaults.py | MODEL_CHOICES + MODEL_INFERENCE_STEPS |
models/common/cli/save.py | Route mflux-save to the correct variant class (txt2img vs edit vs turbo — wrong class silently drops weights; see #405) |
Main README.md | Model table row + attribution line |
src/mflux/models/<model>/README.md | Examples aligned with Flux2-style layout; disk sizes measured (du, mflux-save) |
src/mflux/assets/ | Hero/showcase image if other models have one (git add -f when *.jpg is gitignored) |
| Surface | What to do |
|---|---|
*WeightDefinition | get_components(), get_download_patterns(), get_tokenizers() — only list artifacts mflux actually loads |
| Weight mapping | Explicit WeightTarget list; verify tensor names/shapes against HF cache blobs |
| Tokenizer | Exercise local-path load, partial HF cache, and any special formats (protobuf, sentencepiece, etc.) — see #383, #389, #390 |
| Optional reference components | Document in README what the upstream pipeline includes but mflux omits (extra encoders, preprocessors, etc.) |
| Surface | What to do |
|---|---|
*LoRAMapping | Support multiple export key conventions (diffusers, PEFT .default.weight, kohya/diffusion_model.* aliases) — silent zero-key loads were fixed repeatedly (#376, #374, #397) |
| Tests | Fast tests that real community LoRA filenames map to non-zero keys |
| Inference CLI | --lora-paths / --lora-scales via shared parser (no bespoke loader) |
| Surface | What to do |
|---|---|
| Thin CLI | CommandLineParser + CallbackManager.register_callbacks(...) |
DimensionResolver | Use in generate/edit CLIs when width/height can be omitted (API/OpenWebUI paths) — #378 |
latent_creator | pack_latents / unpack_latents; img2img path must match txt2img normalization (BN, scale factor) |
tiling_config | If initializer sets custom tiling, ensure MemorySaver does not overwrite it |
| Guidance defaults | Distilled vs base: match ModelConfig, CLI default, README, and training preview adapter |
mflux-save round-trip | Save quantized model → load from local path → generate; confirm model.safetensors.index.json if sharded |
| Surface | What to do |
|---|---|
training/runner.py | Register *TrainingAdapter; handle low_ram / tiling like other models |
| Example JSON | models/common/training/_example/train_<model>.json + .gitignore un-ignore |
| Preview generation | Adapter should use canonical steps/guidance for distilled vs base (unit test this) |
Local model_path | Confirm mflux-train works with saved local weights — #370 |
| Surface | What to do |
|---|---|
| Slow golden test | tests/image_generation/test_generate_image_<model>.py + reference_*.png on CI hardware |
| Fast tests | LoRA mapping, training-adapter preview defaults, argparser if new CLI flags |
make lint / make test-fast | Before slow tests |
When fixing a gap for model N, ask whether the same gap exists for other recent models and whether a shared fix belongs in models/common/ (preferred over copy-paste per model).
uv for running scripts and tests: uv run <command>.uv run python -m <module> for local modules.