> 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-hi/training/axolotl-training.md).

# Axolotl Universal Fine-tuning

Axolotl HuggingFace Transformers, PEFT, TRL और DeepSpeed को एक ही YAML-चालित इंटरफ़ेस में समेटता है। आप अपने मॉडल, डेटासेट, प्रशिक्षण विधि, और हाइपरपैरामीटर एक कॉन्फ़िग फ़ाइल में परिभाषित करते हैं — फिर एक एकल कमांड के साथ लॉन्च करें। मानक वर्कफ़्लो के लिए Python स्क्रिप्टिंग की आवश्यकता नहीं।

{% hint style="success" %}
सभी उदाहरण GPU सर्वरों पर चलते हैं जो कि के माध्यम से किराये पर लिए गए हैं [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace).
{% endhint %}

## प्रमुख विशेषताएँ

* **सिर्फ YAML विन्यास** — सब कुछ एक फ़ाइल में परिभाषित करें, Python की आवश्यकता नहीं
* **सभी प्रशिक्षण विधियाँ** — LoRA, QLoRA, पूर्ण फाइन-ट्यून, DPO, ORPO, KTO, RLHF
* **बॉक्स से बहु-GPU समर्थन** — एक फ्लैग के साथ DeepSpeed ZeRO 1/2/3 और FSDP
* **सैंपल पैकिंग** — अनुक्रम लंबाई भरने के लिए छोटे उदाहरणों को जोड़ें, 3–5× थ्रूपुट वृद्धि
* **Flash Attention 2** — समर्थित हार्डवेयर पर स्वचालित VRAM बचत
* **व्यापक मॉडल समर्थन** — Llama 3.x, Mistral, Qwen 2.5, Gemma 2, Phi-4, DeepSeek, Falcon
* **बिल्ट-इन डेटासेट फॉर्मैट** — alpaca, sharegpt, chat\_template, completion, और कस्टम

## आवश्यकताएँ

| घटक    | न्यूनतम        | अनुशंसित             |
| ------ | -------------- | -------------------- |
| GPU    | RTX 3060 12 GB | RTX 4090 24 GB (×2+) |
| VRAM   | 12 GB          | 24+ GB               |
| RAM    | 16 GB          | 64 GB                |
| डिस्क  | 50 GB          | 100 GB               |
| CUDA   | 11.8           | 12.1+                |
| Python | 3.10           | 3.11                 |

**Clore.ai मूल्य निर्धारण:** RTX 4090 ≈ $0.5–2/दिन · RTX 3090 ≈ $0.3–1/दिन · RTX 3060 ≈ $0.15–0.3/दिन

## त्वरित प्रारम्भ

### 1. Axolotl इंस्टॉल करें

```bash
# क्लोन और इंस्टॉल करें
git clone https://github.com/OpenAccess-AI-Collective/axolotl.git
cd axolotl

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

या Docker इमेज का उपयोग करें (पुनरुत्पादकता के लिए अनुशंसित):

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

### 2. एक कॉन्फ़िग फ़ाइल बनाएं

इसे सहेजें जैसा कि `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. प्रशिक्षण लॉन्च करें

```bash
# एकल GPU
accelerate launch -m axolotl.cli.train config.yml

# बहु-GPU (सभी उपलब्ध GPUs)
accelerate launch --multi_gpu -m axolotl.cli.train config.yml
```

प्रशिक्षण प्रगति stdout में लॉग होती है और वैकल्पिक रूप से Weights & Biases पर।

## विन्यास गहरी जानकारी

### डेटासेट फॉर्मैट

Axolotl मूल रूप से कई इनपुट फॉर्मैट्स का समर्थन करता है:

```yaml
# Alpaca-शैली (instruction / input / output)
datasets:
  - path: yahma/alpaca-cleaned
    type: alpaca

# ShareGPT मल्टी-टर्न चैट
datasets:
  - path: anon8231489123/ShareGPT_Vicuna_unfiltered
    type: sharegpt
    conversation: chatml

# चैट टेम्पलेट (टोकनाइज़र से स्वचालित पहचान)
datasets:
  - path: HuggingFaceH4/ultrachat_200k
    type: chat_template
    field_messages: messages
    message_field_role: role
    message_field_content: content

# स्थानीय JSONL फ़ाइल
datasets:
  - path: /workspace/data/my_dataset.jsonl
    type: alpaca
    ds_type: json
```

### DeepSpeed के साथ बहु-GPU

