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

# DeepSpeed ट्रेनिंग

Clore.ai GPUs पर DeepSpeed के साथ बड़े मॉडल कुशलतापूर्वक ट्रेन करें

Microsoft DeepSpeed के साथ बड़े मॉडलों को कुशलता से प्रशिक्षित करें।

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

## CLORE.AI पर किराए पर लेना

{% hint style="warning" %}
**Clore.ai marketplace पर multi-GPU 80GB-class rigs सूचीबद्ध नहीं हैं।** आज सूचीबद्ध सबसे बड़े boxes 4× RTX PRO 6000 Blackwell (प्रत्येक 96GB, कुल 380GB) और 8–11× RTX 5090 (प्रत्येक 32GB) हैं। A100 / H200 / B200 क्षमता [bare metal](https://clore.ai/bare-metal) के रूप में अनुरोध पर बेची जाती है। देखें [GPU मूल्य और उपलब्धता](/guides/guides_v2-hi/getting-started/pricing.md) किसी deployment का आकार तय करने से पहले।
{% endhint %}

1. विज़िट करें [CLORE.AI मार्केटप्लेस](https://clore.ai/marketplace)
2. GPU प्रकार, VRAM और कीमत के अनुसार फ़िल्टर करें
3. चुनें **ऑन-डिमांड** (स्थिर दर) या **स्पॉट** (बोली मूल्य)
4. अपना ऑर्डर कॉन्फ़िगर करें:
   * Docker इमेज चुनें
   * पोर्ट सेट करें (SSH के लिए TCP, वेब UI के लिए HTTP)
   * यदि आवश्यक हो तो environment variables जोड़ें
   * स्टार्टअप कमांड दर्ज करें
5. भुगतान चुनें: **CLORE**, **BTC**या **USDT/USDC**
6. ऑर्डर बनाएं और डिप्लॉयमेंट की प्रतीक्षा करें

### अपने सर्वर तक पहुँचें

* कनेक्शन विवरण यहाँ खोजें **मेरे ऑर्डर**
* वेब इंटरफ़ेस: HTTP पोर्ट URL का उपयोग करें
* SSH: `ssh -p <port> root@<proxy-address>`

## DeepSpeed क्या है?

DeepSpeed सक्षम बनाता है:

* ऐसे मॉडल प्रशिक्षित करना जो GPU मेमोरी में फिट नहीं होते
* मल्टी-GPU और मल्टी-नोड प्रशिक्षण
* ZeRO अनुकूलन (मेमोरी दक्षता)
* मिश्रित परिशुद्धता प्रशिक्षण

## ZeRO चरण

| चरण           | मेमोरी बचत                    | गति            |
| ------------- | ----------------------------- | -------------- |
| ZeRO-1        | ऑप्टिमाइज़र स्थितियाँ विभाजित | तेज़           |
| ZeRO-2        | + ग्रेडिएंट्स विभाजित         | संतुलित        |
| ZeRO-3        | + पैरामीटर विभाजित            | अधिकतम बचत     |
| ZeRO-Infinity | CPU/NVMe ऑफलोड                | सबसे बड़े मॉडल |

## त्वरित डिप्लॉय

**Docker इमेज:**

```
pytorch/pytorch:2.11.0-cuda12.8-cudnn9-devel
```

**पोर्ट:**

```
22/tcp
```

**कमांड:**

```bash
pip install deepspeed transformers datasets accelerate
```

## इंस्टॉलेशन

```bash
pip install deepspeed

# इंस्टॉलेशन सत्यापित करें
ds_report
```

## मूल प्रशिक्षण

### DeepSpeed कॉन्फ़िगरेशन

**ds\_config.json:**

```json
{
    "train_batch_size": 32,
    "gradient_accumulation_steps": 4,
    "optimizer": {
        "type": "AdamW",
        "params": {
            "lr": 1e-4,
            "betas": [0.9, 0.999],
            "eps": 1e-8,
            "weight_decay": 0.01
        }
    },
    "scheduler": {
        "type": "WarmupLR",
        "params": {
            "warmup_min_lr": 0,
            "warmup_max_lr": 1e-4,
            "warmup_num_steps": 100
        }
    },
    "fp16": {
        "enabled": true,
        "loss_scale": 0,
        "initial_scale_power": 16
    },
    "zero_optimization": {
        "stage": 2,
        "contiguous_gradients": true,
        "overlap_comm": true
    }
}
```

### प्रशिक्षण स्क्रिप्ट

```python
import torch
import deepspeed
from transformers import AutoModelForCausalLM, AutoTokenizer

# आरंभ करें
model = AutoModelForCausalLM.from_pretrained("gpt2")
tokenizer = AutoTokenizer.from_pretrained("gpt2")

# DeepSpeed आरंभ
model_engine, optimizer, _, _ = deepspeed.initialize(
    model=model,
    model_parameters=model.parameters(),
    config="ds_config.json"
)

# प्रशिक्षण लूप
for epoch in range(num_epochs):
    for batch in dataloader:
        inputs = tokenizer(batch["text"], return_tensors="pt", padding=True, truncation=True)
        inputs = {k: v.to(model_engine.device) for k, v in inputs.items()}

        outputs = model_engine(**inputs, labels=inputs["input_ids"])
        loss = outputs.loss

        model_engine.backward(loss)
        model_engine.step()
```

## ZeRO चरण 2 कॉन्फ़िगरेशन

```json
{
    "train_batch_size": "auto",
    "gradient_accumulation_steps": "auto",
    "gradient_clipping": 1.0,
    "fp16": {
        "enabled": true
    },
    "zero_optimization": {
        "stage": 2,
        "allgather_partitions": true,
        "allgather_bucket_size": 2e8,
        "reduce_scatter": true,
        "reduce_bucket_size": 2e8,
        "overlap_comm": true
    }
}
```

## ZeRO चरण 3 कॉन्फ़िगरेशन

बड़े मॉडलों के लिए:

```json
{
    "train_batch_size": "auto",
    "gradient_accumulation_steps": "auto",
    "fp16": {
        "enabled": true
    },
    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {
            "device": "cpu",
            "pin_memory": true
        },
        "offload_param": {
            "device": "cpu",
            "pin_memory": true
        },
        "overlap_comm": true,
        "contiguous_gradients": true,
        "sub_group_size": 1e9,
        "reduce_bucket_size": "auto",
        "stage3_prefetch_bucket_size": "auto",
        "stage3_param_persistence_threshold": "auto",
        "stage3_max_live_parameters": 1e9,
        "stage3_max_reuse_distance": 1e9,
        "stage3_gather_16bit_weights_on_model_save": true
    }
}
```

## Hugging Face Transformers के साथ

### Trainer एकीकरण

```python
from transformers import Trainer, TrainingArguments

training_args = TrainingArguments(
    output_dir="./output",
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,
    learning_rate=1e-4,
    num_train_epochs=3,
    fp16=True,
    deepspeed="ds_config.json",
    logging_steps=10,
    save_steps=500,
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_dataset,
    tokenizer=tokenizer,
)

trainer.train()
```

## मल्टी-GPU प्रशिक्षण

### चलाने का कमांड

```bash

# एक नोड, 4 GPU
deepspeed --num_gpus=4 train.py --deepspeed ds_config.json

# विशिष्ट GPU
deepspeed --include="localhost:0,1,2,3" train.py --deepspeed ds_config.json
```

### torchrun के साथ

```bash
torchrun --nproc_per_node=4 train.py --deepspeed ds_config.json
```

## मल्टी-नोड प्रशिक्षण

### होस्टफ़ाइल

**होस्टफ़ाइल:**

```
node1 slots=4
node2 slots=4
```

### शुरू करें

```bash
deepspeed --hostfile=hostfile train.py --deepspeed ds_config.json
```

### SSH सेटअप

```bash

# नोड्स के बीच पासवर्ड-रहित SSH सुनिश्चित करें
ssh-keygen -t rsa
ssh-copy-id user@node2
```

## मेमोरी-कुशल कॉन्फ़िगरेशन

### 24GB GPU पर 7B मॉडल

```json
{
    "bf16": {"enabled": true},
    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {"device": "cpu"},
        "offload_param": {"device": "cpu"}
    },
    "gradient_checkpointing": true,
    "train_micro_batch_size_per_gpu": 1,
    "gradient_accumulation_steps": 16
}
```

### 24GB GPU पर 13B मॉडल

```json
{
    "bf16": {"enabled": true},
    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {"device": "cpu"},
        "offload_param": {"device": "cpu"},
        "stage3_param_persistence_threshold": 0
    },
    "gradient_checkpointing": true,
    "train_micro_batch_size_per_gpu": 1,
    "gradient_accumulation_steps": 32
}
```

## ग्रेडिएंट चेकपॉइंटिंग

एक्टिवेशन को पुनर्गणना करके मेमोरी बचाएँ:

```python
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
model.gradient_checkpointing_enable()
```

## चेकपॉइंट सहेजना और लोड करना

### सहेजें

```python

# DeepSpeed चेकपॉइंटिंग को संभालता है
model_engine.save_checkpoint("./checkpoints", tag="step_1000")
```

### लोड करें

```python
model_engine.load_checkpoint("./checkpoints", tag="step_1000")
```

### HuggingFace प्रारूप में सहेजें

```python

# DeepSpeed चेकपॉइंट को HF प्रारूप में बदलें
from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint

state_dict = get_fp32_state_dict_from_zero_checkpoint("./checkpoints/step_1000")
model.load_state_dict(state_dict)
model.save_pretrained("./hf_model")
```

## निगरानी

### TensorBoard

```json
{
    "tensorboard": {
        "enabled": true,
        "output_path": "./logs",
        "job_name": "training_run"
    }
}
```

### Weights & Biases

```json
{
    "wandb": {
        "enabled": true,
        "project": "my_project"
    }
}
```

## सामान्य समस्याएँ

### मेमोरी समाप्त

```json
// आज़माएँ:
{
    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {"device": "cpu"},
        "offload_param": {"device": "cpu"}
    },
    "train_micro_batch_size_per_gpu": 1
}
```

### धीमा प्रशिक्षण

* CPU ऑफलोडिंग कम करें
* बैच आकार बढ़ाएँ
* 3 के बजाय ZeRO Stage 2 का उपयोग करें

### NCCL त्रुटियाँ

```bash

# परिवेश चर सेट करें
export NCCL_DEBUG=INFO
export NCCL_IB_DISABLE=1
```

## प्रदर्शन सुझाव

| सुझाव                            | प्रभाव        |
| -------------------------------- | ------------- |
| fp16 की बजाय bf16 का उपयोग करें  | बेहतर स्थिरता |
| ग्रेडिएंट चेकपॉइंटिंग सक्षम करें | कम मेमोरी     |
| बैच आकार समायोजित करें           | बेहतर थ्रूपुट |
| NVMe ऑफलोड का उपयोग करें         | बड़े मॉडल     |

## प्रदर्शन तुलना

| मॉडल | GPU     | ZeRO चरण | प्रशिक्षण गति   |
| ---- | ------- | -------- | --------------- |
| 7B   | 1x A100 | ZeRO-3   | \~1000 tokens/s |
| 7B   | 4x A100 | ZeRO-2   | \~4000 tokens/s |
| 13B  | 4x A100 | ZeRO-3   | \~2000 tokens/s |
| 70B  | 8x A100 | ZeRO-3   | \~800 tokens/s  |

## समस्या निवारण

## लागत का अनुमान

CLORE.AI मार्केटप्लेस की सामान्य दरें (2024 तक):

| GPU       | प्रति घंटा दर | प्रति दिन दर | 4-घंटे का सत्र |
| --------- | ------------- | ------------ | -------------- |
| RTX 3060  | \~$0.03       | \~$0.70      | \~$0.12        |
| RTX 3090  | \~$0.06       | \~$1.50      | \~$0.25        |
| RTX 4090  | \~$0.10       | \~$2.30      | \~$0.40        |
| A100 40GB | \~$0.17       | \~$4.00      | \~$0.70        |
| A100 80GB | \~$0.25       | \~$6.00      | \~$1.00        |

*मूल्य प्रदाता और मांग के अनुसार बदलते हैं। देखें* [*CLORE.AI मार्केटप्लेस*](https://clore.ai/marketplace) *वर्तमान दरों के लिए।*

**पैसे बचाएँ:**

* का उपयोग करें **स्पॉट** बाधित किए जा सकने वाले कार्य के लिए मार्केट — लगभग एक-तिहाई सर्वरों की स्पॉट कीमत ऑन-डिमांड से कम होती है (मध्य \~13% छूट), बाकी उससे मेल खाते हैं
* से भुगतान करें **CLORE** टोकन
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले चरण

* [LLM को फ़ाइन-ट्यून करें](/guides/guides_v2-hi/training/finetune-llm.md) - LoRA प्रशिक्षण
* vLLM इन्फ़रेंस - प्रशिक्षित मॉडल को तैनात करें
* [Hugging Face मार्गदर्शिका](/guides/guides_v2-hi/training/huggingface-transformers.md) - Transformers लाइब्रेरी


---

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