Skip to content

[Feature] AMD NPU: show the NPU and its resident model in the live monitor - #17508

Merged
danielhanchen merged 15 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-live-monitor
Nov 14, 2026
Merged

danielhanchen merged 15 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-live-monitor

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

With a GGUF model loaded, the live monitor (floating and Settings > System) splits the memory bars per model. With an AMD Ryzen AI NPU model loaded (FastFlowLM through Unsloth Studio's private Lemonade server) there was no breakdown, and no sign of the NPU at all.

  • For a resident NPU model, /api/inference/status reports resident_mib as the RSS of lemond's process tree, floored at the catalog size, with resident_on_gpu: false. The Loaded models label gains an NPU case.
  • An NPU card in both monitors, shown only when /api/npu/status reports a supported XDNA 2 NPU: device, driver, and the resident model with its size in system RAM.
  • On Windows, /api/system adds npu_load_percent, read from the GPU Engine counters for the NPU's adapter LUID (DEVPKEY_GPU_LUID), the source Task Manager's NPU graph uses. Linux has no counter (amdxdna exposes no busy file; fdinfo busy time arrives in kernel 7.4), so the card shows no load there rather than 0%.

Tests: new backend tests (process-tree RSS, catalog floor, unloaded NPU, 9 for the load reading) and frontend tests for the label, the card and its strings in all 25 locales. Typecheck is clean. Run on Windows 11, Ryzen 9 9950X, two R9700, no NPU: the LUID-to-counter lookup returned a real R9700's load. 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 4 49a3094 | phase 5 db8d450. Shot at db8d450; this PR's head has since moved to 2ed8460 (LUID lookup throttle and an import path, no visible change). Light mode, mint theme, glass on, same on both sides.

Before | after: Settings > System > Live monitor gets an NPU tile with the device, driver and the resident model's size in system RAM. The VRAM tile change is #17523.
17508

Before | after: the floating Live monitor gets an NPU row with the resident model.
17508

Real NPU and before/after evidence

Run on a real XDNA 2 NPU (Ryzen AI Max+ 395, Windows 11, NPU driver 32.0.20102.4480, Lemonade 2026.44.1, FastFlowLM 1.0.12), with Studio's own NPU backend loading qwen3:0.6b and generating (11 runs, about 104 tok/s):

reading this PR independent GPU Engine counter read
NPU load while generating, max / median 98.8% / 94.4% 99.3% / 97.9%
model loaded, idle 0.0%
after unload 0.0%
resident size 2021 MiB, resident_on_gpu: false (catalog floor 619 MiB)
resident size after unload null

The NPU's DEVPKEY_GPU_LUID is one of the adapter LUIDs Windows lists under GPU Adapter Memory, and the merge base has no NPU reading at all. On Linux (same hardware, amdxdna 2.25) the NPU is detected and the load reads null, as intended.

Before (merge base) | after (this PR), Chromium. NPU responses spoofed per side with what each side's backend returns for a resident FastFlowLM model; hardware fields are the real box's.

Floating live monitor: an NPU row with the load and the resident model's size in system RAM.
17508 floating monitor

Settings > System > Live monitor: an NPU tile with the device, driver, load and resident model.
17508 system live monitor

Settings > System > Live monitor and the floating monitor get an NPU card when
/api/npu/status reports a supported XDNA 2 NPU: the device, its driver, and the
NPU model resident in system RAM. On Windows /api/system now reports
npu_load_percent from the GPU Engine counters of the NPU's own adapter, matched
by the LUID its PnP node carries; Linux has no counter for it, so the card shows
no load there.
@LeoBorcherding LeoBorcherding changed the title [Feature] AMD NPU: show a resident NPU model's memory in the live monitor [Feature] AMD NPU: show the NPU and its resident model in the live monitor Nov 11, 2026
With no model loaded Windows lists no GPU Engine instances for the NPU, so
every poll cleared the LUID and respawned Get-PnpDevice. Only a failed
counter read clears it now; an empty counter list is an idle reading.
An Infinity sample was clamped to 100% and read as a fully busy NPU. Reject
it as the GPU counter parser already does.
…invariant

An idle NPU and a stale LUID both list no counters, so the LUID is now
looked up again once it has been silent for 60 s. Counter values are
formatted with the invariant culture so comma-decimal hosts still parse.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Screenshots of this PR's change:

Settings > System > Live monitor: the NPU card shows the device, its driver, and the resident model with its size in system RAM.

17508-live-monitor-npu.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.

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 13, 2026
@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 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-14T10:28:46.333463Z 647582b 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 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: 2baaac5923

ℹ️ 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".

"\\Utilization Percentage' -ErrorAction SilentlyContinue).CounterSamples;"
"if($s){$s|ForEach-Object{'{0}|{1}' -f $_.InstanceName,$_.CookedValue.ToString([cultureinfo]::InvariantCulture)}}else{'__NONE__'}"
)
stdout = _rocm_windows_counter_stdout_uncached(ps)

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 Suppress console windows for the recurring NPU probes

