Plugin registration
Every launcher uses ensure_loaded() to discover plugins once. Kernel and runtime entry points publish declarations before argument parsing. There is no separate headless registration stage, no requirement for an empty argument hook, and no undo/replay operation between argument parsing and rank startup.
Registration covers names, profiles, argument schemas, factories, and capabilities. It must not construct models, allocate execution resources, or import optional execution implementations merely to publish their declarations. Each consuming process resolves the implementations it needs during component construction and kernel planning. Existing concrete class/callable registrations remain supported.
Model declarations
A registered architecture owns both its lightweight profile factory and its execution reference. Profile lookup, numerical-policy resolution, and composite HF-config handling use the factory without loading the model class. The loader resolves the class for that same architecture. Architecture ordering and explicit replacement of an in-tree model retain their existing meaning.
The following example declares a model without importing its execution module. Replace the my_plugin module paths, ExampleForCausalLM class and architecture names, and model_profile factory with your plugin's values:
from tokenspeed.runtime.plugins.registry import register_model
from tokenspeed_kernel.import_ref import ImportRef
from my_plugin.profiles import model_profile
def register():
register_model(
ImportRef("my_plugin.models.decoder", "ExampleForCausalLM"),
architectures=("ExampleForCausalLM",),
profile_factory=model_profile,
)The profile factory and everything it imports must remain independent of model execution. Its construction/configuration callbacks may themselves be references; their owning initialization step resolves them. Defining the profile on a class in a heavy model module and importing that class to read its profile defeats this boundary.
Built-in architecture names are indexed in runtime/models/catalog.py. Adding a model requires its declaration there; model discovery does not scan and import every implementation module. The model-registry integration test resolves each model's published EntryClass through the real loader to check catalog coverage. Attention, linear-attention, cache, and sampling registrations follow the same declaration/implementation boundary. Their native names remain known before optional implementations are imported, so duplicate names and permitted overrides do not depend on import order.
Tests that inspect backend capabilities resolve the declaration through the same registry lookup as runtime consumers. Tests simulating another platform declare each backend choice they exercise, including backends expected to reject the configuration; importing an implementation does not register it.
Scoped drafter references name the model class by its defining module and qualified name. Dispatch also recognizes a re-export already bound in a loaded module. Use the defining name for scopes whose public module might not be imported. The selected drafter is imported after the model matches.
References and ownership
ImportRef(module, qualname) identifies an importable object; omitting qualname identifies the module itself. construct(...) describes a stateful implementation factory without invoking it. References contain no resolution cache of their own. Their registry or consuming component owns the resolved object and its lifecycle.
Factories bind import references in their construction inputs before invoking the constructor. Kernel selection returns a real callable, including a constructed stateful implementation where required. KernelPlan retains that callable and execution does not go through an import proxy. KernelMethod binds preparation to the same registry-owned instance as execution, preserving shared state.
Concurrent resolution of one kernel entry constructs one implementation. Imports and constructors run outside the registry condition lock; waiters observe either the completed entry or an error. Circular resolution fails explicitly. A result from a replaced declaration cannot overwrite its replacement. Restoring registry snapshots, unregistering declarations, and replacing implementations invalidate the corresponding resolved state and selection caches. Selection repeats admission if registrations change during ranking or construction, so a plan retains the capabilities and callable from the same registry revision. Reloading an implementation keeps registrations made by explicit plugin activation. Re-executing a module removes any declarations its module body no longer makes.
Kernel capabilities
A kernel declaration retains KernelSpec's identity, format signatures, platform requirements, features, traits, solution, and priority. The existing selection logic continues to choose the implementation, including initialization-time KernelPlan admission for batch invariance. Moving registration does not change arithmetic or establish a new numerical qualification.
The declaration may provide these initialization callbacks:
availability: whether an optional provider exports the required operations. Evaluate it after static platform/format/solution filtering, before ranking. A known absent optional capability excludes that candidate; an unexpected provider failure is propagated rather than silently changing implementation.traits_factory: SDK-derived deployment limits, resolved before trait matching. These supplement static traits and must not replace them. Values are constant for the deployment; request dimensions never enter this factory.prepare_implementation: native operator activation and ABI validation before resolving the selected implementation. Resource owners continue to own GPU buffers and their release/resume lifecycle.
Discovery and its diagnostics inspect declarations without invoking those callbacks. Required implementation bindings must be prepared before the affected execution path enters graph capture or begins serving. Lazy import is not a new just-in-time selection policy for the forward loop.
Kernel declarations record their source module. A later import of a built-in implementation cannot overwrite an external declaration already replacing that name. Selection among differently named candidates still uses capabilities and priority. Legacy operator facades may continue registering concrete built-in callables when imported; their consumers load the relevant facade before planning.
Metrics and process startup
A reporter's register() publishes validation and sink-creation callbacks and its plugin provenance. metrics_service.prepare() can validate a selected reporter before ranks start, and MetricsRelay can obtain its entry point from list_plugins(). The relay replays only selected reporter registrations in its own interpreter. Registration does not create sinks or connect an SDK.
A model plugin and a reporter therefore coexist through the same entry-point lifecycle. The reporter needs no argument hook when it defines no extra options. Starting a bundled frontend versus using an external frontend changes process orchestration, not plugin registration or the engine execution path.
Transactions and errors
Runtime entry-point registration uses its existing recording transaction. Kernel entry points snapshot the registry before activation and record import-time declarations. On failure the snapshot is restored, then declarations from newly imported dependencies outside the plugin distribution are retained, including a built-in that the failed plugin shadowed. Installed module records distinguish sibling packages in the distribution from independent modules in a shared namespace. For roots without records, ownership follows the declared top-level packages and the entry point's root. Modules remain cached in Python. On a retry, the loader replays the failed plugin's cached import-time declarations inside the new activation transaction. Explicit registration calls made after a dependency has loaded are part of the plugin activation and are rolled back with it. The loader reads the distribution name and version before activation. Ignored late built-in declarations are visible at debug log level. Only successful entry points publish PluginInfo. Successful registration means that declarations are available; it does not certify that every optional device provider is installed.
An implementation that is actually selected must resolve successfully. Its import, ABI, or constructor error remains a startup or initialization failure. Do not retry an unqualified numerical implementation to conceal that failure.
For more information about typed launch options and immutable per-launch ownership, see plugin server arguments.