Skip to content

Add stable model extension support - #874

Merged
zaneni6 merged 2 commits into
ROCm:mainfrom
jtuyls:users/jtuyls/frontend-extensions
Nov 9, 2026
Merged

zaneni6 merged 2 commits into
ROCm:mainfrom
jtuyls:users/jtuyls/frontend-extensions

Conversation

@jtuyls

@jtuyls jtuyls commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a stable C ABI for externally supplied FastFlowLM model frontends and backend providers.

Extensions can contribute:

  • New frontend families: Add support for architectures FLM does not understand yet, including configuration, prompt formatting, preprocessing, and output decoding.

  • Alternative backend providers: Supply a different engine for an existing family/backend without replacing the built-in implementation globally.

  • Model catalog entries: Add selectable model tags with their frontend family, backend/provider, model files, limits, and platform compatibility.

  • Extension-local runtime assets: Package engine-specific artifacts such as XCLBINs with the extension instead of rebuilding FLM or using global path overrides.

The existing built-in model path remains the default.

Rationale

Adding or replacing a model engine previously required changing and rebuilding FastFlowLM. External engines were coupled to internal C++ classes, registries, global state, and compiler/CRT compatibility.

This change allows independently built model implementations to plug into FastFlowLM without:

  • Linking against FLM C++ implementation symbols.
  • Recompiling FLM with engine overrides.
  • Replacing a built-in engine globally.
  • Using global XCLBIN path overrides.
  • Matching FLM's compiler or C++ standard-library ABI.

Gemma4-open validates the design as an external text, image, and audio provider on XRT and HRX.

Core concepts

Frontend

A frontend owns model-facing behavior:

  • Model configuration and tokenizer setup.
  • Prompt and chat preparation.
  • Image/audio preprocessing.
  • Construction of model-specific prefill payloads.
  • Output decoding.

A frontend is selected by details.family.

Built-in frontends remain registered by FastFlowLM. An extension may register a new frontend family or provide both ends of a private model-specific payload contract.

Backend

A backend identifies the execution contract or kernel flow used by a model package, such as flm or core.

It describes package compatibility and how the frontend should prepare the engine context. It is not the identity of the library implementing that backend.

Backend provider

A provider is one implementation of a backend contract.

Backend registrations are keyed by:

family / backend / provider

For example:

gemma4e / flm / builtin
gemma4e / flm / gemma4-open

This allows an external provider to implement the same logical backend without replacing the built-in implementation. The model catalog selects the exact compatible provider.

For multimodal entries, frontend_provider identifies the producer of opaque prefill payloads. This prevents a backend from receiving payloads generated by an incompatible frontend.

Extension bundle

extension.json is the bundle manifest. It describes how to load an extension:

  • Manifest schema version.
  • Extension name and version.
  • Platform-specific native library.
  • Optional catalog overlay.
  • Optional asset root.

All paths are bundle-relative.

The manifest describes the extension bundle, not the selectable models.

Catalog overlay

The catalog overlay contributes model tags and package metadata. It specifies:

  • Model family.
  • Backend contract.
  • Exact backend provider.
  • Frontend provider where required.
  • Context and prefill limits.
  • Supported platforms and normal model metadata.

Overlays cannot replace built-in tags. They are parsed and validated against staged frontend and backend registrations before anything is committed.

Both manifest and overlay formats have versioned JSON Schemas.

Stable ABI design

The public boundary is C-only and uses:

  • Versioned structures.
  • struct_size for append-only evolution.
  • Opaque handles and byte views.
  • Explicit create/destroy ownership.
  • Error sinks instead of C++ exceptions.
  • Provider-owned state and cleanup.
  • Borrowed runtime handles with documented lifetimes.

The required causal backend surface is intentionally small. Optional state, speculation, and health operations use independently versioned capability tables. Providers that do not expose those capabilities remain valid.

Model-specific payloads remain provider-owned and opaque to the generic loader.

Important implementation types

FrontendRegistry

A process-wide singleton for built-in and extension frontends.

It owns loaded extension libraries and validated catalog overlays, and performs transactional extension registration and rollback.

BackendRegistry

A process-wide singleton keyed by family/backend/provider.

It stores factories, traits, asset roots, and provider lifetime ownership. Built-in registrations use provider builtin.

ExtensionAutoModel

Adapts a stable-C frontend implementation to FLM's internal AutoModel.

PreparedRequest

Owns temporary stable-C request and payload views used by the frontend adapter.

ProviderBackend

Adapts a stable-C backend instance to FLM's internal ModelBackend.

ProviderCausalLm

Adapts the minimal causal callback table and optional capability tables to the internal causal_lm interface.

ExtensionFrontendRegistration and ExtensionBackendRegistration

Stage extension contributions before atomic validation and publication.

ModelCatalogOverlay

Holds a parsed, versioned extension catalog contribution.

BackendSelection

Resolves and validates the exact backend/provider pair declared by a model package.

FrontendRegistry and BackendRegistry are the only process-wide registry singletons. Individual model_list instances merge validated overlay snapshots; the model catalog itself is not another mutable singleton.

Atomic registration and lifetime

Extension loading follows a transaction:

  1. Parse and validate the manifest and catalog structure.
  2. Load the native library.
  3. Stage frontend and backend registrations.
  4. Validate the catalog against staged and existing registrations.
  5. Commit frontends, backend providers, and catalog contributions together.
  6. Roll everything back on failure.

Provider libraries remain loaded while their factories, frontends, backends, or provider state may still be used. Extensions are explicitly unloaded before runtime shutdown.

Built-in compatibility

Built-in model registration now uses the same frontend/backend registries but remains selected through provider builtin.

Regression coverage verifies that provider filtering does not remove shipped model tags and that legacy model paths remain selectable.

A downloader compatibility check was also corrected to inspect model metadata without resolving host XCLBIN assets.

Validation

Hardware-free CI coverage includes:

  • Extension loading and rollback.
  • Frontend/backend creation and destruction.
  • Provider and library lifetime.
  • Missing and optional capabilities.
  • Catalog and manifest schema fixtures.
  • Built-in model-tag invariance.
  • Independent C extension consumer.
  • Windows Unicode paths and adjacent DLL dependencies.

Local hardware qualification includes:

  • Full Linux XRT and HRX builds.
  • Full Windows XRT and HRX builds.
  • External Gemma4-open text, image, and audio E2E:
    • Linux/XRT
    • Linux/HRX
    • Windows/XRT
    • Windows/HRX
  • Built-in Qwen 3.5 4B E2E on Windows/XRT.
  • Clean process teardown on both Windows runtimes.

No hardware E2E tests are added to CI.

@jtuyls
jtuyls marked this pull request as draft October 29, 2026 15:31
@jtuyls
jtuyls requested a balanced review from Copilot October 29, 2026 16:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved backend compatibility and capability-handling defects can crash inference, while insufficient catalog overlay validation can cause uncaught startup failures.

10 open issues
What changed in this PR

Adds a stable C ABI for independently built model frontends and backend providers, integrating extensions into FastFlowLM’s model selection and lifecycle while preserving built-in defaults.

Changes:

  • Introduces provider-aware registries, C adapters, catalog overlays, and extension-local assets.
  • Updates model ownership, loading, tokenization, and backend selection to support external implementations.
  • Adds hardware-free contract tests, versioned schemas, SDK packaging, and CI consumer checks.
