Simple training repo which is used to house reference implementations of emerging training algorithms, such as Orthogonal Subspace Fine Tuning (OSFT).
Project description
Mini Trainer
A lightweight, high-performance training library for efficient fine-tuning of large language models up to 70B parameters.
Built for speed, simplicity, and scalability 🚀
✨ Features
- 🔥 Liger Kernels - Minimized memory footprint through chunked loss computation
- ⚡ Smart Batch Packing - Automatic minibatching with numba-optimized LPT algorithm for optimal GPU load balancing
- 🎯 FSDP2 Support - Native PyTorch distributed training with FullyShardedDataParallel
- 🚫 Padding-Free - Leverages Flash Attention for efficient computation without padding overhead
- ♾️ Infinite Sampling - Continuous data streaming without manual epoch configuration
- 🔬 Orthogonal Subspace Fine-Tuning (OSFT) - Advanced continual learning technique for parameter-efficient training
- 📚 Pretraining Mode - Document-style pretraining with configurable block sizes on pre-tokenized
input_ids - 📊 Flexible Logging - JSONL metrics logging with optional Weights & Biases integration
🔬 Orthogonal Subspace Fine-Tuning (OSFT)
Mini Trainer implements Orthogonal Subspace Fine-Tuning (OSFT), a breakthrough continual learning technique that enables models to learn new tasks without catastrophic forgetting. OSFT uses adaptive SVD-based decomposition to intelligently update models in unused parameter subspaces while preserving crucial prior knowledge.
🎥 Learn More
📚 Resources
- 📝 Blog Post: Sculpting Subspaces: How We Solved Continual Learning in LLMs
- 📄 Research Paper: arXiv:2504.07097
🚀 Using OSFT
Enable OSFT in your training runs with the --osft flag:
torchrun --nnodes=1 --nproc-per-node=8 -m mini_trainer.train \
--model-name-or-path meta-llama/Llama-3.1-8B-Instruct \
--data-path ./data.jsonl \
--output-dir ./checkpoints \
--osft \
--osft-unfreeze-rank-ratio 0.25 # train the 25% least important parameters
The --osft-unfreeze-rank-ratio parameter controls how much of the model to update (0.0 = everything frozen, 1.0 = full training).
📦 Installation
From PyPI
# Install base package
pip install rhai-innovation-mini-trainer
# Install CUDA dependencies (required for GPU training)
pip install rhai-innovation-mini-trainer[cuda] --no-build-isolation
From Source (Editable)
# Clone the repository
git clone https://github.com/Red-Hat-AI-Innovation-Team/mini_trainer.git
cd mini_trainer
# Install in editable mode
pip install -e .
# Install CUDA dependencies
pip install -e .[cuda] --no-build-isolation
🎯 Usage
Training is orchestrated through the api_train.py module, which provides a programmatic interface for launching training jobs. You can run training using torchrun for distributed setups:
torchrun --nnodes=1 --nproc-per-node=8 -m mini_trainer.train \
--output-dir ./checkpoints \
--data-path ./data.jsonl \
--model-name-or-path meta-llama/Llama-3.1-8B-Instruct \
--batch-size 128 \
--max-tokens-per-gpu 128000 \
--learning-rate 5e-6 \
--use-liger-kernels
Key Parameters
--model-name-or-path- HuggingFace model identifier or local path--data-path- Path to tokenized training data (JSONL format)--batch-size- Target batch size for training--max-tokens-per-gpu- Maximum tokens per GPU (auto-balances minibatches)--output-dir- Directory for checkpoints and logs--use-liger-kernels- Enable memory-efficient Liger kernels--osft- Enable Orthogonal Subspace Fine-Tuning mode--osft-unfreeze-rank-ratio- Ratio of model parameters to train with OSFT (0.0-1.0)--block-size- Enables pretraining mode with the given block length
For the complete list of arguments and advanced configuration options, see src/mini_trainer/api_train.py.
🛠️ Contributors – Looking for the lazy-init + FSDP2 loading flow?
See docs/distributed_initialization.md for diagrams and a detailed walkthrough of the SFT and OSFT pipelines.
📊 Data Format
Mini Trainer expects pre-tokenized data in JSONL format with the following structure:
{"input_ids": [1, 2, 3, ...], "labels": [1, 2, 3, ...], "len": 128}
{"input_ids": [4, 5, 6, ...], "labels": [-100, -100, 6, ...], "len": 256}
Each line should contain:
input_ids- Tokenized input sequencelabels- Target labels (use-100for tokens to ignore in loss computation)len- Sequence length (optional, computed automatically if missing)
🔄 Data Processing
Mini Trainer does not include data processing utilities. For tokenization and data preparation, please use the instructlab-training APIs, which provide robust data processing pipelines compatible with Mini Trainer's input format.
🧱 Pretraining Mode
Mini Trainer supports pretraining on tokenized document corpora. Pass a --block-size to enable the document pipeline (the input JSONL is expected to have an input_ids column):
torchrun --nnodes=1 --nproc-per-node=4 -m mini_trainer.train \
--model-name-or-path qwen/Qwen2.5-1.5B-Instruct \
--data-path ./documents.jsonl \
--output-dir ./checkpoints \
--batch-size 16 \
--max-tokens-per-gpu 8192 \
--block-size 512
--block-size(required) enables pretraining mode and defines the token length for each block.
Programmatic usage mirrors the CLI via PretrainingConfig:
from mini_trainer import TrainingArgs, PretrainingConfig
args = TrainingArgs(
model_name_or_path="mistralai/Mistral-7B-v0.1",
data_path="documents.jsonl",
output_dir="./checkpoints",
batch_size=128,
max_tokens_per_gpu=40000,
pretraining_config=PretrainingConfig(
block_size=4096,
),
)
🐛 Bug Reports & Issues
Found a bug or have a feature request? We'd love to hear from you! Please open an issue on GitHub with:
- A clear description of the problem
- Steps to reproduce
- Expected vs. actual behavior
- Environment details (Python version, GPU type, etc.)
📝 License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
🙏 Acknowledgments
Built with ❤️ by the Red Hat AI Innovation Team.
Mini Trainer is part of a broader ecosystem of LLM tools developed by the AI Innovation Team. Check out our other projects:
- training_hub - Post-training algorithms for LLMs
- its_hub - Inference-time scaling for LLMs
- sdg_hub - Synthetic data generation pipelines
- reward_hub - State-of-the-art reward models
Visit ai-innovation.team to explore all our open-source tools and research.
Special thanks to the open-source community for contributions and feedback!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rhai_innovation_mini_trainer-0.6.1.tar.gz.
File metadata
- Download URL: rhai_innovation_mini_trainer-0.6.1.tar.gz
- Upload date:
- Size: 8.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06698a6e1fc4fcea4badac65181bde2076ad42ac3f90a588903520211a2d42a8
|
|
| MD5 |
06829e57e47e154a0c04768f5da71119
|
|
| BLAKE2b-256 |
199f0f86b01bda4759824b381d72a2cf5143e2e8bc00c2ac10f0b7910a5cee67
|
Provenance
The following attestation bundles were made for rhai_innovation_mini_trainer-0.6.1.tar.gz:
Publisher:
pypi.yaml on Red-Hat-AI-Innovation-Team/mini_trainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rhai_innovation_mini_trainer-0.6.1.tar.gz -
Subject digest:
06698a6e1fc4fcea4badac65181bde2076ad42ac3f90a588903520211a2d42a8 - Sigstore transparency entry: 999217631
- Sigstore integration time:
-
Permalink:
Red-Hat-AI-Innovation-Team/mini_trainer@4d6dc87f2e0b89e3ac59b4afc0cf5640a9332768 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/Red-Hat-AI-Innovation-Team
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@4d6dc87f2e0b89e3ac59b4afc0cf5640a9332768 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rhai_innovation_mini_trainer-0.6.1-py3-none-any.whl.
File metadata
- Download URL: rhai_innovation_mini_trainer-0.6.1-py3-none-any.whl
- Upload date:
- Size: 91.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0736fa167018d605cabc171ed5e174ab03c7872bbf3da4eee79d9ba08826a6c
|
|
| MD5 |
1740c09015fc4a6c2fc931033ce32607
|
|
| BLAKE2b-256 |
a4816982ff413408a8466f0f28883cb05523e6caba62e8171a74f3c7ce1fc2aa
|
Provenance
The following attestation bundles were made for rhai_innovation_mini_trainer-0.6.1-py3-none-any.whl:
Publisher:
pypi.yaml on Red-Hat-AI-Innovation-Team/mini_trainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rhai_innovation_mini_trainer-0.6.1-py3-none-any.whl -
Subject digest:
d0736fa167018d605cabc171ed5e174ab03c7872bbf3da4eee79d9ba08826a6c - Sigstore transparency entry: 999217882
- Sigstore integration time:
-
Permalink:
Red-Hat-AI-Innovation-Team/mini_trainer@4d6dc87f2e0b89e3ac59b4afc0cf5640a9332768 -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/Red-Hat-AI-Innovation-Team
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@4d6dc87f2e0b89e3ac59b4afc0cf5640a9332768 -
Trigger Event:
release
-
Statement type: