Skip to content

[Feature] AMD NPU: power mode, prefill chunk length and image pre-resize in model settings - #17510

Merged
danielhanchen merged 27 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-advanced-settings
Nov 14, 2026
Merged

danielhanchen merged 27 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-advanced-settings

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Advanced run settings for NPU (FastFlowLM via Lemonade) models: Power Mode, Prefill Chunk Length (clamped to context) and Image Pre-resize (vision only, Lemonade levels 0 to 4), sent as flm_args on /v1/load; Default sends nothing. A change reloads instead of answering already_loaded; /status reports what the resident asked for; bad values get a 400 before anything unloads.

Tested on Windows 11, Ryzen 9 9950X + 2x R9700, no NPU: 24 new backend tests, 6 new frontend tests, related suites green (3 symlink failures also fail on main). Not run on a Ryzen AI NPU.

Screenshots

NPU spoofed: fake Lemonade/FastFlowLM on a Windows 11 PC with no NPU; no speed numbers. Before | after: fork phase stack, phase 1 ac3e06e | phase 2 945ba98. Shot at 945ba98; this PR's head has since moved to b45bf6c (prefill chunk now held to the resolved context, backend and tests only). Light mode, mint theme, glass on, same on both sides.

Before | after: NPU Run settings gain an Advanced section with Power Mode, Prefill Chunk Length and Image Pre-resize.
17510

Also checked by building Unsloth Studio from this PR's merge base (left) and head (right), on the same spoofed AMD NPU:

Chat > run settings of an NPU model: Advanced settings now offer Power Mode and Prefill Chunk Length (Image Pre-resize appears for vision models).

Before and after

…size run settings

FastFlowLM tuning for AMD NPU models under Advanced settings, sent to
Lemonade as the flm_args recipe option. Each persists like any run
setting (saved sets, Always load, the server-shared override) and a
change makes /load reload instead of answering already_loaded.
…ops below it

FastFlowLM loads with min(chunk, context) and the status echoes that, so a
saved chunk above a lowered context never matched the load: the panel stayed
dirty and Apply answered already_loaded. The context edit now clamps the chunk
in the same patch. The prefill placeholder reads "default" like the hint.
…ts them

An older client's save left the three NPU keys out, they defaulted to None and
the replacement row dropped the saved NPU tuning. The route now keeps a stored
NPU setting the payload omits, like the MLX offload knobs, and the client sends
them as null when unset so clearing one still clears it.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Screenshots of this PR's change:

Run settings for an NPU model with Advanced settings on: Power Mode and Prefill Chunk Length (Image pre-resize shows only for vision models). The placeholder reads "auto" here; the head now says "default".

17510-17511-run-settings.png
Taken on Windows 11 (Ryzen 9 9950X + 2x R9700, no NPU) with a spoofed NPU: a fake Lemonade 2026.44.1 + FastFlowLM 1.0.12 that answers Unsloth Studio's API, running the stacked branch #17519 at e8d25a4. It shows the UI; it is not a run on a Ryzen AI NPU.

…ad response

POST /api/inference/load returned the three NPU run settings as null even when the
resident load applied them, so a client reading the load response saw the wrong
settings. The NPU load response now reads them from the resident flm_args, as
the status endpoint does.
oobabooga added a commit to LeoBorcherding/unsloth that referenced this pull request Nov 12, 2026
# Conflicts:
#	studio/backend/core/inference/npu_backend.py
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Measured on a real NPU: AMD Strix Halo (DevLab runner, Linux), FastFlowLM 1.0.12, Lemonade 2026.44.1, fork phase 5 92c2fbb, temperature 0 (oobabooga/unsloth run 43276227073). Each setting is a reload, and the Lemonade log shows flm serve started with --pmode turbo / --pmode powersaver and --prefill-chunk-len 512 / 2048, so the settings reach FastFlowLM.

power

Power mode changes nothing measurable on Strix Halo (all within 2%).

chunk

FastFlowLM's default chunk is already the fast one. A 512 chunk makes a 1,764-token prompt take 2.4x longer on Qwen3.6-35B-A3B-NPU2 (25.6 vs 10.5 s) and 1.2x longer on Qwen3.5-9B-NPU2, and 2048 matches the default. So the defaults stay as they are. These settings are for hardware or prompts where they help; image pre-resize wasn't measured.

@danielhanchen danielhanchen self-assigned this Nov 13, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T13:54:00.786263Z ca0fd89 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 13, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 941b01ffe8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	studio/backend/core/inference/npu_backend.py
#	studio/backend/routes/inference.py
#	studio/backend/tests/test_gguf_load_cache_reuse.py
#	studio/frontend/src/features/model-picker/components/model-config-page.tsx

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3345c207d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

replaced = True
self._raise_if_load_cancelled(model_id)
# Held to the context this load resolved, which only the load knows under Auto.
flm_args = clamp_prefill_chunk(flm_args, ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the requested prefill chunk across Auto-context loads

When an Auto-context preset's saved chunk exceeds the RAM-fit context on a later load—for example, 8192 saved but 4096 resolved—this overwrites the requested chunk, so _Loaded.flm_args and /status retain only 4096. useActiveModelConfig then uses 4096 as the configuration value, while ModelConfigPage compares it exactly against the saved 8192. For a pinned set, reopening settings consequently shows “Unsaved changes” immediately after loading that set, and saving writes the transient RAM-fit value back into the preset. Preserve requested and effective chunk values separately, or normalize both sides of the frontend preset comparison to the resolved context.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6be93cc: the resident now keeps the requested chunk (what settings saved), lemond still gets it clamped to the resolved context, and the already-loaded check clamps both sides to the resident context.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 6be93ccbcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: ca0fd8933e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 4f9f1d2 into unslothai:main Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants