https://github.com/louisbrulenaudet/logfire-callback
A callback for logging training events from Hugging Face's Transformers to Logfire 🤗
https://github.com/louisbrulenaudet/logfire-callback
callback huggingface huggingface-transformers logfire logfire-callback logging pydantic trainer training transformers
Last synced: 7 months ago
JSON representation
A callback for logging training events from Hugging Face's Transformers to Logfire 🤗
- Host: GitHub
- URL: https://github.com/louisbrulenaudet/logfire-callback
- Owner: louisbrulenaudet
- License: apache-2.0
- Created: 2025-03-23T09:07:30.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-03-23T12:12:03.000Z (7 months ago)
- Last Synced: 2025-03-23T12:19:58.106Z (7 months ago)
- Topics: callback, huggingface, huggingface-transformers, logfire, logfire-callback, logging, pydantic, trainer, training, transformers
- Language: Python
- Homepage: https://louisbrulenaudet.com
- Size: 498 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Security: SECURITY.md
Awesome Lists containing this project
README

# Logfire-callback, observability for Hugging Face's Transformers training loop 🤗
[](https://opensource.org/licenses/Apache-2.0)    A callback for logging training events from Hugging Face's Transformers to [Logfire](https://logfire.sh) 🤗
## Overview
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.
## Installation
Install the package using pip:
```bash
pip install logfire-callback
```## Usage
First, ensure you have a Logfire API token and set it as an environment variable:
```bash
export LOGFIRE_TOKEN=your_logfire_token
```Then use the callback in your training code:
```python
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## Development
### Prerequisites
- Python 3.11 or higher
- [uv](https://github.com/astral-sh/uv) for package management### Setting up the development environment
1. Clone the repository:
```bash
git clone https://github.com/louisbrulenaudet/logfire-callback
cd logfire-callback
```2. Initialize the development environment:
```bash
make init
```### Available Make Commands
- `make test` - Execute test suite
- `make init` - Initialize development environment
- `make install-dev` - Install development dependencies
- `make run` - Run the application
- `make check` - Run code quality checks
- `make format` - Format source code
- `make upgrade` - Update project dependencies
- `make pre-commit` - Run pre-commit checks
- `make build` - Build the project
- `make publish` - Publish the project
- `make coverage` - Run tests with coverage## License
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
## Links
- [GitHub Repository](https://github.com/louisbrulenaudet/logfire-callback)
- [Issue Tracker](https://github.com/louisbrulenaudet/logfire-callback/issues)## Requirements
- Python >= 3.11
- transformers >= 4.49.0
- logfire >= 3.9.0## Citing this project
If you use this code in your research, please use the following BibTeX entry.```BibTeX
@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}
}```
## Feedback
If you have any feedback, please reach out at [louisbrulenaudet@icloud.com](mailto:louisbrulenaudet@icloud.com).