> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monostate.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment Variables

> Configure AITraining via environment variables

# Environment Variables

Configure AITraining behavior through environment variables.

## Authentication

### Hugging Face

```bash theme={null}
export HF_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxx"
```

Required for:

* Private models
* Private datasets
* Pushing to Hub

### Weights & Biases

```bash theme={null}
export WANDB_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
```

Required when using `--log wandb`.

## GPU Configuration

### Select GPUs

```bash theme={null}
# 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

```bash theme={null}
# Limit memory fragmentation and enable expandable segments
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512,expandable_segments:True
```

### GPU Override

```bash theme={null}
# 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

```bash theme={null}
# Disable MPS (force CPU on Mac)
export AUTOTRAIN_DISABLE_MPS=1

# Force enable MPS even with incompatible settings
export AUTOTRAIN_ENABLE_MPS=1
```

<Note>
  When MPS is disabled or incompatible, AITraining automatically sets `PYTORCH_ENABLE_MPS_FALLBACK=1` for CPU fallback.
</Note>

## Security Settings

### Remote Code Execution

```bash theme={null}
# Disable trust_remote_code for all model loading (more secure)
export ALLOW_REMOTE_CODE=false
```

<Warning>
  Setting `ALLOW_REMOTE_CODE=false` may prevent loading models that require custom code (like some multimodal models). Default is `true`.
</Warning>

## Logging

### W\&B Settings

```bash theme={null}
export WANDB_PROJECT=my-project
export WANDB_ENTITY=my-team
export WANDB_MODE=offline  # Don't sync to cloud
```

## Hub Settings

### Default Username

```bash theme={null}
export HF_USERNAME=my-username
```

### Cache Directory

```bash theme={null}
export HF_HOME=/path/to/cache
export TRANSFORMERS_CACHE=/path/to/cache
```

## Training Settings

### Disable Telemetry

```bash theme={null}
export HF_HUB_DISABLE_TELEMETRY=1
```

### Offline Mode

```bash theme={null}
export TRANSFORMERS_OFFLINE=1
export HF_HUB_OFFLINE=1
```

## Usage Examples

### Full Setup Script

Create a setup script `setup_env.sh`:

```bash theme={null}
#!/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:

```bash theme={null}
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:

```bash theme={null}
export $(cat .env | xargs)
aitraining --config training.yaml
```

## Internal Variables

These are set automatically by AITraining:

| Variable                 | Value   | Purpose                                |
| ------------------------ | ------- | -------------------------------------- |
| `TF_CPP_MIN_LOG_LEVEL`   | `3`     | Suppress TensorFlow warnings           |
| `TOKENIZERS_PARALLELISM` | `false` | Disable tokenizer parallelism warnings |
| `BITSANDBYTES_NOWELCOME` | `1`     | Suppress bitsandbytes welcome message  |
| `AUTOTRAIN_TUI_MODE`     | `1`     | Set when running in TUI mode           |

### Debug Variables

| Variable           | Default | Purpose                                              |
| ------------------ | ------- | ---------------------------------------------------- |
| `PAUSE_ON_FAILURE` | `1`     | Pause 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

<CardGroup cols={2}>
  <Card title="YAML Configs" href="/cli/yaml-configs">
    Configuration files
  </Card>

  <Card title="Installation" href="/cli/installation-setup">
    Initial setup
  </Card>
</CardGroup>
