A flexible framework for training, fine-tuning, and evaluating large language models (LLMs) on a variety of datasets, supporting both HuggingFace models and custom PyTorch models.
- Model Agnostic: Use HuggingFace models or your own PyTorch models (e.g., GPT2, DeepSeek).
- Dataset Flexibility: Train on HuggingFace datasets, plain text, code, or your own data.
- Custom Trainers: Easily implement new training objectives by overriding a single method.
- Multi-GPU Training: Built-in support for distributed (DDP) training.
- Rich Logging: Colorful terminal logs and live loss visualization.
pip install -r requirements.txt- Text/Code: Place your files in a directory and use the provided parsing utilities.
- HuggingFace Datasets: Load any dataset using the
datasetslibrary.
- Use any HuggingFace tokenizer or your own.
- Example:
from tokenizer import get_tokenizer tokenizer = get_tokenizer("RWKV/RWKV7-Goose-World2.8-0.1B-HF")
- Plain Text: Use
TextDatasetto create a dataset from your files. - Instruction/Reasoning: Use
SFTDatasetfor chat-style or reasoning data. - Streaming: Use
StreamingTextDatasetorStreamingSFTDatasetfor large datasets.
- HuggingFace: Load any model with
AutoModelForCausalLM. - Custom: Use provided models like
GPT2(models.GPT2) or implement your own.
- Configuration: Set up a
Configobject with your model, dataset, and hyperparameters. - Trainer: Use a built-in trainer (e.g.,
PreTrain,KDL,GRPOTrainer) or create your own. - Run Training:
from trainer import PreTrain, Config trainer = PreTrain(run_name="my_run", cfg=configuration) trainer.fit()
- Enable DDP by passing
gpu_idsin your config and launching withtorch.multiprocessing. - See the DDP pattern in the codebase for launching multi-process training.
To implement a new training objective, subclass Trainer and override the compute_loss(self, batch) method:
class MyCustomTrainer(Trainer):
def compute_loss(self, batch):
# Your custom loss logic here
return loss- Pretraining on Text: Use
TextDatasetandPreTrain. - Supervised Fine-Tuning (SFT): Use
SFTDatasetandPreTrain. - Knowledge Distillation: Use
KDLtrainer with a teacher model. - Reinforcement Learning (GRPO): Use
GRPOTrainerwith a custom reward function.
- Training logs are colorized and informative.
- Live loss plots can be enabled for real-time monitoring.
- Checkpoints are saved automatically.
- Resume or evaluate by loading checkpoints with the provided methods.
- Add new models in the
models/directory. - Add new trainers in
trainer/custom_trainers/. - Use or extend dataset utilities in
create_dataset.pyandparse_files.py.
MIT License
- Built on PyTorch and HuggingFace Transformers.