Skip to content

[Feature] AMD NPU: Settings > Storage counts and lists downloaded NPU models and deletes them per folder through Lemonade - #17535

Merged
danielhanchen merged 19 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-models-in-storage
Nov 14, 2026
Merged

danielhanchen merged 19 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-models-in-storage

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Settings > Storage had no NPU row, so FastFlowLM model downloads under the NPU model path were invisible and could only be removed from the NPU picker one chat model at a time. Embeddings, transcription and single-turn models, and partial pulls kept for resuming, had no way to be deleted at all.

Storage now measures the NPU model folder and lists each model folder with the checkpoint from FastFlowLM's manifest. Per-folder delete and bulk Clear go through lemond (/v1/delete), never rmtree, so its registry stays in sync with the disk. They cover every FastFlowLM model lemond lists, not just the chat catalog, plus any registered model with files on disk. Neither will delete a model while it's downloading, and a download asked for during a delete is refused right away rather than waiting on it. Folders lemond doesn't own are left alone.

Tests

tests/test_npu_storage.py covers size, listing, per-folder and bulk delete, hidden non-chat checkpoints, partial pulls, refusing during a pull, and refusing a pull during a delete without blocking. The frontend npu-api and npu-storage-rows tests cover the client.

Tested on Windows 11, Ryzen 9 9950X + 2x R9700, no NPU: backend unit tests with lemond and the FastFlowLM manifest mocked. 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 2 945ba98 | phase 3 3669e68. Shot at 3669e68; this PR's head has since moved to 43ef4b7 (backend and test changes only). Light mode, mint theme, glass on, same on both sides.

Before | after: Settings > Storage gets an "AMD NPU models" row with a warning that Clear deletes them. It reads 0 B because the fake lemond writes no model files.
17535

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

Settings > System > Storage > Details: downloaded NPU models are listed with their size and folder, with a clear action.

Before and after

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 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-13T19:56:32.021638Z 99e342f 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: 70d31f5fd4

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

Comment on lines +589 to +590
const isModels = (entry: (typeof cache.entries)[number]) =>
entry.key === "hf_hub" || entry.key === "npu_models";

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 Attribute NPU storage to the folder's actual disk

When UNSLOTH_STUDIO_HOME is on a different volume from the disk reported by /api/system, this counts its NPU models in the system disk's Models segment. describe_cache() only computes device-aware system_disk_bytes for Hugging Face caches, so the NPU entry receives null; diskBytes() then uses its full size because the NPU directory is outside hfCache.cacheHome. Consequently, models on another disk inflate system-disk usage attribution and incorrectly reduce the Other segment. Supply device-aware system_disk_bytes for npu_models, or otherwise check its volume before counting these bytes here.

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 changing this: Settings already counts every cache outside the Hugging Face folder (uv, pip, the compile caches under the Studio home) on the system disk; NPU models follow the same rule, and a Studio home on another volume moves those rows too.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@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: 99e342f1f2

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

Comment on lines +772 to +775
resident = self.resident()
if resident is not None and resident.model.id in model_ids:
raise NpuError(f"Unload {resident.model.id} before deleting this folder.")
with reserve(model_ids):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Lock the folder-level resident check against concurrent loads

When another tab loads a shared-folder twin during a Storage delete, the resident snapshot here can run before load() commits; the first delete() then waits for the load's _lock, but afterward only checks the exact model ID. For example, clearing gemma4-it:e2b can therefore delete the newly resident gemma4e-flash:e2b weights through the other ID before the loaded twin is refused. Unlike the already-fixed resident-at-start case, the additional concurrency evidence is that load() holds _lock while these group-level checks run outside it. Hold _lock across the folder-level residency check and all member deletes, including the corresponding bulk-clear path.

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 changing this: Studio cannot load a -flash twin (single-turn models are kept out of the catalog and load() resolves only catalog ids), so the example cannot happen; the remaining case needs a second tab to start a load inside the delete itself.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 99e342f1f2

ℹ️ 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/frontend/tests/npu-api.test.ts

[skip ci]
# Conflicts:
#	studio/backend/core/inference/npu_backend.py
#	studio/backend/routes/npu.py
#	studio/frontend/src/features/npu/api.ts
#	studio/frontend/tests/npu-api.test.ts

[skip ci]
# Conflicts:
#	studio/backend/core/inference/npu_backend.py

[skip ci]
@danielhanchen
danielhanchen merged commit ce3e500 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