Skip to content

Studio NPU: read the FastFlowLM model list when flm prints more after it - #18806

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
debojyoti-dev:fix/flm-list-trailing-output-18763
Nov 23, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
debojyoti-dev:fix/flm-list-trailing-output-18763

Conversation

@debojyoti-dev

@debojyoti-dev debojyoti-dev commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Related to #18763

What this changes

Since #18554, Studio lists NPU models through flm_host.py on Windows and Linux. Flm.catalog() ran flm list --json, joined stdout and stderr, and passed everything from the first { to json.loads. When flm prints anything after the JSON (a runtime notice on stderr, a status line on stdout), json.loads raises Extra data: line N column 1, and the whole NPU model list fails with that message, as in the report (v0.1.922, FastFlowLM 1.0.13).

catalog() now reads only the JSON object that holds models (json.JSONDecoder().raw_decode, tried at the first brace and at braces that start a line) and skips the text around it. If no such object is found, the error names flm's output (flm list failed: ...) instead of a JSON parser position.

Tests

  • test_npu_flm_host.py: the model list with a line after it on stderr, a line after it on stdout, and a status line before it; a truncated list reports flm's output.
  • End to end on Windows (no NPU here): a stand-in flm.exe printing the FastFlowLM 1.0.13 model list (rebuilt from its model_list.json the way flm list --json dumps it) followed by one stderr line. Only the NPU hardware probe was replaced; Studio started the real flm_host.py process and GET /api/npu/models went through routes/npu.py.
    • main: 409 Listing NPU models failed: Extra data: line 2580 column 1 (char 93218)
    • this PR: 200, 45 chat models
    • without the extra line, both list the same 45 models.
  • test_npu_flm_host.py + test_npu_backend.py: 28 passed with this change, 24 on main (test_npu_backend.py is skipped on Windows).
Before After
before after

Not tested on a real Ryzen AI NPU or on Linux.

Maintainer validation (AMD CI, real Strix Halo NPU)

Ran on the gfx1151 pool with the pinned FastFlowLM 1.0.13 (flm list --json, validate, version) and Flm.catalog() at main versus this branch:

host scenario main this PR
Linux, amdxdna loaded, /dev/accel/accel0 no models, 2 models pulled by 1.0.13, 2 pulled by 1.0.12 then listed by 1.0.13, 8 MiB memlock, a second flm serve holding the NPU 59 models listed 59 models listed
Windows 11, NPU Compute Accelerator (17F0), validate ready default 72 models listed 72 models listed

On these hosts flm prints nothing around the JSON, so they list on main too and this is a no-regression check. The reporter's error offset (line 2025, char 73430) is exactly the end of the 1.0.13 model list JSON with 7 models installed, so the failure is text printed after the list, which this change skips.

flm_host joined flm list --json stdout and stderr and parsed everything
after the first brace, so any line flm printed after the JSON failed the
whole NPU model list with "Extra data: line N column 1". Read just the
JSON object that holds "models" and skip text around it.

Fixes unslothai#18763
danielhanchen added a commit that referenced this pull request Nov 21, 2026
…p dunders spreading the decode-rewrap scan (#18815)

## Problem

`(Python 3.13, diffusion)` fails on `main` and on every PR based on it
(for example #18806) with two failures:

```
test_diffusion_family_data_freeze.py::test_family_data_resolves_identically   AssertionError: tables
test_diffusion_vae_oom.py::test_every_decode_rewrap_site_restores_the_oom_scope  510 sites flagged, first ('diffusion.py', 'DiffusionBackend.__init__')
```

Both reproduce locally on `main` (`d8ff4de6a1`). Running both tests on
each Studio inference commit since the last green `main` attributes
them:

| commit | freeze | decode rewrap |
|---|---|---|
| `8d41610c50` (#18800) | pass | pass |
| `d66aa77cee` (#18779) | fail | pass |
| `6f4c2a7bd9` (#18780) | fail | fail |

## Causes

**Family data freeze (#18779).** #18779 adds the dense FastWan students
as trusted video repos. The frozen table was not regenerated, so the
only difference is two new `trusted_video_repos` entries,
`fastvideo/fastwan2.1-t2v-1.3b-diffusers` and
`fastvideo/fastwan2.2-ti2v-5b-fullattn-diffusers`. The PR is right; the
fixture is behind.

**Decode-rewrap scan (#18780).** The test seeds every function that
assigns `.decode`, then marks any function that calls one of those *by
bare name* as a rewrap helper too, to a fixpoint. #18780's opt-in draft
decode is a context manager, `TinyVaeDraftDecode`, which swaps
`vae.decode` in `__enter__` and restores it in `__exit__`. That made
`__enter__` and `__exit__` seeds, and a bare-name match on `__exit__` /
`__enter__` reaches every function that drives any context manager by
hand, so the fixpoint spread to 510 functions. The draft swap itself is
scoped and restores the previous `decode` on exit, and its fallback
calls the decode it replaced, so the OOM scope is intact. The PR is
right; the scan's name matching is too loose for dunders.

## Fix

Test-only:

- `tests/fixtures/diffusion_family_data_freeze.json`: regenerated with
`UNSLOTH_FREEZE_UPDATE=1`. The diff is exactly the two FastWan repos (2
lines added).
- `test_every_decode_rewrap_site_restores_the_oom_scope`: dunder method
names are not propagated by name. A dunder is reached through `with` or
an object protocol, never by a call to that name, so matching it by name
cannot identify a caller. Named helpers such as `install_untiled_decode`
still propagate as before.

## Verification

- `test_diffusion_family_data_freeze.py`, `test_diffusion_vae_oom.py`,
`test_video_tiny_vae.py`, `test_video_tiny_vae_wiring.py`: 134 passed, 5
skipped.
- Sabotage: adding `def _sabotage_leak(vae):
install_untiled_decode(vae)` to `video.py` fails the rewrap test with
`[('video.py', '_sabotage_leak')]`, so a real unguarded rewrap is still
caught. Restored afterwards.
- The freeze fails on `main` without the regenerated fixture, as on CI.
@danielhanchen danielhanchen self-assigned this Nov 22, 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 22, 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-22T15:52:33.330745Z 00d198e 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

Copy link
Copy Markdown

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

Reviewed commit: 00d198e4e7

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

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