GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Mojo24x7/pixart-sigma-axm1: PixArt-Sigma 512 text-to-image on the AXERA AX650/AX8850 NPU (Radxa AICore AX-M1) - 27s per image, Pulsar2 conversion pipeline and runtime

BranchesTags
Open more actions menu

Latest commit

 

History

4 Commits
4 Commits

Folders and files

NameName
Last commit message
Last commit date
conversion
conversion
 
 
deploy
deploy
 
 
runtime
runtime
 
 
samples
samples
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 

Repository files navigation

PixArt-Σ 512 on Radxa AICore AX-M1 (AXERA AX8850) — NPU text-to-image

Text-to-image with PixArt-Sigma 512 running on the Radxa AICore AX-M1 (AXERA AX8850, 24 TOPS, 8 GB) via Pulsar2. The DiT + VAE run on the NPU (Pulsar2 .axmodel, U16); the T5-XXL text encoder runs on the host CPU as int8 (ONNX Runtime).

  • ~36 s / 512×512 image (20 DPM steps, CFG 4.5) on the AX-M1 — vs ~180 s for the same model as RK3588 rknn fp16 (~6.6× faster).
  • Clean & photorealistic — U16 quantization of the PixArt DiT does not grain the output (verified across many prompts; unlike Z-Image / SD1.5, which U16 wrecks — see §10).
  • Pipeline: T5-XXL (CPU int8 ORT) → DiT (AX-M1 axmodel, U16) → VAE (AX-M1 axmodel, U16).
  • Bonus: an RK3588 rknn fp16 variant (DiT+VAE, 512) is included for boards without an AX-M1 (~3 min/image).

This repo is a conversion + runtime for the AX-M1. It does not retrain PixArt — it ports the published weights to the AX8850 NPU. See Credits & Licenses.

Pre-built models are on Hugging Face

https://huggingface.co/Mojo24x7/PixArt-Sigma-512-AX650

You do not need to run the conversion. The .axmodel files and the int8 T5 encoder are published, so you can go straight to generating images:

# install the deps first - see Requirements, axengine is NOT on PyPI
hf download Mojo24x7/PixArt-Sigma-512-AX650 --local-dir ./pixart-ax
python3 runtime/pixart_full_ax.py --model-dir ./pixart-ax \
    -p "macro photograph of fresh strawberries with water droplets on dark slate, studio lighting, high detail, photorealistic" \
    -o strawberries.png --seed 7
file size
dit.axmodel 720 MB
vae.axmodel 71 MB
t5/t5_enc_int8_ext.onnx + .data 4.77 GB
neg_emb.npy, neg_mask.npy pre-encoded empty negative prompt

The conversion pipeline below is for rebuilding them yourself, changing resolution, or porting a different PixArt checkpoint. Budget ~2 h 22 m for the DiT build — see §10 on why a whole-transformer Pulsar2 build is so slow.


Samples — generated on the AX-M1

All 512×512, 20 DPM steps, CFG 4.5, ~36 s each. No post-processing, no upscaling.

strawberries tabby cat
macro photograph of fresh strawberries with water droplets on dark slate, studio lighting a close-up photograph of a tabby cat in golden hour sunlight, sharp focus on the eyes, soft bokeh
F1 mountain starry flowers
an F1 race car on a mountain road, snowy peaks, photorealistic a starry night over a flower meadow, folk-art

Look at the strawberry seed texture and the water droplets: no graining, no cracked texture. That is the U16 finding in §10 made visible — the same U16 pipeline visibly wrecks Z-Image-Turbo and SD1.5 on this hardware.

In fairness: U16 is not artifact-free. Roughly one image in two carries a few small isolated colour speckles, most often against flat sky or dark backgrounds. They are a world away from the graining that makes Z-Image unusable here, but they are visible if you look for them.

Usage

# deps first - see Requirements above (axengine comes from a GitHub wheel, not PyPI)

# pre-built models — no conversion needed
hf download Mojo24x7/PixArt-Sigma-512-AX650 --local-dir ./pixart-ax