बनाएँ `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
}
```

अपने कॉन्फ़िग में जोड़ें:

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

फिर लॉन्च करें:

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

### DPO / ORPO संरेखण

```yaml
base_model: meta-llama/Meta-Llama-3.1-8B-Instruct
rl: dpo
# या: 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
```

### पूर्ण फाइन-ट्यून (कोई LoRA नहीं)

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

# कोई एडाप्टर नहीं, कोई क्वांटाइज़ेशन नहीं
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  # 8B+ पूर्ण फाइन-ट्यून के लिए आवश्यक
```

## उपयोग के उदाहरण

### प्रशिक्षण के बाद इन्फरेंस

```bash
# इंटरैक्टिव इन्फरेंस लॉन्च करें
accelerate launch -m axolotl.cli.inference config.yml \
  --lora_model_dir /workspace/axolotl-output
```

### LoRA को बेस मॉडल में मर्ज करें

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

### डेटासेट पूर्व-प्रोसेस करें (प्रशिक्षण से पहले मान्य करें)

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

यह डेटासेट को टोकनाइज़ और मान्य करता है। लंबी प्रशिक्षण रन से पहले फॉर्मेट त्रुटियों को पकड़ने के लिए उपयोगी।

## VRAM उपयोग संदर्भ

| मॉडल          | विधि       | GPUs | VRAM/GPU | कॉन्फ़िग                 |
| ------------- | ---------- | ---- | -------- | ------------------------ |
| 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  | पूर्ण      | 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 | पूर्ण      | 4    | \~40 GB  | DeepSpeed ZeRO-3+offload |

## टिप्स

* **हमेशा सक्षम करें `sample_packing: true`** — एकल सबसे बड़ा थ्रूपुट सुधार (छोटे डेटासेट पर 3–5×)
* **उपयोग करें `flash_attention: true`** Ampere+ GPUs पर 20–40% VRAM बचत के लिए
* **QLoRA से शुरू करें** प्रयोगों के लिए, केवल तब पूर्ण फाइन-ट्यून पर स्विच करें जब LoRA गुणवत्ता स्थिर हो जाए
* **सेट करें `val_set_size: 0.02`** प्रशिक्षण के दौरान ओवरफ़िटिंग की निगरानी करने के लिए
* **पहले पूर्व-प्रोसेस करें** — चलाएँ `axolotl.cli.preprocess` लंबी रन में कमिट करने से पहले डेटा फॉर्मैटिंग को मान्य करने के लिए
* **Docker इमेज का उपयोग करें** पुनरुत्पादक वातावरण के लिए — निर्भरता संघर्ष से बचाता है
* **`lora_target_linear: true`** LoRA को सभी लीनियर लेयर्स पर लागू करता है, आमतौर पर केवल attention को लक्षित करने से बेहतर

## समस्याओं का निवारण

| समस्या                             | समाधान                                                                          |
| ---------------------------------- | ------------------------------------------------------------------------------- |
| `OutOfMemoryError`                 | कम करें `micro_batch_size` को 1 पर, सक्षम करें `gradient_checkpointing`         |
| डेटासेट फॉर्मैट त्रुटियाँ          | चलाएँ `python -m axolotl.cli.preprocess config.yml` डिबग करने के लिए            |
| `sample_packing` पहले एपोच पर धीमा | सामान्य — प्रारंभिक पैकिंग गणना एक बार होती है                                  |
| बहु-GPU प्रशिक्षण अटका हुआ है      | NCCL जांचें: `export NCCL_DEBUG=INFO`, सुनिश्चित करें सभी GPUs दिखाई दे रहे हैं |
| `flash_attention` इम्पोर्ट एरर     | इंस्टॉल करें: `pip install flash-attn --no-build-isolation`                     |
| लॉस घट नहीं रहा                    | LR को 1e-4 पर कम करें, वार्मअप बढ़ाएँ, डेटासेट की गुणवत्ता जांचें               |
| WandB कनेक्शन त्रुटि               | चलाएँ `wandb login` या सेट करें `wandb_project:` खाली स्ट्रिंग पर               |

## संसाधन

* [Axolotl GitHub](https://github.com/OpenAccess-AI-Collective/axolotl)
* [उदाहरण कॉन्फ़िग](https://github.com/OpenAccess-AI-Collective/axolotl/tree/main/examples)
* [CLORE.AI मार्केटप्लेस](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-hi/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.
