Repository navigation
Conversation
…ma 4 at 16k Moves the `--rai` backend from ryzenai-corelib 0.11 to 0.26 and builds on what the new corelib offers. corelib 0.26 (pinned exactly): - Follow the ABI changes: `create_tensor_window` takes strides, `linear_attention_bf16` takes rows, and models are built with `model_weights_create_path` + `model_create`. - A 3-D matmul output that writes the KV cache is a strided window `[max_seq*head, head, 1]` (Phi-4, Qwen3, Qwen3.5 V writes; Gemma 4 E4B staging window). - Per-op engines open their stream through `corelib::OpenModelStream`, which enables the model's kernel bundle before any kernel query. - corelib's per-model libraries are copied beside `flm.exe` on Windows and beside corelib by `home_install.sh` on Linux. Nothing needs `RYZENAI_CORELIB_DD_ROOT` or `RYZENAI_CORELIB_KERNELS_ROOT` any more. Qwen3.6-35B-A3B (new `qwen3.6-moe-rai:35b-a3b`, text only): - Runs on corelib's model API; context up to 262144 in 4096-row pages, a prompt is a single `model_forward`, and checkpoint/restore use corelib state snapshots. - Fetch logits only for the row that gets sampled. Gemma 4: - Context of 1..4096 on flat attention, or a multiple of 4096 up to 16384 on corelib paged attention; the aie_next catalog entries default to 16384. A paged continuation starts from its own page. - `gemma4-it-rai:e4b` is offered again. Shared: - `Sampler::sampler_topk_apply` selects top-k with a k-entry heap in one pass (same ranking and tie rule). Tests: new `src/test/qwen36_rai`, and the Gemma 4, Phi-4 and Qwen3 rai tests and fake corelib follow the 0.26 ABI and the 16k paged context. Co-authored-by: Cursor <cursoragent@cursor.com>
Qwen3, Qwen3.5 and Gemma 4 on the `rai` backend stop driving corelib op by op and run as corelib's own models (`ryzenai_corelib_model_*`), the way Qwen3.6 already does. All four share one engine and one backend; each model is a short spec. Phi-4 is unchanged (corelib's `phi4mini` takes ONNX only, and FastFlowLM ships a GGUF). - `flm::rai::CorelibModel` (`rai/corelib_model`): a `causal_lm` over a corelib model, generalized from the Qwen3.6 engine. `ModelSpec` states where a multi-row pass may start (`Continuation`: anywhere, only at 0, or at 0 / a 4096-row page boundary) and how to rewind (`Rewind`: seek, state snapshot, or reset and replay). Token ids and the context limit are checked before corelib is called; a failed forward, restore or reset poisons the engine. - `flm::rai::Factory(BackendSpec)` (`rai/corelib_model_backend`): refuses preemption and a context outside the model's rule, reads the package's BOS/EOS ids, and resolves the GGUF before the runtime or weights are touched. - Removed: the per-op engines, GGUF readers, shape plans and host math of Qwen3, Qwen3.5 and Gemma 4; `rai/gguf_file`, `rai/weight_cache`, the Q8/RMSNorm parts of `rai/host_ops`, and 14 unused corelib entry points. corelib packs the weights on every load; old `<gguf stem>.rai-weights.bin/.json` files can be deleted. - Tests: new `src/test/rai_model` (engine and backend against the fake corelib; the Qwen3.6 tests move here). Gemma 4's registry, catalog and server-gate tests move to `test_gemma4_registry.cpp`; the op-level Gemma 4 and Qwen3 suites are gone. Gemma 4 is slower on corelib 0.26's built-in model than on the per-op engine (prefill ~1.5-2x, decode 24-29% slower, slower loads). The cause is in corelib's host per-layer-embedding projection and serial weight packing; FastFlowLM picks up the fix with a corelib version bump. Co-authored-by: Cursor <cursoragent@cursor.com>
…efill chunks to pages corelib 0.28 pages Qwen3.5's KV cache up to 32768 and runs Qwen3.6's prefill past page 0 in whole-page passes. A later turn's prompt is now chunked on multiples of 4096 counted from position 0, so its chunks start on page boundaries. Co-authored-by: Cursor <cursoragent@cursor.com>
No ABI change FastFlowLM meets. 0.29 speeds up Gemma 4's per-layer-embedding projection and runs Qwen3.6's prefill chunks inside a page on the NPU. Co-authored-by: Cursor <cursoragent@cursor.com>
This branch has not been deployed
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.
Follow-up to #748. Moves the
raibackend from ryzenai-corelib 0.11 to 0.29.2, adds Qwen3.6-35B-A3B, runs Gemma 4 at 16k and Qwen3.5 at 32k, and has Qwen3, Qwen3.5, Gemma 4 and Qwen3.6 run as corelib's own models behind one shared engine.Commits:
ryzenai_corelib_model_*, like Qwen3.6. Phi-4 stays per-op.Models
qwen3.6-moe-rai:35b-a3bgemma4-it-rai:e2bgemma4-it-rai:e4bqwen3-rai:*qwen3.5-rai:9bphi4-mini-it-rai:4bWhat changes
corelib 0.29.2 (version pinned exactly)
create_tensor_windowtakesstrides,linear_attention_bf16takesrows, and models are built withmodel_weights_create_path+model_create(name, weights, options).[max_seq*head, head, 1], and opens its stream throughcorelib::OpenModelStream, which enables the model's kernel bundle before any kernel query (a new stream resolves no kernels on its own).Packaging
ryzenai_corelibplus oneryzenai_corelib_model_<name>library per model and loads them only from its own directory. A Windows rai build copies them besideflm.exe;home_install.shcopies them beside corelib on Linux.RYZENAI_CORELIB_DD_ROOT/RYZENAI_CORELIB_KERNELS_ROOTare no longer needed, and the installer stops staging DynamicDispatch.One engine:
flm::rai::CorelibModel(include/rai/corelib_model.hpp,common/rai/corelib_model.cpp)causal_lmover a corelib model. Each model is a shortModelSpecnaming what differs:Continuation: where a multi-row pass may start past position 0 — anywhere (Qwen3.5, Qwen3.6), only at 0 (Qwen3, so a later prompt re-runs the conversation), or at 0 / a 4096-row page boundary (Gemma 4).Rewind:kSeekfor attention-only models (every pass states its position; rewind just moves it),kSnapshotfor Qwen3.6 (model_state_save/restore, reused only if its history is a prefix of the current one),kReplayfor Qwen3.5 (reset and replay).One backend:
flm::rai::Factory(BackendSpec)(include/rai/corelib_model_backend.hpp)tokenizer_config.json+config.json, e.g. Gemma 4 → {1, 106}), and resolves the GGUF before the runtime or weights are touched. Image requests on rai return HTTP 400.Page-aligned prefill chunks (
AutoModel::_chunked_insert,model_backend.hpp)ModelBackend::aligns_prefill_chunks(), defaultfalse, so FastFlowLM's own engines are unaffected. The corelib-model backend returnstrue: a later turn's prompt is chunked on multiples of 4096 counted from position 0 instead of from the turn's start, so every chunk after the first starts on a page boundary and corelib runs it as whole pages on the NPU. Prompts carrying a multimodal payload keep the old chunking.Removed
rai/gguf_file,rai/weight_cache, the Q8/RMSNorm parts ofrai/host_ops, and 14 corelib entry points nothing calls.<gguf stem>.rai-weights.bin/.jsonfiles can be deleted.Shared
Sampler::sampler_topk_applyselects top-k with a k-entry heap in one pass instead ofpartial_sorting a vocab-sized array each token. Same ranking and lowest-id tie rule; checked against the old code on 63 inputs (vocab 1..248320, k = 1/2/20/40, heavy ties).Docs:
src/common/models/README.mdgains a section on models corelib runs whole;docs/rai-setup-linux.mdand the model pages cover 0.26 and the dropped weight cache.Results
All on an
aie_nextNPU, Windows.Unit tests (fake corelib):
rai_model(new: 36 engine tests covering everyRewind/Continuationcombination, poisoning and capacity, plus 14 backend tests),phi4_rai,gemma4_raipass. The real-package tokenizer test was skipped.This PR (corelib 0.29.2) vs before — "before" is the first commit's build on corelib 0.26: the per-op engines for Phi-4, Qwen3, Qwen3.5 and Gemma 4, and Qwen3.6 on corelib's model API. Both builds run interleaved, Gemma 4 twice each, with the NPU checked idle before and after every run. Long-prompt TTFT is the median of three ~1.1k-token prompts; decode is the median over three short prompts, 64 greedy tokens each.
gemma4-it-rai:e2bgemma4-it-rai:e4bqwen3.6-moe-rai:35b-a3bqwen3.5-rai:9bqwen3-rai:0.6bphi4-mini-it-rai:4b(per-op in both)* This PR's Phi-4 run had no weight-cache directory set, so it packed on load; the "before" run loaded from its cache.
Loads are slower for Gemma 4 and Qwen3 because corelib packs the weights on every load and this path has no packed-weight cache.
Two-turn continuation at
--ctx-len 16384: turn 1 is ~6.8k tokens carrying a passkey; turn 2 resends it with the reply and adds ~6.9k tokens, chunked on page boundaries (1395 / 4096 / 1414).qwen3.6-moe-rai:35b-a3bgemma4-it-rai:e2bMeasured on the second commit (corelib 0.26):
flm serveprocess: every answer matches a fresh run, no errors.Long-context passkey recall (passkey at 45% depth, measured on the first commit):
gemma4-it-rai:e2bgemma4-it-rai:e4bqwen3.6-moe-rai:35b-a3bGemma 4 on corelib's built-in model. On corelib 0.26 it was slower than the per-op engine (prefill ~1.5–2×, decode 24–29% slower), because of corelib's host per-layer-embedding projection. corelib 0.29 fixes that projection: prefill is now faster than the per-op engine, and decode is equal on E4B and ~5–8% lower on E2B. Loads stay slower, as above.
Not done yet
main(merge was clean; the merged tree has not been built)flm_raiand thehome_install.sh --raismoke test