Skip to content
AbrahamPaulJPublic

About

Convert a Stable Diffusion 1.5 or SDXL checkpoint into a Qualcomm NPU model on the phone itself, with no PC. Supports LoRA merging, swapping LoRA/Controlnet/IPAdapters at runtime..

Resources

Contributing

Stars

52 stars

Watchers

0 watching

Forks

Repository files navigation

npuforge

Convert SD1.5 and SDXL checkpoints, including SD1.5 inpainting models, into Qualcomm QNN models entirely on an Android phone.

Host regression tests

Technical overview · Results · Build · Tests · Limitations

npuforge turns a local .safetensors checkpoint into an importable model ZIP for Snapdragon NPU image generation. The phone converts the weights, merges optional UNet LoRAs, and compiles QNN context binaries. Each export includes the checkpoint's own text encoder(s), embeddings, VAE encoder and VAE decoder.

To our knowledge, npuforge is the first publicly documented Android app to convert SDXL checkpoints into QNN models entirely on-device. A review of related projects on 16 September 2026 found host-side conversion and mobile inference workflows, but no equivalent in-app SDXL conversion path. Related work and scope of this claim.

Once the APK and checkpoint are on the phone, SD1.5 conversion runs offline. The app uses bundled graph templates and tokenizer data. Three files are downloaded once, only when needed: SDXL conversions download the SDXL fp16-fix VAE weights (335 MB) and compile them on the phone once; turning a plain SD1.5 checkpoint into an inpainting model uses the SD1.5 inpainting difference (1.7 GB); and Build for an older chip uses the older-chip tools (56 MB). Each can also be imported from a file. Template preparation and building the APK are developer tasks performed separately on a workstation.

