Skip to main content

rullama_finetune/
lib.rs

1//! Local LoRA fine-tuning for the rullama Rust runtime.
2//!
3//! Same trainer on native and `wasm32-unknown-unknown`. The forward,
4//! backward, LoRA state, optimizer, and dataset parsing all compile on
5//! both targets — the only native-only bits are filesystem helpers
6//! that wrap the bytes-based core API (see `load_jsonl_from_bytes` /
7//! `save_adapter_to_bytes` / `load_adapter_into_state_from_bytes`).
8//!
9//! Module map:
10//!
11//! - [`shared`] — config / error / progress types.
12//! - [`dataset_loader`] — JSONL parser (bytes-in core + native path
13//!   wrapper) + `Tokenizer` trait + byte-level and HF-`tokenizers`-backed
14//!   implementations.
15//! - [`lr_schedule`] — warmup + linear / cosine / cosine-warm-restarts
16//!   schedules. Cosine clamps `progress` at 1.0.
17//! - [`lora`] — LoRA A/B state, forward correction, A/B grad accumulation.
18//! - [`scratch`] — per-step GPU scratch buffers for the backward pass.
19//! - [`session`] — `TrainingSession` driving one training step
20//!   end-to-end (forward → loss → backward → Adam).
21
22// See the equivalent note in the rullama crate root — numeric/GPU training code
23// where these lints add noise without readability gains.
24#![allow(
25    clippy::too_many_arguments,
26    clippy::type_complexity,
27    clippy::needless_range_loop
28)]
29
30/// JSONL dataset loader + tokenizer trait.
31pub mod dataset_loader;
32/// Per-LoRA GPU state: A and B matrices for each wrapped projection.
33pub mod lora;
34/// Learning rate schedules.
35pub mod lr_schedule;
36/// Per-step GPU scratch buffers for the backward pass.
37pub mod scratch;
38/// `TrainingSession` — drives one training step end-to-end.
39pub mod session;
40/// Shared configuration, error, and progress types.
41pub mod shared;
42
43/// JS-facing wasm-bindgen surface — only compiled for wasm32.
44#[cfg(target_arch = "wasm32")]
45pub mod wasm_bindgen_api;
46
47#[cfg(not(target_arch = "wasm32"))]
48pub use session::load_adapter_into_state;
49pub use session::{TrainingSession, load_adapter_into_state_from_bytes};