1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! 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→trg`→[`engine::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 `en`→`es` model in
//! Remote Settings, download+verify it into the local cache (a no-op on a cache
//! hit), build the [`engine::Engine`], and translate.
//!
//! ```no_run
//! # #[cfg(feature = "net")] {
//! 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.");
//! # }
//! # Ok::<(), String>(())
//! ```
//!
//! 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.
// Tolerance comparator, built only for `cargo test` so the ops unit tests can
// assert against it. The public comparison harness lives in `fxtranslate-oracle`.
/// 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.
// Portable model discovery (feature `discovery`; `download` implies it): record
// parsing, pivot/catalog routing, and the pure verify+decompress. All wasm-safe.
// Native model management (feature `download`; `net` adds the built-in HTTP
// client). The `std::fs`/`dirs` cache storage lives inside `cache` behind
// `download`; these modules are native-only.