File Description
src/​test/​phi4_core/​CMakeLists.txt Keeps downloader compatibility tests independent of runtime assets.
src/​test/​model_list_platform/​test_model_list_platform.cpp Tests overlays, provider validation, and built-in tag preservation.
src/​test/​model_list_platform/​fixtures/​valid-model-catalog-overlay-v1.json Adds a valid provider-selected catalog fixture.
src/​test/​model_list_platform/​fixtures/​invalid-model-catalog-overlay-v1.json Adds an unsupported-schema fixture.
src/​test/​model_list_platform/​CMakeLists.txt Supplies overlay fixtures and schema paths.
src/​test/​model_frontend/​test_model_frontend.cpp Tests registration, loading, rollback, and provider lifetimes.
src/​test/​model_frontend/​stubs/​device_runtime.hpp Supplies a hardware-free runtime stub.
src/​test/​model_frontend/​fixtures/​valid-model-extension-v1.json Adds a valid bundle manifest fixture.
src/​test/​model_frontend/​fixtures/​invalid-model-extension-v1.json Adds an invalid manifest fixture.
src/​test/​model_frontend/​fake_model_extension.c Implements C providers for contract tests.
src/​test/​model_frontend/​fake_model_extension_dependency.c Supplies a private shared-library dependency fixture.
src/​test/​model_frontend/​CMakeLists.txt Builds loader tests, fake providers, and adapter compilation checks.
src/​test/​model_extension_contracts/​CMakeLists.txt Groups hardware-free extension contract suites.
src/​test/​model_extension_consumer/​provider.c Adds an independent C SDK consumer.
src/​test/​model_extension_consumer/​CMakeLists.txt Verifies installed SDK discovery and compilation.
src/​test/​model_backend/​test_model_backend.cpp Tests exact backend/provider selection and override rejection.
src/​test/​model_backend/​CMakeLists.txt Replaces runtime dependencies with test stubs.
src/​test/​gemma4_core/​test_gemma4_registry.cpp Updates registry and package-selection regression checks.
src/​src/​main.cpp Loads extensions and merges their validated catalog contributions.
src/​src/​benchmarking.hpp Uses registry-compatible frontend ownership.
src/​server/​rest_handler.hpp Adopts extension-compatible frontend ownership.
src/​schemas/​model-extension-manifest-v1.schema.json Defines the versioned extension bundle format.
src/​schemas/​model-catalog-overlay-v1.schema.json Defines provider-selected catalog entries.
src/​runner/​runner.hpp Adopts extension-compatible frontend ownership.
src/​runner/​runner.cpp Accepts registry-created frontend results.
src/​pull/​model_downloader.hpp Removes the configuration-loader dependency.
src/​pull/​model_downloader.cpp Checks compatibility directly from model metadata.
src/​include/​utils/​vm_args.hpp Adds repeatable --model-extension arguments.
src/​include/​program_args.hpp Stores extension manifests in load order.
src/​include/​models/​gemma4e/​gemma4e_payload.hpp Separates private Gemma multimodal payload types.
src/​include/​models/​gemma4e/​flm/​aie2p/​gemma4e_npu.hpp Imports the extracted payload definitions.
src/​include/​model_list.hpp Merges overlays and filters explicit provider selections.
src/​include/​lm_config.hpp Accepts extension-local execution asset roots.
src/​include/​buffer.hpp Allows runtime headers to be supplied through include paths.
src/​include/​AutoModel/​modeling_qwen3vl.hpp Makes the Qwen3VL engine dependency explicit.
src/​include/​AutoModel/​modeling_qwen3_6_moe.hpp Makes the Qwen3.6 MoE engine dependency explicit.
src/​include/​AutoModel/​modeling_qwen3_5vl.hpp Makes the Qwen3.5VL engine dependency explicit.
src/​include/​AutoModel/​modeling_qwen2vl.hpp Makes the Qwen2VL engine dependency explicit.
src/​include/​AutoModel/​modeling_minicpm_v.hpp Makes the MiniCPM engine dependency explicit.
src/​include/​AutoModel/​modeling_gemma4e.hpp Imports explicit engine and payload dependencies.
src/​include/​AutoModel/​modeling_gemma4_12b.hpp Makes the Gemma4 12B engine dependency explicit.
src/​include/​AutoModel/​model_frontend.hpp Declares frontend registration, ownership, and extension lifecycle APIs.
src/​include/​AutoModel/​model_extension.h Defines the public versioned C extension ABI.
src/​include/​AutoModel/​model_extension_frontend.hpp Declares staged frontend registrations and adapter factories.
src/​include/​AutoModel/​model_extension_backend.hpp Declares staged backend registrations and publication support.
src/​include/​AutoModel/​model_catalog_overlay.hpp Parses and validates catalog contributions.
src/​include/​AutoModel/​model_backend.hpp Adds provider-aware registry and selection APIs.
src/​include/​AutoModel/​backend_contract.hpp Centralizes backend and provider identifiers.
src/​include/​AutoModel/​automodel.hpp Adds extension-facing tokenizer hooks and provider state.
src/​include/​AutoModel/​all_models.hpp Replaces frontend switch dispatch with registry lookup.
src/​common/​AutoModel/​modeling_qwen3.cpp Adds an explicit Qwen3 engine include.
src/​common/​AutoModel/​modeling_qwen3_8mtp.cpp Adds an explicit Qwen3.8 MTP engine include.
src/​common/​AutoModel/​modeling_qwen3_6_moe.cpp Adds an explicit MoE engine include.
src/​common/​AutoModel/​modeling_qwen3_6_moe_image.cpp Adds the image-processing engine dependency.
src/​common/​AutoModel/​modeling_qwen3_5vl.cpp Adds an explicit Qwen3.5VL engine include.
src/​common/​AutoModel/​modeling_qwen3_5vl_image.cpp Adds the image-processing engine dependency.
src/​common/​AutoModel/​modeling_qwen2.cpp Adds an explicit Qwen2 engine include.
src/​common/​AutoModel/​modeling_phi4.cpp Adds an explicit Phi4 engine include.
src/​common/​AutoModel/​modeling_nanbeige.cpp Adds an explicit Nanbeige engine include.
src/​common/​AutoModel/​modeling_minicpm_v.cpp Adds an explicit MiniCPM engine include.
src/​common/​AutoModel/​modeling_minicpm_v_image.cpp Adds the image-processing engine dependency.
src/​common/​AutoModel/​modeling_llama3.cpp Adds an explicit Llama engine include.
src/​common/​AutoModel/​modeling_lfm3.cpp Adds an explicit LFM3 engine include.
src/​common/​AutoModel/​modeling_lfm2.cpp Adds an explicit LFM2 engine include.
src/​common/​AutoModel/​modeling_gpt_oss.cpp Adds an explicit GPT-OSS engine include.
src/​common/​AutoModel/​modeling_gemma4e.cpp Adds explicit standard and flash engine includes.
src/​common/​AutoModel/​modeling_gemma4_12b.cpp Adds an explicit Gemma4 12B engine include.
src/​common/​AutoModel/​modeling_gemma4_12b_image.cpp Adds the image-processing engine dependency.
src/​common/​AutoModel/​modeling_gemma3.cpp Adds an explicit Gemma engine include.
src/​common/​AutoModel/​modeling_gemma3_text.cpp Adds an explicit text-only Gemma engine include.
src/​common/​AutoModel/​model_extension_frontend.cpp Adapts C frontend callbacks to AutoModel.
src/​common/​AutoModel/​model_extension_detail.hpp Shares span, error, cleanup, and runtime-handle helpers.
src/​common/​AutoModel/​model_extension_backend.cpp Adapts C backend callbacks and optional capabilities.
src/​common/​AutoModel/​model_backend.cpp Implements provider registration and exact selection.
src/​common/​AutoModel/​builtin_frontends.cpp Registers built-in frontend factories.
src/​common/​AutoModel/​builtin_backends.cpp Makes built-in engine dependencies explicit.
src/​common/​AutoModel/​automodel.cpp Integrates provider loading and frontend-neutral token handling.
src/​CMakeLists.txt Exports and installs the extension SDK and schemas.
src/​cmake/​FastFlowLMModelExtensionConfig.cmake.in Defines SDK package discovery and runtime metadata.
src/​cmake/​FastFlowLMModelExtension.cmake Defines the public extension interface target.
.github/​workflows/​windows-build.yml Adds contract tests, SDK consumer checks, and packaging.
.github/​workflows/​debian-portable.yml Adds contract tests, installed SDK checks, and packaged SDK files.

Review effort: Balanced

Comment thread src/common/AutoModel/automodel.cpp Resolved
Comment thread src/common/AutoModel/automodel.cpp Resolved
Comment thread src/runner/runner.hpp Resolved
Comment thread src/server/rest_handler.hpp Resolved
Comment thread src/src/main.cpp Resolved
@jtuyls
jtuyls force-pushed the users/jtuyls/frontend-extensions branch 2 times, most recently from bc808ca to c14dd61 Compare October 30, 2026 13:35
@jtuyls
jtuyls requested a balanced review from Copilot October 30, 2026 14:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread src/pull/model_downloader.cpp Resolved
@jtuyls
jtuyls force-pushed the users/jtuyls/frontend-extensions branch from c14dd61 to 27e6e21 Compare October 30, 2026 14:49
@jtuyls
jtuyls requested a balanced review from Copilot October 30, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical issues allow overlays to redirect built-in aliases, requests to reuse unrecoverably failed backend engines, and accepted entries with missing download metadata to crash model listing.

6 open issues

Review effort: Balanced

Comment thread src/test/model_frontend/CMakeLists.txt Resolved
@jtuyls
jtuyls force-pushed the users/jtuyls/frontend-extensions branch from 27e6e21 to 08797b0 Compare November 3, 2026 14:38
@jtuyls
jtuyls marked this pull request as ready for review November 3, 2026 17:04
@jtuyls
jtuyls requested a review from tawei-amd November 3, 2026 17:04
@jtuyls
jtuyls force-pushed the users/jtuyls/frontend-extensions branch from 08797b0 to 0b23424 Compare November 6, 2026 07:16

@zaneni6 zaneni6 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for this, Jorn, it's a really well-built change! The loader is careful: an explicit --model-extension flag only, bundle-relative paths that are checked, LOAD_LIBRARY_SEARCH_* flags, ABI and runtime checks, no exceptions crossing the C boundary, and clean rollback. Built-in tags still resolve to the same frontends and engines on XRT and HRX, and it's great that the Copilot comments are addressed. I mostly looked at how it lands next to what's on main now and at the XRT/HRX side, and had a few thoughts. Please feel free to push back on any of them.

