Tech18 min read

Porting Ming-Image-0.2-Design-Layer to M1 Max MPS for Anime Character Layer Decomposition

IkesanContents

On November 25, inclusionAI uploaded Ming-Image-0.2-Design-Layer to Hugging Face. It decomposes a single image into RGBA layers with transparency, and version 0.2 adds “character rigging decomposition” to split character illustrations into parts such as bangs, eyes, clothes, and legs.

Back in April, when I used See-through to automatically decompose an anime standing illustration into 23 layers and export a PSD, Kana’s side ponytail stayed merged with the back hair because See-through uses a fixed set of part categories without a ponytail slot. Since Ming-Image-0.2-Design-Layer lets you specify each target layer in English text, I wanted to see if it could separate the side ponytail into its own layer.

The officially verified setup requires a single NVIDIA CUDA GPU with 80GiB of dedicated VRAM, whereas an M1 Max MacBook Pro shares 64GB of unified memory between CPU and GPU and cannot run CUDA-specific code on Apple Silicon’s MPS (Metal Performance Shaders) backend as-is. I started by patching what was needed to get it running on an M1 Max.

ItemDetails
AuthorinclusionAI
ReleaseNovember 25, 2026 (Hugging Face repo created; updated December 1)
LicenseMIT
Inference codeinclusionAI/Ming-Image
Total weights65.2GB

The 65.2GB of weights are split across five modules.

ModuleSizeRole
mllm34.02GBMultimodal LLM (BailingMoeV2) that reads the input image and English layer specs internally
transformer24.62GBDiffusion model (DiT, 6B parameters) that draws the layers, stored in 32-bit float (fp32)
connector6.17GBConverts LLM outputs into conditioning for the diffusion model (Qwen2-based, 1.5B parameters, fp32)
vae0.25GBAutoencoderKLQwenImage, 4-channel (RGBA) input version
mlp0.12GBProjection layer for conditioning

Recommended settings from the model card:

ItemRecommendation
ResolutionTwo tiers: 512 or 1024; output preserves input aspect ratio
Steps12
CFG (prompt adherence)2.0
PrecisionBF16 (16-bit bfloat)
HardwareVerified on a single CUDA GPU (80GiB VRAM)

The prompt begins with Decompose this image into N layers followed by per-layer specifications. Layer 1 is the frontmost layer, and the last layer is the background. For character rigging decomposition, an external VLM (vision-language model)—used only to write the text spec, not to split the image itself—takes the official system prompt and the image to generate the English specification, which is then fed into Ming-Image’s internal mllm and diffusion pipeline. The two external VLMs listed by the authors are Ling-3.2-flash and Qwen3.8-27B.

Test Environment

ItemDetails
MachineMacBook Pro M1 Max 64GB
ExecutionOfficial infer.py via a wrapper that applies MPS patches
Python3.12 (uv)
Key librariestorch 2.15.0, transformers 4.57.1, diffusers 0.36.0, accelerate 1.13.0
VLM for layer specsQwen3.8-27B (OpenAI-compatible API via ModelScope, temperature 0)
Common settingsResolution 512, 12 steps, CFG 2.0, BF16
InputThe same full-body Kana standing illustration from the See-through post (1280×1280), composited onto a white background

The official requirements pair torch 2.4.0 with transformer-engine 1.11.0, along with flash-attn for acceleration. Both transformer-engine and flash-attn are CUDA-only, so I skipped them; the codebase already has fallback branches when they are absent.

Kana’s original image is a transparent PNG, but all three official sample inputs are RGB images with solid backgrounds, so I composited her onto white before passing the image in.

Patches to Run on M1 Max

Instead of modifying the official repository files, I wrote a wrapper that monkey-patches three components before loading.

TargetOriginal codeReplacement
Mixed precisiontorch.cuda.amp.autocasttorch.autocast("mps", dtype=torch.bfloat16)
Image encoder attentionClass using flash-attnClass using PyTorch’s standard SDPA (Scaled Dot-Product Attention)
Diffusion model attentionStandard diffusers SDPAOne sample at a time, splitting queries into 2048-token chunks for SDPA
SDPA masktrue / false booleanDrop if all true, otherwise convert to additive 0 and -inf

