Skip to main content

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

Project description

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 - Run the test suite
  • make check - Run code quality checks
  • make format - Format source code
  • make build - Build the project
  • make upgrade - Update project dependencies
  • make pre-commit - Run pre-commit checks

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logfire_callback-1.0.0.tar.gz (555.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logfire_callback-1.0.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file logfire_callback-1.0.0.tar.gz.

File metadata

  • Download URL: logfire_callback-1.0.0.tar.gz
  • Upload date:
  • Size: 555.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for logfire_callback-1.0.0.tar.gz
Algorithm Hash digest
SHA256 31bfdc2c62c5f6ccf5f83732d7b00bd101957690ea95c1e744a46deb102711a2
MD5 8b94d2a22d9a5e353f23992c1ad5e591
BLAKE2b-256 6fb84b97040ebe3b80cee786acf99533e112387bbed36ba654c640dabb692a00

See more details on using hashes here.

File details

Details for the file logfire_callback-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for logfire_callback-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d3bb02646ed7f7fcce476dc5f06b84abaff60cf12b1a1f21d04108e116036eb
MD5 adbd05356fa781b5935b16af2b0a0bdf
BLAKE2b-256 b432d13193c31edfeda2c43eecef764af94911b3b0eb1731163cea950d92fbec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page