python3 runtime/pixart_full_ax.py \
    -m ./pixart-ax \
    -p "macro photograph of fresh strawberries with water droplets on dark slate, studio lighting, high detail, photorealistic" \
    -o strawberries.png --seed 7 --neg-cache
[t5]  8.2s
[npu] models loaded 11.1s
  step 20/20  25.83s
[dit] 25.8s  (1.29s/step)
[vae] 1.1s
saved strawberries.png  (seed 7, 20 steps, cfg 4.5)

That command reproduces samples/strawberries.png in this repository exactly — same prompt, same seed, same 20 steps. If your output matches, your setup is correct.

flag default what
-m, --model-dir . directory with dit.axmodel, vae.axmodel, t5/
-p, --prompt required what to generate
-n, --negative cartoon, blurry, … negative prompt
-o, --out out.png output file
-s, --steps 20 denoise steps — each costs ~1.3 s
-c, --cfg 4.5 guidance scale
--seed 1234 -1 for random
--neg-cache off use the pre-encoded empty negative and skip one T5 pass (−8.5 s)
--threads 8 CPU threads for T5

Timing, measured

stage where time notes
T5-XXL int8 encode host CPU, 8 threads 8.5 s per prompt; --neg-cache avoids a second pass
model load AX-M1 12 s once — amortised by the service below
DiT denoise, 20 steps AX-M1 NPU 26.1 s 1.30 s/step; 2 DiT calls per step for CFG = 40 invocations
VAE decode 64→512 AX-M1 NPU 1.0 s
total, cold ~47 s
total, warm (models resident) ~36 s

Steps scale linearly at ~1.3 s each: -s 10 ≈ 13 s of denoise, -s 30 ≈ 39 s. 20 is the quality/speed knee for this model.

For anything interactive use runtime/pixart_service.py, which loads all three models once and serves over HTTP — every request after the first is then ~36 s with no reload, and the T5 encoder is lazily loaded and released after an idle timeout.

python3 runtime/pixart_service.py --model-dir ./pixart-ax --port 8801
curl -s -X POST localhost:8801/api/run/txt2img -H 'Content-Type: application/json' \
     -d '{"prompt":"macro photograph of fresh strawberries with water droplets on dark slate","steps":20}'

For comparison

target per image note
AX-M1 (AX8850), this repo ~36 s DiT + VAE on the NPU
RK3588 NPU, rknn fp16 (runtime/pixart_run.py) ~180 s same model, 6.6× slower

1. Credits & Acknowledgements

  • PixArt-Σ (the model) — Chen et al., "PixArt-Σ: Weak-to-Strong Training of Diffusion Transformer for 4K Text-to-Image Generation", 2024. Weights: PixArt-alpha. https://github.com/PixArt-alpha/PixArt-sigma
  • T5-XXL v1.1 text encoder — Google (Raffel et al., "Exploring the Limits of Transfer Learning …", 2020).
  • SDXL VAE (AutoencoderKL) — Stability AI.
  • diffusers / transformers — Hugging Face.
  • Pulsar2 + AXCL + axengine (NPU toolchain/runtime) — AXERA. https://huggingface.co/AXERA-TECH
  • Radxa AICore AX-M1 hardware — Radxa. https://docs.radxa.com/en/aicore/ax-m1
  • RKNN toolkit (RK3588 variant) — Rockchip.
  • This AX-M1 port (conversion scripts, DepthToSpace un-patchify fix, T5-int8-CPU pipeline, runtime/service) — Rocklabs.

2. Licenses

This repository ships code (conversion + runtime scripts) and small sample PNGs. The converted .axmodel weights are published separately at Mojo24x7/PixArt-Sigma-512-AX650 and inherit the upstream licences below; the original PyTorch checkpoints are not redistributed. Respect each upstream licence:

  • PixArt-Σ weights: PixArt-α's license (see their repo — research/creative use; check current terms).
  • T5-XXL: Apache-2.0. SDXL VAE: Stability AI license. diffusers/transformers: Apache-2.0.
  • The conversion/runtime code in this repo: MIT (Rocklabs), attribution appreciated.
  • If you publish the resulting .axmodel files, you inherit the PixArt-Σ + SDXL-VAE + T5 license terms.

