Skip to main content

ModelFlow

Struct ModelFlow 

Source
pub struct ModelFlow { /* private fields */ }
Expand description

Block assembly-line builder — tier-0 model author surface.

Implementations§

Source§

impl ModelFlow

Source

pub fn profile_file( self, path: impl AsRef<Path>, default: fn() -> CompileProfile, ) -> ModelFlow

Load tier-1 profile from a *.rlx.toml file (falls back to default on error).

Source

pub fn profile_encoder(self) -> ModelFlow

Encoder / embedding model defaults (Direct lowering, no KV fusion).

Source

pub fn gather_from_input( self, input_name: impl Into<String>, weight_key: impl Into<String>, ) -> ModelFlow

Gather rows from a side input into the primary flow (starts embedding stack).

Source

pub fn gather_add( self, input_name: impl Into<String>, weight_key: impl Into<String>, ) -> ModelFlow

Add an embedding looked up from a side input.

Source

pub fn layer_norm( self, gamma_key: impl Into<String>, beta_key: impl Into<String>, eps: f32, ) -> ModelFlow

LayerNorm with separate gamma/beta weights.

Source

pub fn gelu_ffn(self, layer_prefix: impl Into<String>) -> ModelFlow

BERT-style GELU FFN under a layer prefix.

Source

pub fn repeat_nomic_layers( self, count: usize, hidden_size: usize, num_heads: usize, head_dim: usize, eps: f32, ) -> ModelFlow

Repeat NomicBERT encoder layers.

Source

pub fn bert_encoder_layer(self, spec: BertEncoderLayerSpec) -> ModelFlow

BERT-style encoder layer (fused QKV + padding-mask attention + GELU FFN).

Source

pub fn repeat_bert_layers( self, count: usize, prefix: impl Into<String>, qkv_style: BertQkvStyle, hidden_size: usize, num_heads: usize, eps: f32, ) -> ModelFlow

Repeat BERT encoder layers with auto-named prefixes.

Source

pub fn attn_mask_ones(self, batch: usize, seq: usize) -> ModelFlow

Synthesize an all-ones attention mask for vision encoders (no padding).

Source

pub fn repeat_dinov2_layers( self, count: usize, hidden_size: usize, num_heads: usize, eps: f32, ) -> ModelFlow

Repeat DINOv2 ViT encoder blocks.

Source

pub fn repeat_vision_layers( self, count: usize, hidden_size: usize, num_heads: usize, eps: f32, ) -> ModelFlow

Repeat NomicVision encoder blocks.

Source

pub fn repeat_siglip_layers( self, count: usize, hidden_size: usize, num_heads: usize, eps: f32, ) -> ModelFlow

Compatibility shim: repeat SigLIP-style vision layers.

Source

pub fn cls_token_pool(self, batch: usize, hidden: usize) -> ModelFlow

Pool CLS token: [batch, seq, hidden][batch, hidden].

Source

pub fn profile_prefill(self) -> ModelFlow

Fusion-first prefill defaults.

Source

pub fn profile_decode(self) -> ModelFlow

Decode / KV-cache defaults (Fusable lowering).

Source

pub fn embed(self, weight_key: impl Into<String>) -> ModelFlow

Token embedding (model.embed_tokens.weight by default).

Source

pub fn token_embed(self) -> ModelFlow

HuggingFace-style token embedding table.

Source

pub fn rope_tables(self, tables: RopeTablesStage) -> ModelFlow

Precomputed RoPE sin/cos tables stored as params.

Source

pub fn zero_beta(self, len: usize) -> ModelFlow

Rank-1 zero vector for RMSNorm beta slots (LLaMA has no beta).

Source

pub fn zero_beta_named(self, name: impl Into<String>, len: usize) -> ModelFlow

Source

pub fn bind_decode_inputs( self, num_layers: usize, custom_mask: bool, ) -> ModelFlow

Bind decode inputs (call after declaring rope_cos, past_k_*, …).

Source

