-
Notifications
You must be signed in to change notification settings - Fork 112
Add server_url parameter for self-hosting Trackio servers
#510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
42a8022
e83a7fb
a445046
eac6063
8d8f5da
76a7812
e27eb74
06c051c
4f1ec0d
c791948
aa44b36
73097fe
cd136ec
f5f3b88
6994031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "trackio": minor | ||
| --- | ||
|
|
||
| feat:Add server_url and TRACKIO_SERVER_URL for self-hosted servers; space_id and TRACKIO_SPACE_ID take precedence when both are set |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,9 +35,9 @@ Trackio's main features: | |
| ``` | ||
| and keep your existing logging code. | ||
|
|
||
| - **Local-first** design: dashboard runs locally by default. You can also host it on Spaces by specifying a `space_id` in `trackio.init()`. | ||
| - Persists logs in a Sqlite database locally (or, if you provide a `space_id`, in a private Hugging Face Dataset) | ||
| - Visualize experiments with a **Svelte 5** dashboard locally (or, if you provide a `space_id`, on Hugging Face Spaces) | ||
| - **Local-first** design: dashboard runs locally by default. You can send metrics to a **Hugging Face Space** with `space_id` or to a **self-hosted Trackio server** you run yourself with `server_url` (or `TRACKIO_SERVER_URL`). If both a Space and a self-hosted URL are configured, the Space wins. | ||
| - Persists logs in a Sqlite database locally (or on the remote target you chose: Space, or the machine hosting your self-hosted server) | ||
| - Visualize experiments with a **Svelte 5** dashboard locally, on Hugging Face Spaces, or on your own host when you self-host the server | ||
| - **LLM-friendly**: Built with autonomous ML experiments in mind, Trackio includes a CLI for programmatic access and a Python API for run management, making it easy for LLMs to log metrics and query experiment data. | ||
| - Use `trackio query project --project <name> --sql "SELECT ..."` for read-only SQL when `trackio list` and `trackio get` are not enough | ||
| - See the storage schema and direct query reference at https://huggingface.co/docs/trackio/storage_schema | ||
|
|
@@ -155,6 +155,18 @@ trackio.init(project="my-project", space_id="username/space_id") | |
|
|
||
| it will use an existing or automatically deploy a new Hugging Face Space as needed. You should be logged in with the `huggingface-cli` locally and your token should have write permissions to create the Space. | ||
|
|
||
| ## Self-hosted Trackio server | ||
|
|
||
| You can run the Trackio dashboard and API on your own machine or infrastructure and point training jobs at it over HTTP. Pass the **full URL including the `write_token` query** (as printed when the server starts, or use the `full_url` return value from `trackio.show()`): | ||
|
|
||
| ```py | ||
| trackio.init(project="my-project", server_url="http://127.0.0.1:7860?write_token=YOUR_TOKEN") | ||
| ``` | ||
|
|
||
| You can also set `TRACKIO_SERVER_URL` to that full URL instead of passing `server_url`. If `space_id` / `TRACKIO_SPACE_ID` and `server_url` / `TRACKIO_SERVER_URL` are both set, Trackio uses the Hugging Face Space and ignores the self-hosted URL. | ||
|
||
|
|
||
| See the documentation: [Self-host the Server](https://huggingface.co/docs/trackio/self_hosted_server). | ||
|
|
||
| ## Syncing Offline Projects to Spaces | ||
|
|
||
| If you've been tracking experiments locally and want to move them to Hugging Face Spaces for sharing or collaboration, use the `sync` function: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,18 @@ export TRACKIO_DIR="/path/to/trackio/data" | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Note: This environment variable applies as long as Trackio is not running in a Space with persistent storage enabled. If Trackio is running in a Space with persistent storage enabled (which is detected with the `PERSISTANT_STORAGE_ENABLED` env variable), then the Trackio data will be stored in `/data/trackio`. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ### `TRACKIO_SERVER_URL` | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Full URL of a self-hosted Trackio server (HTTP or HTTPS), **including the `write_token` query parameter** (same URL as the dashboard’s write-access link or the `full_url` from `trackio.show()`). When set, `trackio.init()` sends metrics to that server. Equivalent to passing `server_url=` to `trackio.init()`. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| **Precedence:** If `TRACKIO_SPACE_ID` is also set (or `space_id` is passed in code), the Hugging Face Space is used and `TRACKIO_SERVER_URL` is ignored. Same rule when both `space_id` and `server_url` are passed: `space_id` wins. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| See [Self-host the Server](self_hosted_server.md). | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||
| export TRACKIO_SERVER_URL="http://127.0.0.1:7860?write_token=YOUR_TOKEN" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| Full URL of a self-hosted Trackio server (HTTP or HTTPS), **including the `write_token` query parameter** (same URL as the dashboard’s write-access link or the `full_url` from `trackio.show()`). When set, `trackio.init()` sends metrics to that server. Equivalent to passing `server_url=` to `trackio.init()`. | |
| **Precedence:** If `TRACKIO_SPACE_ID` is also set (or `space_id` is passed in code), the Hugging Face Space is used and `TRACKIO_SERVER_URL` is ignored. Same rule when both `space_id` and `server_url` are passed: `space_id` wins. | |
| See [Self-host the Server](self_hosted_server.md). | |
| ```bash | |
| export TRACKIO_SERVER_URL="http://127.0.0.1:7860?write_token=YOUR_TOKEN" | |
| Base URL of a self-hosted Trackio server (HTTP or HTTPS). When set, `trackio.init()` sends metrics to that server. Equivalent to passing `server_url=` to `trackio.init()`. | |
| Do **not** rely on a `write_token` query parameter in `TRACKIO_SERVER_URL` for metric ingestion. Write-access links (such as the dashboard’s write-access URL or the `full_url` from `trackio.show()`) may include `write_token`, but that token is for write-enabled dashboard / mutation flows rather than the logging path configured by this environment variable. | |
| **Precedence:** If `TRACKIO_SPACE_ID` is also set (or `space_id` is passed in code), the Hugging Face Space is used and `TRACKIO_SERVER_URL` is ignored. Same rule when both `space_id` and `server_url` are passed: `space_id` wins. | |
| See [Self-host the Server](self_hosted_server.md). | |
| ```bash | |
| export TRACKIO_SERVER_URL="http://127.0.0.1:7860" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Self-host the Trackio server | ||
|
|
||
| You can run the Trackio dashboard and API on your own machine (or any host you control) and send metrics from training scripts to that server over HTTP. This is an alternative to logging to a Hugging Face Space via `space_id`. | ||
|
|
||
| ## Run the server locally | ||
|
|
||
| Install Trackio, then start the dashboard. By default it listens on `127.0.0.1` and uses the port from `GRADIO_SERVER_PORT` if set, otherwise **7860** (see [Launch the Dashboard](launch.md)). | ||
|
|
||
| <hfoptions id="language"> | ||
| <hfoption id="Shell"> | ||
|
|
||
| ```sh | ||
| trackio show | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| <hfoption id="Python"> | ||
|
|
||
| ```py | ||
| import trackio | ||
|
|
||
| trackio.show() | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| </hfoptions> | ||
|
|
||
| Leave that process running while you train. The terminal prints a base URL for the UI and a URL that includes a **write token**; anyone who can reach that URL with the token can perform write operations supported by the server (for example renaming runs), so treat it like a secret on untrusted networks. | ||
|
|
||
| ## Listen on all interfaces | ||
|
|
||
| To access the dashboard from another machine on your network (or from containers), bind to all interfaces: | ||
|
|
||
| <hfoptions id="language"> | ||
| <hfoption id="Shell"> | ||
|
|
||
| ```sh | ||
| trackio show --host 0.0.0.0 | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| <hfoption id="Python"> | ||
|
|
||
| ```py | ||
| import trackio | ||
|
|
||
| trackio.show(host="0.0.0.0") | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| </hfoptions> | ||
|
|
||
| Ensure your firewall and security policies allow the traffic you intend. | ||
|
|
||
| ## Point training code at your server | ||
|
|
||
| In your training script, pass the **full URL including the `write_token` query parameter** (the same URL the dashboard prints for write access, or the `full_url` return value from `trackio.show()`). Logging requires that token; a host-only URL like `http://127.0.0.1:7860/` is not sufficient. You can also set the environment variable `TRACKIO_SERVER_URL` to that full URL instead of passing an argument. | ||
|
|
||
|
abidlabs marked this conversation as resolved.
|
||
| ```py | ||
| import trackio | ||
|
|
||
| trackio.init( | ||
| project="my-project", | ||
| server_url="http://127.0.0.1:7860?write_token=YOUR_TOKEN", | ||
| ) | ||
| trackio.log({"loss": 0.25}) | ||
| trackio.finish() | ||
| ``` | ||
|
|
||
| Precedence: **`space_id` / `TRACKIO_SPACE_ID` always wins** over `server_url` / `TRACKIO_SERVER_URL` when both are set (in code or in the environment). Trackio then behaves as if only the Space were configured. | ||
|
|
||
| Hugging Face–specific options such as `dataset_id` and `bucket_id` apply only when logging to a Space. When only `server_url` is in effect, configure persistence on the machine where the server runs (for example via `TRACKIO_DIR` on that host). See [Environment Variables](environment_variables.md). | ||
|
|
||
| ## Related | ||
|
|
||
| - [Launch the Dashboard](launch.md) — CLI options, port, and remote access | ||
| - [Environment Variables](environment_variables.md) — `TRACKIO_SERVER_URL`, `TRACKIO_DIR`, and others | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -213,6 +213,7 @@ def init( | |||||||||||||||||||||||||||||||||||||||
| name: str | None = None, | ||||||||||||||||||||||||||||||||||||||||
| group: str | None = None, | ||||||||||||||||||||||||||||||||||||||||
| space_id: str | None = None, | ||||||||||||||||||||||||||||||||||||||||
| server_url: str | None = None, | ||||||||||||||||||||||||||||||||||||||||
| space_storage: SpaceStorage | None = None, | ||||||||||||||||||||||||||||||||||||||||
| dataset_id: str | None = None, | ||||||||||||||||||||||||||||||||||||||||
| bucket_id: str | None = None, | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -249,6 +250,18 @@ def init( | |||||||||||||||||||||||||||||||||||||||
| via the `TRACKIO_SPACE_ID` environment variable. You cannot log to a | ||||||||||||||||||||||||||||||||||||||||
| Space that has been **frozen** (converted to the static SDK); use | ||||||||||||||||||||||||||||||||||||||||
| ``trackio.sync(..., sdk="static")`` only after you are done logging. | ||||||||||||||||||||||||||||||||||||||||
| Takes precedence over `server_url` and `TRACKIO_SERVER_URL` when more than | ||||||||||||||||||||||||||||||||||||||||
| one is set. | ||||||||||||||||||||||||||||||||||||||||
| server_url (`str`, *optional*): | ||||||||||||||||||||||||||||||||||||||||
| Full URL of a self-hosted Trackio server, including the ``write_token`` query | ||||||||||||||||||||||||||||||||||||||||
| parameter (for example the ``full_url`` value returned by ``trackio.show()``, | ||||||||||||||||||||||||||||||||||||||||
| or the write-access URL printed when the dashboard starts). Logging and other | ||||||||||||||||||||||||||||||||||||||||
| remote calls require that token; a base URL without ``write_token`` is not | ||||||||||||||||||||||||||||||||||||||||
| enough. Example: | ||||||||||||||||||||||||||||||||||||||||
| ``"https://trackio.internal.example.com?write_token=..."``. When set, metrics are sent to | ||||||||||||||||||||||||||||||||||||||||
| that server over HTTP instead of creating or syncing to a Hugging Face | ||||||||||||||||||||||||||||||||||||||||
| Space. Can also be set via the `TRACKIO_SERVER_URL` environment variable. | ||||||||||||||||||||||||||||||||||||||||
| Ignored when `space_id` or `TRACKIO_SPACE_ID` is set. | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| Full URL of a self-hosted Trackio server, including the ``write_token`` query | |
| parameter (for example the ``full_url`` value returned by ``trackio.show()``, | |
| or the write-access URL printed when the dashboard starts). Logging and other | |
| remote calls require that token; a base URL without ``write_token`` is not | |
| enough. Example: | |
| ``"https://trackio.internal.example.com?write_token=..."``. When set, metrics are sent to | |
| that server over HTTP instead of creating or syncing to a Hugging Face | |
| Space. Can also be set via the `TRACKIO_SERVER_URL` environment variable. | |
| Ignored when `space_id` or `TRACKIO_SPACE_ID` is set. | |
| Base URL of a self-hosted Trackio server. For example: | |
| ``"https://trackio.internal.example.com"``. If you are using a write-access | |
| URL returned by ``trackio.show()`` or printed when the dashboard starts, it | |
| may also include a ``write_token`` query parameter, for example | |
| ``"https://trackio.internal.example.com?write_token=..."``. Depending on the | |
| server configuration, that token may be required for some write/admin | |
| operations, but it is not required for all logging requests. When set, | |
| metrics are sent to that server over HTTP instead of creating or syncing to | |
| a Hugging Face Space. Can also be set via the `TRACKIO_SERVER_URL` | |
| environment variable. Ignored when `space_id` or `TRACKIO_SPACE_ID` is set. |
Copilot
AI
Apr 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security: when remote_source is a user-provided URL (server_url), passing huggingface_hub.utils.get_token() into RemoteClient will send the user's Hugging Face token as an HTTP Authorization header to that server. Please avoid attaching HF tokens when the remote target is not a Hugging Face Space (e.g., pass hf_token=None for URLs and only use HF tokens for resolved HF Space sources). Also ensure the fallback RemoteClient construction paths in the _safe_get_*_for_init helpers follow the same rule.
| hf_token=huggingface_hub.utils.get_token(), | |
| hf_token=None | |
| if server_url is not None | |
| else huggingface_hub.utils.get_token(), |
Uh oh!
There was an error while loading. Please reload this page.