I chunked the diffusion model’s attention because of the long sequence length. The model concatenates all output layers and the reference image into a single token sequence for joint attention. Even at resolution 512, 12 layers exceed 10,000 tokens, so splitting the queries prevents MPS SDPA from allocating a massive token×token attention matrix at once. I converted boolean masks to additive 0/-inf because in an earlier model analysis, passing boolean masks to MPS produced NaN values.

I launched with --device mps --device-map none to place everything on MPS (the command below also includes MING_FREE_MLLM=1, an environment variable for freeing the MLLM that I added in the next step).

Run command
MING_FREE_MLLM=1 python run_mps.py \
  --model ./weights \
  --task layer-decompose \
  --input-image kana_white.png \
  --prompt kana_rigging_prompt.txt \
  --resolution 512 \
  --device mps --device-map none \
  --local-files-only \
  --output-dir out/k2

Verifying with the Official Sample

First, I ran the official rigging sample (rigging_input.png and its 11-layer spec rigging_prompt.txt) as-is.

Official sample decomposition: input, recomposition, and 11 layers

Top-left is the input, next to it is the recomposed image stacking all output layers from back to front, and the remaining tiles show each layer with transparency as a checkerboard. Head (Source Base) is redrawn as a featureless head, and the back hair and legs are filled in behind the bangs and skirt. Rather than simple cutouts, the model paints in occluded regions.

On this first run, mllm alone took 34GB, pushing /usr/bin/time -l peak memory footprint to 79.7GB—exceeding the M1 Max’s 64GB and swapping to SSD—while generation took about 24 minutes (1449.6 seconds). Right after loading, MPS allocation was 51.0GB, and three modules—MLLM, image encoder, and connector—are only used once to compute conditioning from the prompt and image, sitting idle during the 12-step sampling loop. Suspecting SSD swap was slowing things down, I added MING_FREE_MLLM=1 to free those three modules right before sampling and reran with the same seed.

ConditionLoadGenerationPer stepPeak memory
As-is66.3s1449.6s~116s79.7GB
Free MLLM before generation59.1s1420.9s~116s55.4GB

Freeing them produced pixel-identical outputs across all 11 layers (max difference 0) while cutting peak memory down to 55.4GB. However, generation time barely moved from 1449.6s to 1420.9s. Since each step still took ~116 seconds even without swapping, the bottleneck was the computation itself. From here on, I kept MLLM freeing enabled to save memory.

Generating Kana’s Layer Spec with Qwen3.8-27B

Passing the official rigging system prompt (assets/layer_rigging_rewriter_system_prompt.txt) and white-background Kana to Qwen3.8-27B returned a 12-layer spec in 16.6 seconds.

Layer spec generated by Qwen3.8-27B
Decompose this image into 12 layers with the following specifications:

Number of layers: 12
Layer 1: Front Hair. Brown bangs and side strands framing the face, overlapping the forehead and cheeks.
Layer 2: Face Base. Light skin tone covering the face and neck, with subtle blush on the cheeks.
Layer 3: Eyes. Brown irises with dark pupils and white highlights, framed by simple upper and lower eyelashes.
Layer 4: Eyebrows. Thin brown eyebrows positioned above the eyes.
Layer 5: Mouth. Small, simple brown line indicating a neutral expression.
Layer 6: Neckwear. Solid red necktie tied at the collar, hanging down the center of the chest.
Layer 7: Topwear. White long-sleeved collared shirt with a button placket and cuffs, tucked into the skirt.
Layer 8: Arms and Hands. Bare skin hands hanging naturally at the sides, emerging from the shirt cuffs.
Layer 9: Bottomwear. Dark grey pleated skirt with a solid waistband, falling to mid-thigh.
Layer 10: Legs and Footwear (Both). Black sheer thigh-high stockings on both legs, paired with brown loafer shoes.
Layer 11: Back Hair. Brown hair gathered into a side ponytail with a blue hair tie, plus an ahoge.
Layer 12: Background. Solid white backdrop with no additional textures, shadows, or marks.

Checking this against the image and the official system prompt showed three mismatches.

ItemQwen3.8-27B outputImage / official rule
Face basePlaced at Layer 2, in front of eyes, eyebrows, and mouthOfficial rule states eyes, eyebrows, and mouth must have smaller numbers (in front of) the face base
AhogeIncluded in Back HairLocated at the front top of the head
LegsSheer thigh-high stockingsActually black opaque tights