pub fn repeat_layers( self, count: usize, stage_for_layer: impl Fn(usize) -> FlowStage + Send + Sync + 'static, ) -> ModelFlow

Repeat a per-layer stage count times (layer index passed to closure).

Source

pub fn named_layer(self, name: impl Into<String>, inner: FlowStage) -> ModelFlow

Named decoder layer (shows up in fusion / inspect dumps).

Source

pub fn layer( self, name: impl Into<String>, build: impl FnOnce(LayerStack) -> LayerStack, ) -> ModelFlow

Build a named layer from a LayerStack closure.

Source

pub fn llama_prefill_layer( self, layer_idx: usize, spec: LlamaDecoderSpec, ) -> ModelFlow

Fused LLaMA prefill layer (default fast path).

Source

pub fn llama_prefill_layer_composed( self, layer_idx: usize, spec: LlamaDecoderSpec, ) -> ModelFlow

Composed LLaMA prefill layer (small blocks — customize via LayerStack).

Source

pub fn linear(self, weight_key: impl Into<String>, transpose: bool) -> ModelFlow

Source

pub fn residual_save(self) -> ModelFlow

Source

pub fn residual_add(self) -> ModelFlow

Source

pub fn swiglu( self, gate_key: impl Into<String>, up_key: impl Into<String>, down_key: impl Into<String>, ) -> ModelFlow

Source

pub fn swiglu_hf_mlp(self, prefix: impl Into<String>) -> ModelFlow

Source

pub fn self_attn_prefill(self, spec: SelfAttnPrefillSpec) -> ModelFlow

Source

pub fn gdn_scan(self, stage: GdnScanStage) -> ModelFlow

Source

pub fn store_stream(self, name: impl Into<String>) -> ModelFlow

Source

pub fn load_stream(self, name: impl Into<String>) -> ModelFlow

Source

pub fn bind_inputs_to_streams( self, pairs: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>, ) -> ModelFlow

Bind declared graph inputs into named streams (multi-input models).

Example: FLUX .bind_inputs_to_streams(&[("hidden", "img"), ("encoder", "txt")]).

Source

pub fn dual_stream<F>( self, name: impl Into<String>, stream_a: impl Into<String>, stream_b: impl Into<String>, f: F, ) -> ModelFlow
where F: Fn(&mut Emit<'_>, FlowValue, FlowValue) -> Result<(FlowValue, FlowValue), Error> + Send + Sync + 'static,

Source

pub fn plugin<F>(self, f: F) -> ModelFlow
where F: Fn(&mut Emit<'_>, Option<FlowValue>) -> Result<Option<FlowValue>, Error> + Send + Sync + 'static,

Source

pub fn plugin_named<F>(self, name: impl Into<String>, f: F) -> ModelFlow
where F: Fn(&mut Emit<'_>, Option<FlowValue>) -> Result<Option<FlowValue>, Error> + Send + Sync + 'static,

Source

pub fn hidden_states(self) -> ModelFlow

Hidden states output (no LM head).

Source

pub fn llama_decoder_layer( self, layer_idx: usize, spec: LlamaDecoderSpec, ) -> ModelFlow

LLaMA prefill decoder block at layer_idx.

Source

pub fn llama_decode_layer( self, layer_idx: usize, spec: LlamaDecodeLayerSpec, kv_out: SideOutputs, ) -> ModelFlow

LLaMA decode block with KV-cache concat.

Source

pub fn llama_kv_tap( self, layer_idx: usize, head_dim: usize, eps: f32, sink: &SideOutputs, ) -> ModelFlow

Side-effect K/V tap before a prefill layer (exports cache tensors).

Source

pub fn final_norm(self, eps: f32) -> ModelFlow

Final RMSNorm before LM head (model.norm.weight by default).

Source

pub fn rms_norm(self, weight_key: impl Into<String>, eps: f32) -> ModelFlow

Source

pub fn gather_last_token_dynamic(self, batch: usize) -> ModelFlow

Gather last token (dynamic last_token_idx input).

Source

pub fn gather_last_token_at(self, batch: usize, seq: usize) -> ModelFlow

Gather last token at fixed sequence length.

Source

pub fn lm_head( self, vocab_size: usize, hidden_size: usize, tie_word_embeddings: bool, ) -> ModelFlow

Causal LM head — tied or separate weights.

Source

pub fn raw_stage(self, stage: FlowStage) -> ModelFlow

Tier-2 escape hatch — append a raw stage.

Source

pub fn raw_stages( self, stages: impl IntoIterator<Item = FlowStage>, ) -> ModelFlow

Append multiple raw stages in order.

Source

pub fn sequence(self, stages: impl IntoIterator<Item = FlowStage>) -> ModelFlow

Run a list of stages as one nested sequence (side-effect stages allowed).

Source

pub fn when( self, cond: bool, f: impl FnOnce(ModelFlow) -> ModelFlow, ) -> ModelFlow

Conditionally transform the builder (e.g. optional vision tower).

Source

pub fn custom<F>(self, f: F) -> ModelFlow
where F: Fn(&mut Emit<'_>, Option<FlowValue>) -> Result<Option<FlowValue>, Error> + Send + Sync + 'static,

Tier-2 custom subgraph — prefer promoting repeated patterns to blocks.

Source

pub fn custom_named<F>(self, name: impl Into<String>, f: F) -> ModelFlow
where F: Fn(&mut Emit<'_>, Option<FlowValue>) -> Result<Option<FlowValue>, Error> + Send + Sync + 'static,

Named custom subgraph (shows up in fusion / inspect dumps).

Source

pub fn patch(self, f: impl FnOnce(ModelFlow) -> ModelFlow) -> ModelFlow

Patch the builder after preset assembly (arch recipes, Llama32Flow hooks).

Source§

impl ModelFlow

Source

pub fn new(name: impl Into<String>) -> ModelFlow

Source

pub fn with_extensions(self, plan: FlowExtensionPlan) -> ModelFlow

HIR extensions to apply after assemble, before compile (retroactive plugins).

Source

pub fn input(self, name: impl Into<String>, shape: Shape) -> ModelFlow

Declare a graph input. The first input starts the tensor flow; later inputs are side declarations only (e.g. last_token_idx).

Source

pub fn with_profile(self, profile: CompileProfile) -> ModelFlow

Source

pub fn profile(&self) -> &CompileProfile

Source

pub fn stage(self, stage: FlowStage) -> ModelFlow

Source

pub fn output(self, name: impl Into<String>) -> ModelFlow

Source

pub fn outputs( self, names: impl IntoIterator<Item = impl Into<String>>, ) -> ModelFlow

Source

pub fn with_extra_outputs(self, ids: Vec<HirNodeId>) -> ModelFlow

Append side outputs (e.g. per-layer KV taps) after the primary output.

Source

pub fn from_recipe(recipe: &impl ModelRecipe) -> ModelFlow

Build from a composable recipe, then optionally patch before compile.

Source

pub fn build(self, weights: &mut dyn WeightSource) -> Result<BuiltModel, Error>

Source

pub fn build_with( self, weights: &mut dyn WeightSource, _gguf_packed: Option<&GgufPackedParams>, ) -> Result<BuiltModel, Error>

Compatibility shim: older callers passed GGUF packed matmul params.

The current flow builder ignores packed params; packed lowering lives in model crates.

Trait Implementations§

Source§

impl Debug for ModelFlow

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl FlowBuildExt for ModelFlow

Source§

fn with_lm_head(self, vocab: usize, hidden: usize, tied: bool) -> Self

Source§

fn logits(self) -> Self

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.