Skip to main content

rlx_models/
lib.rs

1// RLX — versatile ML compiler + runtime.
2// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! RLX model loading — parse configs, load weights, build IR graphs.
17//!
18//! This crate is a thin facade over per-model workspace members (`rlx-qwen3`,
19//! `rlx-sam`, …). Depend on a specific model crate directly when you only need
20//! one family.
21
22pub use rlx_core::{
23    BertConfig, EmbedGgufKind, FlowBuildExt, GgufDirGuide, GgufModelFamily, GgufTensorNameResolver,
24    LlamaFamilyGgufResolver, LoadOpts, LoadWeightsOptions, LoadedWeights, NomicBertConfig,
25    NomicVisionConfig, PassThroughGgufResolver, Qwen35NativeGgufResolver, RegisteredFormat,
26    ResolveOpts, ResolveWeightsOptions, STANDARD_DEVICE_NAMES, WeightDrainPolicy,
27    WeightFormatRegistration, WeightLoader, WeightMap, WeightMapSource, arch_registry,
28    assert_gguf_family, config, dataprocessing, flow_bridge, flow_util, format_for_extension,
29    gguf_architecture_str, gguf_dir_guide, gguf_f32_bytes_estimate, gguf_family_for_arch,
30    gguf_resolve, gguf_runner_hint, gguf_support, into_compile_parts, is_standard_device,
31    list_registered_formats, lm, load_from_path, load_weight_map_resolved, load_weights_resolved,
32    open as open_weights, open_map, open_map_with, open_with, register_gguf_tensor_resolver,
33    register_weight_format, resolve_weights_file, resolve_weights_file_with_options,
34    validate_sam_device, validate_standard_device, vision_ops_ir, weight_loader, weight_map,
35    weight_registry, weights,
36};
37pub use rlx_flow::{BuiltModel, CompileProfile};
38
39pub mod bert {
40    pub use rlx_bert::bert::*;
41}
42pub mod bert_flow {
43    pub use rlx_bert::flow::*;
44}
45pub mod clinicalbert {
46    pub use rlx_clinicalbert::*;
47}
48pub mod nomic {
49    pub use rlx_nomic::nomic::*;
50}
51pub mod nomic_flow {
52    pub use rlx_nomic::flow::*;
53}
54pub mod vision {
55    pub use rlx_vision::vision::*;
56}
57pub mod vision_flow {
58    pub use rlx_vision::flow::*;
59}
60pub mod dinov2 {
61    pub use rlx_dinov2::*;
62}
63pub mod bioclip2 {
64    pub use rlx_bioclip2::*;
65}
66pub mod embed {
67    pub use rlx_embed::*;
68}
69pub mod flux2 {
70    pub use rlx_flux2::*;
71}
72pub mod diamond {
73    pub use rlx_diamond::*;
74}
75pub mod qwen3 {
76    pub use rlx_qwen3::*;
77}
78pub mod qwen35 {
79    pub use rlx_qwen35::*;
80}
81pub mod llama32 {
82    pub use rlx_llama32::*;
83}
84pub mod gemma {
85    pub use rlx_gemma::*;
86}
87pub mod llada2 {
88    pub use rlx_llada2::llada2::*;
89}
90pub mod tide {
91    pub use rlx_llada2::tide::*;
92}
93pub mod sam {
94    pub use rlx_sam::*;
95}
96pub mod sam2 {
97    pub use rlx_sam2::*;
98}
99pub mod sam3 {
100    pub use rlx_sam3::*;
101}
102pub mod vjepa2 {
103    pub use rlx_vjepa2::*;
104}
105pub mod wav2vec2_bert {
106    pub use rlx_wav2vec2_bert::*;
107}
108pub mod wav2vec2_asr {
109    pub use rlx_wav2vec2_asr::*;
110}
111pub mod diarize {
112    pub use rlx_diarize::*;
113}
114pub mod whisper {
115    pub use rlx_whisper::*;
116}
117pub mod vad {
118    pub use rlx_vad::*;
119}
120pub mod aec {
121    pub use rlx_aec::*;
122}
123pub mod voxtral {
124    pub use rlx_voxtral::*;
125}
126pub mod qwen3_asr {
127    pub use rlx_qwen3_asr::*;
128}
129pub mod voxtral_tts {
130    pub use rlx_voxtral_tts::*;
131}
132
133pub mod qwen3_tts {
134    pub use rlx_qwen3_tts::*;
135}
136pub mod locateanything {
137    pub use rlx_locateanything::*;
138}
139pub mod ocr {
140    pub use rlx_ocr::*;
141}
142pub mod neutts {
143    pub use rlx_neutts::*;
144}
145pub mod orpheus {
146    pub use rlx_orpheus::*;
147}
148pub mod kittentts {
149    pub use rlx_kittentts::*;
150}
151pub mod florence2 {
152    pub use rlx_florence2::*;
153}
154pub mod mimi {
155    pub use rlx_mimi::*;
156}
157pub mod tsac {
158    pub use rlx_tsac::*;
159}
160pub mod moshi {
161    pub use rlx_moshi::*;
162}
163pub use rlx_neutts::{
164    BackboneModel, DEFAULT_N_CTX, GenerationConfig, NeuCodecDecoder, NeuCodecEncoder, NeuTTS,
165    STOP_TOKEN, build_prompt, extract_ids,
166};
167
168#[deprecated(note = "use `rlx_models::ocr`")]
169pub mod ocrs {
170    pub use rlx_ocr::*;
171}
172
173// ── Stub families (PLAN.md M4 — no runner yet). Each exposes a
174// `*Runner::builder().build()` that returns an error pointing at the
175// milestone, so callers get a typed surface to wire against today.
176pub mod mistral {
177    pub use rlx_mistral::*;
178}
179pub mod bonsai {
180    pub use rlx_bonsai::*;
181}
182pub mod minicpm5 {
183    pub use rlx_minicpm5::*;
184}
185pub mod phi {
186    pub use rlx_phi::*;
187}
188pub mod omnicoder {
189    pub use rlx_omnicoder::*;
190}
191pub mod granite {
192    pub use rlx_granite::*;
193}
194pub mod cohere {
195    pub use rlx_cohere::*;
196}
197pub mod mask_hyper_matmul_ir {
198    pub use rlx_sam_ir::mask_hyper_matmul_ir::*;
199}
200pub mod mask_prompt_ir {
201    pub use rlx_sam_ir::mask_prompt_ir::*;
202}
203pub mod mlp_relu_ir {
204    pub use rlx_sam_ir::mlp_relu_ir::*;
205}
206pub mod twoway_transformer_ir {
207    pub use rlx_sam_ir::twoway_transformer_ir::*;
208}
209
210pub mod run;
211mod sam_runner;
212
213pub use rlx_core::flow_bridge::{
214    apply_compile_profile, compile_graph_encoder, compile_graph_legacy,
215    compile_graph_llama32_decode, compile_graph_llama32_prefill, compile_graph_qwen3_decode,
216    compile_graph_qwen3_prefill, compile_graph_qwen35_decode, compile_graph_qwen35_prefill,
217    compile_graph_sam, compile_graph_with_profile, load_compile_profile, profile_near_weights,
218};
219pub use rlx_core::flow_util::{
220    build_graph, built_from_graph, built_from_hir, built_from_hir_with_profile, compile_built,
221    compile_built_cpu, compile_graph_encoder_with_params, compile_graph_profile,
222    compile_graph_qwen3_prefill_with_params, compile_graph_qwen35_decode_with_params,
223    compile_graph_qwen35_prefill_with_params, compile_graph_sam_with_params, graph_from_built,
224    graph_from_hir,
225};
226
227pub use bert::{build_bert_graph, build_bert_graph_sized};
228pub use bert_flow::{BertFlow, build_bert_built};
229pub use diarize::{DiarizeConfig, DiarizeSession, SpeakerTurn as DiarizeSpeakerTurn};
230pub use dinov2::{
231    DinoV2Built, DinoV2Config, DinoV2Flow, DinoV2PreprocessWeights, build_dinov2_built,
232    build_dinov2_graph_sized,
233};
234pub use embed::{
235    Arch, BertTokenizer, EmbeddingModel, ImageEmbeddingModel, ModelArch, ModelInfo, Pooling,
236    RlxBertModel, RlxEmbed, RlxNomicModel, RlxVisionModel, TokenizedBatch, assemble_vision_hidden,
237    compile_model, detect_arch, embed_with_rlx, models_map,
238};
239pub use flux2::{
240    DEFAULT_TEXT_ENCODER_LAYERS, Flux2CfgCombineFlow, Flux2CfgCombineGraph, Flux2Checkpoint,
241    Flux2Config, Flux2Flow, Flux2ForwardBuilt, Flux2ForwardGraph, Flux2ForwardInput,
242    Flux2GraphParams, Flux2PromptOutput, Flux2Session, Flux2SessionCache, Flux2SessionKey,
243    Flux2TextEncoderBuilt, Flux2TextEncoderFlow, Flux2VaeConfig, Flux2VaeDecoderFlow,
244    Flux2VaeEncoderFlow, Flux2VaeGraph, Flux2VaeWeights, Flux2Weights, build_flux2_cfg_combine_hir,
245    build_flux2_forward_graph, build_flux2_forward_hir, build_flux2_minimal_graph,
246    build_flux2_minimal_hir, build_flux2_text_encoder_hir, cfg_combine, compile_flux2_cfg_combine,
247    compile_flux2_forward, compile_flux2_forward_via_flow, compile_flux2_minimal,
248    compile_flux2_text_encoder_hir, download_flux2_repo, encode_flux2_prompt,
249    encode_prompt_embeds_default_layers, encode_prompt_padded, extract_flux2_vae_weights,
250    extract_flux2_weights, extract_text_encoder_weights, flux2_decode_packed_latents,
251    flux2_prefers_compiled_hir, flux2_prefers_compiled_te, flux2_rgb_to_u8,
252    flux2_transformer_forward, host_temb, load_and_apply_flux2_lora, load_flux2_vae_weights,
253    load_flux2_weights, load_rgb_planar, load_text_encoder_weights, parse_lora_scale,
254    prepare_latent_ids, prepare_text_ids, prepare_weight_map, resolve_text_encoder_dir,
255    resolve_tokenizer_path, resolve_transformer_config, resolve_vae_dir, tiny_text_encoder_config,
256};
257pub use gemma::{
258    GemmaArch, GemmaConfig, GemmaFlow, GemmaGenerator, build_gemma_decode_graph_sized,
259    build_gemma_graph_sized, build_gemma_graph_sized_last_logits, build_gemma_graph_sized_packed,
260    encode_prompt as gemma_encode_prompt, encode_prompt_auto as gemma_encode_prompt_auto,
261    gemma_cfg_from_gguf, resolve_tokenizer_path as gemma_resolve_tokenizer_path,
262};
263pub use llada2::{
264    LLaDA2MoeConfig, LLaDA2Runner, LLaDA2RunnerBuilder, LLaDA2Weights, build_llada2_forward_graph,
265    default_memory_budget_bytes, validate_device as validate_llada2_device,
266};
267pub use llama32::{
268    Llama32Config, Llama32Flow, Llama32Generator, build_llama32_decode_graph_sized,
269    build_llama32_graph_sized, build_llama32_graph_sized_last_logits,
270    build_llama32_graph_sized_packed, encode_prompt as llama32_encode_prompt,
271    encode_prompt_auto as llama32_encode_prompt_auto, llama32_cfg_from_gguf,
272    resolve_tokenizer_path as llama32_resolve_tokenizer_path,
273};
274pub use nomic::{build_nomic_diagnostic_graph, build_nomic_graph_sized};
275pub use nomic_flow::{NomicFlow, build_nomic_built};
276pub use ocr::{
277    BLACK_VALUE, DEFAULT_ALPHABET, DecodeMethod, DetectionParams, DimOrder, HF_DETECTION_RTEN,
278    HF_DETECTION_ST, HF_RECOGNITION_RTEN, HF_RECOGNITION_ST, ImageSource, OcrConfig, OcrEngine,
279    OcrEngineParams, OcrInput, OcrOutput, OcrRunner, OcrRunnerBuilder, RotatedRect, TextChar,
280    TextLine, TextWord, resolve_model_dir,
281};
282pub use qwen3::{
283    Qwen3Config, Qwen3Flow, Qwen3Generator, Qwen3PrefillOpts, Qwen3Speculator, SampleOpts,
284    build_qwen3_graph_sized, build_qwen3_prefill_built, sample_token,
285};
286pub use qwen3_tts::{
287    HF_MODEL_ID_06B_CUSTOM as QWEN3_TTS_HF_MODEL_ID, PRESET_SPEAKERS as QWEN3_TTS_SPEAKERS,
288    Qwen3TtsBenchReport, Qwen3TtsConfig, Qwen3TtsRunner, Qwen3TtsWeightStore, TalkerEngine,
289};
290pub use qwen35::{
291    ChatMessage, ChatRole, MatWeight, Qwen35Config, Qwen35FullAttnLayer, Qwen35LayerFfn,
292    Qwen35LinearLayer, Qwen35MoeFfn, Qwen35MtpLayer, Qwen35PrefillOutput, Qwen35Runner,
293    Qwen35RunnerBuilder, Qwen35TrunkLayer, Qwen35Weights, build_qwen35_decode_graph,
294    build_qwen35_decode_hir_dynamic_ext, build_qwen35_graph_sized, build_qwen35_graph_sized_ext,
295    build_qwen35_graph_sized_stub, build_qwen35_prefill_cache_graph,
296    build_qwen35_prefill_cache_graph_ext, build_qwen35_prefill_cache_hir_dynamic_ext,
297    decode_step_feeds, encode_chat_auto, format_chatml, messages_from_prompt, mrope_prefill_feeds,
298    mrope_row_for_sections, mrope_slice_at_pos, mtp_draft_vocab_size, pack_input_ids,
299    parse_messages_json, recurrent_output_count, seed_cache_from_outputs,
300    supports_multimodal_mrope, synth as qwen35_synth, text_section_pos, validate_device,
301    zero_recurrent_inputs,
302};
303pub use rlx_flux2::{Flux2Output, Flux2Runner, Flux2RunnerBuilder};
304pub use run::{
305    ConfigSource, DinoV2Output, DinoV2Runner, DinoV2RunnerBuilder, DinoV2Variant, Llama32Runner,
306    Llama32RunnerBuilder, LmRunner, ModelRunner, Precision, Qwen3Runner, Qwen3RunnerBuilder,
307    SamArch, SamPredictionAny, SamRunner, SamRunnerBuilder, Vjepa2Output, Vjepa2PoolOutput,
308    Vjepa2PredictOutput, Vjepa2Runner, Vjepa2RunnerBuilder, Wav2Vec2BertRunner,
309    Wav2Vec2BertRunnerBuilder, WeightFormat, debug_resolve_name, dispatch, dispatch_help,
310    list_mtp_keys, open_gguf_loader, open_loader, open_loader_resolved, open_loader_with_format,
311    register_runner, registered_runners, run_registered,
312};
313pub use sam::{
314    NeckWeights as SamNeckWeights, SamConfig, SamEncoderBuilt, SamEncoderConfig, SamEncoderFlow,
315    SamPreprocessWeights, apply_neck_host as sam_apply_neck_host,
316    assemble_patch_tokens as sam_assemble_patch_tokens, build_sam_encoder_built,
317    build_sam_encoder_graph, preprocess_image as sam_preprocess_image,
318};
319pub use sam2::{
320    FpnLevel as Sam2FpnLevel, FpnNeckWeights as Sam2FpnNeckWeights, Sam2, Sam2Config,
321    Sam2DecoderConfig, Sam2FpnConfig, Sam2HieraConfig, Sam2ImageEncoderBuilt, Sam2ImageEncoderFlow,
322    Sam2ImagePrediction, Sam2MaskDecoderOutput, Sam2MaskDecoderWeights, Sam2MemoryAttentionWeights,
323    Sam2MemoryConfig, Sam2MemoryEncoderConfig, Sam2MemoryEncoderOutput, Sam2MemoryEncoderWeights,
324    Sam2PreprocessWeights, Sam2PromptEncoderOutput, Sam2PromptEncoderWeights,
325    Sam2TwoWayTransformerWeights, Sam2VideoState, apply_fpn_neck as sam2_apply_fpn_neck,
326    apply_fpn_neck_host as sam2_apply_fpn_neck_host,
327    assemble_patch_tokens as sam2_assemble_patch_tokens, build_sam2_image_encoder_built,
328    build_sam2_image_encoder_graph, mask_decoder_forward as sam2_mask_decoder_forward,
329    memory_attention_forward as sam2_memory_attention_forward,
330    memory_encoder_forward as sam2_memory_encoder_forward,
331    preprocess_image as sam2_preprocess_image,
332    prompt_encoder_forward as sam2_prompt_encoder_forward,
333    two_way_transformer_forward as sam2_two_way_transformer_forward,
334};
335pub use sam3::{
336    Sam3, Sam3CompiledDecoder, Sam3Config, Sam3DetectorConfig, Sam3DetectorDecoderBuilt,
337    Sam3DetectorDecoderFlow, Sam3DetectorEncoderFlow, Sam3EncodedImage, Sam3ImagePrediction,
338    Sam3PreprocessWeights, Sam3TextConfig, Sam3TrackerConfig, Sam3VideoFramePrediction,
339    Sam3VideoState, Sam3VitConfig, assemble_patch_tokens as sam3_assemble_patch_tokens,
340    build_sam3_detector_decoder_built, build_sam3_detector_encoder_built,
341    build_sam3_detector_encoder_graph, forward_decoder_ir_on,
342    preprocess_image as sam3_preprocess_image,
343};
344pub use tide::{
345    BlockDenoiseConfig, BlockDenoiseLoop, GenerateConfig, PredictiveOffloadInfo,
346    PredictiveOffloadParams, TideOffloadStats, TideRunner, aggregate_offload_stats,
347    refresh_experts,
348};
349pub use vision::{VisionPreprocessWeights, build_vision_graph_sized};
350pub use vision_flow::{NomicVisionBuilt, NomicVisionFlow, build_nomic_vision_built};
351pub use vjepa2::{
352    Vjepa2Config, Vjepa2EncoderBuilt, Vjepa2EncoderFlow, Vjepa2EncoderOutput, Vjepa2EncoderWeights,
353    Vjepa2Masks, Vjepa2ModelWeights, Vjepa2PatchEmbedWeights, Vjepa2PoolerFlow,
354    Vjepa2PoolerWeights, Vjepa2PredictorFlow, Vjepa2PredictorWeights,
355    build_vjepa2_encoder_graph_sized, conv3d_patch_embed, encode_video_native,
356    extract_encoder_weights, extract_model_weights, extract_patch_embed_weights,
357    extract_pooler_weights, extract_predictor_weights, normalize_video_hwc, pool_native,
358    predict_native,
359};
360pub use voxtral::{
361    FAMILY as VOXTRAL_FAMILY, HF_MODEL_ID_MINI_3B, LanguageModelPrefixLoader,
362    MelSpectrogram as VoxtralMel, VoxtralAudioConfig, VoxtralConfig, VoxtralRunner,
363    VoxtralRunnerBuilder, VoxtralWeightPrefix, build_voxtral_decode_built,
364    build_voxtral_encoder_built, build_voxtral_prefill_built, build_voxtral_projector_built,
365    fuse_inputs_embeds, pcm_to_mel as voxtral_pcm_to_mel, transcription_prompt_ids,
366};
367pub use voxtral_tts::{
368    CodecDecoder, HF_MODEL_ID as VOXTRAL_TTS_HF_MODEL_ID, PRESET_VOICES as VOXTRAL_TTS_VOICES,
369    VoxtralTtsBenchReport, VoxtralTtsConfig, VoxtralTtsRunner, VoxtralTtsWeightStore,
370};
371pub use wav2vec2_asr::{AlignSession, AlignedWord, Wav2Vec2AsrConfig, align_model_for_language};
372pub use wav2vec2_bert::{
373    LogMelExtractor, LogMelFeatures, Wav2Vec2BertConfig, Wav2Vec2BertFlow,
374    Wav2Vec2BertPreprocessConfig, build_wav2vec2_bert_built, build_wav2vec2_bert_graph_sized,
375    load_wav_mono_f32,
376};
377pub use whisper::{
378    MelSpectrogram, SubtitleFormat, TranscriptSegment, WhisperConfig, WhisperDecoderFlow,
379    WhisperEncoderFlow, WhisperKvCache, WhisperPipeline, WhisperPipelineOpts, WhisperRunner,
380    WhisperRunnerBuilder, WhisperTranscript, WhisperWeightPrefix, WordAlignMode, WordTiming,
381    build_whisper_decode_step_built, build_whisper_decoder_built,
382    build_whisper_decoder_graph_sized, build_whisper_decoder_prefill_built,
383    build_whisper_encoder_built, build_whisper_encoder_graph_sized, default_mel_frames, pcm_to_mel,
384    to_json_pretty, to_srt, to_tsv, to_vtt,
385};