New in 1.0.13

  • The SDXL VAE is built on the phone. SDXL conversions download the fp16-fix VAE weights once and compile both VAE graphs for the phone's own chip, then reuse them. This removes the grey dots in SDXL renders: they came from the precompiled decoder that every SDXL export carried up to 1.0.12. Reconvert SDXL exports made with 1.0.12 or earlier; they keep the dots until then. It also replaces a decoder that could load only on 8 Gen 3 or newer (the new one is not yet run on an 8 Gen 2). The first SDXL conversion takes about 20 minutes longer while the VAE is built, and the phone-built decoder is a little slower (1.6 to 2.5 s per 1024 px decode against 1.2 to 1.3 s on a Galaxy S25 Ultra).
  • SDXL conversion on the phone writes about 0.3 TB to its storage. See the warning below; the PC kit avoids it.
  • Build for older chips (SD1.5). A phone newer than the target can build an export for v75 (8 Gen 3), v73 (8 Gen 2), "v73, 2 MB" (8s Gen 3) or v69 (8 Gen 1) with Build for on the Convert tab, using QAIRT's x86 compiler under emulation (56 MB tools download). On a Galaxy S25 Ultra a v73 build took 204 s and rendered bit-identically to the phone's own export; no real older phone has loaded one yet.
  • Integer SD1.5 VAE for the 8s Gen 3 and 8s Gen 4 (SM8635, SM8735). Their NPUs have no fp16, so their SD1.5 conversions now compile an integer VAE instead of stopping at the VAE encoder. An integer-VAE export rendered on an 8 Elite phone at 48.7 to 49.6 dB against the fp16 VAE (no visible difference at 1x), but neither chip has run a conversion or a render yet. SDXL stays unavailable on them.
  • SD1.5 extra sizes and long prompts. A plain SD1.5 conversion can add 512x768 and 768x512, each one more UNet compile (about twice the main compile's time and up to about 40% more memory). Nightmare Mobile lists and renders both sizes (5.3 to 5.6 s at 20 steps on the S25 Ultra). A 231-token prompt option compiles too, but no app can use it yet (Nightmare needs new SD1.5 code first).
  • Snapdragon 888 and older are refused before a conversion starts, instead of failing at the compile after copying the checkpoint. A chip the app does not know may still try, and a "Device Creation failure" now comes with the chip and its likely causes.
  • Folder export. Export as: Folder writes the same files to Download/npuforge/<name>/ with no zip. Nightmare Mobile lists the folder once it is moved into its models folder, which needs no extra space (a zip import needs room for the zip and its unpacked copy). Not yet run on a phone.
  • LoRA strength starts at 1.0 (it was 0.8). Exports list their baked LoRAs in the manifest, and a baked speed LoRA sets the export's default sampler, steps and CFG (Speed LoRAs).
  • Text-encoder LoRAs: kohya text-encoder modules now merge into the checkpoint's own CLIPs (host-tested only; not for Swap exports).
  • Storage checks and I/O in the report. Compiles that keep their working memory in files check free storage first (SDXL UNet 14 GB, SDXL VAE 8 GB, SD1.5 on a low-RAM phone 5 GB) and stop with the amount needed. The conversion report has a "Storage I/O" line for each tool with the bytes it wrote.
  • PC conversion kit: Convert on a PC.

What it enables

  • Local model conversion: choose a checkpoint, convert it on the phone, and import the exported ZIP into Fancy-Ai or Nightmare Mobile.
  • Checkpoint-owned components: preserve a fine-tune's trained CLIP and VAE weights, including SDXL's two text encoders.
  • Baked-in LoRAs: merge supported UNet adapters before quantization, with an independent strength for each adapter.
  • On-phone QNN compilation: run the ARM64 QAIRT context generator inside the Android app, with storage-backed allocation for large SDXL compilation jobs (at a cost in flash writes, below).
  • SD1.5 inpainting models: 9-channel inpainting checkpoints (the "-inpainting" releases) are detected and converted automatically. Any plain SD1.5 checkpoint can also be converted as an inpainting model: the app adds the official SD1.5 inpainting difference to it on the phone.
  • SD1.5 Swap (experimental): Convert as → SD1.5 Swap builds the UNet with LoRA (rank 64, 160 layers), ControlNet residuals and (since 1.0.7) IP-Adapter image-prompt K/V as graph inputs, so Nightmare Mobile picks LoRAs, canny / depth / openpose ControlNets and a reference picture (IP-Adapter Plus or Plus-Face) per render, with no reconversion. About 15–20% slower per image than a plain conversion (the IP inputs add 3% when unused); the compile takes about twice as long. 512×512. Exports from 1.0.6 keep working without a reference picture. Details: docs/SD15-LORA-CN-TEMPLATE.md.
  • SDXL Swap (1.0.11; ControlNet and IP-Adapter 1.0.12): Convert as → SDXL Swap builds an SDXL checkpoint into the SDXL Swap template (calibrated on Illustrious-XL, NoobAI-XL v-pred and SDXL base), prompts up to 462 tokens, with LoRA, ControlNet and IP-Adapter as graph inputs, each ticked or left out per conversion (a feature left out costs nothing). LoRA slows every render by about 30% in our phone measurements. ControlNet (canny / depth / openpose) and IP-Adapter (Plus / Face) are a preview and render in Nightmare Mobile 1.6.109 or newer: ControlNet was rendered on an Illustrious conversion with two LoRAs and depth; IP-Adapter's adapters were trained on SDXL base, and on Illustrious Face gave poor results (Plus untested). Inpaint is in the template but not offered: SDXL Swap inpaint conversions render blotchy fills. Every export carries a swap_features.json manifest, so Nightmare shows what a conversion can take. A LoRA-only export needs Nightmare Mobile 1.6.096 or newer. Speed LoRAs work only partly through Swap's run-time LoRA; bake them into a plain export (Speed LoRAs). Details: docs/SDXL-SWAP-TEMPLATE.md.
  • Clip skip 1 or 2: choose how SD1.5 text encoders are built. 2 is the default and matches earlier exports; 1 uses the full text encoder.
  • V-prediction compatibility: the app reads standard modelspec.prediction_type checkpoint metadata and lets the user override it. V-prediction exports include the V_PRED marker understood by compatible LocalDream-based runtimes, including Nightmare Mobile 1.6.075 and later.
  • Low-RAM phones: below 10 GB of RAM, the SD1.5 compile keeps its working memory in a temporary file instead of RAM, so Android is far less likely to stop the conversion. It takes about twice as long.
  • Downloads that survive bad connections: downloads resume where they stopped and fall back between Hugging Face and the hf-mirror.com mirror. The Utility tab's Download source picks which to try first; phones set to China's timezone start with the mirror.
  • Inspectable implementation: Kotlin/Jetpack Compose app, native C/C++ converters, Python reference tools, and host regression tests.

Supported generation apps

Output models work only with:

Import the exported ZIP through either app's custom-model workflow. SD1.5 exports, including inpainting models, need Nightmare Mobile 1.6.033 or later (float32 VAE). An export with a baked DMD2 LoRA opens at the LCM Trailing (DMD2) sampler in Nightmare Mobile 1.6.362 or later; older versions ignore that default (Speed LoRAs). Inpainting in Fancy-Ai is untested. Device and QNN runtime compatibility still apply.

How it works

flowchart LR
    A[Local checkpoint] --> B[Native weight conversion]
    L[Optional UNet LoRAs] --> B
    T[Bundled templates and recipes] --> B
    B --> C[UNet and VAE weight packs]
    C --> D[QNN compilation on phone]
    A --> E[CLIP conversion to MNN]
    D --> F[Importable model ZIP]
    E --> F
Loading

A template stores a fixed graph and calibrated activation ranges. A recipe maps checkpoint tensors into that graph, including layout changes and weight quantization. Preparing these once per supported architecture allows subsequent checkpoints to be converted without repeating workstation export and calibration.

The current UNet templates use INT8 weights and 16-bit activations (W8A16). CLIP graphs use MNN; the UNet and both VAE graphs use QNN. VAE arithmetic on HTP is FP16. Graph shapes and activation ranges remain fixed, and each phone compiles for its own chip; compatibility and quality must be established for each model family.

Architecture and engineering details

Demonstrated results

Result Evidence and scope
117 s SD1.5 conversion 24 s weight conversion + 93 s QNN compilation on Galaxy S25 Ultra; original UNet pipeline
437 s SDXL conversion Reported total for the earlier O=3 pipeline on Galaxy S25 Ultra; predates checkpoint-owned CLIP/VAE conversion
15 s SDXL image generation Generated from the exported model: 1024 × 1024, 8 steps, CFG 1; generation time, not conversion time
Pony restored by checkpoint-owned CLIPs Reported successful render after replacing only the text-encoder components
Illustrious full-component conversion Successful reported output from waiIllustriousSDXL_v170; 1024 × 1024, 30 steps, CFG 7
LoRA conversion fixes confirmed Latest test APK reported working after DMD2 mapping, compiler allocation and workspace fixes
SD1.5 inpainting on the phone DreamShaper 8 inpainting, DreamShaper 8 base and CuteYukiMix converted in the app and inpainted in Nightmare Mobile; phone and PC builds render byte-identical images
Low-RAM compile Compiler RAM 2.89 GB → 0.03 GB on Galaxy S25 Ultra with an identical output; not yet run on an 8 GB phone
Today's SDXL conversion in the app Galaxy S25 Ultra, WAI-REALISM-Illustrious v1.0, 1 December 2026: 60 min 28 s including the one-time VAE build (21.4 min); 40 min 38 s with the VAE cached
Today's SD1.5 conversion in the app Galaxy S25 Ultra, DreamShaper 8, 1 December 2026: 176.6 s; 20-step 512 px render 3.5 to 4.0 s in Nightmare Mobile

These are individual measurements and tester reports. The 117 s and 437 s figures are historical baselines, not timings for today's full-component pipeline. Results, methodology and remaining measurements.

Use the app

  1. Install an APK built with the required runtime and generated assets.
  2. Select a complete SD1.5 or SDXL .safetensors checkpoint, through the system picker or a file manager such as MiXplorer.
  3. Confirm the prediction type. Checkpoint metadata selects it when available; epsilon remains the fallback for older files.
  4. For SD1.5, choose Text-to-image or Inpainting, a clip skip and, optionally, the extra sizes.
  5. Optionally add LoRAs and set their strengths (1.0 by default).
  6. Optionally pick Build for an older chip, and Export as Zip or Folder.
  7. Start conversion and import Download/npuforge/<name>.zip into Fancy-Ai or Nightmare Mobile.

The current app targets Android 13+ on ARM64 Snapdragon devices: Snapdragon 8 Gen 1 or newer for SD1.5, 8 Gen 3 or newer for SDXL. Snapdragon 888 and older are not supported, and the app refuses them before a conversion starts. Convert on the phone you will generate on, or use Build for: the compiler builds for the chip it runs on, so an export from a newer chip will not load on an older one. The Galaxy S25 Ultra with 12 GB RAM is the main demonstrated device. Available memory, storage, firmware and compiler behavior matter; installed RAM alone does not establish compatibility. Export Save full troubleshooting log when reporting a failure.

SDXL on the phone writes about 0.3 TB to flash

An SDXL UNet compile needs more memory than a phone can spare, so the app keeps the compiler's working memory in files, and the compiler rewrites it constantly. Measured on a Galaxy S25 Ultra (1 December 2026): one SDXL conversion wrote 328 GB to the phone's storage, 310 GB of it in the 37-minute UNet compile. That is wear on the phone's flash with every SDXL conversion; how much of a particular phone's rated endurance it uses depends on that phone and was not measured. A variant that keeps part of the working memory in RAM cut writes about 6.6 times in tests, but no compile with it has finished yet, so it is off.

  • For SDXL, prefer the PC kit. It builds the same export on an x86_64 PC with no flash wear on the phone.
  • If you convert SDXL on the phone, keep 14 GB free (the app checks) and read the report's "Storage I/O" lines, which give the bytes each tool wrote.
  • SD1.5 conversions on phones with 10 GB of RAM or more compile in memory. On low-RAM phones the SD1.5 UNet compile uses the same file-backed memory; its writes have not been measured.

Speed LoRAs

Speed (step-distilled) LoRAs such as DMD2, LCM-LoRA, SDXL-Lightning, Hyper-SD and Turbo save time only by needing fewer UNet calls: 4 to 8 steps at CFG 1 against 40 calls at 20 steps and CFG 7.5.

  • Bake them into a plain export, at strength 1.0. Baked, the whole LoRA reaches the UNet (788 of 788 modules for the seven public SDXL speed LoRAs checked). A Swap export's run-time LoRA carries only part of the effect: in the x86 HTP simulator it delivered 27 to 42% of DMD2's per-step effect, and in emulated renders Lightning 4-step went soft and washed out.

  • A baked speed LoRA sets the export's defaults (config.json) when the file name or its metadata names it:

    LoRA Sampler Steps CFG
    DMD2 LCM Trailing (DMD2) 8 1
    LCM-LoRA LCM 8 1
    SDXL-Lightning N-step DPM++ 2M N 1
    Hyper-SD N-step DPM++ 2M N (8 if unnamed) 1
    Hyper-SD N-step CFG DPM++ 2M N (12 if unnamed) 5
    Turbo DPM++ 2M 8 1
  • These defaults need Nightmare Mobile 1.6.362 or later. LCM Trailing is new there; an older Nightmare ignores an unknown sampler and opens a DMD2 export at its own default, so pick LCM by hand. Do not use Euler with DMD2. 1.6.362 also fixes the Euler, Euler A and DPM++ SDE timesteps that made Lightning grainy at 4 to 8 steps.

  • These are host, GPU and simulator results on SDXL base; a baked export with these defaults has not been rendered on a phone yet.

Convert on a PC

The same conversion also runs on an x86_64 Linux PC or WSL, with no phone, and can build for any Snapdragon HTP target, SDXL for older chips included. Download the PC kit from Hugging Face (AbrahamPJ/npuforge-pc-kit), then:

./npuforge-pc-kit-1/npuforge-pc convert model.safetensors --target v79,v75,v73

It writes one export zip per target, the zip the app would write, with its own manifest marker (npuforge-pc). The kit runs the app's own templates and converters. Its packs were byte-identical to the APK converters' on DreamShaper 8, and its contexts report the requested HTP arch and SoC model. One PC-made SD1.5 export (v79) imported into Nightmare Mobile and rendered bit-identically to the phone's own export; PC-made SDXL, Swap and older-chip exports have not been loaded on a phone yet. An SDXL conversion needs about 16 GB of RAM on the PC (18 GB for SDXL Swap) and causes no flash wear on the phone. Targets, options and how it works: docs/PC.md.

Build and test

The Android build runs on Linux x86-64 or Windows, with JDK 21, Android SDK 37 and NDK 30.0.16248370. A working APK also needs externally supplied QAIRT runtime files and generated graph assets. Those are not all present in a fresh clone.

# After provisioning the assets and SDK described in docs/BUILD.md:
./gradlew :app:assembleDebug :app:lintDebug

Host regression tests use synthetic tensors and need no phone, checkpoint or Qualcomm SDK:

python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements-test.txt
python -m unittest discover -s tests -p 'test_*.py' -v

See build instructions, test coverage, and contributing.

Current scope

  • SD1.5 at 512 × 512 (text-to-image and 9-channel inpainting; plain SD1.5 also at 512 × 768 and 768 × 512) and SDXL at 1024 × 1024; complete LDM-layout F16/F32/BF16 checkpoints, including mixed weight dtypes. BF16 input is expanded to FP32; compiled graph precision is unchanged.
  • Supported UNet LoRA layers include attention, ResNets and sampler convolutions. Unmatched tensors produce a warning; matched layers still merge. Kohya text-encoder LoRAs merge into the checkpoint's CLIPs (host-tested only; not for Swap exports). PEFT-format adapters and complete DoRA/LyCORIS semantics are not supported.
  • Checkpoint-owned components address weight mismatches. They cannot guarantee that the fixed activation calibration suits every fine-tune.
  • SDXL inpainting models and other resolutions need new templates; see the roadmap. SDXL image-to-image and a broader device matrix still need documented evaluation.

Known issues

  • 8s Gen 4 and 8s Gen 3 (SM8735, SM8635) are untested. Their SD1.5 conversions now use the integer VAE, but no conversion or render has run on either chip. Earlier reports also saw QAIRT 2.49 and newer UNets rejected on the SM8735. On the SM8635 the phone's own conversion keeps the templates' 8 MB VTCM setting for its 2 MB NPU, which may not load; a newer phone's Build for: v73, 2 MB or the PC kit's v73_2mb target builds for 2 MB. SDXL is not available on these chips.
  • SDXL conversion on the phone is slow and writes heavily to flash: about 40 minutes and 0.3 TB on a Galaxy S25 Ultra (above).
  • 231-token SD1.5 prompts compile but no generating app reads them yet.
  • SDXL Swap inpaint is not offered (blotchy fills), and the SDXL VAE encoder built on the phone has not yet been used by an img2img or inpaint render.

Complete compatibility notes · Roadmap

Repository guide

Path Purpose
app/ Android UI, foreground conversion service and ZIP export
native/ Weight converter, CLIP writer and compiler allocator
tools/ Python reference conversion and template authoring helpers
tests/ Native/Python regression and allocator tests
docs/ Architecture, results, build instructions and research records
template/ Original SD1.5 recipe and compact constants pack; separate provenance

License and provenance

Original application, converter and tooling source is under the MIT License. The checked-in template artifacts have separate non-commercial provenance. Qualcomm SDK files, generated model libraries and checkpoints are not covered by the source license and are not distributed here. See NOTICE for the artifact boundaries and outstanding distribution questions.

Credits

  • SD1.5 inpainting difference (downloaded on demand): computed from RunwayML's sd-v1-5-inpainting and v1-5-pruned-emaonly, CreativeML OpenRAIL-M.
  • SD1.5 inpainting template: calibrated on Lykon's DreamShaper 8 Inpainting (CreativeML OpenRAIL-M), exported with Local Dream's modified diffusers UNet (xororz, CC BY-NC 4.0).
  • SDXL VAE (downloaded on demand, compiled on the phone): madebyollin/sdxl-vae-fp16-fix, MIT. Up to 1.0.12 the app downloaded VAE contexts precompiled by Mr.J (Mr-J-369/Fancy-AI).
  • hf-mirror.com: an independent Hugging Face mirror, used as a download source.
  • Qualcomm QAIRT runtime and compiler; MNN (Alibaba, Apache-2.0) text-encoder format.

An independent project by Abraham Paul Jaison. Qualcomm, Snapdragon and other product names identify the technologies used; no affiliation or endorsement is claimed.

About

Convert a Stable Diffusion 1.5 or SDXL checkpoint into a Qualcomm NPU model on the phone itself, with no PC. Supports LoRA merging, swapping LoRA/Controlnet/IPAdapters at runtime..

Resources

Contributing

Stars

52 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages