Repository: huggingface/transformers
Pull request: Deprecate Trackio environment variables and deploy to Spaces by default

This PR

- Deploys Trackio by default (instead of keeping local). See internal discussion here https://huggingface.slack.com/archives/C08SW1X12C8/p1758056496519289?thread_ts=1757706409.065919&cid=C08SW1X12C8 and
- Drops environment variables in favour of explicit args. See https://github.com/gradio-app/trackio/pull/212#pullrequestreview-3234300545
  
  ```diff
  - import os
    
    import numpy as np
    from datasets import Dataset
    from transformers import Trainer, AutoModelForCausalLM, TrainingArguments
    
  - os.environ["TRACKIO_PROJECT"] = "my-awesome-project"
  - os.environ["TRACKIO_SPACE_ID"] = "my-awesome-username/my-awesome-space"
    
    # Create a fake dataset
    data = np.random.randint(0, 1000, (8192, 64)).tolist()
    dataset = Dataset.from_dict({"input_ids": data, "labels": data})
    
    # Train a model using the Trainer API
    trainer = Trainer(
        model=AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-0.6B"),
  -     args=TrainingArguments(run_name="Qwen3-0.6B-training", report_to="trackio"),
  +     args=TrainingArguments(run_name="Qwen3-0.6B-training", report_to="trackio", project="my-awesome-project", trackio_space_id="my-awesome-username/my-awesome-space"),
        train_dataset=dataset,
    )
    trainer.train()
  ```

Changed files:
filename: src/transformers/integrations/integration_utils.py
patch: @@ -1081,19 +1081,28 @@ def setup(self, args, state, model, **kwargs):
         """
         Setup the optional Trackio integration.
 
-        To customize the setup you can also override the following environment variables:
-
-        Environment:
-        - **TRACKIO_PROJECT** (`str`, *optional*, defaults to `"huggingface"`):
-            The name of the project (can be an existing project to continue tracking or a new project to start tracking
-            from scratch).
-        - **TRACKIO_SPACE_ID** (`str`, *optional*, defaults to `None`):
-            If set, the project will be logged to a Hugging Face Space instead of a local directory. Should be a
-            complete Space name like `"username/reponame"` or `"orgname/reponame"`, or just `"reponame" in which case
-            the Space will be created in the currently-logged-in Hugging Face user's namespace. If the Space does not
-            exist, it will be created. If the Space already exists, the project will be logged to it.
+        To customize the setup you can also set the arguments `project`, `trackio_space_id` and `hub_private_repo` in
+        [`TrainingArguments`]. Please refer to the docstring of for more details.
         """
         if state.is_world_process_zero:
+            if os.getenv("TRACKIO_PROJECT"):
+                logger.warning(
+                    "The `TRACKIO_PROJECT` environment variable is deprecated and will be removed in a future "
+                    "version. Use TrainingArguments.project instead."
+                )
+                project = os.getenv("TRACKIO_PROJECT")
+            else:
+                project = args.project
+
+            if os.getenv("TRACKIO_SPACE_ID"):
+                logger.warning(
+                    "The `TRACKIO_SPACE_ID` environment variable is deprecated and will be removed in a future "
+                    "version. Use TrainingArguments.trackio_space_id instead."
+                )
+                space_id = os.getenv("TRACKIO_SPACE_ID")
+            else:
+                space_id = args.trackio_space_id
+
             combined_dict = {**args.to_dict()}
 
             if hasattr(model, "config") and model.config is not None:
@@ -1104,10 +1113,11 @@ def setup(self, args, state, model, **kwargs):
                 combined_dict = {**{"peft_config": peft_config}, **combined_dict}
 
             self._trackio.init(
-                project=os.getenv("TRACKIO_PROJECT", "huggingface"),
+                project=project,
                 name=args.run_name,
-                space_id=os.getenv("TRACKIO_SPACE_ID", None),
+                space_id=space_id,
                 resume="allow",
+                private=args.hub_private_repo,
             )
 
             # Add config parameters (run may have been created manually)

filename: src/transformers/training_args.py
patch: @@ -616,6 +616,14 @@ class TrainingArguments:
             `"clearml"`, `"codecarbon"`, `"comet_ml"`, `"dagshub"`, `"dvclive"`, `"flyte"`, `"mlflow"`, `"neptune"`,
             `"swanlab"`, `"tensorboard"`, `"trackio"` and `"wandb"`. Use `"all"` to report to all integrations
             installed, `"none"` for no integrations.
+        project (`str`, *optional*, defaults to `"huggingface"`):
+            The name of the project to use for logging. Currently, only used by Trackio.
+        trackio_space_id (`str` or `None`, *optional*, defaults to `"trackio"`):
+            The Hugging Face Space ID to deploy to when using Trackio. Should be a complete Space name like
+            `'username/reponame'` or `'orgname/reponame' `, or just `'reponame'` in which case the Space will be
+            created in the currently-logged-in Hugging Face user's namespace. If `None`, will log to a local directory.
+            Note that this Space will be public unless you set `hub_private_repo=True` or your organization's default
+            is to create private Spaces."
         ddp_find_unused_parameters (`bool`, *optional*):
             When using distributed training, the value of the flag `find_unused_parameters` passed to
             `DistributedDataParallel`. Will default to `False` if gradient checkpointing is used, `True` otherwise.
@@ -680,7 +688,9 @@ class TrainingArguments:
             The token to use to push the model to the Hub. Will default to the token in the cache folder obtained with
             `hf auth login`.
         hub_private_repo (`bool`, *optional*):
-            Whether to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.
+            Whether to make the repo private. If `None` (default), the repo will be public unless the organization's
+            default is private. This value is ignored if the repo already exists. If reporting to Trackio with
+            deployment to Hugging Face Spaces enabled, the same logic determines whether the Space is private.
         hub_always_push (`bool`, *optional*, defaults to `False`):
             Unless this is `True`, the `Trainer` will skip pushing a checkpoint when the previous push is not finished.
         hub_revision (`str`, *optional*):
@@ -1206,6 +1216,20 @@ class TrainingArguments:
     report_to: Union[None, str, list[str]] = field(
         default=None, metadata={"help": "The list of integrations to report the results and logs to."}
     )
+    project: str = field(
+        default="huggingface",
+        metadata={"help": "The name of the project to use for logging. Currenly, only used by Trackio."},
+    )
+    trackio_space_id: Optional[str] = field(
+        default="trackio",
+        metadata={
+            "help": "The Hugging Face Space ID to deploy to when using Trackio. Should be a complete Space name like "
+            "'username/reponame' or 'orgname/reponame', or just 'reponame' in which case the Space will be created in "
+            "the currently-logged-in Hugging Face user's namespace. If `None`, will log to a local directory. Note "
+            "that this Space will be public unless you set `hub_private_repo=True` or your organization's "
+            "default is to create private Spaces."
+        },
+    )
     ddp_find_unused_parameters: Optional[bool] = field(
         default=None,
         metadata={
@@ -1263,7 +1287,10 @@ class TrainingArguments:
     hub_private_repo: Optional[bool] = field(
         default=None,
         metadata={
-            "help": "Whether to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists."
+            "help": "Whether to make the repo private. If `None` (default), the repo will be public unless the "
+            "organization's default is private. This value is ignored if the repo already exists. If reporting to "
+            "Trackio with deployment to Hugging Face Spaces enabled, the same logic determines whether the Space is "
+            "private."
         },
     )
     hub_always_push: bool = field(