On Windows desktop installations with a supported NPU, this adds recurring unhidden PowerShell launches to /api/system, including CUDA/NVIDIA hosts that previously avoided the ROCm counter path. _rocm_windows_counter_stdout_uncached() calls subprocess.run without creationflags or startupinfo, while the desktop backend is launched without a console in studio/src-tauri/src/process.rs:3413; consequently, fresh samples create visible console windows even when no NPU model is loaded. Apply the existing hidden-window subprocess kwargs to both the LUID and engine probes so routine system polling does not repeatedly flash windows.

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.

Not reproducible as described: Desktop starts the backend (unsloth.exe, a console launcher) with CREATE_NO_WINDOW (process.rs), so it owns a windowless console, and powershell.exe children inherit that console by default rather than creating one (Microsoft Learn, Creation of a Console). No new console window is created, and the existing ROCm counter path has used this same helper on Desktop all along.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 13, 2026
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. Another round soon, please!

Reviewed commit: 2baaac5923

ℹ️ 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".

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 13, 2026
meefs pushed a commit to meefs/unsloth that referenced this pull request Nov 14, 2026
…ales (de-DE, fr-FR) because Get-Counter values are formatted with the host culture (unslothai#17520)

On AMD Windows, Unsloth Studio reads GPU utilization from the `GPU
Engine` performance counters through PowerShell. The value was printed
with `-f`, which formats with the host culture, so on de-DE, fr-FR and
other comma-decimal locales each sample came out as `12,5`. Python's
`float()` rejects that, every 3D engine sample was skipped, and GPU
utilization showed as missing.

The counter value is now formatted with
`ToString([cultureinfo]::InvariantCulture)`, in both the shared display
read and the standalone read. It's the same fix the NPU load reader in
unslothai#17508 uses. Infinite, NaN and negative samples are still dropped.

## Tests
`test_rocm_windows_gpu_util_locale.py` uses a fake PowerShell that
prints comma decimals unless the script asks for the invariant culture.
It covers the combined and standalone paths, filtering by adapter, comma
output being skipped rather than misread, and invariant `Infinity`/`NaN`
being dropped. 4 of its 6 tests fail without the fix.

Tested on Windows 11, Ryzen 9 9950X + 2x R9700: the new tests plus the
existing `test_rocm_windows_*` suite (151 passed), and the real counter
scripts run under PowerShell 5.1 with the thread culture forced to de-DE
(the old format printed `12,5`; the new one printed `12.5` and returned
a utilization). Not run on a Windows install whose system locale is
de-DE.

---------

Co-authored-by: Daniel Han <[email protected]>
@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: 6a551e3408

ℹ️ 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".

);
const wantsModels = showShare || showBreakdown;
const [loadedModels, setLoadedModels] = useState<LoadedModelEntry[]>([]);
const [npuStatus] = useNpuStatus();

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 Refresh the monitor's NPU status after enabling the runtime

