Skip to main content

Crate fxtranslate

Crate fxtranslate 

Source
Expand description

fxtranslate: a Rust reimplementation of the Firefox Translations inference engine, validated against the reference C++ engine.

  • trace reads the oracle produced by the C++ TraceRecorder.
  • model reads the marian binary model, giving the logical int8 weights the packed trace can’t.
  • ops holds the CPU ops — float, structural, gather, batched matmul, and the shifted int8 affine.
  • weights resolves model parameters; spm tokenizes; shortlist reads the lexical shortlist; engine runs the transformer and greedy decode.

Model management (feature download, and net for the built-in HTTP client) is the batteries-included, Firefox-independent half: [remote] discovers models in Remote Settings, [cache] downloads + verifies them into a local cache over a pluggable [fetch::Fetch] client, [lang] maps language tags to display names, [route] resolves a language pair to a direct model or a two-leg pivot, and [loader] wires discovery → cache → engine into a single src→trgengine::Engine call. All off by default so the plain engine dependency (and wasm) stays lean; an embedder that brings its own HTTP client enables download and implements [fetch::Fetch].

The trace-comparison harness (tolerance comparator, graph-replay bisector) and the diagnostic binary live in the separate fxtranslate-oracle dev crate.

§Example

The batteries-included path (feature net): discover the enes model in Remote Settings, download+verify it into the local cache (a no-op on a cache hit), build the engine::Engine, and translate.

use fxtranslate::{cache::Cache, fetch::NetworkFetch, loader::load_engine};

let engine = load_engine(&NetworkFetch::new(), &Cache::locate(), "en", "es")?;
assert_eq!(engine.translate("The weather is nice today."), "El clima es agradable hoy.");

With your own HTTP client, enable just download and implement [fetch::Fetch] over your stack; with model files already on disk, skip discovery entirely and call engine::Engine::load directly.

Modules§

engine
Dynamic transformer execution and greedy decoding.
gemm
Accelerated int8 GEMM (gemm::PreparedB): the vendored gemmology SIMD kernel via FFI (gemmology feature, native) or the pure-Rust wasm SIMD128 kernel (wasm32 + simd128). Present under either so the engine has one fast-path surface; when neither is live it is a scalar-returning stub. Accelerated int8 GEMM for the shifted int8 affine (int8shiftAlphaAll).
model
Reader for the marian binary model format (*.intgemm.alphas.bin), the format translator-cli loads (marian-fork/src/common/binary.cpp).
ops
CPU op implementations.
segment
Sentence segmentation for long-input translation.
shortlist
Lexical shortlist reader.
spm
SentencePiece tokenization in Rust.
trace
Reader for the reference-trace format written by the C++ engine’s TraceRecorder (see inference/marian-fork/src/graph/trace_recorder.h).
weights
Model-weights view for dynamic execution.