I prepared condition k1 (12 layers) using Qwen3.8-27B’s spec verbatim, and k2 (12 layers) fixing those three issues while also lowering the face base to Layer 5 and renaming it to Head (Source Base) to match the official sample. Because both k1 and k2 still bundle the side ponytail inside Back Hair, I also added a 14-layer spec (k3) splitting Back Hair into Headwear (scrunchie), Side Ponytail, and the remaining Back Hair.

Specs for k2 and k3

k2

Decompose this image into 12 layers with the following specifications:

Number of layers: 12
Layer 1: Front Hair. Brown bangs, side strands and a single ahoge on top of the head, framing the face and overlapping the forehead and cheeks.
Layer 2: Eyes. Brown irises with dark pupils and white highlights, framed by simple upper and lower eyelashes.
Layer 3: Eyebrows. Thin brown eyebrows positioned above the eyes.
Layer 4: Mouth. Small, simple brown line indicating a neutral expression.
Layer 5: Head (Source Base). Light skin tone covering the face and neck, with subtle blush on the cheeks.
Layer 6: Neckwear. Solid red necktie tied at the collar, hanging down the center of the chest.
Layer 7: Topwear. White long-sleeved collared shirt with a button placket and cuffs, tucked into the skirt.
Layer 8: Arms and Hands. Bare skin hands hanging naturally at the sides, emerging from the shirt cuffs.
Layer 9: Bottomwear. Dark grey pleated skirt with a solid waistband, falling to mid-thigh.
Layer 10: Legs and Footwear (Both). Black opaque tights on both legs, paired with brown loafer shoes.
Layer 11: Back Hair. Brown hair gathered into a side ponytail with a blue hair tie.
Layer 12: Background. Solid white backdrop with no additional textures, shadows, or marks.

k3 (only Layer 11 onward differs from k2)

Decompose this image into 14 layers with the following specifications:

Number of layers: 14
(Layers 1–10 same as k2)
Layer 11: Headwear. Blue scrunchie tying the side ponytail on the upper right side of the head, on the viewer's right.
Layer 12: Side Ponytail. Brown side ponytail hanging from the scrunchie down beside the head on the viewer's right.
Layer 13: Back Hair. Brown hair behind the head and shoulders, without the side ponytail.
Layer 14: Background. Solid white backdrop with no additional textures, shadows, or marks.

Full-Body Standing Illustration Results

I first tested k1, k2, and k3 on the full-body illustration with seed 42, and reran k2 and k3 with seed 7 to check for seed variance.

k1: Qwen3.8-27B Spec Verbatim

The first image shows the full layer sheet, and the second zooms in around the face.

k1 decomposition results

k1 face close-up

LayerContents
1 Front HairBangs and side hair
2 Face BaseHair with ahoge (front hair duplicated into two layers)
3 EyesFeatureless face base
4 EyebrowsEyes and eyebrows
5 MouthMouth
6 NeckwearNecktie
7 TopwearCollar and necktie (overlaps with 6)
8 Arms and HandsFull shirt including sleeves and hands
9–12Skirt, tights and shoes, back hair (including side ponytail and scrunchie), white background

Each layer shifted by one from its name, and the face base (3) landed in front of eyes/eyebrows (4) and mouth (5), leaving the recomposed face blank. Presumably the model followed an approximate default order (“hair → face parts → base”) rather than the layer names.

k2: Spec with Three Fixes

Full layer sheet and face close-up for seed 42.

k2 decomposition results (seed 42)

k2 face close-up (seed 42)

LayerContents
1 Front HairBangs, side hair, ahoge
2 EyesBoth eyes
3 EyebrowsBoth eyebrows
4 MouthMouth (just a small line)
5 Head (Source Base)Featureless face; ears and neck are drawn in, and the forehead under the bangs is filled with skin
6 NeckwearNecktie, with a bit of neck shadow skin tone at the top
7 TopwearShirt, including the viewer’s left sleeve
8 Arms and HandsViewer’s right sleeve and both hands
9 BottomwearSkirt
10 Legs and FootwearTights and shoes, with tights drawn up the thighs under the skirt
11 Back HairBack hair, still merged with the side ponytail and scrunchie
12 BackgroundWhite background