If the floating monitor is already open when the user enables the NPU from Hub or the model picker, its NPU card stays hidden even after a model loads. useNpuStatus() fetches only on mount when called with its default active = true; its updater changes only the calling component's state and the module cache, without notifying other mounted consumers. This monitor therefore retains ready: false, making npuActive() and npuCard() remain false/null until the monitor is closed and reopened. Subscribe this consumer to shared status updates or refresh its status after NPU setup completes.

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 647582b: useNpuStatus now publishes every status update (fetch or setter) to all mounted consumers, so an open monitor picks up ready once the NPU is set up. Test covers two consumers.

@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. Another round soon, please!

Reviewed commit: 647582b52e

ℹ️ 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 dc4ab1d into unslothai:main Nov 14, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 14, 2026
…nreadable shared iGPU sits beside discrete cards that report usage (unslothai#17523)

On a Windows host with 2x Radeon AI PRO R9700 plus the CPU's integrated
Radeon Graphics, Settings > System > Live monitor reads "Unknown / 65.7
GiB VRAM + 34.3 GiB shared". `/api/system` reports real `vram_used_gb`
for both R9700s (21.75, 1.97), but the iGPU's is null and there's no
host aggregate, so `resolveGpuVramUsedGb` returns null for the whole
tile.

`gpuMemoryDisplay` now moves a shared device with no usage counter into
the shared group when every discrete card reports usage and there's no
host aggregate. The tile then reads 23.7 / 63.7 GiB with free taken from
the same cards, and the iGPU shows on the existing "Shared with system
RAM" line. A host aggregate, an unreadable discrete card, or an APU on
its own behave as before. It doesn't touch unslothai#17509's carve-out logic and
merges cleanly with it.

## Tests
`vram-tile-unreadable-igpu.test.ts` uses the reporter's device list: it
fails on main and passes here. The existing `gpu-memory-display`,
`rocm-windows-vram-aggregate` and `gpu-vram-split` suites still pass,
and so do unslothai#17509's tests on a merge with it.

Tested on Windows 11, Ryzen 9 9950X + 2x R9700 + integrated Radeon
Graphics: frontend unit tests and typecheck. Not checked in the running
app.

## Screenshots

NPU spoofed: fake Lemonade/FastFlowLM on a Windows 11 PC with no NPU; no
speed numbers. Before | after: fork phase stack, phase 4 `49a3094` |
phase 5 `db8d450`. Shot at `db8d450`; this PR's head has since moved to
`80154bb` (`06a0c5d` and `80154bb` drop the "Estimated available:
Unknown" line still visible in these shots). Light mode, mint theme,
glass on, same on both sides.

Before | after, 2x R9700 plus an unreadable iGPU: the VRAM tile reads
"16.4 GiB / 63.7 GiB" instead of "Unknown", with the iGPU on a "Shared
with system RAM" line. The NPU tile is unslothai#17508.

![17523](https://raw.githubusercontent.com/LeoBorcherding/unsloth/213eeb5869056aa16d7170b41f6949f57ee3517a/npu-phases/phase-5/17508-17523-system-live-monitor.png)

Before | after: the floating monitor moves the iGPU under "Shared with
system RAM" next to the two R9700s. The NPU row is unslothai#17508.

![17523](https://raw.githubusercontent.com/LeoBorcherding/unsloth/213eeb5869056aa16d7170b41f6949f57ee3517a/npu-phases/phase-5/17508-17523-floating-monitor.png)

## Before / after (Studio built from merge base and from this branch)

`/api/system`'s `gpu` block stubbed with the reporter's 2x R9700 +
unreadable iGPU reading; everything else is the real server. The VRAM
tile goes from "Unknown / 65.7 GiB VRAM + 34.3 GiB shared" to "23.7 GiB
/ 63.7 GiB, 40 GiB free, Shared with system RAM".
![17523
settings](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/17523/pr17523_pair_01_q-68b0a7e12e33.png)

Floating monitor: the iGPU moves under "Shared with system RAM" beside
the two R9700 rows.
![17523
floating](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/17523/pr17523_pair_00_q-0b9434df5882.png)

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
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