Repository navigation
Studio NPU: pin the AMD-signed FastFlowLM 1.0.13 and hide its decision models - #18553
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Nov 20, 2026
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
[skip ci]
rhsCZ
pushed a commit
to rhsCZ/unsloth
that referenced
this pull request
Nov 20, 2026
…hai#18577) Non-streaming `/v1/chat/completions` on an AMD NPU model never returns `usage`, so the OpenAI SDK reads `usage=None`. Streaming with `stream_options.include_usage` does return it. **Cause.** `_npu_chat_completions` always streams from FastFlowLM and collects the stream for a JSON caller. FastFlowLM sends usage in its own empty-choices chunk, and `_proxy_to_external_provider` drops that chunk unless the payload opts in (`_is_openai_usage_only_sse`). The non-streaming payload never opts in, so `_NpuStreamRelay` never sees usage and the collected body has none. **Fix.** When the caller didn't ask for a stream, set `stream_options.include_usage` on the upstream copy of the payload. Streaming requests are unchanged. **Test.** `test_non_streaming_reply_keeps_a_separate_usage_chunk` makes the fake FastFlowLM send usage the way the real one does: a separate chunk, only on `include_usage`. It fails on main with `KeyError: 'usage'` and passes here. The existing fake put usage inline on the finish chunk, which the proxy never drops, so the existing test passed on main. All 657 NPU backend tests pass (2 skipped). ### Before and after on a Strix Halo NPU Both legs in one job, [run 44657898339](https://github.com/oobabooga/unsloth/actions/runs/44657898339), each a fresh `install.sh --local` in its own home, `unsloth run --model LFM3-1.7B-NPU2 --context-length 4096`, then the same requests. | request | main `3942942` | this PR `7fa1666` | |---|---|---| | `stream: false` | 200, no `usage` key | 200, `usage` with prompt 17, completion 200, total 217, plus FastFlowLM's KV fields | | `stream: false`, `enable_tools: false` | 200, no `usage` key | 200, `usage` present | | OpenAI SDK `chat.completions.create` | `usage=None` | `CompletionUsage(completion_tokens=109, prompt_tokens=17, total_tokens=126, ...)` | | `stream: true` with `include_usage` | usage chunk | usage chunk (unchanged) | | `stream: true`, no `stream_options` | no usage | no usage (unchanged) | The same `usage=None` shows on the v0.1.920-beta release install (tag `2f2490c`) with Qwen3.6-35B-A3B-NPU2 in runs 44644638040 and 44654204267. | machine | what ran | measured at | |---|---|---| | AMD DevLab Strix Halo, Ryzen AI MAX+ 395 (NPU Strix Halo, aie2p 6x8), Ubuntu 24.04.5, kernel 7.0.0-43-generic, amdxdna 2.25.260102.56 (dkms), NPU firmware 1.1.2.65, XRT 2.25.37, FastFlowLM v1.0.12, Lemonade 2026.44.1 | before/after above | `7fa1666` vs `3942942` | Not run: Windows (the route is OS-independent, but nobody ran the Windows NPU path), Strix Point / Krackan / Gorgon Point NPUs, and FastFlowLM 1.0.13 from unslothai#18553. The change is in Unsloth Studio's route only, so it doesn't depend on the NPU part.
Stanley00
pushed a commit
to stanley-fork/unsloth
that referenced
this pull request
Nov 20, 2026
Stacked on unslothai#18553 (signed FastFlowLM 1.0.13). Even with FastFlowLM signed, `lemond.exe` is not: the Lemonade 2026.47.1 zip and the files inside its signed MSI are unsigned. Whether Smart App Control allows `lemond.exe` depends on cloud reputation and changes over time. On the test machine it was refused for most of a day, then allowed. This PR removes Lemonade from the Windows path, so everything Studio starts for the NPU is either Studio's own Python or AMD-signed. ## Design Studio only uses a small slice of lemond: `/v1/health`, `/v1/models` (plus `/{id}/options`), `/v1/install`, `/v1/pull`, `/v1/load`, `/v1/unload`, `/v1/delete`, `/internal/set` and the OpenAI chat routes. FastFlowLM's own CLI already covers that slice (`flm list --json`, `pull`, `serve`, `remove`, `version`). - `core/inference/flm_host.py` (new): serves that slice from Studio's Python and starts the signed `flm.exe`. - Catalog rows keep lemond's ids (`qwen3:0.6b` -> `qwen3-0.6b-FLM`) and labels, so saved chats and settings still resolve. - Load starts `flm serve <tag> --ctx-len N` with any `flm_args`. Health reports `recipe_options.ctx_size` the way lemond does. - Chat is proxied, with the `model` field rewritten to the tag. - flm's output is relayed to stdout, so Studio's load-failure explanations keep working. - It exits, stopping `flm serve`, if Studio dies. - `install_lemonade_prebuilt.py`: on Windows, `install()` downloads the pinned FastFlowLM zip, checks its sha256 and extracts it where lemond's `/v1/install` would. `installed_lemond()` then returns `flm_host.py`. - Linux runs the same way (see below). - `UNSLOTH_NPU_LEMONADE=1` keeps Lemonade on Windows too. - `lemonade_server.py`: a `.py` binary runs on `sys.executable`. - `npu_backend.py` is otherwise unchanged. Enable stops a running server before an upgrade install, since Windows locks the files being replaced. Existing installs migrate on first use. The old `{"lemond": ...}` marker reads as a pending upgrade, so the next catalog read runs Enable. That installs FastFlowLM directly and keeps every downloaded model, which lives in `flm/`, not in the binary folder. ## Testing On a Ryzen AI MAX+ 395 with Smart App Control on: - Fresh Enable takes 7 s: `versions={'lemonade': None, 'fastflowlm': '1.0.13'}` and 58 catalog rows, with the decision models hidden. - Download `qwen3-0.6b-FLM` through `/api/npu/models/.../download`, load it through `/api/inference/load`, then stream and non-stream `/v1/chat/completions`. No `lemond` process exists at any point. - A real UI run against the patched backend (built frontend): pick the model, it loads on the NPU, the answer streams with the Thinking block. Passed in Chromium and Edge. - Migration: a root installed by Lemonade 2026.44.1 with a validated marker switches to `flm_host.py` on first catalog read. The downloaded model still loads and chats. - Found and fixed during these runs: flm prints emoji, and the output relay died on Windows' cp1252 pipe. flm serve then blocked on a full stdout pipe and non-stream chats timed out after 300 s. The relay now writes UTF-8 and never stops draining (there is a regression test). Parity with lemond, on one root (same `flm.exe` and model files), with the same requests sent to `lemond.exe` 2026.44.1 and to `flm_host.py`: - All 72 catalog rows match: ids, checkpoints, labels, sizes, downloaded flags and context windows. - Identical answers for auth, an unknown load (404), an unknown delete (422), pull of a downloaded model, load, health (`ctx_size` 4096), chat (non-stream and stream, same greedy output and usage fields), tools, `/v1/completions`, 3 concurrent chats and unload. - Prompt text kept in Studio's log: 0 for both. flm's output is tagged `(Process)` in lemond's line format, so Studio keeps it only while a load is open, as with lemond. - The one difference: lemond loads a model when a chat names one that is not loaded, flm_host answers 503. Studio never sends a chat without a resident model. Switching paths, through `LemonadeNpuBackend` with a Studio restart each time: Lemonade, Lemonade, direct, direct, Lemonade, direct on the same root. Every run passes Enable twice, lists the same 58 rows, keeps the downloaded model, loads it and gets the same answer. `lemond.exe` runs only on the Lemonade runs. `lfm2.5-it-1.2b-FLM` downloaded fresh through each path gives byte-identical files, and loads, answers and deletes the same way. Unit tests in `tests/test_npu_flm_host.py` (17 cases) pass on Windows and Linux. They cover: - catalog mapping, the context window from the downloaded config, and auth (only `/live` is open) - flm output tagged `(Process)` so prompts stay out of Studio's log - install, plus pull complete and error events - load with ctx and `flm_args`, health, a chat proxied by tag, and unload - a failed load naming flm's reason, and delete of a serving model - `[ERROR]` printed with exit code 0 counting as a failure - the direct install's layout, reuse and pin change - when Lemonade is still used, and the `.py` launcher Existing NPU suites: 475 passed on Linux, 188 on Windows. `ruff-unsloth` format is AST-identical and `ruff check` passes. Not covered: macOS (no NPU path), and Linux NPU hardware. Linux behaviour is unchanged. ## Linux too, and hardware results Linux now runs FastFlowLM through `flm_host.py` as well, so no platform starts Lemonade. `UNSLOTH_NPU_LEMONADE=1` still selects lemond. Checked on the AMD Strix Halo runners (Windows 11 and Ubuntu 24.04, XDNA2 NPU), current `main` against this branch on the same machine, plus lemond 2026.44.1 on the same FastFlowLM 1.0.13 files as a reference: - Windows `main` starts `lemond.exe` and nothing else unsigned; this branch starts only `python.exe` (PSF), `conhost.exe` and AMD-signed `flm.exe`, and never `lemond.exe`. - flm_host matches lemond on all 72 FastFlowLM catalog rows, the Studio catalog before and after a download, load context, health, options, greedy answers (stream and non-stream), usage tokens, finish reasons, the 404 / 422 error statuses and pull. - A second Enable after a restart changes none of FastFlowLM's files and downloads nothing. A `main` install with a downloaded model switches to flm_host on first use and keeps the model. - `xrt-smi examine -r aie-partitions` lists the `flm serve` process during generation, on both hosts. - Decode speed through flm_host equals lemond's (101 tok/s on Qwen3-0.6B), and time to first token matches (0.61 s each) after pooling the upstream client and turning off Nagle for the event stream. Settings > About for an NPU running FastFlowLM without Lemonade (the NPU status is stubbed the same on both sides; the llama.cpp and environment rows differ only because they had not loaded yet on the left):  --------- Co-authored-by: oobabooga <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FastFlowLM re-uploaded its v1.0.13 Windows assets today with Authenticode signatures from AMD (
flm.exe,flm-setup.msiand 40 of the DLLs). v1.0.12, which Studio pins now, is unsigned. On a machine with Smart App Control on, Windows refusesflm.exeor one of its statically linked model DLLs, and the NPU never works.Changes
lemonade_prebuilt_pins.json: FastFlowLM v1.0.12 -> v1.0.13, written byscripts/update_lemonade_pins.py --only fastflowlm --write. The Windows sha256c1746055...is the signed re-upload. Lemonade stays at 2026.44.1.npu_backend.py: hidedecisionmodels from the chat catalog. 1.0.13 adds sevend3:*decision models that lemond labelschat, butflm serve d3:edgerefuses to start ("is a decision model: serve it withflm serve --decision"), so picking one failed the load.fake_lemond.py: a decision row, so the existing catalog test covers the exclusion.Testing
On a Ryzen AI MAX+ 395 with Smart App Control on:
flm.exeand its DLLs load with no Code Integrity blocks.flm validate --jsonreportsready: true; with v1.0.12 the same machine exits0xC0E90002with no output.qwen3-0.6b-FLMthrough Studio, loading it and chatting all work.d3-edge-FLM, and loading it failed withFastFlowLM failed to start.NPU backend suites: 475 passed on Linux (WSL).
test_npu_backend.py::test_catalog_keeps_flm_chat_models_onlycovers the decision row.The unsigned leftovers in the zip (
abseil_dll.dlland the threelibprotobuf*DLLs) are not imported byflm.exe, and nothing in them was blocked during the runs above.