Everything aligned with its layer name, and the recomposed face showed eyes and mouth properly. However, the original cheek blush disappeared from the face base, the mouth opened slightly compared to the original line, and the left and right sleeves split across two layers. The side ponytail and scrunchie also remained merged in Back Hair.

To check reproducibility across seeds, I reran with seed 7 (full sheet first, face close-up second).

k2 decomposition results (seed 7)

k2 face close-up (seed 7)

LayerContents
1 Front HairBangs, side hair, ahoge
2 EyesOnly the viewer’s right eye and the tip of the ahoge
3 EyebrowsBoth eyes and both eyebrows together
4 MouthMouth
5 Head (Source Base)Face base (cheek blush remained)
6 NeckwearNecktie
7 TopwearShirt
8 Arms and HandsBoth sleeves and hands together
9–12Skirt, tights and shoes, back hair, white background

The overall order matched the names, though eyes and eyebrows got mixed up. Since k2 still keeps the side ponytail in Back Hair, I moved on to k3.

k3: Spec Splitting Side Ponytail and Scrunchie

Full layer sheet, face close-up, and hair close-up for seed 42.

k3 decomposition results (seed 42)

k3 face close-up (seed 42)

k3 hair close-up (seed 42)

LayerContents
1 Front HairBangs and side hair (no ahoge)
2 EyesHair with ahoge (front hair duplicated like in k1)
3 EyebrowsEyes and eyebrows
4 MouthOnly 9 pixels, almost empty
5 Head (Source Base)Empty
6 NeckwearFace base
7 TopwearNecktie
8 Arms and HandsShirt torso
9 BottomwearSide ponytail, plus both sleeves and hands
10 Legs and FootwearSkirt
11 HeadwearTights and shoes
12 Side PonytailBlue scrunchie
13 Back HairBack hair without the side ponytail
14 BackgroundWhite background

Even though the face instructions were identical to k2, the name-to-content alignment broke again. Still, the separation itself worked: the side ponytail came out as its own strand detached from the back hair, and the scrunchie came out on its own layer with no ponytail left in Back Hair. The recomposed face kept eyes and eyebrows in front of the base, though the scrunchie (12) ended up behind the side ponytail (9) and was partially hidden.

I reran with seed 7 (full sheet, face close-up, hair close-up).

k3 decomposition results (seed 7)

k3 face close-up (seed 7)

k3 hair close-up (seed 7)

LayerContents
1–8Identical shift to seed 42
9 BottomwearBoth sleeves and hands
10 Legs and FootwearSkirt
11 HeadwearScrunchie together with tights and shoes
12 Side PonytailSide ponytail matching the name (with part of the scrunchie)
13 Back HairBack hair without the ponytail, same as seed 42
14 BackgroundWhite background

Because k3 shifted in the exact same way across both seeds, it looks like a deterministic issue with the 14-layer spec rather than seed variance. With the full-body illustration, I could not get both a detached side ponytail and an unshifted face.

Generation time, peak memory, and recomposition error (mean absolute error 0–255 between the recomposed stack and the input) across all full-body runs:

ConditionSeedGeneration timePeak memoryRecomposition error
k1421761.8s55.6GB1.65
k2421762.0s55.6GB1.52
k271762.1s55.6GB1.51
k3422181.9s58.0GB1.63
k372182.0s59.8GB1.65

Per-step time was ~144 seconds for 12 layers and ~178 seconds for 14 layers. This is slower than the portrait-oriented (896×1200) official sample (~116 seconds), possibly because the square Kana image produces a longer token sequence. Recomposition error stayed around 1.5–1.7 in every run; because it only measures visual similarity after stacking everything back together, it cannot distinguish swapped or shifted layers.

Redrawing as a Bust-Up Shot

In the full-body 1280×1280 image, Kana stands only 357px wide, making her face roughly 100px—which shrinks to ~40px wide (and ~10px per eye) at resolution 512. In contrast, the official 896×1200 sample fills the frame with the character, with the face occupying over 20% of the image height. Matching that proportion with Kana’s proportions means framing from the waist up.

Instead of cropping the full-body image, I generated a new 832×1024 bust-up illustration using Kana’s LoRA—keeping the same white shirt, red necktie, and grey skirt—and passed it to Qwen3.8-27B to generate a layer spec, which I used unmodified.

