> ## 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.

# Variables de Entorno

> Configura AITraining mediante variables de entorno

# Variables de Entorno

Configura el comportamiento de AITraining mediante variables de entorno.

## Autenticación

### Hugging Face

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

Requerido para:

* Modelos privados
* Datasets privados
* Push a Hub

### Weights & Biases

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

Requerido al usar `--log wandb`.

## Configuración de GPU

### Seleccionar GPUs

```bash theme={null}
# Usar solo GPU 0
export CUDA_VISIBLE_DEVICES=0

# Usar GPUs 0 y 1
export CUDA_VISIBLE_DEVICES=0,1

# Deshabilitar GPU (solo CPU)
export CUDA_VISIBLE_DEVICES=""
```

### Gestión de Memoria

```bash theme={null}
# Limitar fragmentación de memoria y habilitar segmentos expandibles
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512,expandable_segments:True
```

### Sobrescribir GPU

```bash theme={null}
# Forzar entrenamiento CPU (sobrescribir detección de GPU)
export AUTOTRAIN_FORCE_NUM_GPUS=0

# Forzar GPU única
export AUTOTRAIN_FORCE_NUM_GPUS=1
```

## Configuraciones Mac (Apple Silicon)

### Control MPS

```bash theme={null}
# Deshabilitar MPS (forzar CPU en Mac)
export AUTOTRAIN_DISABLE_MPS=1

# Forzar habilitar MPS incluso con configuraciones incompatibles
export AUTOTRAIN_ENABLE_MPS=1
```

<Note>
  Cuando MPS está deshabilitado o es incompatible, AITraining establece automáticamente `PYTORCH_ENABLE_MPS_FALLBACK=1` para fallback en CPU.
</Note>

## Configuraciones de Seguridad

### Ejecución de Código Remoto

```bash theme={null}
# Deshabilitar trust_remote_code para todo cargado de modelo (más seguro)
export ALLOW_REMOTE_CODE=false
```

<Warning>
  Establecer `ALLOW_REMOTE_CODE=false` puede impedir cargar modelos que requieren código personalizado (como algunos modelos multimodales). El predeterminado es `true`.
</Warning>

## Logging

### Configuraciones W\&B

```bash theme={null}
export WANDB_PROJECT=my-project
export WANDB_ENTITY=my-team
export WANDB_MODE=offline  # No sincronizar con la nube
```

## Configuraciones del Hub

### Nombre de Usuario Predeterminado

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

### Directorio de Caché

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

## Configuraciones de Entrenamiento

### Deshabilitar Telemetría

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

### Modo Offline

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

## Ejemplos de Uso

### Script de Configuración Completo

Crea un script de configuración `setup_env.sh`:

```bash theme={null}
#!/bin/bash

# Autenticación
export HF_TOKEN="hf_your_token_here"
export WANDB_API_KEY="your_wandb_key"

# Configuraciones de GPU
export CUDA_VISIBLE_DEVICES=0,1

# Caché
export HF_HOME=~/.cache/huggingface

# Configuraciones del proyecto W&B
export WANDB_PROJECT=my-project
```

Ejecuta antes del entrenamiento:

```bash theme={null}
source setup_env.sh
aitraining llm --train ...
```

### Usando Archivos .env

Crea un archivo `.env`:

```
HF_TOKEN=hf_xxxxx
WANDB_API_KEY=xxxxx
CUDA_VISIBLE_DEVICES=0
```

Carga con:

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

## Variables Internas

Estas se establecen automáticamente por AITraining:

| Variable                 | Valor   | Propósito                                              |
| ------------------------ | ------- | ------------------------------------------------------ |
| `TF_CPP_MIN_LOG_LEVEL`   | `3`     | Suprimir advertencias de TensorFlow                    |
| `TOKENIZERS_PARALLELISM` | `false` | Deshabilitar advertencias de paralelismo del tokenizer |
| `BITSANDBYTES_NOWELCOME` | `1`     | Suprimir mensaje de bienvenida de bitsandbytes         |
| `AUTOTRAIN_TUI_MODE`     | `1`     | Establecido al ejecutar en modo TUI                    |

### Variables de Debug

| Variable           | Predeterminado | Propósito                                                    |
| ------------------ | -------------- | ------------------------------------------------------------ |
| `PAUSE_ON_FAILURE` | `1`            | Pausar Space en fallo de entrenamiento (para backend Spaces) |

## Prioridad

Al usar `--config`, el archivo de configuración toma control total de los parámetros de entrenamiento. Las variables de entorno se usan para autenticación y configuraciones del sistema (como `HF_TOKEN`, `WANDB_API_KEY`, `CUDA_VISIBLE_DEVICES`).

## Próximos Pasos

<CardGroup cols={2}>
  <Card title="Configuraciones YAML" href="/cli/yaml-configs">
    Archivos de configuración
  </Card>

  <Card title="Instalación" href="/cli/installation-setup">
    Configuración inicial
  </Card>
</CardGroup>
