feat(imagegen): add MiniMax-H3-Image (minimax_h3_image) generation and editing
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 6/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- machine-learning
Direzione di ricerca
Start with the family detection in src/imagegen/probe.rs (IMAGE_FAMILIES at line 42, model_types_from_metadata at line 216) and the FAMILIES list in src/imagegen/registry.rs line 47, then read docs/vision-model-scope.md line 79. A first step is registering minimax_h3_image so the probe recognizes the checkpoint. Done means generate-image gets past detection, though the full runtime (conditioner, transformer, VAE) is a multi-week port.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Add MiniMax-H3-Image (family minimax_h3_image) to the image generation runtime: text-to-image and editing with 1 to 16 ordered reference images, using a Qwen3-VL-32B conditioner, a 33B diffusion transformer with six step-specific output heads (distilled to exactly 6 steps at guidance 1), and a tiled ViT-decoder VAE, generating near 16 MP. Today mlxcel generate-image -m nativ-community/MiniMax-H3-Image-4bit fails because the probe does not know the family. docs/vision-model-scope.md:79 and #524 scoped out only the joint video and audio minimax_h3 release; the image-only release is a different, in-scope product for the existing image runtime, so this issue also corrects that scope record.
Upstream reference
- Blaizzy/mlx-vlm#2702 (
bdc6bd73), https://github.com/Blaizzy/mlx-vlm/tree/main/mlx_vlm/models/minimax_h3_image - Pipeline: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/pipeline.py (
MiniMaxH3ImagePipeline._encode_prompt,generate_array) - Packing and schedule: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/packing.py (
SAMPLE_SIGMAS,sampling_schedule,canvas_size,bound_short_edge,build_image_layout) - Transformer: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/transformer.py (
MiniMaxH3ImageTransformer), built on the shared H3 blocks in https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3/transformer.py (timestep_embedding,TimestepEmbedding,MiniMaxH3RotaryPosEmbed,apply_rotary_emb,MiniMaxH3AdaLayerNormModulation,MiniMaxH3AdaLayerNormOut,MiniMaxH3Attention,MiniMaxH3FeedForward,MiniMaxH3TokenRefiner,MiniMaxH3TransformerBlock,build_adaln_cache,drop_adaln_weights) - VAE: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/vae.py (
MiniMaxH3ImageViTDecoder,MiniMaxH3ImageVAE.encode,decode,sanitize) on https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3/visual_vae.py (MiniMaxH3VideoCausalConv3d,MiniMaxH3VideoEncoder3d,MiniMaxH3VideoTransformerBlock,MiniMaxH3DiagonalGaussianDistribution,_split_tiles,_stitch_tiles) - Config: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/config.py and https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3/config.py; conditioner: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3/conditioner.py (
MiniMaxH3Conditioner._encode, layerMINIMAX_H3_TEXT_ENCODER_LAYER = 50inconstants.py); weights and download: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/weights.py, https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/download.py; image helpers: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3/processing.py (process_qwen_images,resize_lanczos,decode_image), https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3/packing.py (patchify_video_latents,unpatchify_video_tokens) - README: https://github.com/Blaizzy/mlx-vlm/blob/main/mlx_vlm/models/minimax_h3_image/README.md. Weights use the MiniMax H3 Image Community License.
Architecture (from upstream code and the published configs)
- Detection:
model_index.json_class_name: MiniMaxH3ImagePipeline(official) ormodel_type: minimax_h3_imagewithmlx_vlm_format: minimax_h3_image(MLX conversions). - Transformer (
transformer_diffusers/config.json,_class_name MiniMaxH3ImageTransformer2DModel):num_attention_heads 56,attention_head_dim 128,hidden_size 5376,num_layers 50,num_refiner_layers 2,ffn_dim 14336,in_channels 24,patch_size [1, 2, 2](patch dim 96),text_dim 5120,freq_dim 256,time_embed_hidden_dim 5376,time_embed_dim 2688,rope_freq_dim 16,rope_theta 10000, eps 1e-5 everywhere,num_pdd_heads 6(must be 6 with a spatial patch, else a load error).proj_in: 96 -> 5376;context_embedder: 5120 -> 5376then thetoken_refiner(2 pre-norm blocks: RMSNorm, attention, RMSNorm, SwiGLU FF; final RMSNorm).- The packed sequence is text tokens, then reference image tokens, then target image tokens, scattered into a zero tensor at
text_indicesandimage_indices. - Timestep embedding:
[cos, sin]oft * exp(-ln(10000) * i / 128)in f32 (256),time_embedder(Linear 256 to 5376, SiLU, Linear to 2688). - AdaLN: each of the 50 blocks has
adaln_proj(Linear(2688 -> 6 * 5376 * 3)onsilu(temb)) reshaped to one(shift, scale, gate) x 2set per (timestep row, modality tag); a token picks rowtimestep_index * 3 + tag(tags: image 0, text 1, audio 2; the audio slot is unused but present in the weights). - Block:
x + gate_msa * attn((1 + scale_msa) * RMSNorm(x) + shift_msa), then the same with the FF; attention has q/k/v/out without bias, per-head RMSNorm on q and k, full (unmasked) SDPA at scale128 ** -0.5, and 3-axis RoPE on the first 96 dims of each head (per axis1 / theta ** (arange(0, 32, 2) / 32), concatenated over the three axes and duplicated, rotate-half), the last 32 dims passing through. FF:proj: 5376 -> 2 * 14336,h * silu(gate),Linear(14336 -> 5376). - Output:
norm_outRMSNorm with(shift, scale)chosen by timestep row, thenpdd_proj_out[step](5376 -> 96) on the image rows only. - Positions (
build_image_layout): text tokenkis(k, 0, 0); image gridi(references in order, then the target) uses(text_count + i, y, x)withy,xfromlinspace(left, left + ratio, n, endpoint=False) * 32,ratio = size / sqrt(h * w),left = (1 - ratio) / 2, on the patch grid; computed in f64 and cast to f32.
- Schedule: fixed
SAMPLE_SIGMAS = (1.0, 0.9675236940383911, 0.8875485062599182, 0.75, 0.5327739119529724, 0.23200887441635132, 0.0); step timesteps1 - sigmain f32; each step's timestep table is[t_step, 0.999](row 0 for the target, row 1 for references). Exactly 6 steps and guidance 1; anything else, or a negative prompt, is rejected. Upstream materializes the six AdaLN caches once and then drops the AdaLN projection weights (about 26 GB at bf16). - Sampling: one key from
seed, split before each draw in this order: each reference's VAE posterior sample, the target noisenormal((1, 24, 1, lh, lw)), each reference's mixing noise. References enter as0.999 * z + 0.001 * noiseand stay fixed; the target rows take Euler stepsrows += (sigma_s - sigma_{s+1}) * velocityin f32. - Canvas:
scale = max(1, sqrt(min_generation_area / (w * h)))withmin_generation_areadefault 4194304 (valid 1024..16777216), sides rounded to multiples of 32; latent gridcanvas / 16; the decoded image is LANCZOS-resized to the requested size. Default size 4096x4096. - Conditioner: Qwen3-VL-32B (64 layers, hidden 5120) in
text_encoder/with its vision tower; returns the pre-final-norm hidden state after layer 50. Token sequence with no chat template: for each reference, the tokens of"Picture {i}: "(tag 1),<|vision_start|>,<|image_pad|>timest * h * w / 4,<|vision_end|>(tag 0); then the prompt tokens (tag 1), each part truncated tomax_sequence_length(1..4096, default 4096). Conditioner references are resized so the short edge is 1024 (multiples of 32, LANCZOS) and run through the Qwen3-VL image processor. Iftext_encoder/config.jsonis absent,model_index.jsonnames a shared repo (MiniMaxAI/MiniMax-H3, subfoldertext_encoder). - VAE (
vae_diffusers/config.json,_class_name AutoencoderKLMiniMaxH3Image):latent_channels 24,block_out_channels [128, 256, 256, 512, 512, 1024],layers_per_block 2,spatial_downsample_factors [2, 2, 2, 2, 1, 1](16x), causal 3D-conv encoder with reflect spatial padding and GroupNorm 32 (eps 1e-6) run on one frame, a diagonal Gaussian posterior; decoder is a ViT (decoder_num_layers 24, 16 heads of 64, 4 register tokens plus one zero token, FF mult 4, LayerNorm out, eps 1e-5, 2D RoPE on half of each head with theta 100 over positions in[-1, 1]),proj_outto3 * 16 * 16per latent and unpatchified, decoded in tiles of 256 output pixels with at least 64 pixels of overlap (_split_tilesworks in pixels and slices the latent by the 16x ratio), each tile evaluated on its own, then blended by_stitch_tiles. Latentlatents_mean/latents_stdfrom the config normalize encode and decode. Pixels use ImageNet mean and std on both sides. - Edit references: 1 to 16; each short edge bounded to
[1024, 2048](multiples of 32, LANCZOS), cropped to multiples of 16, VAE-encoded, posterior sampled, rounded through f16, cropped to even latent sizes, normalized. References keep their aspect ratio and are not resized to the target canvas. Prompts refer to them as<Picture 1>,<Picture 2>, ... - Weights: official checkpoints are strict-loaded from
transformer_diffusers/andvae_diffusers/(the VAE through itssanitize); MLX conversions fromtransformer/,vae/,text_encoder/withquantization(affine, group 64) applied to every module whose.scalestensor is present; sensitive projections and the VAE stay at source precision.
Checkpoints and host
| Checkpoint | Download | Notes |
|---|---|---|
nativ-community/MiniMax-H3-Image-4bit |
54.48 GB | Validation target; not gated |
nativ-community/MiniMax-H3-Image-8bit |
77.32 GB | Second validation checkpoint |
MiniMaxAI/MiniMax-H3-Image (bf16) |
135.3 GB used (text_encoder/ 66.7 GB, transformer_diffusers/ 66.3 GB, vae_diffusers/ 2.3 GB, tokenizer/, model_index.json, pdd_config.json) |
The repo totals about 204 GB because it also holds native transformer/ and vae/ duplicates; download only the listed parts, as upstream's download.py does |
The 4-bit and 8-bit runs fit a 128 GB machine: the conditioner, transformer and VAE load in turn and the conditioner is freed before the transformer loads. Validate bf16 on a machine with 256 GB or more, since 135 GB of weights plus page cache do not fit a 128 GB box comfortably even though the staged resident peak is about 70 GB. Prompt expansion (MiniMaxAI/MiniMax-H3-Image-PE, 17.9 GB NVFP4 Qwen3.5) is not needed for this issue.
Current behavior
src/imagegen/probe.rs:42(IMAGE_FAMILIES) andsrc/imagegen/registry.rs:47(FAMILIES) have nominimax_h3_image;model_types_from_metadata(src/imagegen/probe.rs:216) readsmodel_typeand_class_name, so both detection keys can be added there.docs/vision-model-scope.md:79listsminimax_h3as out of scope (video and audio), which is correct for that release but is the only record that mentions H3 at all.- Reusable pieces: mlxcel's generative Qwen3-VL (
src/models/qwen3_vl.rs,forward_hidden_pre_normat:1133, used by the Qwen-Image conditionersrc/imagegen/qwen_image/text_encoder.rs), which returns the last layer only; the Qwen3-VL image processor path the Qwen-Image and Mage-Flow conditioners use (src/imagegen/mage_flow/conditioner.rs);src/imagegen/pipeline.rs:241(ImageGenerationModel); the staged load-and-free pattern of MOSS-Image (src/imagegen/moss_image/pipeline.rs); the Ideogram 4 refusal ofprompt_expansion_model(src/imagegen/ideogram4/config.rs:264-272).
Proposed solution
New module src/imagegen/minimax_h3_image/ (mod.rs with pub const FAMILY: &str = "minimax_h3_image" and pub fn load, config.rs, conditioner.rs, layout.rs (canvas, short-edge bound, positions, schedule), transformer.rs, adaln.rs (the cache and the weight drop), vae.rs (encoder, posterior, ViT decoder, tiling), pipeline.rs, weights.rs, tests beside each). The shared H3 blocks are ported here under the image family; the video and audio H3 stay out of scope, and if that family is ever ported it should import these blocks rather than copy them.
- Conditioner: add
pub(crate) fn forward_hidden_pre_norm_at_layer(&self, ..., stop_after_layer: usize)tosrc/models/qwen3_vl.rsbesideforward_hidden_pre_norm(the existing function becomes a call with the last layer; Qwen-Image output unchanged), and load only the first 50 decoder layers. - Detection:
model_types_from_class_name("MiniMaxH3ImagePipeline")andmodel_type: minimax_h3_imagegiveminimax_h3_image; add the probe name and the registry row, and aStandaloneArchitectureFamilyinsrc/models/registry.rs(categoryimage generation,IMAGE_GENERATE, aliasesminimax-h3-image, output image). - Requests:
defaults6 steps, guidance 1.0, size 4096x4096;check_requestrejects other steps or guidance, negative prompts, more than 16 references, and unknownextrakeys (allowed:min_generation_area,max_sequence_length,upsample_prompt,prompt_expansion_model);upsample_prompt: trueorprompt_expansion_modelreturns a 400 naming the reason (prompt expansion is not implemented; pass a detailed English caption), as Ideogram 4 does. Size multiple is 32 at the canvas level; the requested output size is any positive size and is reached by the final resize. - Memory: build the six AdaLN caches on the first request, then drop the AdaLN projection weights, and evaluate after every transformer block as upstream does to bound the lazy graph.
- Response metadata:
revised_promptis the prompt used, plusreference_images.
Scope
In scope: the module, probe and registry rows, generation and editing for the 4-bit, 8-bit and bf16 checkpoints, mlxcel generate-image and /v1/images/generations / /v1/images/edits, docs/image-generation.md (a MiniMax-H3-Image section with options, memory and parity), docs/supported-models.md (Image generation list), and docs/vision-model-scope.md: keep the minimax_h3 row out of scope but state that the image-only minimax_h3_image release is ported under this issue, and add a minimax_h3_image row to the image generation table. Reference #524 in the scope-doc change. NOTICE for the mlx-vlm port.
Out of scope: the joint video and audio minimax_h3 family, prompt expansion through MiniMax-H3-Image-PE (enabled by default upstream; a follow-up should add in-process prompt expansion for this family and FLUX.3 together), num_images > 1, quantizing the official bf16 checkpoint in mlxcel.
Implementation notes
- Dtype: transformer at checkpoint precision (bf16 or affine-quantized), Euler state f32, positions computed in f64 then f32, reference latents rounded through f16 as upstream does; the bf16 to f16 conversion policy must not touch the quantized conversions' bf16 scales.
- Edge cases: a reference with a short edge under 32 px (error), above 2048 (shrunk), an extreme aspect ratio, a requested size below
min_generation_area(generated larger, then resized),min_generation_areaout of range (400), a prompt over 4096 tokens (truncated), a checkpoint withouttext_encoder/(resolve the referenced repo locally or fail naming it). - Error handling: missing component directories and class-name mismatches name the expected layout (
transformer_diffusers/for official,transformer/for converted).
Acceptance criteria
- Unit tests: probe detection for both
model_index.jsonforms;canvas_sizefor 1024x1024, 4096x4096 and 1000x3000;bound_short_edge;build_image_layoutpositions for one reference plus a target on small grids against upstream values;sampling_schedule; AdaLN row selectiont * 3 + tag; the transformer and token refiner on a tiny random config against upstream formulas; the AdaLN cache path equals the live path before the weights are dropped. - VAE tests: a tiny random encoder and ViT decoder against upstream formulas; tiled decode of a 2x2-tile latent equals an untiled decode within the stitching blend.
- Real-checkpoint parity on
nativ-community/MiniMax-H3-Image-4bitagainst mlx-vlm withupsample_prompt=falseon both sides: bit-identical initial noise for seed 42; conditioner hidden state at layer 50 relative error under 1e-2; on upstream's conditioner output, a 1024x1024 generation withmin_generation_area 1024and a single-reference edit at 30 dB PSNR or better; end-to-end numbers recorded indocs/image-generation.md. Repeat the generation on the 8-bit checkpoint and, on a 256 GB machine, the bf16 checkpoint. -
mlxcel generate-image -m nativ-community/MiniMax-H3-Image-4bit -p "<detailed caption>" --size 4096x4096 --seed 42 -o out.pngwrites the image;--task edit --image out.png -p "Make the teapot in <Picture 1> blue, preserving its shape, the room, and the lighting"works;mlxcel-server --image-model <path>serves both routes;--steps 8andupsample_prompt: truereturn errors. -
mlxcel arch --jsonlistsminimax_h3_image;docs/vision-model-scope.mdstates the split betweenminimax_h3andminimax_h3_image. - Qwen-Image's conditioner output is unchanged after the
qwen3_vl.rschange (its parity tests pass).
Verification
cargo test --profile test-fast imagegen::minimax_h3_image
cargo test --profile test-fast imagegen::qwen_image
cargo test --profile test-fast qwen3_vl
make verify-test
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
./target/release/mlxcel generate-image -m models/MiniMax-H3-Image-4bit -p "A red ceramic teapot on a wooden table beside a sunlit window, soft morning light, detailed natural textures" --size 1024x1024 --seed 42 -o /tmp/h3.png --gen-kwargs '{"min_generation_area": 1024}'
Related
- #524 (vision scope tracking that set
minimax_h3out of scope), image generation runtime #2341 and epic #2348, MOSS-Image (the staged-load precedent), Qwen-Image #2342 (the Qwen3-VL conditioner hook extended here). - FLUX.3 #3230 has the same prompt-expansion gap.
- Lingua principale
- Rust
- Stelle
- 505
- Fork
- 81
- Merge medio
- 14h 2m
- PR unite (30g)
- 448
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di lablup/mlxcel
-
area:core priority:high status:ready type:security
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
priority:medium status:ready type:security
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
area:models modeltype:text priority:medium status:in-progress type:bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 57/100
I maintainer di solito rispondono entro 1 giorno
-
area:models priority:low status:ready type:test
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
area:models modeltype:omni priority:medium status:ready type:bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di lablup/mlxcel
Issue simili
-
area:ui effort:medium enhancement P7 source:agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousApertamaintainer-needed p2 remote triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug help wanted ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#4605 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno