Module circuit_exec

Module circuit_exec 

Source
Expand description

2026-09-28: The circuit executor: run a model’s decode from its fused circuit plan instead of the hand-written layer loops. At boot it instantiates the model’s circuit, fuses it under the live policy with the kernels the loaded modules contain, lays its buffers out in one workspace and compiles a straight-line program::Program for single-sequence decode and one per multi-sequence batch width; a decode step then runs the program for its width between the legacy prologue (embedding, metadata upload) and the logits.

Owner: model-layers circuit executor. Invariants:

  • Every emitter launches through an existing ops::* function; the executor adds no launch code of its own.
  • Anything the circuit does not model (a layer feature, a switch, a head feature, a plan kernel no emitter launches) refuses the build; a decode never runs a plan that misdescribes the model.
  • The workspace is allocated once, at build, and never moves, so captured graphs stay valid. Every program lays its buffers out from the workspace base: programs run one at a time on the model’s stream, so they share it, and it is sized for the largest.

Re-exports§

pub use bindings::AttnFacts;
pub use bindings::BoundWeight;
pub use bindings::CircuitBindings;
pub use bindings::CircuitLayer;
pub use bindings::DraftBinding;
pub use bindings::DraftRows;
pub use bindings::GdnFacts;
pub use bindings::HeadBinding;
pub use bindings::MixerFacts;
pub use bindings::RopeFacts;
pub use bindings::WeightSlot;
pub use compile::DraftFixed;
pub use compile::Fixed;
pub use program::DraftPrograms;
pub use program::DraftRunner;
pub use program::GdnState;
pub use program::Program;
pub use program::StepEnv;

Modules§

bindings
2026-09-28: CircuitBindings, the supertrait of TransformerLayer through which a layer hands the circuit executor its weights by role and the facts its kernels need. Layers keep owning their weights; a binding is a copy of pointers.
compile
2026-09-28: Plan to program. layout states the storage the emitters’ kernels need (the residual stream and the logits bound to the model’s buffers, in-place outputs, packed outputs); the caller places the rest in one workspace allocated at boot; compile asks each group’s emitter for its launches.
fixed
2026-09-30: The device addresses a program is compiled against: the model’s buffers and metadata uploads (Fixed) and the MTP draft head’s (DraftFixed). Split from compile.rs.
kernels
2026-09-28: The kernels the circuit executor can launch, resolved at boot through literal lookups (so the kernel-lookup audit records each at its line here), and the probe of every kernel any rule names, which is what the fuser treats as available.
policy
2026-09-28: The live policy a plan is fused under: every setting the rules read, taken from the switch the legacy dispatch reads for it (the sources INSTANCES.toml cites), plus the switches no rule models, which the executor refuses when they are away from their default.
program
2026-09-28: A compiled circuit program: the straight-line launches of one plan, with every host decision (kernel, grid, sizes, pointers into the model’s fixed buffers and the workspace) made at compile time.
routes
2026-09-30: The runtime routes the executor runs. A FUSIONS.toml [[runtime]] route (metrale_circuit::runtime) is compiled into its own program beside the primary one, at every mode and row count it applies to. Each step evaluates the route’s condition exactly as the legacy dispatch does and runs the matching program.
sources
2026-09-28: The circuit texts this binary was built from: INSTANCES.toml, the circuits, their block libraries, the precision tables and each hardware’s FUSIONS.toml, embedded so a plan matches the kernels compiled in. met circuit and the executor both read them here.
spec_key
2026-10-04: The plan digests that key a measured speculative-cost table (--spec-cost-model measured): per measured mode (verify, verify_batch, draft), one digest over every plan the recipe’s circuit instance declares for that mode, each verify/draft plan followed by its runtime-route arms, fused offline as met circuit show fuses them. The golden plans specify the kernel routing of the legacy forward too, so the key describes the kernels either forward runs; it needs no executor. met benchmark spec-cost-table writes it, and the serve recomputes it at boot and refuses a table whose key differs.
verify_batch
2026-09-30: The batched MTP verify’s programs (Mode::VerifyBatch). A batched verify’s plan depends on its row table (the runs of equal k and their contiguity), and a serve meets many tables, so each program is compiled the first time its table is verified and kept in a bounded cache. The legacy forward’s graphs are keyed by the batch’s (slot, k) pairs, which fix the table, so a graph captured around a program replays that program’s launches.

Structs§

Boot
2026-09-28: What a build reads.
CircuitExec
2026-09-28: A built executor: the decode program and the workspace it runs in.
TargetModules
2026-09-28: The compiled kernel modules of the served target, (module, PTX): the fuser’s view of which kernels exist (kernels::available_in).

Enums§

Fusions
2026-09-28: Which rules a build may select.