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

# Variáveis de Ambiente

> Configure o AITraining via variáveis de ambiente

# Variáveis de Ambiente

Configure o comportamento do AITraining através de variáveis de ambiente.

## Autenticação

### Hugging Face

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

Necessário para:

* Modelos privados
* Datasets privados
* Push para Hub

### Weights & Biases

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

Necessário ao usar `--log wandb`.

## Configuração de GPU

### Selecionar GPUs

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

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

# Desabilitar GPU (apenas CPU)
export CUDA_VISIBLE_DEVICES=""
```

### Gerenciamento de Memória

```bash theme={null}
# Limitar fragmentação de memória e habilitar segmentos expansíveis
export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512,expandable_segments:True
```

### Sobrescrever GPU

```bash theme={null}
# Forçar treinamento CPU (sobrescrever detecção de GPU)
export AUTOTRAIN_FORCE_NUM_GPUS=0

# Forçar GPU única
export AUTOTRAIN_FORCE_NUM_GPUS=1
```

## Configurações Mac (Apple Silicon)

### Controle MPS

```bash theme={null}
# Desabilitar MPS (forçar CPU no Mac)
export AUTOTRAIN_DISABLE_MPS=1

# Forçar habilitar MPS mesmo com configurações incompatíveis
export AUTOTRAIN_ENABLE_MPS=1
```

<Note>
  Quando o MPS está desabilitado ou incompatível, o AITraining define automaticamente `PYTORCH_ENABLE_MPS_FALLBACK=1` para fallback em CPU.
</Note>

## Configurações de Segurança

### Execução de Código Remoto

```bash theme={null}
# Desabilitar trust_remote_code para todo carregamento de modelo (mais seguro)
export ALLOW_REMOTE_CODE=false
```

<Warning>
  Definir `ALLOW_REMOTE_CODE=false` pode impedir o carregamento de modelos que requerem código customizado (como alguns modelos multimodais). O padrão é `true`.
</Warning>

## Logging

### Configurações W\&B

```bash theme={null}
export WANDB_PROJECT=my-project
export WANDB_ENTITY=my-team
export WANDB_MODE=offline  # Não sincronizar com a nuvem
```

## Configurações do Hub

### Nome de Usuário Padrão

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

### Diretório de Cache

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

## Configurações de Treinamento

### Desabilitar Telemetria

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

### Modo Offline

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

## Exemplos de Uso

### Script de Configuração Completo

Crie um script de configuração `setup_env.sh`:

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

# Autenticação
export HF_TOKEN="hf_your_token_here"
export WANDB_API_KEY="your_wandb_key"

# Configurações de GPU
export CUDA_VISIBLE_DEVICES=0,1

# Cache
export HF_HOME=~/.cache/huggingface

# Configurações do projeto W&B
export WANDB_PROJECT=my-project
```

Execute antes do treinamento:

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

### Usando Arquivos .env

Crie um arquivo `.env`:

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

Carregue com:

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

## Variáveis Internas

Essas são definidas automaticamente pelo AITraining:

| Variável                 | Valor   | Propósito                                        |
| ------------------------ | ------- | ------------------------------------------------ |
| `TF_CPP_MIN_LOG_LEVEL`   | `3`     | Suprimir avisos do TensorFlow                    |
| `TOKENIZERS_PARALLELISM` | `false` | Desabilitar avisos de paralelismo do tokenizer   |
| `BITSANDBYTES_NOWELCOME` | `1`     | Suprimir mensagem de boas-vindas do bitsandbytes |
| `AUTOTRAIN_TUI_MODE`     | `1`     | Definido ao executar no modo TUI                 |

### Variáveis de Debug

| Variável           | Padrão | Propósito                                                  |
| ------------------ | ------ | ---------------------------------------------------------- |
| `PAUSE_ON_FAILURE` | `1`    | Pausar Space em falha de treinamento (para backend Spaces) |

## Prioridade

Ao usar `--config`, o arquivo de configuração assume controle total dos parâmetros de treinamento. Variáveis de ambiente são usadas para autenticação e configurações do sistema (como `HF_TOKEN`, `WANDB_API_KEY`, `CUDA_VISIBLE_DEVICES`).

## Próximos Passos

<CardGroup cols={2}>
  <Card title="Configurações YAML" href="/cli/yaml-configs">
    Arquivos de configuração
  </Card>

  <Card title="Instalação" href="/cli/installation-setup">
    Configuração inicial
  </Card>
</CardGroup>
