Skip to content

Add contrib models: LongCat-Image-Edit, Qwen-Image-Edit, Wan2.2-TI2V-5B#117

Open
whn09 wants to merge 7 commits intoaws-neuron:mainfrom
whn09:contrib/diffusion-models
Open

Add contrib models: LongCat-Image-Edit, Qwen-Image-Edit, Wan2.2-TI2V-5B#117
whn09 wants to merge 7 commits intoaws-neuron:mainfrom
whn09:contrib/diffusion-models

Conversation

@whn09
Copy link
Copy Markdown

@whn09 whn09 commented Apr 9, 2026

Description

Add NxDI contrib models for three diffusion/generation models: LongCat-Image-Edit (FLUX-style image editing), Qwen-Image-Edit (Qwen2.5-VL-based image editing), and Wan2.2-TI2V-5B (text/image-to-video generation). All three run on trn2.48xlarge with CFG Parallel or Context Parallel strategies and include NKI Flash Attention kernels for Trainium2.

Model Information

Model Name: LongCat-Image-Edit, Qwen-Image-Edit, Wan2.2-TI2V-5B

Model Architecture: Multi-component diffusion models (Vision Encoder + Language Model + DiT/FLUX Transformer + VAE)

Purpose: Image editing (LongCat, Qwen), text/image-to-video generation (Wan2.2)

Checklist

Required Components

  • Accuracy Test (test/integration/test_model.py)

    • LongCat-Image-Edit: Full end-to-end CFG inference verified (1024x1024, 50 steps, 18.17s)
    • Qwen-Image-Edit: Full end-to-end V3 CFG inference verified (1024x1024, 50 steps, 37.62s total)
    • Wan2.2-TI2V-5B: Full end-to-end T2V inference verified (512x384, 81 frames, 15.77s CFG)
  • README.md with the following sections:

    • Usage Example: Complete compile + inference workflows for each model
    • Compatibility Matrix: Tested on Trn2 (trn2.48xlarge) with Neuron SDK 2.22+
    • Example Checkpoints: Links to HuggingFace model hubs
    • Testing Instructions: pytest and manual test commands
  • Source Code (src/)

    • Compilation scripts for each component (transformer, VAE, text/vision encoders)
    • Inference runner scripts with CFG Parallel / Context Parallel support
    • NKI Flash Attention kernels, TP sharding utilities, Neuron-compatible RoPE

Optional Components

  • Unit Tests — Integration tests in test/integration/ for each model

Folder Structure

contrib/models/LongCat-Image-Edit/
  README.md
  requirements.txt
  assets/test.png
  src/
    run_longcat_image_edit.py           # Main inference script
    neuron_commons.py                   # NKI attention, encoder wrappers
    neuron_parallel_utils.py            # FLUX TP sharding
    neuron_rope.py                      # 3-axis RoPE
    compile_transformer.py              # FLUX transformer (TP=4, CP=2)
    compile_transformer_cfg.py          # FLUX transformer (TP=4, DP=2, CFG)
    compile_vae.py                      # AutoencoderKL (1024x1024)
    compile_vision_encoder.py           # Qwen2.5-VL ViT (TP=4)
    compile_language_model.py           # Qwen2.5-VL LM (TP=4)
    compile.sh, cache_hf_model.py, setup_nvme.sh
  test/integration/test_model.py

contrib/models/Qwen-Image-Edit/
  README.md
  requirements.txt
  assets/image1.png, image2.png
  src/
    run_qwen_image_edit.py              # Main inference (6 compilation APIs)
    neuron_commons.py                   # SDPA implementations
    autoencoder_kl_qwenimage_neuron.py  # Neuron-compatible 3D VAE
    compile_transformer_v3_cfg.py       # V3 CFG (fastest, recommended)
    compile_transformer_v3_cp.py        # V3 Context Parallel
    compile_transformer_v{1,2}*.py      # V1/V2 variants
    compile_vae.py, compile_text_encoder.py, ...
  test/integration/ (6 test files)

contrib/models/Wan2.2-TI2V-5B/
  README.md
  requirements.txt
  assets/cat.png
  src/
    run_wan2.2_ti2v.py                  # T2V and I2V inference
    neuron_commons.py                   # Rolling cache decoder, attention utils
    compile_transformer.py              # DiT transformer (TP=4, CFG/CP)
    compile_decoder_rolling.py          # Stateful rolling cache VAE decoder
    compile_text_encoder.py             # UMT5 (ModelBuilder, TP=4)
    compile.sh, cache_hf_model.py, setup_nvme.sh
  test/integration/test_model.py

Testing

How did you test this change?

All models compiled and tested end-to-end on trn2.48xlarge (Neuron SDK 2.22+, PyTorch 2.9).

LongCat-Image-Edit:

Config Total Time Per Step Notes
CFG Parallel (TP=4, DP=2) 18.17s 0.36s Recommended
H100 reference (single GPU) 23.61s 0.47s Baseline

Qwen-Image-Edit:

Version Per Step Total (50 steps) Notes
V3 CFG (TP=4, DP=2, NKI Flash) ~0.75s 37.62s Fastest, recommended
V3 CP (TP=4, CP=2, NKI Flash) ~0.77s 38.67s Context Parallel
V1 Flash / V2 Flash (TP=8) ~1.2s ~60s NKI kernel
V1 baseline (TP=8) ~2.4s ~120s Standard SDPA

Wan2.2-TI2V-5B:

Resolution Frames CFG (s) H100 (s)
512x384 81 15.77 16.13
640x480 121 45.15 39.67
1280x704 81 155.06 87.66

Compatibility

