Expand description
RLX model loading — parse configs, load weights, build IR graphs.
This crate is a thin facade over per-model workspace members (rlx-qwen3,
rlx-sam, …). Depend on a specific model crate directly when you only need
one family.
Modules§
- arch_
registry - Architecture registry (plan #82).
- config
- Model configuration structs — parsed from HuggingFace config.json.
- dataprocessing
- Reusable batch-prep utilities (plan #83).
- embed
- flow_
bridge - Bridge between
rlx-modelsloaders/runtime andrlx-flow. - flow_
util - Shared helpers for tier-0 model flow migration.
- flux2
- gguf_
resolve - Pluggable GGUF tensor-name resolution per
general.architecture. - gguf_
support - Shared GGUF helpers for LM runners (architecture checks, path resolution).
- lm
- Shared causal-LM flow helpers — re-export tier-0 surface for model authors.
- qwen35
- qwen35_
synth - Synthetic configs/weights for tests and
qwen35_inferencebench. Synthetic Qwen3.5 weights for integration tests and criterion benches. - vision_
ops_ ir - Shared HIR builders for NCHW vision ops (
Conv,ConvTranspose2d,LayerNorm2d, bias broadcast). Used by SAM / SAM2 / SAM3. - weight_
loader - Pluggable weight loader trait (plan #56).
- weight_
map - Safetensors weight loading — standalone, no framework dependency.
- weight_
registry - Extensible weight-format registry — register custom loaders for new extensions.
- weights
- Model-agnostic weight I/O — paths, formats, drain policy only.
Structs§
- Bert
Config - BERT model configuration.
- Bert
Tokenizer - Wrapper around HuggingFace tokenizer configured for BERT-style encoding.
- Built
Model - Result of assembling a model flow.
- Chat
Message - One turn in a ChatML conversation.
- Compile
Profile - Tier-1 compile configuration. Load from
*.rlx.tomlor use Rust presets. - Flux2
CfgCombine Flow - Tier-0 CFG combine:
neg + scale * (pos - neg). - Flux2
CfgCombine Graph - Flux2
Checkpoint - Resolved on-disk layout for a FLUX.2 HF repo (diffusers-style tree).
- Flux2
Config - FLUX.2 rectified-flow transformer (denoiser) configuration.
- Flux2
Flow - Tier-0 FLUX.2 dual-stream flow builder.
- Flux2
Forward Built - Full forward build product (includes non-f32 typed param blobs).
- Flux2
Forward Graph - Flux2
Forward Input - Inputs for one transformer forward (noise prediction).
- Flux2
Output - Noise prediction from
Flux2Runner::forward. - Flux2
Prompt Output - Flux2
Runner - FLUX.2 denoiser runner — native CPU or compiled HIR on any
Device. - Flux2
Runner Builder - Builder for
Flux2Runner. - Flux2
Session - One loaded FLUX.2 pipeline — cheap to clone via
Arc. - Flux2
Session Cache - Process-wide cache of
Flux2Runnerinstances (CLI--reuse-session/ serve mode). - Flux2
Session Key - Cache key for deduplicating loaded runners.
- Flux2
Text Encoder Built - Flux2
Text Encoder Flow - Tier-0 FLUX.2 text encoder flow (Qwen3-shaped causal LM trunk).
- Flux2
VaeConfig - Flux2
VaeDecoder Flow - Tier-0 FLUX.2 VAE decoder flow.
- Flux2
VaeEncoder Flow - Tier-0 FLUX.2 VAE encoder flow.
- Flux2
VaeGraph - Flux2
VaeWeights - Flux2
Weights - Gguf
DirGuide - Llama
Family Gguf Resolver - HF
model.layers.N.*↔ GGUFblk.N.*(Llama, Qwen3, Qwen35, …). - Load
Weights Options - Options for
load_weights_resolved— prefercrate::weights::LoadOptspresets at call sites. - Model
Info - Metadata for an embedding model.
- Nomic
Bert Config - NomicBERT model configuration.
- Nomic
Vision Config - NomicVision model configuration.
- Qwen35
Config - Qwen3.5 model config — fields covering both the per-layer Mamba+ Attention block and the MTP head.
- Qwen35
Full Attn Layer - Standard full-attention trunk layer (interspersed every
full_attention_intervalblocks). Perqwen35.cpp::load_block_trunknon-recurrent branch. - Qwen35
Linear Layer - Gated DeltaNet (“linear attention”) trunk layer. Mirrors
qwen35.cpp::load_block_trunkfor theis_recurrent(il)branch. - Qwen35
MoeFfn - MoE FFN tensors for one decoder layer (trunk or MTP).
- Qwen35
MtpLayer - One MTP (NextN) layer. Per
qwen35.cpp::load_block_mtp. - Qwen35
Native Gguf Resolver - Qwen3.5 native
blk.N.*names; also accept HF aliases via the Llama mapper. - Qwen35
Prefill Output - Qwen35
Runner - Qwen35
Runner Builder - Qwen35
Weights - Top-level Qwen3.5 / Qwen3.6 weight bundle.
- Registered
Format - One registered on-disk format (built-in or custom).
- Resolve
Weights Options - Options for
resolve_weights_file_with_options. - RlxBert
Model - RLX-compiled BERT model ready for inference.
- RlxEmbed
- High-level embedding model — auto-detects BERT / NomicBERT / NomicVision.
- RlxNomic
Model - RLX-compiled NomicBERT with shape-bucketed compile cache.
- RlxVision
Model - RLX-compiled NomicVision encoder (patch preprocess host-side, trunk on RLX).
- Tokenized
Batch - Output of batch tokenization: token IDs, attention masks, and token type IDs.
- Weight
Format Registration - Describes one on-disk weight format.
- Weight
Map - Map of tensor name → (f32 data, shape).
- Weight
MapSource - Adapt in-memory
WeightMaptoWeightSource.
Enums§
- Arch
- Detected embedding architecture from
config.json. - Chat
Role - Conversation role for
ChatMessage. - Embed
Gguf Kind - BERT vs NomicBERT discriminator from GGUF metadata.
- Embedding
Model - Supported text embedding models.
- Gguf
Model Family - LM families in this workspace that load
.ggufweights. - Image
Embedding Model - Supported image embedding models.
- Loaded
Weights - Result of resolving and opening weights.
- MatWeight
- Storage variant for matmul weight tensors. The big projections
(qkv / gate / ffn / lm_head) dominate the load footprint; the
Packedvariant keeps GGUF K-quant bytes in-place so the graph can emitOp::DequantMatMulinstead of a full F32 dequant. - Model
Arch - Model architecture type.
- Pooling
- Pooling strategy for reducing token hidden states to one vector per sequence.
- Qwen35
Layer Ffn - Per-layer feed-forward: dense SwiGLU or MoE (routed + gated shared expert).
- Qwen35
Trunk Layer - One trunk-layer tensor bundle. Either a gated-DeltaNet “linear attention” block or a standard full-attention block.
- Weight
Drain Policy - How
WeightMap::drain_loader/WeightMap::from_weight_loaderhandle leftovers.
Constants§
- DEFAULT_
TEXT_ ENCODER_ LAYERS - Default hidden-state indices for FLUX.2 Klein (matches mflux).
- STANDARD_
DEVICE_ NAMES - CLI / help string for
--device.
Traits§
- Flow
Build Ext - Gguf
Tensor Name Resolver - Resolve a builder-requested tensor name to the name stored in a GGUF file.
- Weight
Loader - Common interface every weight format must satisfy. Mirrors the
existing
WeightMapAPI so the safetensors impl is a one-line adapter.
Functions§
- apply_
compile_ profile - Apply tier-1 profile options to runtime compile options.
- assemble_
vision_ hidden - Assemble encoder input
[batch, seq, hidden]from NCHW pixels + preprocess weights. - assert_
gguf_ family - Open the file and ensure
general.architecturematchesexpected. - build_
flux2_ cfg_ combine_ hir - HIR graph:
neg + guidance_scale * (pos - neg)in f32. - build_
flux2_ forward_ graph - build_
flux2_ forward_ hir - Build the full denoiser forward graph in HIR.
- build_
flux2_ minimal_ graph - Lower minimal HIR to legacy
Graph(MIR inner) forSession::compile. - build_
flux2_ minimal_ hir - Build a compile-minimal HIR module:
x_embedder(hidden)→proj_out. - build_
flux2_ text_ encoder_ hir - build_
graph - Build via flow and lower to MIR graph + params.
- build_
qwen35_ decode_ graph - Single-token decode graph at prefix length
past_seq. - build_
qwen35_ decode_ hir_ dynamic_ ext - Decode HIR with symbolic past length (
sym::PAST_SEQ) for dynamic compile cache. - build_
qwen35_ graph_ sized - Build the Qwen3.5 forward IR.
- build_
qwen35_ graph_ sized_ ext - Forward graph with optional runtime MRoPE inputs (
rope_cos/rope_sin). - build_
qwen35_ graph_ sized_ stub - Legacy redirect — qwen35 forward is implemented via
build_qwen35_graph_sized. Kept so older call sites get a clear message instead of a missing-symbol error. - build_
qwen35_ prefill_ cache_ graph - Prefill graph that seeds
super::cache::Qwen35DecodeCache. - build_
qwen35_ prefill_ cache_ graph_ ext - Prefill-cache graph with optional runtime MRoPE inputs (multimodal).
- build_
qwen35_ prefill_ cache_ hir_ dynamic_ ext - Prefill-cache HIR with symbolic seq dim (
sym::SEQ) for dynamic compile cache. - built_
from_ graph - built_
from_ hir - built_
from_ hir_ with_ profile - cfg_
combine - Native CFG blend in float32.
- compile_
built - Compile a
BuiltModelon the given device using its embedded profile. - compile_
built_ cpu - Compile a
BuiltModelon CPU with default options (embedding quick-check tests). - compile_
flux2_ cfg_ combine - compile_
flux2_ forward - compile_
flux2_ forward_ via_ flow - Compile denoiser via tier-0
Flux2Flowwrapper (same numerics assuper::hir_builder::compile_flux2_forward). - compile_
flux2_ minimal - Compile minimal HIR on CPU (HIR → MIR → LIR).
- compile_
flux2_ text_ encoder_ hir - compile_
graph_ encoder - Bidirectional encoder defaults (BERT, DINOv2, Wav2Vec2, vision towers).
- compile_
graph_ encoder_ with_ params CompileProfile::encoder+ params.- compile_
graph_ legacy - Unprofiled compile (parity probes / bisect tests).
- compile_
graph_ llama32_ decode - Llama 3.2 decode graphs.
- compile_
graph_ llama32_ prefill - Llama 3.2 prefill graphs.
- compile_
graph_ profile - Lower a graph with a tier-1 profile and attach params (tests / examples).
- compile_
graph_ qwen3_ decode - Qwen3 single-token decode graphs.
- compile_
graph_ qwen3_ prefill - Qwen3 prefill / full-sequence graphs.
- compile_
graph_ qwen3_ prefill_ with_ params CompileProfile::qwen3_prefill+ params.- compile_
graph_ qwen35_ decode - Qwen3.5 decode-step graphs.
- compile_
graph_ qwen35_ decode_ with_ params CompileProfile::qwen35_decode+ params.- compile_
graph_ qwen35_ prefill - Qwen3.5 prefill-cache / predict graphs.
- compile_
graph_ qwen35_ prefill_ with_ params CompileProfile::qwen35_prefill+ params.- compile_
graph_ sam - Compile a SAM/SAM2/SAM3 vision subgraph with tier-1 encoder profile options.
- compile_
graph_ sam_ with_ params CompileProfile::sam_encoder+ params.- compile_
graph_ with_ profile - Compile a vision subgraph with explicit tier-1 profile options.
- compile_
model - Compile an embedding graph for the given batch/seq on
device. - decode_
step_ feeds - Build host feeds for a single decode step from
cache. - detect_
arch - Detect architecture from config.json fields.
- download_
flux2_ repo - embed_
with_ rlx - Embed texts with a compiled BERT model: tokenize, forward, pool, L2-normalize.
- encode_
chat_ auto - Resolve tokenizer next to weights and encode a chat conversation.
- encode_
flux2_ prompt - End-to-end: tokenize (optional) + text encoder → embeddings + text ids.
- encode_
prompt_ embeds_ default_ layers - Encode with default Klein layer indices (9, 18, 27).
- encode_
prompt_ padded - Encode and pad/truncate to fixed
seq_len(pad token id 0). - extract_
flux2_ vae_ weights - extract_
flux2_ weights - extract_
text_ encoder_ weights - flux2_
decode_ packed_ latents - Full post-denoise decode: packed transformer latents → 8-bit RGB planar
[batch, 3, H, W]. - flux2_
prefers_ compiled_ hir - True when the denoiser / VAE should use compiled HIR (non-CPU backends).
- flux2_
prefers_ compiled_ te - Text encoder HIR on CUDA compiles a full Qwen3 trunk and can take hours + fill VRAM while the denoiser is still resident. Native CPU encode once, then drop TE.
- flux2_
rgb_ to_ u8 - Planar RGB
[-1,1]→ interleavedu8HWC for PNG. - flux2_
transformer_ forward - Run the FLUX.2 transformer and return noise prediction
[batch, img_seq, patch_size² * out_channels]. - format_
chatml - Format messages as a ChatML prompt ending with an open assistant turn.
- format_
for_ extension - Extension → format id (last registration wins).
- gguf_
architecture_ str general.architecturestring from GGUF metadata, if present.- gguf_
dir_ guide - Numbered
.gguflisting + resolve hints for a directory (CLI / errors). - gguf_
f32_ bytes_ estimate - Rough F32 dequant footprint (every tensor × 4 bytes).
- gguf_
family_ for_ arch - Map a GGUF architecture tag to the runner family that should load it.
- gguf_
runner_ hint - Suggested runner / crate for a GGUF architecture tag (for CLI and errors).
- graph_
from_ built - Build a flow and return
(Graph, params)— preferred compile entry point. - graph_
from_ hir - Lower an existing HIR module through
BuiltModel(utility for HIR-first builders). - host_
temb - Host-side temb for compiled forward (timestep × 1000, optional guidance × 1000).
- into_
compile_ parts - Split built flow for compile — no Graph/HIR imports needed at call site.
- is_
standard_ device - True when
deviceis inSTANDARD_DEVICES. - list_
registered_ formats - All registered formats (built-ins first, then custom registrations).
- load_
and_ apply_ flux2_ lora - Load LoRA from safetensors and merge into
base. - load_
compile_ profile - Load a tier-1 profile from disk; fall back to
defaultwhen missing or invalid. - load_
flux2_ vae_ weights - load_
flux2_ weights - load_
from_ path - Dispatch on the file extension via
crate::weight_registry. - load_
rgb_ planar - Load an image, resize to
(width, height), return planar NCHW f32 in[-1, 1]. - load_
text_ encoder_ weights - load_
weight_ map_ resolved - Convenience: resolve + drain to F32
WeightMap. - load_
weights_ resolved - Resolve a file or directory, enforce GGUF arch policy, open via registry, optionally drain.
- messages_
from_ prompt - Convenience: system (optional) + user prompt → ChatML messages.
- models_
map - Get the global model registry.
- mrope_
prefill_ feeds - Flattened
[seq * head_half]cos/sin for runtime MRoPE graph inputs. - mrope_
row_ for_ sections - Build one MRoPE cos/sin row from explicit per-section positions.
- mrope_
slice_ at_ pos - Slice MRoPE cos/sin at absolute text position
pos. - mtp_
draft_ vocab_ size - MTP LM head output width: full vocab, or trimmed for FastMTP draft speed.
- open_
map - Resolve + drain to F32
WeightMap. - open_
map_ with - Resolve + drain with options.
- open_
weights - Resolve + open (live
WeightLoader). - open_
with - Resolve + open with options.
- pack_
input_ ids - Pack per-row prompts into
[batch, max_seq]row-major F32 ids (zero-pad). - parse_
lora_ scale - Parse
--lora-scalestyle input; rejects NaN/inf. - parse_
messages_ json - Parse a JSON array of
{ "role": "...", "content": "..." }. - prepare_
latent_ ids - FLUX.2 latent position ids
[batch, h*w, 4]with(t=0, h, w, l=0). - prepare_
text_ ids - Build FLUX.2-style text position ids
[batch, seq, 4]flattened as[seq*4]. - prepare_
weight_ map - Full load-time adaptation pipeline.
- profile_
near_ weights - Load
profile_filenext toweights(parent directory); fall back todefault. - recurrent_
output_ count - Number of extra graph outputs after logits (and optional MTP).
- register_
gguf_ tensor_ resolver - Register a custom resolver (call before first GGUF load). Later registrations win among resolvers that match the same architecture.
- register_
weight_ format - Register a custom weight format (call before the first load). Later entries override built-ins when the same extension is registered twice.
- resolve_
text_ encoder_ dir - Resolve
text_encoder/next to a transformer weights file or model root. - resolve_
tokenizer_ path - Resolve tokenizer path: explicit,
tokenizer/tokenizer.json, or siblingtokenizer.json. - resolve_
transformer_ config - Resolve transformer
config.jsonfrom explicit override or sibling search. - resolve_
vae_ dir - Resolve
vae/next to a transformer weights file or model root. - resolve_
weights_ file - Resolve
--weightsto a single file: pass-through for files, or pick one.gguf/model.safetensorsinside a directory. - resolve_
weights_ file_ with_ options - Resolve with optional GGUF file selection inside a directory.
- seed_
cache_ from_ outputs - Parse prefill-cache graph outputs into logits/hidden +
Qwen35DecodeCache. Whentrunk_is_hidden, the first output is[batch × hidden_size]not logits. - supports_
multimodal_ mrope - True when the checkpoint declares a non-zero 4th MRoPE section (vision).
- text_
section_ pos - Text-modality default:
[p, p, p, 0]per llama.cpp token batches. - tiny_
text_ encoder_ config Qwen3Configsized forsuper::weights::synthetic_text_encoder_weightstests.- validate_
device - Validate that
deviceis in the workspace standard backend set (CPU, Metal, MLX, CUDA, ROCm, WGPU, Vulkan). Build withall-backendsonrlx-qwen35to link every native runtime backend into therlx-qwen35binary. - validate_
sam_ device - SAM v1 also documents
tpuon [rlx_sam::Sam::from_safetensors_on]. - validate_
standard_ device - Fail fast on exotic runtime devices (TPU, ANE, OpenGL, …).
- zero_
recurrent_ inputs - Zero-initialized recurrent inputs for a prefill-cache seed graph.
Type Aliases§
- Flux2
Graph Params - Param tensors keyed by name for
rlx_runtime::CompiledGraph::set_param. - Load
Opts - Alias for
LoadWeightsOptions. - Pass
Through Gguf Resolver - Alias for
PrefixStripGgufResolver(older name). - Resolve
Opts - Alias for
ResolveWeightsOptions.