Layer spec generated by Qwen3.8-27B (bust-up)
Decompose this image into 10 layers with the following specifications:

Number of layers: 10
Layer 1: Front Hair. Brown hair with center-parted bangs, side locks framing the face, a top ahoge, and a side ponytail secured by a blue scrunchie.
Layer 2: Eyebrows. Thin brown eyebrows positioned above each eye, following the gentle curve of the upper eyelids.
Layer 3: Eyes. Large brown eyes with detailed irises, dark pupils, white highlights, and upper lash lines on both sides.
Layer 4: Mouth. A small, neutral straight line in muted reddish-brown centered on the lower face.
Layer 5: Head (Source Base). Light skin face with soft cheek blush, covering the forehead, cheeks, and chin without features.
Layer 6: Neck. A short pale skin patch connecting the chin to the shirt collar, with subtle shadow at the top.
Layer 7: Neckwear. A dark red necktie knotted at the collar, hanging straight down the center of the white shirt.
Layer 8: Topwear. A white long-sleeved collared shirt with a pointed collar, covering the torso and both down-swept sleeves.
Layer 9: Bottomwear. A dark blue-gray pleated skirt with a solid waistband, visible at the bottom edge of the frame.
Layer 10: Background. Plain white backdrop with no texture, ground shadow, or non-character marks.

This time, Qwen placed Head (Source Base) at Layer 5 without any numbering errors. There is no Back Hair layer; the ahoge, side ponytail, and scrunchie are all grouped under Front Hair.

Full layer sheet and face close-up:

Bust-up decomposition results (seed 42)

Bust-up face close-up (seed 42)

LayerContents
1 Front HairBangs, side hair, ahoge, side ponytail, scrunchie
2 EyebrowsBoth eyebrows
3 EyesBoth eyes
4 MouthMouth and a small dot for the nose
5 Head (Source Base)Featureless face, including ears and cheek blush
6 NeckNeck
7 NeckwearNecktie
8 TopwearShirt (both sleeves)
9 BottomwearSkirt
10 BackgroundWhite background

All 10 layers matched their names, and eyes and eyebrows—which had mixed or split in the full-body runs—separated cleanly onto one layer each. The only minor artifact in the recomposed image was a slight blur at the bottom of the neck layer, leaving the inside of the collar slightly greyish.

ConditionSeedGeneration timePeak memoryRecomposition error
Bust-up (10 layers)421329.5s53.7GB4.33

The output dimensions preserved the input aspect ratio at 448×551, taking ~111 seconds per step. While the recomposition error of 4.33 looks higher than the full-body runs, the full-body image was mostly white background, diluting the average. In the bust-up, the character occupies 45% of the frame, with an error of 5.44 on the character and 3.43 on the background—largely because the input background averaged around RGB 251 rather than pure white, while the background layer came out near 255.

Since k3 still shifted on the full-body image even after fixing the spec numbering, the small face size likely played a role. However, because I only ran the bust-up once (seed 42, 10 layers) and Qwen made no numbering mistakes there, it remains unclear how much of the improvement came from the larger face versus having fewer layers.

Differences from See-through

ItemSee-through (April)Ming-Image-0.2-Design-Layer (This test)
EnvironmentRunPod RTX PRO 6000M1 Max 64GB (ported to MPS)
Inference time2m 5s~22–36 minutes at 512 (1330–2182s)
Layer definitionFixed part categories (up to 23)Specified per layer in English text
Face partsFine split (eyebrows, eyelashes, sclera, iris, mouth, nose)Eyes, eyebrows, mouth (depends on spec)
Occluded regionsInpaintedPainted in (head, back hair, thighs)
Side ponytailMerged with back hairSeparated from back hair in full-body k3
Name-content matchMatched fixed categories on full-body inputShifted on small-face full-body input; matched on bust-up (1 run, seed 42)

While k3 separated the side ponytail from the back hair on the full-body image, the face layers shifted; on the 10-layer bust-up, the face separated cleanly while the side ponytail stayed in Front Hair. At 22–36 minutes per run on an M1 Max, iterating on specs is slow, so a GPU environment like in my earlier test using Qwen-Image-Layered on RunPod for Live2D face part separation is much more practical for trial and error.