1. Rebase onto main (gpt-oss conflict with #965)
src/common/AutoModel/modeling_gpt_oss.cpp now conflicts with #965. I think the right resolution is main's file plus your #include "models/gpt_oss/flm/aie2p/gpt_oss_npu.hpp" line, since #965 already switched to lm_engine->restore()/checkpoint().

  • Keeping only main's side fails to compile (gpt_oss_npu_state_api is not declared once automodel.hpp stops including engine headers).
  • Keeping only this PR's side drops #965's _continue_verbatim / forwards_past_eos() gating for the GPU backend.

builtin_backends.cpp auto-merges fine with #965's oga-hipep registrations. One small thing after the rebase: the new logits.size() < in_features check in _sample makes the fakes in src/test/oga_hipep/frontend (test_qwen_frontend, test_gpt_oss_frontend) fail, since they return buffer<bf16>(1) with a 64-wide sampler. CI doesn't build those, so it wouldn't show up there. Would you mind re-running CI after the rebase?

2. --backend / FLM_BACKEND no longer override the catalog
resolve_backend_selection (model_backend.cpp ~line 242) now rejects any backend that differs from the catalog entry's. Before, it only checked that the family registers it. For example, FLM_BACKEND=core with qwen3:0.6b on a core-enabled build used to load and now errors. If that's intended, could the CLI/server docs (docs/docs/instructions/cli.md around the backend section) and the --backend help text be updated in the same PR? They publish straight to the site.

3. Extension steps inside the package build jobs
The model-extension contract tests and the Gemma4-open fixture build run as steps inside lin-build / win-build, before packaging. So a failure there means no package for that variant, none of its NPU tests run, and the XRT or HRX release is held, even when flm itself built fine. They also add roughly 6–10 minutes per Windows build: they use the VS generator without sccache, and the same contracts compile in 6 builds. The fixture also downloads the codec tarballs again each time, including from downloads.xiph.org, which #967 just had to work around. Would it be possible to move these into their own jobs that depend on the build, or into cpu-tests.yml? They could still count toward the verdict, without blocking packaging and the NPU sweep.

4. Path checks for overlay name / files
load_model_catalog_overlay only checks that name and files are non-empty strings, and get_model_path / get_model_file_path join them directly. So .., absolute or drive-relative entries let flm pull write, and flm remove delete, outside the model folder. With #965's new folder cleanup in remove_model, that could become a remove_all on an unexpected folder.

Related: the Gemma4-open fixture's catalog uses the same Gemma4-E2B-IT-NPU2 folder as the built-in gemma4-it:e2b, so flm remove gemma4-open-it:e2b would delete the built-in model's weights. Maybe require name to be a single relative component that doesn't match a built-in entry's folder, and reject .. / rooted entries in files?

Smaller ideas, fine for follow-ups (they only apply when an extension is loaded):

  • Built-in multimodal frontends still reinterpret_cast the engine, for example modeling_qwen3_6_moe.cpp:202/257, modeling_minicpm_v_image.cpp, modeling_gemma4_12b_image.cpp. An extension backend provider for one of those built-in families, with an overlay entry that leaves out vlm, would reach them on an image request. Maybe reject extension backend providers for families whose frontend downcasts, or use dynamic_cast with a request error?
  • An extension frontend can register the reserved whisper-v3 / embed-gemma / d3 family names.
  • accepts_private_payloads pairs frontend and backend by provider-id string, so two different extensions could use the same id.
  • The FLM_TEST_PREFILL_FAULT hook calls tokenizer->decode while ExtensionAutoModel resets the tokenizer.
  • changes.py doesn't know the new test/schema paths yet, so edits to only those run the full NPU sweep.
  • Release zips and tarballs now ship the SDK (header, CMake package, schemas), but the MSI doesn't, and the schema folder differs between Linux and Windows. Maybe worth a line in the release notes.

Thanks again, this is a big step for the project!

@jtuyls
jtuyls force-pushed the users/jtuyls/frontend-extensions branch 2 times, most recently from 4dc2f33 to 721adcb Compare November 9, 2026 07:00
@jtuyls

jtuyls commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Hi @zaneni6, thanks for the thorough review! Everything is addressed in this PR, including the smaller ideas, since most of them were small. The PR is rebased onto current main (now past #972, #986 and #988) and is still two commits. CI is green.

1. Rebase and the gpt-oss conflict. I resolved modeling_gpt_oss.cpp as you suggested: main's file plus the gpt_oss_npu.hpp include. The oga-hipep frontend fakes now return full-width logits (kVocab), and test_qwen_frontend and test_gpt_oss_frontend pass locally. Later rebases also brought in hy-memory (registered as a built-in frontend, plus its engine include in builtin_backends.cpp) and the removal of qwen3.5-flash (its registration and includes removed).

2. --backend / FLM_BACKEND. That wasn't intended for built-in models. For built-in catalog entries, the override works as before again: any backend the family registers is accepted, so FLM_BACKEND=core with qwen3:0.6b loads again. Only entries from a --model-extension catalog are strict, because their frontend and backend come as a pair from one provider. cli.md now says so in the backend section. The --backend help text didn't need to change, since built-in behaviour is the same as before.

3. Extension steps in the package builds. Both are out of lin-build / win-build, and those actions now match main.

  • The contract tests moved to cpu-tests.yml: one Linux job and one Windows job, each building both the XRT and HRX variants. The Windows job uses Ninja under the MSVC environment.
  • The Gemma4-open fixture builds in a new reusable workflow, model-extension-build.yml. It runs after each package build and compiles against the SDK inside that package, so it builds the way a third party would.
  • The codec tarballs are cached, so the fixture no longer downloads from xiph on every run.
  • A fixture failure now only affects the verdict, not packaging or the NPU sweep.

4. Overlay paths. name must now be a single relative folder name, and an entry is rejected if it reuses a built-in entry's folder. files and xclbin_folder entries must stay inside the model folder, so .., absolute and drive-relative paths are rejected. There are negative tests for each in test_model_list_platform. The Gemma4-open fixture now uses its own folder, Gemma4-Open-E2B-IT-NPU2, with its xclbins under the same name, so removing it no longer touches gemma4-it:e2b.

Smaller ideas, also done here:

  • Downcasting frontends: extensions can't register a backend provider for qwen3.6-moe, minicpm-v-4.7, minicpm-v-4.7-moe or gemma4-12b, the built-in families whose frontends cast the engine to their concrete type. The DFlash families null-check their dynamic_cast, so they're still allowed.
  • Reserved names: extensions can't register frontends for whisper-v3, embed-gemma or d3, or backends for them.
  • Provider ids: a provider id now belongs to a single extension. A second extension that uses it fails to load, with a message naming both extensions.
  • FLM_TEST_PREFILL_FAULT: the hook skips decoding when there's no host tokenizer, which is the case for extension frontends.
  • changes.py: it maps the new test, schema and SDK CMake paths to chat, so changes to only those no longer run the full sweep.
  • SDK packaging: the MSI now has a "Model extension SDK" feature with the header, CMake package and schemas, and every package installs the schemas to share/flm/schemas.

One note: the new vision-stale check from #959 reports a warning, not a failure, for the extension. An extension's private payload has no cache identity the host can see, so the host refills those requests instead of reusing the cached image.

Replace the compiled model-family switch with factories keyed by catalog family while preserving the existing construction and fallback behavior. Use provider-compatible ownership so later extensions can destroy frontends in the module that created them.
@jtuyls
jtuyls force-pushed the users/jtuyls/frontend-extensions branch from 721adcb to f3eb450 Compare November 9, 2026 16:53
@zaneni6
zaneni6 merged commit 0ac7cd7 into ROCm:main Nov 9, 2026
51 checks passed
@zaneni6

zaneni6 commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot, Jorn, for addressing everything so thoroughly, including the smaller ideas! I checked the fixes against the code, CI was all green, and it's merged now. 🎉

A few small leftovers I noticed while checking. None of them blocked the merge, so they're just ideas for a follow-up whenever convenient:

  • Release gate: the four extension builds and four extension NPU tests are in the XRT/HRX verdict without a !inputs.release guard (build-and-test.yml ~784-791), so a fixture-only break, such as the rustup bootstrap or a submodule fetch, would hold an XRT or HRX release. That may be what you want. If not, the models-from-source jobs show a pattern for keeping them out.
  • .deb SDK: debian/rules:37 still runs rm -rf .../opt/fastflowlm/include after cmake --install, so the .deb ships the FastFlowLMModelExtension CMake package but not model_extension.h, which it points at.
  • MSI default: the new "Model extension SDK" feature is Level=1, so default and silent installs now also write include\, lib\cmake\ and share\flm\schemas\. That's harmless, but if it should be opt-in, Level=1000 (like the desktop shortcuts) would do it.
  • Overlay folder check: names are compared after ASCII lower-casing only. On Windows a trailing . (e.g. Qwen3-0.6B-NPU2.) resolves to the built-in folder but passes the reuse check. Also, preferred_source is merge-patched after validation, and only its name/files are checked (model_list.hpp ~530), so keys like xclbin_folder there aren't validated.
  • Windows fixture deps: the fixture configure requires the vcpkg include dir (model_extension_gemma4e/CMakeLists.txt ~45-56), so a later change that drops vcpkg from setup_windows_deps.ps1 would need to touch it too.

Thanks again for the great work on this!

michyu-amd added a commit that referenced this pull request Nov 9, 2026
automodel.hpp no longer pulls in every engine header (#874), so the
harness has to include hunyuan_npu.hpp itself.

Co-Authored-By: Claude <noreply@anthropic.com>
@michyu-amd michyu-amd mentioned this pull request Nov 9, 2026
zaneni6 added a commit that referenced this pull request Nov 9, 2026
The Windows model-extension build (from #874, merged into main after this
branch started) passed -DVCPKG_INCLUDE_DIR=C:\dev\vcpkg\installed\x64-windows\include.
That directory only ever supplied curl's headers, and this branch no longer
creates C:\dev\vcpkg: curl's headers are committed under third_party/curl.
The merged result failed to configure on both Windows runtimes:
"VCPKG_INCLUDE_DIR must name an existing directory".

The extension now takes curl's headers from third_party/curl/include next
to FLM_SOURCE_DIR, so the workflow no longer passes the directory.

Built locally against the fastflowlm-windows package artifact from CI run
42713502798: it configures and builds, and the bundle has the extension
DLL, catalog and xclbins.

Co-Authored-By: Claude <noreply@anthropic.com>
@jtuyls jtuyls mentioned this pull request Nov 10, 2026
@jtuyls

jtuyls commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks a lot, Jorn, for addressing everything so thoroughly, including the smaller ideas! I checked the fixes against the code, CI was all green, and it's merged now. 🎉

A few small leftovers I noticed while checking. None of them blocked the merge, so they're just ideas for a follow-up whenever convenient:

  • Release gate: the four extension builds and four extension NPU tests are in the XRT/HRX verdict without a !inputs.release guard (build-and-test.yml ~784-791), so a fixture-only break, such as the rustup bootstrap or a submodule fetch, would hold an XRT or HRX release. That may be what you want. If not, the models-from-source jobs show a pattern for keeping them out.
  • .deb SDK: debian/rules:37 still runs rm -rf .../opt/fastflowlm/include after cmake --install, so the .deb ships the FastFlowLMModelExtension CMake package but not model_extension.h, which it points at.
  • MSI default: the new "Model extension SDK" feature is Level=1, so default and silent installs now also write include\, lib\cmake\ and share\flm\schemas\. That's harmless, but if it should be opt-in, Level=1000 (like the desktop shortcuts) would do it.
  • Overlay folder check: names are compared after ASCII lower-casing only. On Windows a trailing . (e.g. Qwen3-0.6B-NPU2.) resolves to the built-in folder but passes the reuse check. Also, preferred_source is merge-patched after validation, and only its name/files are checked (model_list.hpp ~530), so keys like xclbin_folder there aren't validated.
  • Windows fixture deps: the fixture configure requires the vcpkg include dir (model_extension_gemma4e/CMakeLists.txt ~45-56), so a later change that drops vcpkg from setup_windows_deps.ps1 would need to touch it too.

Thanks again for the great work on this!

Thanks for merging and the follow-up comments, @zaneni6! I created a follow-up PR here: #997. I kept the SDK feature on by default as making it opt-in for MSI isn't that convenient. The files are small and just a header, CMake config and schemas, so installing them by default is cheap, but let me know if you explicitly want it to be opt-in and I can make the change.

@jtuyls
jtuyls deleted the users/jtuyls/frontend-extensions branch November 10, 2026 23:31
tawei-amd pushed a commit that referenced this pull request Nov 18, 2026
…ywhere in the string (#1047)

* feat(core): ryzenai-corelib 0.70.0, get_npu replaces npu_usable and testing_npu_arch

Moves the core backend to ryzenai-corelib 0.70.0 (corelib main at
39c30eab). What changed in corelib 0.61 to 0.70 that reaches FastFlowLM:

- 0.70, NPU query: ryzenai_corelib_npu_usable and the testing hook
  ryzenai_corelib_testing_npu_arch are gone. ryzenai_corelib_get_npu
  (none / aiem / aie2p) and ryzenai_corelib_npu_name replace them, so
  corelib_api.hpp no longer includes corelib/testing.h.
- The runtime's readiness check now asks for aiem. The old npu_usable was
  false on AIE2P, whose kernels corelib runs only behind an xclbin
  FastFlowLM never gives it; get_npu now answers aie2p there, so checking
  for "any NPU" would have offered the core backend on Strix.
- NpuArch names the enum with npu_name, "" for none, as before, so dev04 /
  aie2p platform detection is unchanged.
- 0.61 / 0.68, model structs: model_metadata gains max_draft_tokens and
  audio_token_id; session_options gains draft_tokens. FastFlowLM
  zero-initialises both at their full sizeof, so no draft is asked for.
- 0.62 / 0.67, matmul: the 4-bit layout is mladf_v4 (was mladf) beside
  AIE2P's mladf_v2, and matmul_bf16_kernel_info gains format. FastFlowLM
  names neither; the fake corelib fills format.
- 0.68: ssmlp_bf16_weights_desc gains ungated; unused here.
- Model libraries and their names are unchanged. The weights loader's
  switch from bad_argument to unsupported for a wrong tensor type does not
  matter here: FastFlowLM does not branch on corelib's status codes.

The fake corelib answers get_npu from one enum and npu_name as corelib
spells it; the tests refuse none and aie2p, and read "" for none.

On an AIE4 (Medusa) test machine, qwen3-core 0.6b/1.7b/4b/8b,
phi4-mini-it-core:4b, qwen3.5-core 4b/9b and llama3.2-core:1b each load,
pass the readiness check through get_npu, report no fallback and answer
correctly, at decode rates within a few percent of corelib 0.59's.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(chat): a JSON Schema pattern matches anywhere in the string, and keeps a one-character class's length bounds

JSON Schema finds a string pattern anywhere in the string; xgrammar
matches the regex against the whole string. A field written as

    {"type": "string", "minLength": 1, "maxLength": 128, "pattern": "\\S"}

("not blank") therefore allowed exactly one character, and xgrammar also
drops minLength/maxLength whenever a pattern is present (it logs "pattern
combined with minLength/maxLength is not supported").

Found running an agent benchmark with qwen3.6-moe-core:35b-a3b: every
free-text argument of a forced chart-generation tool call came back as one
character ("caption":"7","alt_text":"A","labels":["P","C"]). The caller
rejected it, the grammar left the model no other call to make, and it
repeated until the tool-iteration limit.

normalize_schema() now:

- pads the side(s) a string pattern leaves unanchored with ".*" ("\S"
  becomes ".*(\S).*"). A pattern anchored at both ends is left as it is,
  so "^\d{4}-\d{2}-\d{2}$" keeps its meaning.
- lets a lone character class that only has to occur somewhere ("\S",
  "\d", "[a-z]", ...) lead, and turns the schema's length bounds into the
  repetition after it: "\S" with maxLength 128 becomes "\S.{0,127}", so
  the bounds xgrammar would drop are enforced.
- keeps minLength/maxLength and drops the pattern instead when that
  repetition would be longer than 128. xgrammar compiles a longer regex
  repetition into a rule of its own and cannot build that rule inside a
  nested object ("cannot build the decoding grammar: Check failed:
  per_rule_fsm_hashes[...].has_value()"), so the request would fail with
  HTTP 400; a string past its maxLength is the likelier mistake.

response_format schemas now go through normalize_schema() as tool
parameters already did, so they get the same reading.

New live cases in src/test/openai_api_test: test_tool_calls
function_unanchored_pattern and function_nested_long_bounded_pattern, and
test_response_format schema_unanchored_pattern. The two unanchored cases
fail on main ('P' for "Paris"); the nested one fails with the HTTP 400
above if the bounds are folded at any length. On an AIE4 (Medusa) test
machine with qwen3.6-moe-core:35b-a3b:
test_tool_calls.py 18/18, test_response_format.py 12/12.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(core): ryzenai-corelib 0.87.0, has_feature replaces get_npu and npu_name

Moves the core backend to ryzenai-corelib 0.87.0 (corelib main at
5bf19507). What changed in corelib 0.71 to 0.87 that reaches FastFlowLM:

- 0.73, NPU query: ryzenai_corelib_get_npu, ryzenai_corelib_npu_name and
  the ryzenai_corelib_npu enum are gone. ryzenai_corelib_has_feature and
  ryzenai_corelib_feature_name replace them, over ryzenai_corelib_feature
  (npu, npu_aiem, npu_aie2p, gpu, npu_direct).
- The runtime's readiness check asks has_feature(npu_aiem). AIE2P is
  still refused, since FastFlowLM never gives corelib an xclbin, and the
  error names npu_aie2p or none.
- NpuArch passes corelib's spelling through (npu_aiem, npu_aie2p, ""), and
  platform_from_corelib_arch maps npu_aiem to dev04. FastFlowLM still
  keeps no table of devices.
- Everything else FastFlowLM resolves is unchanged: every other entry
  point in FLM_CORELIB_FUNCTIONS keeps its signature, and model_metadata
  and session_options keep their layout. 0.87's single PDI list per
  stream, NPU direct, the .amd.gguf exports (0.80, 0.83) and the new ops do
  not touch FastFlowLM's calls.
- 0.83: corelib's 4-bit GGUF types are renamed (AMD_Q4_G128, AMD_Q4_G32,
  new AMD_Q4_G64). Files published under the old type codes (ggml 128,
  129) are still read as before, so the catalog's AMD files need no
  change.
- Model libraries: ryzenai_corelib_model_d3 is new. The core build copies
  ryzenai_corelib_model_*.dll by glob, so it lands beside flm.exe without
  a change; no -core tag uses it yet.
- Not taken here: corelib now lets Llama 3.2-1B/3B and 3.1-8B read a
  Q4_G128 GGUF in place of their Q8_0. Q8_0 still loads, so the catalog's
  Llama entries stay on Q8_0; switching them is a separate change.

The fake corelib answers has_feature from one NPU feature, or none, and
feature_name as corelib spells it. The tests refuse none and npu_aie2p,
each named in the error, and read "" for none. The Linux setup guide's
version check now prints 0, 87, 0.

On an AIE4 (Medusa) test machine, with the core flm.exe statically linked
against corelib's default build (no --npu-direct): every -core tag except
Llama 3B/8B loads, passes the readiness check through has_feature(npu_aiem),
reports no fallback and answers correctly, at decode rates matching
0.70's. Gemma 4 E2B/E4B, Qwen3.8 and Qwen3.6 recall a code from the middle
of 4k and 12k prompts (Qwen3.6 also at 24k).

An flm.exe linked against a corelib built with --npu-direct engages NPU
direct for Qwen3.6 and gives the same greedy output, with prefill about
10-15% faster from 12k tokens. The core build stays on corelib's default
build: --npu-direct needs CHESS in WSL, so turning it on is a build-only
follow-up.

Co-authored-by: Cursor <cursoragent@cursor.com>

* test(core): the frontend stubs return a full vocabulary of logits; the DFlash entries hold no licence

Two checks added on main left two Windows-only core suites failing on
main itself. Only tests change here.

- test_phi4_frontend, test_llama_frontend: #874 added a check to
  AutoModel::_sample that refuses logits shorter than the sampler's
  in_features, which is vocab_size from config.json. Each test's
  FakeEngine returned buffer<bf16>(1) from forward and prefill, so every
  test that samples failed with "Backend returned fewer logits than the
  frontend vocabulary". They now return kVocabSize logits, as the core
  backend does: 200064 for Phi-4 and 128256 for Llama. config.json takes
  vocab_size from the same constant.
- test_model_downloader: #950 dropped LICENSE.OpenMDW-1.1 and LICENSE from
  the files of nemotron3.5-bolt-dflash:e4b and qwen3.8-dflash2:27b, but
  the test still expected them. It now expects config.json and
  dflash_weight.q4nx, as the catalog lists.

The check itself is unchanged. The real core backend returns logits as
wide as corelib's vocab_size, which equals config.json's for the shipped
-core tags, so it does not trip there.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(core): ryzenai-corelib 0.103.0

Moves the core backend to ryzenai-corelib 0.103.0 (corelib main at
49a8ed3c). What changed in corelib 0.88 to 0.103 that reaches FastFlowLM:

- Every entry point in FLM_CORELIB_FUNCTIONS keeps its signature, and
  model_metadata keeps its layout, so the only code change is the
  required version in corelib_api.hpp.
- model_session_options: lora is gone (0.97: a session runs LoRA kernels
  when its model has an adapter set), and low_memory (0.96) and
  kv_cache_bits (0.98) are appended. FastFlowLM value-initialises the
  struct and sets only max_sequence_length, so the defaults hold: no LoRA,
  the embedding table mapped, a BF16 KV cache.
- Additive only, as far as FastFlowLM's calls go: uint8 tensors,
  stream_set_low_memory, PQ2_0 weights, head_gate_bf16, hadamard_bf16, and
  NPU direct on AIE2P. FastFlowLM still refuses AIE2P.
- Model libraries: qwen2, lfm2, lfm3, hyv3, glide, minicpm_ocr and
  minicpmv47 are new. The core build copies ryzenai_corelib_model_*.dll by
  glob, so they land beside flm.exe without a change; no -core tag uses
  them yet.
- Not taken here: the 8-bit KV cache (kv_cache_bits 8, AIE4 NPU direct
  only) and low_memory sessions. Both are opt-in and would be separate
  changes.

The docs' version checks and the required-version notes move to 0.103.

On an AIE4 (Medusa) test machine, qwen3-core 0.6b/1.7b/4b/8b,
phi4-mini-it-core:4b, qwen3.5-core 4b/9b and llama3.2-core:1b each load,
report no fallback and answer correctly, at decode rates matching 0.87's.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(chat): Gemma4 and LFM2 tool grammars keep a string's minLength/maxLength

The argument grammars FastFlowLM writes itself (Gemma4, LFM2) gave every
string property the unbounded string rule, so a tool parameter with
maxLength 20 took a whole sentence: test_tool_calls
function_pattern_keeps_length_bounds failed on gemma4-it:e2b, Linux and
Windows. normalize_schema had also folded the bounds into a pattern that
only xgrammar's JSON schema reads.

These grammars now read the schema as sent and spell bounds up to
XGRAMMAR_REGEX_REPEAT_LIMIT: Gemma4 through counted gstr_<low>_<high>
rules (a "<" step takes the next character too, so lengths stay exact
and "<|" still cannot occur), LFM2 through a {low,high} repetition where
an escape is one character. Array items keep their bounds too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(chat): pad an unanchored pattern without ending the string; leave flags and inner anchors as sent

Review follow-ups to the pattern rewrite:

- The padding is now a class of what a JSON string holds unescaped, not
  ".*". xgrammar keeps '"', '\' and control characters out of a pattern's
  matches only when the pattern is printable ASCII; any other pattern
  compiles without that guard, where ".*" could close the string and add
  keys ("(é|x)" took x", "k": "y). The folded repetition after a lone
  class uses the same class.
- A pattern opening with an inline flag such as "(?i)" is left as sent:
  padded, it no longer builds.
- A pattern with an anchor inside a group, such as "(?:^abc)", is left as
  sent: xgrammar ignores an anchor in the middle, so padding would have
  let "xabc" through.
- Each top-level alternative is padded on its own, so "^a|b" reads as
  "starts with a, or holds b" rather than "^(a|b).*".
- normalize_schema no longer enters const, enum, default or examples,
  which are values, nor "not", whose meaning a rewrite would change. A
  property named like one of them is still a schema.
- The comment on unsatisfiable bounds now says what happens: xgrammar
  ignores the bounds beside a pattern. The folded form's narrowing is
  noted.

The live tests check for the expected word instead of a length above
one, which a valid one-character answer would have failed.

New checks in test_chat_tools cover each case through the grammar engine;
on the previous code "^a|b" and the non-ASCII injection fail, and the
inline-flag and inner-anchor patterns crash the harness.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: tawei-amd <tawei@amd.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants