# Vergleich von Fine-Tuning-Tools

Wählen Sie das richtige Fine-Tuning-Framework zum Training von LLMs auf Clore.ai GPU-Servern.

{% hint style="info" %}
**Fine-Tuning** passt ein vortrainiertes LLM an Ihre spezifische Aufgabe oder Domäne an. Dieser Leitfaden vergleicht die vier führenden Open-Source-Tools: Unsloth, Axolotl, LLaMA-Factory und TRL — und behandelt Geschwindigkeit, Speichereffizienz, unterstützte Modelle und Bedienkomfort.
{% endhint %}

***

## Schnelle Entscheidungsübersicht

|                                    | Unsloth                                         | Axolotl                            | LLaMA-Factory        | TRL              |
| ---------------------------------- | ----------------------------------------------- | ---------------------------------- | -------------------- | ---------------- |
| **Am besten für**                  | Geschwindigkeit + Speicher                      | Konfigurationsgesteuertes Training | Einsteigerfreundlich | Forschung + RLHF |
| **Geschwindigkeit vs. Basislinie** | 2–5× schneller                                  | \~1× (Standard)                    | \~1× (Standard)      | \~1× (Standard)  |
| **Speicherreduzierung**            | 70–80% weniger                                  | QLoRA-Standard                     | QLoRA-Standard       | Standard         |
| **RLHF/DPO/PPO**                   | Grundlegend                                     | ✅                                  | ✅                    | ✅ (nativ)        |
| **WebUI**                          | ❌                                               | ❌                                  | ✅                    | ❌                |
| **GitHub-Sterne**                  | 23K+                                            | 9K+                                | 37K+                 | 10K+             |
| **Lizenz**                         | LGPL (kostenlos für nicht-kommerzielle Nutzung) | Apache 2.0                         | Apache 2.0           | Apache 2.0       |

***

## Übersicht

### Unsloth

Unsloth konzentriert sich laserartig auf eine Sache: Fine-Tuning so schnell und speichereffizient wie möglich zu machen. Es schreibt Schlüsseloperationen in Triton neu und optimiert CUDA-Kerne.

**Philosophie**: Maximale Geschwindigkeit, minimaler VRAM — keine Kompromisse.

```python
from unsloth import FastLanguageModel
import torch

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="unsloth/Llama-3.2-8B-Instruct",
    max_seq_length=2048,
    load_in_4bit=True,  # 4-Bit-Quantisierung
)

model = FastLanguageModel.get_peft_model(
    model,
    r=16,              # LoRA-Rang
    target_modules=["q_proj", "k_proj", "v_proj", "up_proj", "down_proj"],
    lora_alpha=16,
    lora_dropout=0,
    bias="none",
    use_gradient_checkpointing="unsloth",  # ~30% mehr Batch-Größe
    random_state=42,
)
```

### Axolotl

Axolotl wickelt HuggingFace Transformers mit einem YAML-basierten Konfigurationssystem ein. Es übernimmt die Komplexität der Trainingseinrichtung, sodass Sie sich auf Daten und Hyperparameter konzentrieren können.

**Philosophie**: Alles in YAML, volle Flexibilität darunter.

```yaml
# config.yml
base_model: meta-llama/Meta-Llama-3-8B
model_type: LlamaForCausalLM
tokenizer_type: AutoTokenizer

datasets:
  - path: mhenrichsen/alpaca_data_cleaned
    type: alpaca

load_in_4bit: true
adapter: qlora

lora_r: 32
lora_alpha: 16
lora_target_modules:
  - q_proj
  - k_proj
  - v_proj
  - o_proj

num_epochs: 3
micro_batch_size: 2
gradient_accumulation_steps: 4
learning_rate: 2e-4
```

### LLaMA-Factory

LLaMA-Factory unterstützt die größte Bandbreite an Modellen (100+) und Trainingsmethoden und bietet eine Web-UI für die Konfiguration. Es ist die zugänglichste Option für Nicht-Forscher.

**Philosophie**: Alles funktioniert, für alle.

```bash
# Training über die Kommandozeile
llamafactory-cli train \
  --model_name_or_path meta-llama/Meta-Llama-3-8B \
  --stage sft \
  --do_train \
  --dataset alpaca_gpt4_en \
  --template llama3 \
  --finetuning_type lora \
  --lora_rank 8 \
  --output_dir saves/llama3-8b-lora \
  --num_train_epochs 3.0 \
  --per_device_train_batch_size 2

# Oder WebUI verwenden
llamafactory-cli webui
```

### TRL (Transformer Reinforcement Learning)

TRL ist HuggingFaces offizielle RLHF-Bibliothek. Sie ist der Standard für PPO, DPO, ORPO und andere Alignment-Trainingsmethoden.

**Philosophie**: Forschung zuerst, Alignment-Training nativ.

```python
from trl import SFTTrainer, SFTConfig
from transformers import AutoModelForCausalLM, AutoTokenizer
from datasets import load_dataset

model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B")

training_args = SFTConfig(
    output_dir="./results",
    num_train_epochs=3,
    per_device_train_batch_size=2,
    gradient_accumulation_steps=4,
    learning_rate=2e-4,
    logging_steps=10,
)

trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    args=training_args,
    train_dataset=load_dataset("tatsu-lab/alpaca", split="train"),
)

trainer.train()
```

***

## Geschwindigkeitsbenchmarks

### Vergleich der Trainingsgeschwindigkeit (Tokens/Sekunde)

Testaufbau: LLaMA 3.1 8B, LoRA r=16, 4-Bit-Quantisierung, Batch-Größe 4, A100 80GB

| Tool                         | Tokens/Sek | vs. Basislinie | Speicher (VRAM) |
| ---------------------------- | ---------- | -------------- | --------------- |
| Unsloth (4-Bit)              | \~4,200    | **2,8×**       | \~8GB           |
| Axolotl (QLoRA)              | \~1,500    | 1,0×           | \~16GB          |
| LLaMA-Factory (QLoRA)        | \~1,480    | \~1,0×         | \~16GB          |
| TRL (QLoRA)                  | \~1,450    | \~0,97×        | \~18GB          |
| Unsloth (vollständig 16-Bit) | \~2,800    | **1,9×**       | \~22GB          |

{% hint style="success" %}
**Unsloth-Vorteil ist real**: 2–5× Geschwindigkeit ergibt sich aus kundenspezifischen Triton-Kernen für Attention, Kreuzentropie, RoPE und LoRA. Nicht nur Marketing.
{% endhint %}

### VRAM-Nutzungsvergleich

Training LLaMA 3.1 8B, Sequenzlänge 2048:

| Methode                        | Unsloth | Axolotl | LLaMA-Factory | TRL  |
| ------------------------------ | ------- | ------- | ------------- | ---- |
| Vollständiges Fine-Tune (bf16) | 60GB    | 70GB    | 72GB          | 74GB |
| LoRA (bf16)                    | 18GB    | 24GB    | 25GB          | 26GB |
| QLoRA (4-bit)                  | **8GB** | 16GB    | 16GB          | 18GB |
| QLoRA (4-Bit, langer Kontext)  | 12GB    | 24GB    | 24GB          | 26GB |

**Minimaler GPU für 8B-Modell**:

* Unsloth: RTX 3080 (10GB) ✅
* Andere: RTX 3090 (24GB) erforderlich

***

## Unterstützte Modelle

### Modellunterstützungs-Matrix

| Modellfamilie | Unsloth   | Axolotl   | LLaMA-Factory | TRL |
| ------------- | --------- | --------- | ------------- | --- |
| LLaMA 3.x     | ✅         | ✅         | ✅             | ✅   |
| LLaMA 2       | ✅         | ✅         | ✅             | ✅   |
| Mistral       | ✅         | ✅         | ✅             | ✅   |
| Mixtral MoE   | ✅         | ✅         | ✅             | ✅   |
| Gemma 2       | ✅         | ✅         | ✅             | ✅   |
| Phi-3/3.5     | ✅         | ✅         | ✅             | ✅   |
| Qwen 2.5      | ✅         | ✅         | ✅             | ✅   |
| DeepSeek      | ✅         | ✅         | ✅             | ✅   |
| Falcon        | ✅         | ✅         | ✅             | ✅   |
| GPT-NeoX      | Teilweise | ✅         | ✅             | ✅   |
| T5/FLAN       | ❌         | ✅         | ✅             | ✅   |
| BERT/RoBERTa  | ❌         | ✅         | ✅             | ✅   |
| Vision-LLMs   | Teilweise | Teilweise | ✅             | ✅   |

### Unterstützte Trainingsmethoden

| Methode                         | Unsloth | Axolotl | LLaMA-Factory | TRL       |
| ------------------------------- | ------- | ------- | ------------- | --------- |
| Vollständiges Fine-Tune         | ✅       | ✅       | ✅             | ✅         |
| LoRA                            | ✅       | ✅       | ✅             | ✅         |
| QLoRA                           | ✅       | ✅       | ✅             | ✅         |
| DoRA                            | ✅       | ✅       | ✅             | ❌         |
| PEFT                            | ✅       | ✅       | ✅             | ✅         |
| SFT                             | ✅       | ✅       | ✅             | ✅ (nativ) |
| DPO                             | ✅       | ✅       | ✅             | ✅ (nativ) |
| PPO                             | ❌       | ✅       | ✅             | ✅ (nativ) |
| ORPO                            | ✅       | ✅       | ✅             | ✅         |
| KTO                             | ❌       | ✅       | ✅             | ✅ (nativ) |
| GRPO                            | ✅       | ❌       | ✅             | ✅         |
| CPT (fortgesetztes Pretraining) | ✅       | ✅       | ✅             | ✅         |

***

## Unsloth: Tiefer Einblick

### Was es schnell macht

1. **Triton-Kerne**: Schreibt Flash Attention, Kreuzentropie-Loss und LoRA in Triton neu
2. **Fusionierte Operationen**: Kombiniert mehrere CUDA-Operationen in einem Kernel
3. **Smartes Gradient Checkpointing**: Der "unsloth"-Modus spart \~30% mehr Speicher
4. **Effiziente Backpropagation**: Vermeidet die Materialisierung großer Zwischen-Tensoren

### Installation auf Clore.ai

```bash
# CUDA 12.1
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --no-deps trl peft accelerate bitsandbytes

# Oder mit conda
conda create --name unsloth_env python=3.11
conda activate unsloth_env
conda install pytorch-cuda=12.1 pytorch cudatoolkit xformers -c pytorch -c nvidia -c xformers -y
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --no-deps trl peft accelerate bitsandbytes
```

### Vollständiges Trainingsskript

```python
from unsloth import FastLanguageModel
from trl import SFTTrainer
from transformers import TrainingArguments
from datasets import load_dataset
import torch

# 1. Modell mit Unsloth-Optimierung laden
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="unsloth/Meta-Llama-3.1-8B-Instruct",
    max_seq_length=2048,
    dtype=None,        # Automatische Erkennung
    load_in_4bit=True,
)

# 2. LoRA-Adapter hinzufügen
model = FastLanguageModel.get_peft_model(
    model,
    r=16,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
                    "gate_proj", "up_proj", "down_proj"],
    lora_alpha=16,
    lora_dropout=0,
    bias="none",
    use_gradient_checkpointing="unsloth",
    random_state=3407,
)

# 3. Datensatz laden und formatieren
dataset = load_dataset("tatsu-lab/alpaca", split="train")

def format_prompt(example):
    return {"text": f"### Instruction:\n{example['instruction']}\n\n### Response:\n{example['output']}"}

dataset = dataset.map(format_prompt)

# 4. Trainieren
trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    train_dataset=dataset,
    dataset_text_field="text",
    max_seq_length=2048,
    args=TrainingArguments(
        per_device_train_batch_size=2,
        gradient_accumulation_steps=4,
        warmup_steps=5,
        num_train_epochs=1,
        learning_rate=2e-4,
        fp16=not torch.cuda.is_bf16_supported(),
        bf16=torch.cuda.is_bf16_supported(),
        logging_steps=1,
        optim="adamw_8bit",
        weight_decay=0.01,
        lr_scheduler_type="linear",
        seed=3407,
        output_dir="outputs",
    ),
)
trainer.train()

# 5. Speichern
model.save_pretrained("lora_model")
model.save_pretrained_gguf("model_gguf", tokenizer, quantization_method="q4_k_m")
```

**Schwächen**: Kein PPO, auf die unterstützte Modellliste beschränkt, LGPL-Lizenz (auf kommerzielle Nutzung prüfen)

***

## Axolotl: Tiefer Einblick

### Konfigurations-erste Vorgehensweise

Axolotl glänzt, wenn Sie reproduzierbare, versionskontrollierte Trainingskonfigurationen möchten:

```yaml
# axolotl_config.yml — vollständiges Beispiel
base_model: meta-llama/Meta-Llama-3-8B-Instruct
model_type: LlamaForCausalLM
tokenizer_type: AutoTokenizer

# Daten
datasets:
  - path: tatsu-lab/alpaca
    type: alpaca
  - path: ./my_custom_data.jsonl
    type: sharegpt
dataset_prepared_path: ./prepared_data
val_set_size: 0.01

# Quantisierung
load_in_4bit: true
adapter: qlora
bf16: true
tf32: true

# LoRA
lora_r: 32
lora_alpha: 16
lora_dropout: 0.05
lora_target_modules:
  - q_proj
  - v_proj
  - k_proj
  - o_proj
  - gate_proj
  - up_proj
  - down_proj

# Training
sequence_len: 4096
sample_packing: true  # Packt kurze Sequenzen zur Effizienz
pad_to_sequence_len: true
micro_batch_size: 2
gradient_accumulation_steps: 4
num_epochs: 3
learning_rate: 0.0002
optimizer: adamw_bnb_8bit
lr_scheduler: cosine

# Logging
logging_steps: 10
eval_steps: 100
save_steps: 100
output_dir: ./outputs/my-model

# wandb
wandb_project: my-fine-tune
wandb_run_id: run-001
```

```bash
# Installieren und ausführen
pip install axolotl[flash-attn,deepspeed]
axolotl train axolotl_config.yml
```

**Am besten für**: Teams, die reproduzierbare, konfigurationsversionierte Trainingsläufe wünschen

***

## LLaMA-Factory: Tiefer Einblick

### WebUI-Anleitung

```bash
# Installieren
pip install llamafactory

# WebUI starten
llamafactory-cli webui
# Öffnen Sie http://localhost:7860
```

WebUI-Tabs:

1. **Train** — Basis-Modell, Datensatz, Methode konfigurieren
2. **Evaluieren** — MMLU-, CMMLU-Benchmarks ausführen
3. **Chat** — interaktive Inferenz
4. **Export** — LoRA zusammenführen, nach GGUF quantisieren

### CLI-Trainingsbeispiel

```bash
# Supervised Fine-Tuning
llamafactory-cli train \
  --stage sft \
  --model_name_or_path meta-llama/Meta-Llama-3-8B \
  --dataset alpaca_gpt4_en,glaive_toolcall_en \
  --template llama3 \
  --finetuning_type lora \
  --lora_rank 8 \
  --lora_alpha 16 \
  --lora_target all \
  --output_dir saves/llama3-lora \
  --num_train_epochs 3 \
  --per_device_train_batch_size 2 \
  --gradient_accumulation_steps 4 \
  --learning_rate 2e-4 \
  --quantization_bit 4 \
  --flash_attn fa2

# DPO-Training
llamafactory-cli train \
  --stage dpo \
  --model_name_or_path meta-llama/Meta-Llama-3-8B \
  --dataset dpo_mix_en \
  --template llama3 \
  --finetuning_type lora \
  --output_dir saves/llama3-dpo
```

**Am besten für**: Anfänger, Teams, die eine WebUI und DPO/RLHF ohne tiefgehendes Forschungsvorwissen wollen

***

## TRL: Tiefer Einblick

### RLHF-Pipeline-Beispiel

TRL ist die erste Wahl für Alignment-Training:

```python
from trl import PPOTrainer, PPOConfig, AutoModelForCausalLMWithValueHead
from trl import DPOTrainer, DPOConfig
from datasets import load_dataset

# DPO (Direct Preference Optimization) — die gebräuchlichste Alignment-Methode
model_name = "meta-llama/Meta-Llama-3-8B-Instruct"

dpo_config = DPOConfig(
    model_name_or_path=model_name,
    output_dir="dpo_outputs",
    num_train_epochs=1,
    per_device_train_batch_size=2,
    beta=0.1,             # KL-Strafkoeffizient
    loss_type="sigmoid",  # oder "hinge", "ipo", "kto_pair"
    learning_rate=5e-7,
)

# Präferenzdatensatz laden (Prompt + gewählt + abgelehnt)
dataset = load_dataset("Anthropic/hh-rlhf", split="train")

trainer = DPOTrainer(
    model=model_name,
    args=dpo_config,
    train_dataset=dataset,
)
trainer.train()
```

**Am besten für**: Alignment-Forschung, RLHF, DPO, PPO, ORPO-Implementierungen

***

## Die richtige Werkzeugwahl

### Entscheidungsfluss

```
Brauchen Sie maximale Geschwindigkeit/minimalen VRAM?
  → JA → Unsloth (2–5× schneller, passt auf kleinere GPUs)

Brauchen Sie Alignment-Training (DPO/PPO/RLHF)?
  → JA → TRL oder LLaMA-Factory
  → Forschung/angepasst → TRL
  → Produktion/einfach → LLaMA-Factory

Brauchen Sie reproduzierbare, konfigurations-first Workflows?
  → JA → Axolotl

Nicht-technisches Team oder wollen Sie eine WebUI?
  → JA → LLaMA-Factory

Wollen Sie einfach schnell starten?
  → LLaMA-Factory oder Unsloth
```

### Nach Teamtyp

| Team               | Empfehlung    | Grund                                   |
| ------------------ | ------------- | --------------------------------------- |
| Einzelner Forscher | Unsloth       | Geschwindigkeit + Jupyter-Notebooks     |
| ML-Ingenieur       | Axolotl       | Konfigurationsgesteuert, reproduzierbar |
| Produktteam        | LLaMA-Factory | WebUI, breite Modellunterstützung       |
| Alignment-Team     | TRL           | Native RLHF-Primitiven                  |
| Startup            | Unsloth + TRL | Geschwindigkeit + Alignment bei Bedarf  |

***

## Clore.ai GPU-Empfehlungen

| Aufgabe           | Min. GPU        | Empfohlen    | Tool            |
| ----------------- | --------------- | ------------ | --------------- |
| 7–8B LoRA (QLoRA) | RTX 3080 (10GB) | RTX 3090     | Unsloth         |
| 13B LoRA          | RTX 3090 (24GB) | A6000 (48GB) | Unsloth/Axolotl |
| 70B LoRA          | A100 (80GB)     | 2×A100       | Axolotl/TRL     |
| 8B Volles FT      | A100 (40GB)     | A100 (80GB)  | Beliebig        |
| DPO/PPO 7B        | RTX 4090 (24GB) | A6000 (48GB) | TRL             |

***

## Nützliche Links

* [Unsloth GitHub](https://github.com/unslothai/unsloth) — 23K+ Sterne
* [Axolotl GitHub](https://github.com/axolotl-ai-cloud/axolotl) — 9K+ Sterne
* [LLaMA-Factory GitHub](https://github.com/hiyouga/LLaMA-Factory) — 37K+ Sterne
* [TRL GitHub](https://github.com/huggingface/trl) — 10K+ Sterne
* [HuggingFace PEFT-Dokumentation](https://huggingface.co/docs/peft)

***

## Zusammenfassung

| Tool              | Am besten für                                    | Hauptvorteil                     |
| ----------------- | ------------------------------------------------ | -------------------------------- |
| **Unsloth**       | Geschwindigkeitskritisches Training, kleine GPUs | 2–5× schneller, 70% weniger VRAM |
| **Axolotl**       | Konfigurationsgesteuerte, reproduzierbare Läufe  | YAML-first, viele Datenformate   |
| **LLaMA-Factory** | 100+ Modelle, WebUI, Einsteiger                  | Größte Modellunterstützung, GUI  |
| **TRL**           | RLHF, DPO, Alignmentsforschung                   | Natives Alignment-Training       |

Für die meisten Clore.ai Anwendungsfälle: starten Sie mit **Unsloth** (Geschwindigkeit + Speichereffizienz), fügen Sie hinzu **TRL** wenn Sie DPO- oder PPO-Alignment-Training benötigen.


---

# Agent Instructions: 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:

```
GET https://docs.clore.ai/guides/guides_v2-de/vergleiche/finetuning-comparison.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
