brainwires-training
Model training and fine-tuning for the Brainwires Agent Framework — cloud fine-tuning and local LoRA/QLoRA/DoRA training.
Powered by Burn — Local training in this crate is built on the Burn deep learning framework, a comprehensive deep learning framework written in Rust. Burn provides the GPU-accelerated tensor operations, automatic differentiation, and neural network modules that make local LoRA/QLoRA/DoRA adapter training possible. We are grateful to the Burn team and contributors for their excellent work on the Rust ML ecosystem.
Overview
brainwires-training provides a unified TrainingManager that dispatches fine-tuning jobs to either cloud providers (OpenAI, Together, Fireworks, Anyscale, AWS Bedrock, Google Vertex AI) or a local Burn-based training backend supporting LoRA, QLoRA, and DoRA adapter methods with DPO/ORPO alignment losses.
Design principles:
- Dual-path — one API for cloud fine-tuning and local adapter training; switch with a feature flag
- Provider-agnostic —
FineTuneProvidertrait abstracts all cloud APIs behindsubmit,status,cancel,download - Adapter-first — local training uses parameter-efficient adapters (LoRA/QLoRA/DoRA) rather than full fine-tuning
- Dataset-integrated — consumes
brainwires-datasetstypes directly for seamless data → training pipelines - Observable —
TrainingProgressandTrainingMetricsprovide real-time job monitoring
┌─────────────────────────────────────────────────────────────┐
│ brainwires-training │
│ │
│ ┌────────────────┐ │
│ │TrainingManager │ │
│ └───────┬────────┘ │
│ │ │
│ ┌───────────┴───────────┐ │
│ ▼ ▼ │
│ ┌──────────────────┐ ┌───────────────────┐ │
│ │ Cloud Providers │ │ Local Burn Backend│ │
│ │ ┌──────────────┐ │ │ ┌──────────────┐ │ │
│ │ │ OpenAI │ │ │ │ Adapters │ │ │
│ │ │ Together │ │ │ │ LoRA/QLoRA │ │ │
│ │ │ Fireworks │ │ │ │ DoRA │ │ │
│ │ │ Anyscale │ │ │ └──────────────┘ │ │
│ │ │ Bedrock │ │ │ ┌──────────────┐ │ │
│ │ │ Vertex │ │ │ │ Alignment │ │ │
│ │ └──────────────┘ │ │ │ DPO / ORPO │ │ │
│ └──────────────────┘ │ └──────────────┘ │ │
│ │ ┌──────────────┐ │ │
│ │ │Checkpointing │ │ │
│ │ │ Export │ │ │
│ │ └──────────────┘ │ │
│ └───────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ TrainedModel │ │
│ │ Artifact │ │
│ └─────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Flow: Dataset → TrainingManager → Cloud / Local → Artifacts
Quick Start
Add to your Cargo.toml:
[]
= "0.6"
Submit a cloud fine-tuning job:
use ;
// Create a provider (OpenAI in this example)
let provider = create?;
// Configure the job
let config = CloudFineTuneConfig ;
// Submit and monitor
let job_id = provider.submit.await?;
loop
Features
| Feature | Default | Description |
|---|---|---|
cloud |
Yes | Cloud fine-tuning via reqwest — OpenAI, Together, Fireworks, Anyscale, Bedrock, Vertex |
local |
No | Local adapter training via the Burn framework (LoRA, QLoRA, DoRA) |
full |
No | Enables both cloud and local |
# Local training only (no cloud deps)
[]
= { = "0.6", = false, = ["local"] }
# Full — cloud + local
[]
= { = "0.6", = ["full"] }
Architecture
TrainingManager
Central coordinator that dispatches to the correct backend based on configuration.
| Method | Description |
|---|---|
submit_cloud |
Submit a job to a cloud fine-tuning provider |
submit_local |
Start a local adapter training run |
status |
Query job status by ID |
cancel |
Cancel a running job |
list_jobs |
List all jobs with optional status filter |
Cloud Providers
All providers implement the FineTuneProvider trait:
| Provider | API | Supported Models |
|---|---|---|
| OpenAI | Fine-tuning API | GPT-4o-mini, GPT-4o, GPT-3.5-turbo |
| Together | Fine-tuning API | Llama, Mistral, CodeLlama, etc. |
| Fireworks | Fine-tuning API | Llama, Mixtral, custom |
| Anyscale | Fine-tuning API | Open-source models |
| Bedrock | Custom model training | Titan, Llama (via AWS) |
| Vertex | Model tuning API | Gemini, PaLM |
CloudFineTuneConfig
| Field | Type | Description |
|---|---|---|
model |
String |
Base model identifier |
training_file |
String |
Path to JSONL training data |
validation_file |
Option<String> |
Optional validation data |
hyperparams |
TrainingHyperparams |
Epochs, learning rate, batch size, etc. |
suffix |
Option<String> |
Custom suffix for the fine-tuned model name |
Local Training (Burn Backend)
Requires the local feature. Uses the Burn deep learning framework for GPU-accelerated adapter training.
Adapter Methods
| Method | Description |
|---|---|
LoRA |
Low-Rank Adaptation — adds small trainable matrices to frozen weights |
QLoRA |
Quantized LoRA — 4-bit base model with LoRA adapters |
DoRA |
Weight-Decomposed Low-Rank Adaptation — direction + magnitude decomposition |
LoraConfig
| Field | Type | Default | Description |
|---|---|---|---|
rank |
usize |
8 |
Rank of low-rank matrices (lower = fewer params) |
alpha |
f64 |
16.0 |
Scaling factor (alpha/rank) |
dropout |
f64 |
0.05 |
Dropout applied to adapter layers |
target_modules |
Vec<String> |
["q_proj", "v_proj"] |
Which layers to adapt |
Alignment Methods
| Method | Description |
|---|---|
DPO |
Direct Preference Optimization — learn from chosen/rejected pairs |
ORPO |
Odds Ratio Preference Optimization — single-stage alignment |
LocalTrainingConfig
| Field | Type | Description |
|---|---|---|
adapter |
AdapterMethod |
LoRA, QLoRA, or DoRA |
alignment |
Option<AlignmentMethod> |
Optional DPO/ORPO alignment |
device |
ComputeDevice |
Cpu, Cuda(id), Wgpu, Metal |
hyperparams |
TrainingHyperparams |
Epochs, learning rate, batch size, scheduler |
checkpoint_dir |
Option<String> |
Directory for periodic checkpoint saves |
lora |
LoraConfig |
LoRA-specific configuration |
LrScheduler
| Scheduler | Description |
|---|---|
Constant |
Fixed learning rate |
Cosine |
Cosine annealing to zero |
Linear |
Linear decay to zero |
OneCycle |
1cycle policy (warmup + annealing) |
Job Tracking
| Type | Description |
|---|---|
TrainingJobId |
Unique job identifier |
TrainingJobStatus |
Pending, Running, Completed, Failed(String), Canceled |
TrainingProgress |
Step count, epoch, loss, learning rate |
TrainingMetrics |
Final metrics: train loss, eval loss, duration |
TrainedModelArtifact |
Path to exported model weights + adapter config |
Usage Examples
Local LoRA Training
DPO Alignment Training
Cloud Provider Selection
Monitoring Job Progress
use ;
let manager = new;
let status = manager.status.await?;
match status
Integration with Brainwires
Use via the brainwires facade crate:
[]
= { = "0.6", = ["training"] }
Or depend on brainwires-training directly for standalone training capabilities. The crate depends on brainwires-datasets for data types, so both are pulled in together.
References
Papers
- DPO: Direct Preference Optimization (2023) — the alignment method behind
AlignmentMethod::Dpo - ORPO: Monolithic Preference Optimization (2024) — single-stage alignment,
AlignmentMethod::Orpo - Cramming: Training on a Single GPU in One Day (2023) — efficient small-model training strategies
- Ring Attention: Near-Infinite Context (ICLR 2024) — long-context training
- Evolution Strategies for Billion-Parameter Fine-Tuning (Sept 2025)
- IR-Tuning: Efficient Layer-wise Fine-tuning (Sept 2025)
- QTHA: Quantum-Enhanced Fine Tuning (March 2025)
- Complexity-aware Fine-tuning (June 2025)
- LUNE: Efficient LLM Unlearning via LoRA (Dec 2025)
- Mamba-3: State Space Models (2025)
- Revisiting Chinchilla Scaling Laws (ACL 2025)
Technical Blogs & Guides
- LoRA/QLoRA/DoRA Production Guide (Dec 2025) — comprehensive adapter comparison
- DoRA — NVIDIA Technical Blog — weight-decomposed low-rank adaptation
- How to Align LLMs in 2025 with DPO — practical DPO guide
- Small LLM Training Guide 2026 — end-to-end training walkthrough
- Mixed Precision: FP8 vs BF16 — precision trade-offs
- NVIDIA FP8 Training Blog
- FSDP vs DeepSpeed — HuggingFace — distributed training comparison
Rust ML Ecosystem
- Burn Framework — the local training backend used by this crate
- Candle — HuggingFace — Rust inference framework
- tch-rs: PyTorch Rust Bindings
- PyO3 for AI/Data Science (2025)
- Rust + CUDA for ML (2025)
License
Licensed under the MIT License. See LICENSE for details.