Skip to content

louisbrulenaudet/logfire-callback

Plot

Logfire-callback, observability for Hugging Face's Transformers training loop 🤗

License Maintainer Python Version Code Style Package Manager

A callback for logging training events from Hugging Face's Transformers to Logfire 🤗

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:

pip install logfire-callback

Usage

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

Development

Prerequisites

  • Python 3.11 or higher
  • uv for package management

Setting up the development environment

  1. Clone the repository:
git clone https://github.com/louisbrulenaudet/logfire-callback
cd logfire-callback
  1. Initialize the development environment:
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 file for details.

Links

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.

@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.

About

A callback for logging training events from Hugging Face's Transformers to Logfire 🤗

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published