3. Base models (exact sources)

Download with huggingface_hub:

  • DiT + scheduler: PixArt-alpha/PixArt-Sigma-XL-2-512-MS (the 512 model).
  • T5-XXL encoder + SDXL VAE (diffusers layout): PixArt-alpha/pixart_sigma_sdxlvae_T5_diffusers.
huggingface-cli download PixArt-alpha/PixArt-Sigma-XL-2-512-MS --local-dir base/PixArt-Sigma-512
huggingface-cli download PixArt-alpha/pixart_sigma_sdxlvae_T5_diffusers --local-dir base/pixart_t5_vae

4. Requirements

4.1 Hardware

accelerator AXERA AX650 / AX8850. Tested on a Radxa AICore AX-M1 (M.2, 8 GB)
host any AXCL host with an M.2 slot — tested on a Radxa ROCK 5B+ (RK3588), kernel 6.1.84
host RAM ~6 GB free for the int8 T5 encoder
card memory ~0.8 GB of the AX-M1's 7 GB usable CMM for DiT + VAE
disk ~6 GB for the model download

4.2 AXCL host driver — required, and not a pip package

The accelerator needs Radxa's AXCL host stack installed on the host (docs). On our board:

axclhost 3.10.2 · axclhost-dkms 3.6.5-1 · axclhost-firmware 3.6.5-1 · task-axclhost 3.6.5-1

Verify before going further — if this does not work, nothing else will:

axcl-smi                          # must list the AX8850 and its memory
ls /dev/axcl_host /dev/ax_mmb_dev # both must exist
ls /usr/lib/axcl/                 # the runtime .so files axengine loads

4.3 Python packages

★ axengine is not on PyPI — pip install axengine fails with No matching distribution found. It is a wheel published on AXERA's GitHub releases, and it is a thin ctypes wrapper that loads /usr/lib/axcl at runtime, which is why 4.2 has to be working first.

python3 -V     # 3.11 tested

pip install https://github.com/AXERA-TECH/pyaxengine/releases/download/0.1.3.rc3/axengine-0.1.3-py3-none-any.whl
pip install onnxruntime transformers diffusers torch pillow numpy huggingface_hub

torch is needed only for the scheduler and the RNG; the CPU wheel is fine and no CUDA is involved anywhere.

4.4 Check the stack before downloading 6 GB

python3 -c "import axengine, onnxruntime, torch, diffusers, transformers, PIL, numpy; print('deps OK')"
python3 -c "from axengine import InferenceSession; print('axengine can reach the card')"

4.5 Conversion host — only if you rebuild the models yourself

Not needed to run the published models.

  • x86_64 with Docker and Pulsar2 7.0 (from AXERA-TECH/Pulsar2).
  • ≥ 64 GB RAM for the fp32 DiT ONNX export.
  • Python 3.10/3.11 with torch (CPU), diffusers, transformers, onnx, onnxruntime, onnxsim, numpy, huggingface_hub.
  • Budget ~2 h 22 m for the DiT build — see Findings on why.

5. Repository contents

README.md                     ← this model card
conversion/                   ← build the axmodels from the base model (x86 + Pulsar2)
  pixart_export.py            ← DiT + VAE  →  ONNX (fp32, from diffusers)
  pixart_ln_fix.py            ← inject affine tensors into affine-less LayerNorms
  pixart_unpatch_fix.py       ← strip the 6-D Einsum un-patchify tail
  pixart_d2s_surgery.py       ← re-add un-patchify as Reshape→Transpose→DepthToSpace
  d2s_test.py                 ← proves DepthToSpace compiles on the AX NPU
  pixart_calib.py             ← capture real DiT calibration tuples (onnxruntime denoise)
  pixart_pulsar.json          ← Pulsar2 build config (DiT, U16, NPU3)
  pixart_vae_pulsar.json      ← Pulsar2 build config (VAE)
  t5_export_int8.py           ← T5 encoder → ONNX
  t5_requant_ext.py           ← ORT dynamic int8 quantize (external-data)
  precompute_neg.py           ← pre-encode the negative prompt once
  pixart_encode_test.py       ← sanity-check T5 embeddings
