A callback for logging training events from Hugging Face's Transformers to Logfire 🤗
The logfire-callback
package provides a seamless integration between Hugging Face's Transformers library and Logfire logging service. It allows you to track and monitor your model training progress, metrics, and events in real-time through Logfire's platform.
Install the package using pip:
pip install logfire-callback
First, ensure you have a Logfire API token and set it as an environment variable:
export LOGFIRE_TOKEN=your_logfire_token
Then use the callback in your training code:
from transformers import Trainer, TrainingArguments
from logfire_callback import LogfireCallback
# Initialize your model, dataset, etc.
training_args = TrainingArguments(
output_dir="./results",
num_train_epochs=3,
# ... other training arguments
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
callbacks=[LogfireCallback()] # Add the Logfire callback here
)
trainer.train()
The callback will automatically log:
- Training start with configuration parameters
- Periodic training metrics (loss, learning rate, etc.)
- Evaluation metrics during validation
- Training completion
- Python 3.11 or higher
- uv for package management
- Clone the repository:
git clone https://github.com/louisbrulenaudet/logfire-callback
cd logfire-callback
- Initialize the development environment:
make init
make test
- Execute test suitemake init
- Initialize development environmentmake install-dev
- Install development dependenciesmake run
- Run the applicationmake check
- Run code quality checksmake format
- Format source codemake upgrade
- Update project dependenciesmake pre-commit
- Run pre-commit checksmake build
- Build the projectmake publish
- Publish the projectmake coverage
- Run tests with coverage
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Python >= 3.11
- transformers >= 4.49.0
- logfire >= 3.9.0
If you use this code in your research, please use the following BibTeX entry.
@misc{louisbrulenaudet2025,
author = {Louis Brulé Naudet},
title = {Logfire callback, observability for Hugging Face's transformers training loop},
howpublished = {\url{https://huggingface.co/spaces/louisbrulenaudet/logfire-callback}},
year = {2025}
}
If you have any feedback, please reach out at louisbrulenaudet@icloud.com.