> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-de/training/axolotl-training.md).

# Axolotl universelles Fine-Tuning

YAML-gesteuerte LLM-Feinabstimmung mit Axolotl auf Clore.ai — LoRA, QLoRA, DPO, Multi-GPU

Axolotl bündelt HuggingFace Transformers, PEFT, TRL und DeepSpeed in einer einzigen YAML-gesteuerten Oberfläche. Sie definieren Ihr Modell, Ihren Datensatz, die Trainingsmethode und die Hyperparameter in einer Konfigurationsdatei — und starten dann mit einem einzigen Befehl. Für Standard-Workflows ist kein Python-Scripting erforderlich.

{% hint style="success" %}
Alle Beispiele laufen auf GPU-Servern, die über die [CLORE.AI-Marktplatz](https://clore.ai/marketplace).
{% endhint %}

## Hauptfunktionen

* **Nur-YAML-Konfiguration** — alles in einer Datei definieren, kein Python nötig
* **Alle Trainingsmethoden** — LoRA, QLoRA, vollständiges Fine-Tuning, DPO, ORPO, KTO, RLHF
* **Multi-GPU direkt integriert** — DeepSpeed ZeRO 1/2/3 und FSDP mit einem Flag
* **Sample Packing** — kurze Beispiele verketten, um die Sequenzlänge auszufüllen, 3–5× höherer Durchsatz
* **Flash Attention 2** — automatische VRAM-Einsparung auf unterstützter Hardware
* **Breite Modellunterstützung** — Llama 3.x, Mistral, Qwen 2.5, Gemma 2, Phi-4, DeepSeek, Falcon
* **Integrierte Datensatzformate** — alpaca, sharegpt, chat\_template, completion und benutzerdefiniert

## Anforderungen

| Komponente | Minimum        | Empfohlen            |
| ---------- | -------------- | -------------------- |
| GPU        | RTX 3060 12 GB | RTX 4090 24 GB (×2+) |
| VRAM       | 12 GB          | 24+ GB               |
| RAM        | 16 GB          | 64 GB                |
| Festplatte | 50 GB          | 100 GB               |
| CUDA       | 12.8+          | 12.8+                |
| Python     | 3.10           | 3.11                 |

**Clore.ai-Preise:** RTX 4090 ≈ 0,14–0,42 $/Std. · RTX 3090 ≈ 0,07–0,21 $/Std. · RTX 3060 ≈ 0,03–0,07 $/Std.

## Schnellstart

### 1. Axolotl installieren

```bash
# Klonen und installieren
git clone https://github.com/OpenAccess-AI-Collective/axolotl.git
cd axolotl

pip install packaging ninja
pip install -e '.[flash-attn,deepspeed]'
```

Oder verwenden Sie das Docker-Image (empfohlen für Reproduzierbarkeit):

```bash
docker run --gpus all -it --rm \
  -v /workspace:/workspace \
  winglian/axolotl:main-latest
```

### 2. Eine Konfigurationsdatei erstellen

Speichern Sie dies als `config.yml`:

```yaml
base_model: meta-llama/Meta-Llama-3.1-8B-Instruct
model_type: LlamaForCausalLM
tokenizer_type: AutoTokenizer

load_in_4bit: true
adapter: qlora
lora_r: 32
lora_alpha: 16
lora_dropout: 0.05
lora_target_linear: true

datasets:
  - path: yahma/alpaca-cleaned
    type: alpaca

sequence_len: 2048
sample_packing: true
pad_to_sequence_len: true

wandb_project: axolotl-clore
wandb_name: llama3-qlora

output_dir: /workspace/axolotl-output

gradient_accumulation_steps: 4
micro_batch_size: 2
num_epochs: 1
learning_rate: 2e-4
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
warmup_steps: 10

bf16: auto
flash_attention: true
gradient_checkpointing: true

logging_steps: 10
save_strategy: steps
save_steps: 500
eval_steps: 500

evals_per_epoch:
val_set_size: 0.02
```

### 3. Training starten

```bash
# Einzelne GPU
accelerate launch -m axolotl.cli.train config.yml

# Multi-GPU (alle verfügbaren GPUs)
accelerate launch --multi_gpu -m axolotl.cli.train config.yml
```

Trainingsfortschritt wird in stdout und optional in Weights & Biases protokolliert.

## Detaillierter Konfigurationsüberblick

### Datensatzformate

Axolotl unterstützt mehrere Eingabeformate nativ:

```yaml
# Alpaca-Stil (Instruktion / Eingabe / Ausgabe)
datasets:
  - path: yahma/alpaca-cleaned
    type: alpaca

# ShareGPT-Mehrturn-Chat
datasets:
  - path: anon8231489123/ShareGPT_Vicuna_unfiltered
    type: sharegpt
    conversation: chatml

# Chat-Template (automatische Erkennung aus dem Tokenizer)
datasets:
  - path: HuggingFaceH4/ultrachat_200k
    type: chat_template
    field_messages: messages
    message_field_role: role
    message_field_content: content

# Lokale JSONL-Datei
datasets:
  - path: /workspace/data/my_dataset.jsonl
    type: alpaca
    ds_type: json
```

### Multi-GPU mit DeepSpeed

Erstelle `deepspeed_zero2.json`:

```json
{
  "bf16": { "enabled": true },
  "zero_optimization": {
    "stage": 2,
    "offload_optimizer": { "device": "cpu" },
    "allgather_partitions": true,
    "allgather_bucket_size": 5e8,
    "reduce_scatter": true,
    "reduce_bucket_size": 5e8,
    "overlap_comm": true,
    "contiguous_gradients": true
  },
  "train_micro_batch_size_per_gpu": "auto",
  "gradient_accumulation_steps": "auto",
  "gradient_clipping": 1.0
}
```

Zu Ihrer Konfiguration hinzufügen:

```yaml
deepspeed: deepspeed_zero2.json
```

Dann starten:

```bash
accelerate launch --num_processes 4 -m axolotl.cli.train config.yml
```

### DPO / ORPO-Ausrichtung

```yaml
base_model: meta-llama/Meta-Llama-3.1-8B-Instruct
rl: dpo
# oder: rl: orpo

datasets:
  - path: argilla/ultrafeedback-binarized-preferences
    type: chat_template.default
    field_messages: chosen
    field_chosen: chosen
    field_rejected: rejected

dpo_beta: 0.1
```

### Vollständiges Fine-Tuning (kein LoRA)

```yaml
base_model: meta-llama/Meta-Llama-3.1-8B-Instruct

# Kein Adapter, keine Quantisierung
adapter:
load_in_4bit: false
load_in_8bit: false

learning_rate: 5e-6
micro_batch_size: 1
gradient_accumulation_steps: 8
gradient_checkpointing: true
flash_attention: true
bf16: auto

deepspeed: deepspeed_zero3.json  # erforderlich für vollständiges Fine-Tuning 8B+
```

## Anwendungsbeispiele

### Inference nach dem Training

```bash
# Interaktive Inferenz starten
accelerate launch -m axolotl.cli.inference config.yml \
  --lora_model_dir /workspace/axolotl-output
```

### LoRA in das Basismodell zusammenführen

```bash
accelerate launch -m axolotl.cli.merge_lora config.yml \
  --lora_model_dir /workspace/axolotl-output \
  --output_dir /workspace/merged-model
```

### Datensatz vorverarbeiten (vor dem Training validieren)

```bash
python -m axolotl.cli.preprocess config.yml
```

Dies tokenisiert und validiert den Datensatz. Nützlich, um Formatfehler vor einem langen Trainingslauf zu erkennen.

## Referenz zur VRAM-Nutzung

| Modell        | Methode     | GPUs | VRAM/GPU | Konfiguration            |
| ------------- | ----------- | ---- | -------- | ------------------------ |
| Llama 3.1 8B  | QLoRA 4bit  | 1    | \~12 GB  | r=32, seq\_len=2048      |
| Llama 3.1 8B  | LoRA 16bit  | 1    | \~20 GB  | r=16, seq\_len=2048      |
| Llama 3.1 8B  | Vollständig | 2    | \~22 GB  | DeepSpeed ZeRO-3         |
| Qwen 2.5 14B  | QLoRA 4bit  | 1    | \~16 GB  | r=16, seq\_len=2048      |
| Llama 3.3 70B | QLoRA 4bit  | 2    | \~22 GB  | r=16, seq\_len=2048      |
| Llama 3.3 70B | Vollständig | 4    | \~40 GB  | DeepSpeed ZeRO-3+Offload |

## Tipps

* **Immer aktivieren `sample_packing: true`** — die größte einzelne Verbesserung des Durchsatzes (3–5× bei kurzen Datensätzen)
* **Verwende `flash_attention: true`** auf Ampere+-GPUs für 20–40 % VRAM-Einsparung
* **Mit QLoRA beginnen** für Experimente; erst auf vollständiges Fine-Tuning umstellen, wenn die LoRA-Qualität stagniert
* **Setze `val_set_size: 0.02`** um Überanpassung während des Trainings zu überwachen
* **Zuerst vorverarbeiten** — ausführen `axolotl.cli.preprocess` um die Datenformatierung vor einem langen Lauf zu validieren
* **Verwenden Sie das Docker-Image** für reproduzierbare Umgebungen — vermeidet Abhängigkeitskonflikte
* **`lora_target_linear: true`** wendet LoRA auf alle linearen Schichten an, in der Regel besser als nur die Aufmerksamkeitsschichten zu adressieren

## Fehlerbehebung

| Problem                                       | Lösung                                                                             |
| --------------------------------------------- | ---------------------------------------------------------------------------------- |
| `OutOfMemoryError`                            | Niedriger `micro_batch_size` auf 1 setzen, aktivieren `gradient_checkpointing`     |
| Fehler im Datensatzformat                     | Ausführen `python -m axolotl.cli.preprocess config.yml` zum Debuggen               |
| `sample_packing` langsam in der ersten Epoche | Normal — die anfängliche Packing-Berechnung ist einmalig                           |
| Multi-GPU-Training hängt                      | NCCL prüfen: `export NCCL_DEBUG=INFO`, sicherstellen, dass alle GPUs sichtbar sind |
| `flash_attention` Importfehler                | Installieren: `pip install flash-attn --no-build-isolation`                        |
| Loss nimmt nicht ab                           | LR auf 1e-4 senken, Warmup erhöhen, Datenqualität prüfen                           |
| WandB-Verbindungsfehler                       | Ausführen `wandb login` oder setzen `wandb_project:` auf leeren String             |

## Ressourcen

* [Axolotl GitHub](https://github.com/OpenAccess-AI-Collective/axolotl)
* [Beispielkonfigurationen](https://github.com/OpenAccess-AI-Collective/axolotl/tree/main/examples)
* [CLORE.AI-Marktplatz](https://clore.ai/marketplace)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-de/training/axolotl-training.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
