Skip to main content

Environment Variables

Configure AITraining behavior through environment variables.

Authentication

Hugging Face

export HF_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxx"
Required for:
  • Private models
  • Private datasets
  • Pushing to Hub

Weights & Biases

export WANDB_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Required when using --log wandb.

GPU Configuration

Select GPUs

# Use only GPU 0
export CUDA_VISIBLE_DEVICES=0

# Use GPUs 0 and 1
export CUDA_VISIBLE_DEVICES=0,1

# Disable GPU (CPU only)
export CUDA_VISIBLE_DEVICES=""

Memory Management

# Limit memory fragmentation and enable expandable segments
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512,expandable_segments:True

GPU Override

# Force CPU training (override GPU detection)
export AUTOTRAIN_FORCE_NUM_GPUS=0

# Force single GPU
export AUTOTRAIN_FORCE_NUM_GPUS=1

Mac (Apple Silicon) Settings

MPS Control

# Disable MPS (force CPU on Mac)
export AUTOTRAIN_DISABLE_MPS=1

# Force enable MPS even with incompatible settings
export AUTOTRAIN_ENABLE_MPS=1
When MPS is disabled or incompatible, AITraining automatically sets PYTORCH_ENABLE_MPS_FALLBACK=1 for CPU fallback.

Security Settings

Remote Code Execution

# Disable trust_remote_code for all model loading (more secure)
export ALLOW_REMOTE_CODE=false
Setting ALLOW_REMOTE_CODE=false may prevent loading models that require custom code (like some multimodal models). Default is true.

Logging

W&B Settings

export WANDB_PROJECT=my-project
export WANDB_ENTITY=my-team
export WANDB_MODE=offline  # Don't sync to cloud

Hub Settings

Default Username

export HF_USERNAME=my-username

Cache Directory

export HF_HOME=/path/to/cache
export TRANSFORMERS_CACHE=/path/to/cache

Training Settings

Disable Telemetry

export HF_HUB_DISABLE_TELEMETRY=1

Offline Mode

export TRANSFORMERS_OFFLINE=1
export HF_HUB_OFFLINE=1

Usage Examples

Full Setup Script

Create a setup script setup_env.sh:
#!/bin/bash

# Authentication
export HF_TOKEN="hf_your_token_here"
export WANDB_API_KEY="your_wandb_key"

# GPU settings
export CUDA_VISIBLE_DEVICES=0,1

# Cache
export HF_HOME=~/.cache/huggingface

# W&B project settings
export WANDB_PROJECT=my-project
Source before training:
source setup_env.sh
aitraining llm --train ...

Using .env Files

Create a .env file:
HF_TOKEN=hf_xxxxx
WANDB_API_KEY=xxxxx
CUDA_VISIBLE_DEVICES=0
Load with:
export $(cat .env | xargs)
aitraining --config training.yaml

Internal Variables

These are set automatically by AITraining:
VariableValuePurpose
TF_CPP_MIN_LOG_LEVEL3Suppress TensorFlow warnings
TOKENIZERS_PARALLELISMfalseDisable tokenizer parallelism warnings
BITSANDBYTES_NOWELCOME1Suppress bitsandbytes welcome message
AUTOTRAIN_TUI_MODE1Set when running in TUI mode

Debug Variables

VariableDefaultPurpose
PAUSE_ON_FAILURE1Pause Space on training failure (for Spaces backend)

Priority

When using --config, the config file takes full control of training parameters. Environment variables are used for authentication and system settings (like HF_TOKEN, WANDB_API_KEY, CUDA_VISIBLE_DEVICES).

Next Steps