Tested with:

  • Neuron SDK Version(s): 2.22+
  • Instance Type(s): Trn2 (trn2.48xlarge)
  • PyTorch Version: 2.9
  • Python Version: 3.12

Additional Information

Key design decisions shared across all models:

  • CFG Parallel vs Context Parallel: CFG batches cond+uncond into single forward (no K/V all-gather), ~10% faster for guided generation. CP is better for no-guidance scenarios.
  • NKI Flash Attention: Custom NKI kernels for Trainium2 attention computation, requires XLA_DISABLE_FUNCTIONALIZATION=1.
  • Neuron-compatible RoPE: Uses (cos, sin) tuples instead of complex numbers (C64 unsupported on Neuron).

LongCat-specific:

  • M-RoPE from Qwen2.5-VL for 3D position IDs
  • VAE compiled at full 1024x1024 (no tiling) to avoid seam artifacts

Qwen-Image-Edit-specific:

  • 6 compilation APIs with progressive optimization (V1→V3)
  • Modulation layer sharding reduces memory from ~17GB to ~5.2GB per shard
  • 3D causal VAE with tiled spatial processing

Wan2.2-specific:

  • Stateful rolling cache: 34 feat_cache tensors on-device (HBM) via input-output aliasing, eliminates ~960MB roundtrip per call
  • VAE encoder on CPU due to Neuron compiler bug (NCC_IBIR158)
  • Multi-resolution support up to 720P with tiled spatial decode

Related Issues

N/A

vLLM Integration

  • This model/feature is intended for use with vLLM
  • Documentation includes vLLM registration instructions

By submitting this PR, I confirm that:

  • I have read and followed the contributing guidelines
  • This is a community contribution and may have limited testing compared to officially-supported models
  • The code follows best practices and is well-documented
  • All required components listed above are included

Henan Wan and others added 7 commits April 13, 2026 18:53
Add three diffusion model adaptations for Trainium2 inference:

- LongCat-Image-Edit: FLUX-style image editing (TP=4, CP=2/CFG Parallel)
- Qwen-Image-Edit: Qwen-Image-Edit-2509 with 6 compilation variants
- Wan2.2-TI2V-5B: Text/image-to-video generation with rolling cache

All models compiled and tested on trn2.48xlarge with PyTorch 2.9
and neuronx-cc 2.22.
…rformance

CFG Parallel is ~9% faster than Context Parallel when guidance_scale > 1.
Updated compile.sh, run script, and README to use CFG as default.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…mance

CFG Parallel is ~11% faster than Context Parallel at 512x512 (24.81s vs 27.93s).
Updated compile.sh to use CFG as default (CP=1 to override), updated README.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…age-Edit

Removed:
- run_qwen_image_edit_debug.py (developer debugging script)
- run_qwen_image_edit_gpu.py (CUDA GPU-only, not for Trainium)
- test_attention_fix.py (one-time verification, not integration test)
- visualize_vae_diff.py (developer diagnostic tool)
- assets/output_edited.png (output example, not needed as test input)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…peedup

Pass optimized compiler flags directly to ModelBuilder.compile() instead of
relying on NEURON_CC_FLAGS env var, which is silently ignored.

Changes:
- Upgrade -O1 to -O2
- Add --lnc=2 for Trainium2
- Add --enable-ccop-compute-overlap to pipeline all-reduce with next layer compute
- Add --cc-pipeline-tiling-factor=4 for finer-grained overlap scheduling

Benchmarked on trn2.3xlarge (TP=4, WS=8, 512x384, 81 frames, 50 steps):
  Transformer fwd: 254.0ms -> 208.6ms (-17.9%)
  Step time: 0.612s -> 0.522s (-14.7%)
  MFU: 27.4% -> 33.8% (+6.4pp)

Co-Authored-By: Claude <noreply@anthropic.com>
Pass ccop compute-overlap flags directly to ModelBuilder.compile() instead
of relying on NEURON_CC_FLAGS env var, which is silently ignored when
compiler_args is explicitly passed.

Same fix as Wan2.2-TI2V-5B (PR #2), applied to all 6 remaining
transformer compilation scripts in the diffusion-models branch:

Pattern A (4 files): Added --lnc=2 and --tensorizer-options with
ccop+tiling to existing compile_args parameter:
  - LongCat-Image-Edit/compile_transformer.py
  - LongCat-Image-Edit/compile_transformer_cfg.py
  - Qwen-Image-Edit/compile_transformer_v3_cfg.py
  - Qwen-Image-Edit/compile_transformer_v3_cp.py

Pattern B (2 files): Added compile_args to builder.compile() which
previously passed no compiler_args at all (flags only in env var):
  - Qwen-Image-Edit/compile_transformer_v2.py
  - Qwen-Image-Edit/compile_transformer_v2_flash.py

Kept -O1 (original) since -O2 has not been benchmarked on these models.
The ccop overlap optimization alone gave 17.9% speedup on Wan2.2-TI2V-5B.

Co-Authored-By: Claude <noreply@anthropic.com>
…compiled_models paths

- Wan2.2-TI2V-5B: Update CFG 512x384/81f perf 18.32s→15.77s, default height 512→384
- LongCat-Image-Edit: Update CFG perf 20.39s→18.17s, compiled_models→compiled_models_longcat
- Qwen-Image-Edit: Add end-to-end total time column (~53s V3 CFG), fix CLI flags in example, compiled_models→compiled_models_qwen_image_edit
- All: Add model name suffix to compiled_models/compiler_workdir paths to avoid conflicts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@whn09 whn09 force-pushed the contrib/diffusion-models branch from dae0470 to e9b3ddf Compare April 13, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants