trackio

repository·main·Indexed 23 days ago

https://github.com/gradio-app/trackio

A lightweight, local-first experiment tracking library version 0.5.0 designed for humans and AI agents. It supports local SQLite-based logging and cloud-based collaborative dashboards on Hugging Face Spaces. Trackio provides a wandb-compatible API for Python and includes official clients for Go, JavaScript/TypeScript, and Rust, as well as a REST API for logging metrics.

Tokens
64.9K
Snippets
130
Records
380
Agent score
82%

What's inside trackio

  1. Compare Trackio features with Weights & Biases (W&B)

    main

    Trackio is a lightweight, local-first, and easy-to-self-host alternative to W&B. It covers core experiment-tracking workflows including metrics, configs, run tracking, live dashboards, media (images, audio, video), tables, system metrics, alerts/webhooks, versioned artifacts, and experiment reports.

    Key Differences:

    • Cost: Trackio is free for unlimited personal and team use.
    • Missing Features: Trackio does not currently support Hyperparameter sweeps or a dedicated Artifact registry.
    • Hosting: Trackio uses Hugging Face Spaces for hosted dashboards, whereas W&B uses W&B Cloud.
  2. Configure a persistent default frontend

    main

    Trackio supports account-wide persistent configuration. You can set a default frontend directory that will be used by all Trackio commands and all Trackio projects. This configuration is stored in a JSON file in the Trackio user home directory.

    When a persistent configuration is active, Trackio will print a message indicating which frontend is being used and how to reset it.

  3. Locate Trackio project data and media

    main

    Trackio stores project data in local SQLite databases and media files in a specific directory structure.

    • Database Directory: TRACKIO_DIR, which defaults to ~/.cache/huggingface/trackio.
    • Project Databases: Each project is stored as a separate file named {project}.db within the TRACKIO_DIR.
    • Media Files: All uploaded media and files are stored under TRACKIO_DIR/media/.
  4. Best Practices for Agent-Friendly Alerts

    main

    When designing alerts intended to be parsed by an AI agent or automated script, follow these guidelines:

    1. Structured Signals: Include numeric values and actionable suggestions in the text field (e.g., "loss=5.2. Consider lowering learning rate").
    2. Consistent Severity:
      • trackio.AlertLevel.ERROR: Use for critical failures that require stopping the run and changing the approach.
      • trackio.AlertLevel.WARN: Use for parameter tweaks or non-fatal issues.
      • trackio.AlertLevel.INFO: Use for milestones (e.g., "Run complete").
    3. Efficient Polling: When polling for alerts via the API, use the since parameter with the timestamp of the last processed alert to avoid re-reading old data.
    4. Agent-Ready CLI: Use the --json flag with the Trackio CLI to ensure output is reliably parseable by scripts.
    5. Simplicity: Keep alert conditions simple (one metric per if block) to allow agents to easily adjust thresholds.
  5. What are Artifacts in Trackio

    main

    An artifact is a versioned, named bundle of files attached to a project. It can represent a trained model, a dataset, or evaluation outputs.

    Key features include:

    • Versioning: Each log under the same name creates a new version (v0, v1, etc.). Identical content is automatically de-duplicated.
    • Aliases: Moving pointers like latest (automatic) or custom ones like prod or best that resolve to a specific version.
    • Lineage: Artifacts are linked to the runs that produced them (outputs) and the runs that consumed them (inputs), allowing for full traceability.

    Artifacts work offline with local storage and can sync to a Hugging Face Space or a self-hosted server.

  6. Understand the Trackio Parquet export layout

    main

    Trackio exports SQLite data to Parquet files for syncing, static Spaces, or direct analysis. During export, JSON columns (like metrics or config) are flattened into individual columns for each key found in the JSON payload.

    Local Parquet Exports

    Generated by SQLiteStorage.export_to_parquet(). Files include:

    • {project}.parquet (from metrics)
    • {project}_system.parquet (from system_metrics)
    • {project}_configs.parquet (from configs)
    • {project}_traces.parquet (from traces)
    • {project}_{table}.parquet (for artifact tables: artifacts, artifact_versions, artifact_aliases, run_artifact_links)

    Static Space and Dataset Exports

    Used for browser-only dashboards. Layout includes:

    • metrics.parquet
    • aux/system_metrics.parquet
    • aux/configs.parquet
    • aux/traces.parquet
    • aux/artifacts.parquet (and other artifact tables in aux/)
    • runs.json
    • settings.json
    • media/ (media files)
    • artifacts/blobs/sha256/{prefix}/{digest} (artifact blobs)
  7. Configure remote logging to Hugging Face or a self-hosted server

    main

    By default, Trackio stores metrics locally. You can redirect them using these methods:

    1. Hugging Face Spaces: Pass space_id to init() or set the TRACKIO_SPACE_ID environment variable. Use bucket_id for storage configuration.
    2. Self-hosted Server: Pass server_url to init() or set TRACKIO_SERVER_URL. Authenticate using a write token (provided by your dashboard) via the write_token parameter or TRACKIO_WRITE_TOKEN environment variable.

    Note: If both space_id and server_url are configured, the Hugging Face Space takes precedence and the self-hosted URL is ignored.

  8. Configure Trackio storage backends

    main

    Trackio supports several storage and hosting modes:

    • Local-first: The dashboard runs locally by default and logs are persisted locally.
    • Hugging Face Spaces: Log to a Hugging Face Space for free by providing a space_id.
    • Self-hosted: Log to your own Trackio server by providing a server_url.

    Storage Note:

    • Use bucket_id or the environment variable TRACKIO_BUCKET_ID to persist logs to a Hugging Face Bucket.
    • Deprecated: Persisting to a Hugging Face Dataset via dataset_id or TRACKIO_DATASET_ID is deprecated and will be removed in a future version.
  9. Understand Trackio throughput and logging behavior

    main

    Trackio uses a non-blocking, queue-and-batch architecture designed to prevent logging from slowing down your training loops.

    Local Logging

    trackio.log() is a non-blocking call. It appends data to an in-memory queue and returns immediately. A background thread drains this queue every 0.5 seconds and writes the data to a local SQLite database. This allows for effectively unlimited client-side throughput (thousands of calls per second) without impacting the main execution thread.

    Logging to Hugging Face Spaces

    When a space_id is provided, the background thread batches queued entries and pushes them to the Space via the Gradio client API.

    Performance Characteristics:

    • Burst Performance: ~2,000 logs can be delivered in < 8 seconds.
    • Parallelism: Multiple threads (e.g., 32 threads) can run in parallel, each opening its own Gradio client connection. 32,000 logs can be delivered in ~14 seconds wall time.
    • Batching: There is no hard cap on logs per batch; all entries queued during a 0.5s interval are sent in a single predict() call.
    • Data Safety: Trackio provides zero-loss guarantees. If a batch fails to send (e.g., due to network issues), the data is persisted to the local SQLite database and retried automatically once the connection is restored.

    Note: Trackio is designed defensively. Failures in logging, flushing, or delivery paths should degrade to warnings and local buffering rather than raising exceptions that crash your training code.

  10. What are Trackio Logbooks?

    main

    Trackio logbooks are shareable experiment notebooks used to record the reasoning, commands, results, figures, artifacts (such as checkpoints and datasets), and agent traces associated with an experiment.

    Logbooks are stored locally in the .trackio/logbook directory of your workspace. They can be previewed locally or published as a static Hugging Face Space.

  11. Manage artifact versions and aliases

    main

    Each time you log an artifact with an existing name, Trackio increments the version (e.g., v0 $\rightarrow$ v1) and automatically moves the latest alias to the new version.

    To assign custom aliases (like prod or best), use the aliases parameter in log_artifact:

    trackio.log_artifact(artifact, aliases=["prod", "best"])

    Important Notes:

    • Moving Pointers: Aliases are moving pointers. Re-logging with the same alias re-points it to the new version.
    • Reserved Names: Version specifiers (v0, v1, etc.) are reserved and cannot be used as custom aliases.
    • De-duplication: If you log content identical to an existing version, Trackio reuses that version. Re-logging identical or older content will not move the latest alias backward.
  12. Handle Write Access for Trackio Mutation Tools

    main

    Mutation tools (like delete_run, rename_run, or trigger_sync) are gated and require authentication. Read tools do not require a token.

    Authentication Methods:

    1. Local Dashboard: Pass the write_token argument in your request. The token is printed in the terminal when you run trackio show (or found in the dashboard URL as ?write_token=...).

      • Example: {"project": "my-project", "run": "run-1", "write_token": "<token_from_startup>"}
    2. Hugging Face Spaces: Pass an hf_token argument that has write access to the Space's repository. The local write_token is not used for Spaces.