runtime/
  pixart_full_ax.py           ← self-contained one-shot generate (T5+DiT+VAE)
  pixart_service.py           ← warm HTTP service (OpenAI/sd15-ui job API :8801)
  pixart_run_ax.py, pixart_run.py
deploy/
  pixart-k8s.yaml             ← k3s Deployment+Service (AX-M1 node)
  arbiter.py                  ← (optional) single-tenant AX-M1 scaler if sharing the card
samples/                      ← strawberries.png, cat_golden_hour.png, f1_mountain.png, starry_flowers.png (on-AX-M1 outputs)

6. Running it

See Usage at the top for the command, every flag, and measured per-stage timings. In short: runtime/pixart_full_ax.py -m <dir> -p "<prompt>" for one image, runtime/pixart_service.py for a warm HTTP service that loads the models once, or deploy/pixart-k8s.yaml for k3s.

7. Full conversion procedure (reproducible, x86 + Pulsar2 7.0)

  1. Export DiT + VAE → ONNX (pixart_export.py, CPU fp32). DiT forward wrapped as m([latent], t, [prompt_embeds], patch_size=2)[0]; inputs latent(1,4,64,64), encoder_hidden_states(1,300,4096), timestep(1,), encoder_attention_mask(1,300); output (1,8,64,64) → take [:,:4] (epsilon). (Needs ~24 GB RAM for fp32 → use the 64 GB host.)
  2. LayerNorm affine fix (pixart_ln_fix.py): PixArt's norm_final (+ 56 norms) are affine-less; ONNX LayerNormalization requires Scale/Bias → inject ones-scale / zeros-bias (DIM 1152). Otherwise Pulsar2 rejects the empty affine.
  3. Un-patchify → DepthToSpace (pixart_unpatch_fix.py then pixart_d2s_surgery.py): the DiT output head is an Einsum nhwpqc->nchpwq. ★ Pulsar2 has no Einsum backend, AND the equivalent 6-D Transpose is unsupported by the AX NPU (AxTranspose OpBuildException). Replace with Reshape → 4-D Transpose(0,3,1,2) → DepthToSpace(blocksize=2, mode=DCR) — mathematically identical, all NPU-supported (verify with d2s_test.py). Result pixart_dit_ax3.onnx (Einsum=0, DepthToSpace=1).
  4. Calibration (pixart_calib.py): run an onnxruntime denoise (8 steps, cond+uncond), capture 16 real DiT input tuples → pixart_dit.tar (NumpyObject: sample_k.npy dicts).
  5. Pulsar2 build DiT (pixart_pulsar.json, U16, NPU3):
    docker run --rm -v $PWD:/data pulsar2:7.0 pulsar2 build \
      --input /data/dit_onnx/pixart_dit_ax3.onnx --output_dir /data/pixart_axmodel \
      --config /data/pixart_pulsar.json --target_hardware AX650
    
    → compiled.axmodel (720 MB) = dit.axmodel. (This step is slow, ~2 h — the DiT's attention tiles into ~725 K single-threaded scheduler jobs. For fast/iterative builds, split into subgraphs + parallel-compile; see §10.)
  6. Pulsar2 build VAE (pixart_vae_pulsar.json) on the VAE-decoder ONNX (64→512) → vae.axmodel (71 MB; fast, it's CNN).
  7. T5 int8 (t5_export_int8.py + t5_requant_ext.py): export the T5 encoder to ONNX → ORT quantize_dynamic(weight_type=QInt8, use_external_data_format=True). ★ use_external_data_format=True is mandatory (a single >2 GB int8 .onnx → "Protobuf parsing failed"). Result t5_enc_int8_ext.onnx (+ .data, ~4.8 GB). Uses the penultimate hidden layer (hidden_states[-2]) as PixArt expects.

8. Runtime details (runtime/pixart_service.py)

Warm service (Flask, sd15-ui-compatible job API on :8801):

  • DiT + VAE resident on the AX-M1 (axengine InferenceSession, loaded once — 8 GB card, zero host RAM).
  • Negative prompt pre-encoded once (precompute_neg.py → neg_emb.npy/neg_mask.npy) so T5 only runs on the positive prompt.
  • T5 lazy: loaded (ORT int8, 8 threads) on first request (~16 s), kept warm, auto-unloaded after 5 min idle → host stays lean.
  • Scheduler: DPMSolverMultistepScheduler (linear 1e-4..0.02, epsilon, dpmsolver++, order 2, midpoint), 20 steps, CFG 4.5, VAE scale 0.13025.
  • API: POST /api/run/txt2img {prompt,seed} → {ok,job_id,run_dir}; GET /api/jobs/status?job_id; /api/runs/inspect?path; /api/fs/file?path; /health.
  • Feed helper maps DiT inputs by shape; encoder_attention_mask is int32 for axengine (rknn used int64). VAE input latent(1,4,64,64) fp32.

9. Sample outputs (all generated ON the AX-M1, unretouched)

samples/ — the four images shown at the top of this README, straight off the AX-M1.

10. Key findings / hardware limits (the useful part for the AXERA/Radxa community)

  • U16 is clean for the PixArt DiT. The AX-M1's U16 quantization does not grain PixArt output. This is model-specific — the same U16 path grains Z-Image and SD1.5 badly. Don't assume "U16 grains diffusion"; test per model.
  • Pulsar2 op gaps for DiTs: no Einsum; 6-D Transpose unsupported on the AX NPU. Un-patchify → DepthToSpace. LayerNorm needs explicit affine tensors.
  • Whole-transformer Pulsar2 build is ~2 h (attention → ~725 K single-threaded scheduler jobs). CNNs (VAE) are fast. For fast/iterative builds, split the DiT into per-block subgraphs + par_compile (N processes) — minutes instead of hours.
  • T5-XXL can NOT go on the RK NPU (why T5 stays CPU): rknn per-file ceiling 4.294 GB (uint32) → fp16 T5 fails parse, int8 fails init; per-NPU total ≈ 4 GB → 2× halves can't co-reside; and int8 activation quant destroys T5 (its position-bias mixes ~±5 with the attention mask's −10000 → int8 scale dominated by −10000 → cosine 0.017 vs ref). ORT quantize_dynamic is weight-only (activations fp32) → correct. rkllm handles multi-GB models but only causal decoders (T5 is seq2seq). ⇒ CPU int8 is the right home for T5. It's a 1×/image encoder, not the bottleneck (DiT runs 40×/image).

11. RK3588 rknn variant (no AX-M1)

DiT + VAE converted to rknn fp16 (rknn-toolkit2==2.3.0) run on the RK3588 NPU (~3 min/image). Key gotcha: pass data_format='nchw' to rknnlite.inference for the 4-D latent (DiT + VAE) — the default NHWC misreads NCHW → black/garbage output.

12. Citation

@misc{pixart_axm1_rocklabs_2026,
  title  = {PixArt-Sigma 512 on Radxa AICore AX-M1 (AXERA AX8850)},
  author = {Rocklabs},
  year   = {2026},
  note   = {NPU port: Pulsar2 U16 DiT+VAE, CPU int8 T5. Base model: PixArt-alpha/PixArt-Sigma-XL-2-512-MS.}
}

About

PixArt-Sigma 512 text-to-image on the AXERA AX650/AX8850 NPU (Radxa AICore AX-M1) - 27s per image, Pulsar2 conversion pipeline and runtime

Topics

ax650ax8850axeradiffusionedge-ainpupixartpixart-sigmapulsar2radxark3588text-to-image

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.