mflux-model-porting

Port ML models from diffusers into mflux/MLX with correctness-first deterministic validation.

2.4k|187|Updated Aug 10, 2024
One-click install
npx skills add https://github.com/mflux-community/mflux --skill mflux-model-porting-mflux-community
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mflux-model-porting
Source: https://github.com/mflux-community/mflux/tree/main/.cursor/skills/mflux-model-porting
Command: npx skills add https://github.com/mflux-community/mflux --skill mflux-model-porting-mflux-community

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Porting a generative image model from PyTorch/diffusers into the MLX-based mflux codebase is error-prone: weight key mismatches, RNG differences, silent LoRA load failures, and missed integration surfaces (ModelConfig, CLI registration, CI manifests) repeatedly cause regressions. This Skill provides a repeatable, correctness-first workflow that locks parity with deterministic tests before any refactoring. ## Core Features & Use Cases - Backwards porting workflow: Validate VAE decode in pixel space first, then the transformer loop and schedulers, then the text encoder, committing milestone checkpoints after each validated component. - Deterministic validation: Export exact initial latents from the reference implementation, load them in MLX, and lock outputs with deterministic image/tensor tests run via MFLUX_PRESERVE_TEST_OUTPUT=1 uv run <test command>. - Integration checklist: Tick-list covering pyproject.toml CLI entries, ModelConfig aliases, weight definitions/mappings, LoRA key conventions, training adapters, golden tests, and README structure. - Use Case: When adding a new model family (e.g., a new FLUX variant) to mflux, follow the checklist to mirror the diffusers reference, prove parity with seeded latent injection, then refactor toward shared mflux components without regressions. ## Quick Start Ask the AI to port a new image model from the local diffusers repository into mflux following the mflux-model-porting workflow, starting with VAE validation.

Frequently Asked Questions about mflux-model-porting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I port a diffusers model to MLX in mflux?▼

Port a diffusers model to MLX by working backwards from the image: validate VAE decode first using exported reference latents, then the transformer loop and scheduler, then the text encoder. Lock each component with deterministic tests before refactoring toward mflux style.

How to match PyTorch and MLX outputs when porting models?▼

PyTorch and MLX RNGs differ, so matching integer seeds will not produce identical noise. Export the exact initial noise or latents from the reference implementation using mx.save and load them in MLX with mx.load for strict parity checks.

Why does my MLX port run out of memory on 1024x1024 images?▼

An MLX out-of-memory error on sensible inputs like 1024x1024 usually indicates a porting mistake rather than a hardware limit. Re-check tensor shapes and memory-heavy operations in the ported code before assuming a genuine resource constraint.

Why do LoRA weights load as zero keys in mflux?▼

Silent zero-key LoRA loads happen when the LoRA mapping does not cover the export key convention used by the file. Support multiple conventions including diffusers, PEFT .default.weight, and kohya diffusion_model.* aliases, and add fast tests with real community LoRA filenames.

What integration surfaces are required for a new mflux model?▼

A new mflux model requires a pyproject.toml CLI entry, a ModelConfig entry with aliases and defaults, a WeightDefinition, routing in save.py, README updates, and a CI manifest overlay via scripts/ci_extract_models.py. Training support additionally needs a training adapter and example JSON config.

When should I add mx.compile optimizations during a model port?▼

Add mx.compile and other performance optimizations only after deterministic parity tests pass. Premature optimization during the initial port obscures correctness bugs, so keep the first implementation simple and explicit until outputs are locked.