Skip to content

[Bug] AMD NPU: hand-kept model lists drift from the installed FastFlowLM and converter (Qwen3 14B offered, LFM3 hidden) - #18050

Merged
danielhanchen merged 12 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-compat
Nov 18, 2026
Merged

danielhanchen merged 12 commits into
unslothai:mainfrom
LeoBorcherding:studio/npu-compat

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

NPU model support now comes from what is installed instead of hand-kept lists:

  • GET /api/npu/compat (core/inference/npu_compat.py) reads FastFlowLM's model_list.json, each catalog model's config.json (downloaded copy, else its Hugging Face repo, cached per listing) for layers / hidden size / experts, and the pinned Q4NX converters' ModelArchNames and _QWEN35_GEOMETRY, parsed with ast and never imported. It never starts the runtime.
  • One tag per model: "Runs on NPU", "Convert, then runs", "Converts, won't run", "Not supported", shown in the composer picker, the Hub NPU list and the Q4NX convert card.
  • Removed the hand-kept Q4NX_ARCHITECTURES / Q4NX_SIZES (frontend) and _NPU_SHAPES (backend export guard).
  • NPU_POPULAR, six checkpoints, replaces [Feature] AMD NPU: list new models that run on a Ryzen AI laptop first in the picker and Hub #17513's recommended list as the one order every NPU list uses.
  • The composer picker names NPU rows with [Feature] AMD NPU: name NPU models by their Hugging Face repo instead of the Lemonade ID #17610's npuDisplayName and orders Discover's NPU rows with npuRowsFor.

Base mirror-base/npu-compat is upstream main at a2b1f68.

Screenshots

Composer model picker, On Device tab. Both Studios were built from source (left: the merge base, right: this PR). The /api/npu/* answers come from a real Strix Halo XDNA2 capture and the FastFlowLM 1.0.12 compat table. Each NPU row now shows its support tag ("Runs on NPU").

Before and after

Without a supported NPU, GET /api/npu/compat returns an all-unknown table and installs and fetches nothing (checked on a CPU host and on a Colab T4).

@danielhanchen
danielhanchen marked this pull request as ready for review November 18, 2026 06:59
@danielhanchen
danielhanchen self-requested a review as a code owner November 18, 2026 06:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 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-18T09:02:11.641769Z 2932ed9 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.

@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: 4da7136d36

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

config.json, else its Hugging Face repo, cached on disk per model_list.json."""
if flm_binary is None:
return None
listing_path = flm_binary.parent / "model_list.json"

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 Reuse the supported FastFlowLM manifest locator

On installations that keep manifests in share/flm rather than beside bin/flm, this hard-coded path returns None, even though that layout is already supported by npu_local_models.find_flm_list. Consequently, /api/npu/compat stays unknown and the replacement geometry gate skips validation for every export, allowing unsupported geometries such as Qwen3.5-122B-A10B to reach the converter's fixed 35B-A3B configuration. Use the shared manifest locator here and for the manifest stamp in current().

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 fa34949: flm_shapes and the cache stamp now use npu_local_models.find_flm_list, so a share/flm manifest is read.

Comment on lines +182 to +184
shapes = runnable.get(arch)
if not shapes:
raise RuntimeError(

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 supported Nanbeige architecture alias

For a supported Nanbeige4.1-3B GGUF whose general.architecture is nanbeige, the compatibility table contains its (32, 2560, 0) geometry only under llama, so this new branch aborts the export. The pinned converter still lists nanbeige, and npu_local_models._FLM_BASES['nanbeige'] explicitly supports loading this shape; the previous gate also allowed this architecture through. Normalize the alias or emit an equivalent runtime row before interpreting a missing architecture key as a lack of kernels.

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 fa34949: build_compat adds the Nanbeige llama shape under the nanbeige architecture too, so the export gate and the UI accept it.

? lower.includes("omni") || (matched.length > 0 ? matched.some((s) => s.converts) : !sized)
: !!converter &&
(converter.architectures.includes(arch) ||
converter.basenames.some((prefix) => repoName(lower).startsWith(prefix)));

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 Check the selected filename before refusing basename-routed models

For a valid Qwen2.5-VL-3B GGUF in a renamed Hub repository, the card can pass acme/vision-GGUF Qwen2.5-VL-3B-Instruct-Q4_0.gguf, but repoName() discards the selected filename and tests only vision-GGUF. This reports converts=false, causing q4nxArchFit to return unsupported and disable Convert even when the GGUF retains a supported general.basename. Check the available filename evidence, or leave conversion unknown, rather than making the Hub repository name a conversion requirement.

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 fa34949: basename routing now checks every name passed (repo id and file), so a renamed repo with a Qwen2.5-VL file converts.

…lama shape, check file names for basename routing

[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: fa349490c7

ℹ️ 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 +89 to +90
const matched = shapes.filter((s) => s.sizes.some((size) => namesSize(lower, size)));
const sized = matched.length > 0 || NAMED_SIZE.test(lower);

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 Account for rounded catalog size aliases before rejecting a model

For a supported Phi-4-mini GGUF whose repository or selected filename includes 3.8B, matched is empty because FastFlowLM labels the same (32, 3072, 0) model phi4-mini-it:4b. NAMED_SIZE then makes sized true, causing npuFit to report convertOnly; q4nxArchFit turns that into unsupported and disables Convert even though the backend accepts its geometry. Treat rounded catalog sizes as aliases, or leave an unmatched size unknown until the GGUF geometry is checked, rather than treating an exact token mismatch as proof of missing kernels.

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: real Phi-4-mini GGUF repos and files (unsloth/Phi-4-mini-instruct-GGUF and the like) carry no size token, so they reach the shapes-only path. Matching sizes exactly is what lets the tag tell 14B apart from 8B.

Comment on lines +297 to +299
.map((r) => ({ r, fit: q4nxArchFit(r.ggufArchitecture, r.id, npuCompat) }))
// "Not supported" is left out; a model that runs or only converts stays, tagged.
.filter(({ fit }) => fit.tag !== "unsupported")

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 Retain basename-routed search results until filenames are available

For a generic Hub search returning a supported Qwen2.5-VL-3B GGUF from a renamed repository such as acme/vision-GGUF, this call receives only the repository ID and returns tag: "unsupported", so the filter removes the model before its files can be selected. Although selected-filename matching is fixed, this search path still passes only r.id; passing the supported filename later cannot restore a result that was already filtered out. Preserve basename-dependent results as unknown until filename evidence is available instead of hiding them.

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: a Qwen2.5-VL GGUF in a repo renamed to drop its model name is an edge case, and the selected-file path already reads the file name. Hiding search rows that only a file name could rescue keeps the list honest for every normally named repo.

export function useNpuCompat(active = true): NpuCompat | null {
const [compat, setCompat] = useState<NpuCompat | null>(cached);
useEffect(() => {
if (!active || cached) return;

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 cached compatibility after a runtime upgrade

If Export reads compatibility before Model Hub performs its existing deferred runtime upgrade (useNpuCatalog → refreshNpuModels → NpuBackend._ensure_running), the first successful table remains cached for the entire frontend session. This guard prevents even remounting Export from requesting the updated table, so the backend's manifest-stamp invalidation is never observed and newly supported models remain disabled or hidden until a full page reload. Invalidate or version this cache when NPU status reports a changed FastFlowLM version.

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 33f3fe9: the hook re-reads the table on every mount (the backend memoizes per installed FastFlowLM), so an upgrade shows without a reload.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 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 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: 33f3fe9666

ℹ️ 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 thread studio/backend/core/export/q4nx.py Outdated
Comment on lines 180 to 181
if not arch or runnable is None or (arch == "qwen35" and any("omni" in n for n in names)):
return

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 Preserve fixed-config geometry checks when the catalog is unreadable

On a supported, ready NPU with an incomplete shape cache, a single unavailable catalog config (offline or an HTTP error) makes flm_shapes() return None, so this branch bypasses every geometry check even though FastFlowLM is installed. Using the fixture manifest with only LFM3's config unavailable lets a qwen35moe GGUF with geometry (48, 3072, 256) pass; fetching that unrelated config makes the same input fail. This reopens the unsupported 122B-A10B path into the converter's fixed 35B-A3B configuration, potentially producing an invalid export instead of refusing it. Preserve converter geometry validation, or refuse an unverified fixed-config model, when runtime compatibility is unknown.

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 33f3fe9: when FastFlowLM's table is unknown, qwen35moe (the one architecture the converter configures by name alone) is still held to the 35B-A3B shape, so 122B-A10B is refused as before.

@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: 2932ed9385

ℹ️ 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 b072c74 into unslothai:main Nov 18, 2026
danielhanchen added a commit that referenced this pull request Nov 18, 2026
## Read the NPU compat fixtures as UTF-8


`tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding`
fails on `main` since #18050. It shows up on unrelated PRs as `Repo
tests (CPU, rest-2)`, for example #18104 and #17627:

```
E   AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding ...
E     Left contains one more item: 'studio/backend/tests/test_npu_compat.py:18: read_text()'
```

### Cause

#18050 added two reads of the checked-in fixture
`fixtures/npu_compat/hf_configs.json` that call `.read_text()` with no
encoding:

- `studio/backend/tests/test_npu_compat.py:18`
- `studio/backend/tests/test_export_npu_q4nx.py:677`

Without an encoding, Python decodes with the platform default, which is
the ANSI codepage on Windows. The lint fails that as soon as a fixture
gains a non-ASCII byte.

### Fix

Both reads now pass `encoding = "utf-8"`. The fixture is JSON, so it is
UTF-8 by definition. Nothing else changes.

The other bare `.read_text()` in `test_npu_compat.py`, at line 88, reads
a file the test itself wrote into `tmp_path`. The lint deliberately
leaves those alone, so it is unchanged.

### Verification

- `tests/test_source_read_encoding.py`: fails on `main` on both lines
and passes with this change (16 passed).
- `tests/test_npu_compat.py` and `tests/test_export_npu_q4nx.py`: 96
passed.
- ruff is clean.
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.

2 participants