> 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/language-models/llamacpp-server.md).

# Llama.cpp Server

GPU पर llama.cpp सर्वर के साथ LLMs को प्रभावी ढंग से चलाएँ।

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

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

| पैरामीटर      | न्यूनतम    | अनुशंसित |
| ------------- | ---------- | -------- |
| RAM           | 8GB        | 16GB+    |
| VRAM          | 6GB        | 8GB+     |
| नेटवर्क       | 200Mbps    | 500Mbps+ |
| स्टार्टअप समय | \~2-5 मिनट | -        |

{% hint style="info" %}
GGUF क्वांटाइज़ेशन के कारण Llama.cpp मेमोरी-कुशल है। 7B मॉडल 6-8GB VRAM पर चल सकते हैं।
{% endhint %}

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

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

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

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

## Llama.cpp क्या है?

Llama.cpp LLMs के लिए सबसे तेज़ CPU/GPU इन्फरेंस इंजन है:

* GGUF क्वांटाइज़्ड मॉडलों का समर्थन करता है
* कम मेमोरी उपयोग
* OpenAI-अनुकूल API
* मल्टी-यूज़र समर्थन

## क्वांटाइज़ेशन स्तर

| फॉर्मेट  | आकार (7B) | स्पीड     | गुणवत्ता   |
| -------- | --------- | --------- | ---------- |
| Q2\_K    | 2.8GB     | सबसे तेज  | कम         |
| Q4\_K\_M | 4.1GB     | तेज़      | अच्छा      |
| Q5\_K\_M | 4.8GB     | मध्यम     | बहुत अच्छा |
| Q6\_K    | 5.5GB     | धीमा      | उत्कृष्ट   |
| Q8\_0    | 7.2GB     | सबसे धीमा | सर्वोत्तम  |

## त्वरित तैनाती

**Docker इमेज:**

```
ghcr.io/ggerganov/llama.cpp:server-cuda
```

**पोर्ट:**

```
22/tcp
8080/http
```

**कमांड:**

```bash

# मॉडल डाउनलोड करें
wget https://huggingface.co/bartowski/Meta-Llama-3.1-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf

# सर्वर चलाएँ
./llama-server \
    -m Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf \
    --host 0.0.0.0 \
    --port 8080 \
    -ngl 35 \
    -c 4096
```

## अपनी सेवा तक पहुँचना

डिप्लॉयमेंट के बाद, अपना खोजें `http_pub` URL में **मेरे ऑर्डर**:

1. जाएँ **मेरे ऑर्डर** पृष्ठ
2. अपने ऑर्डर पर क्लिक करें
3. खोजें `http_pub` URL (उदा., `abc123.clorecloud.net`)

उपयोग करें `https://YOUR_HTTP_PUB_URL` की बजाय `localhost` नीचे दिए उदाहरणों में।

### जांचें कि यह काम कर रहा है

```bash
# हेल्थ जाँच
curl https://your-http-pub.clorecloud.net/health

# सर्वर जानकारी प्राप्त करें
curl https://your-http-pub.clorecloud.net/props
```

{% hint style="warning" %}
यदि आपको HTTP 502 मिलता है, सेवा अभी शुरू हो रही हो सकती है या मॉडल डाउनलोड कर रही हो सकती है। 2-5 मिनट प्रतीक्षा करें और पुनः प्रयास करें।
{% endhint %}

## पूर्ण API संदर्भ

### मानक एंडपॉइंट्स

| एंडपॉइंट               | विधि | विवरण                           |
| ---------------------- | ---- | ------------------------------- |
| `/health`              | GET  | हेल्थ जाँच                      |
| `/v1/models`           | GET  | मॉडल सूचीबद्ध करें              |
| `/v1/chat/completions` | POST | चैट (OpenAI अनुकूल)             |
| `/v1/completions`      | POST | टेक्स्ट पूर्णता (OpenAI अनुकूल) |
| `/v1/embeddings`       | POST | एम्बेडिंग्स जनरेट करें          |
| `/completion`          | POST | नेटिव completion एंडपॉइंट       |
| `/tokenize`            | POST | टेक्स्ट को टोकनाइज़ करें        |
| `/detokenize`          | POST | टोकन को डिटोकनाइज़ करें         |
| `/props`               | GET  | सर्वर गुण                       |
| `/metrics`             | GET  | Prometheus मेट्रिक्स            |

#### टेक्स्ट टोकनाइज़ करें

```bash
curl https://your-http-pub.clorecloud.net/tokenize \
    -H "Content-Type: application/json" \
    -d '{"content": "Hello world"}'
```

प्रतिक्रिया:

```json
{"tokens": [15496, 1917]}
```

#### सर्वर गुण

```bash
curl https://your-http-pub.clorecloud.net/props
```

प्रतिक्रिया:

```json
{
  "total_slots": 1,
  "chat_template": "...",
  "default_generation_settings": {...}
}
```

## सोर्स से बनाएं

```bash

# रेपो क्लोन करें
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp

# CUDA के साथ बनाएँ
make LLAMA_CUDA=1

# या CMake के साथ
mkdir build && cd build
cmake .. -DLLAMA_CUDA=ON
cmake --build . --config Release
```

## मॉडल डाउनलोड करें

```bash

# Llama 3.1 8B
wget https://huggingface.co/bartowski/Meta-Llama-3.1-8B-Instruct-GGUF/resolve/main/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf

# Mistral 7B
wget https://huggingface.co/bartowski/Mistral-7B-Instruct-v0.3-GGUF/resolve/main/Mistral-7B-Instruct-v0.3-Q4_K_M.gguf

# Mixtral 8x7B
wget https://huggingface.co/bartowski/Mixtral-8x7B-Instruct-v0.1-GGUF/resolve/main/Mixtral-8x7B-Instruct-v0.1-Q4_K_M.gguf

# Phi-2
wget https://huggingface.co/bartowski/Phi-4-GGUF/resolve/main/Phi-4-Q4_K_M.gguf

# CodeLlama 7B
wget https://huggingface.co/bartowski/CodeLlama-7B-Instruct-GGUF/resolve/main/CodeLlama-7B-Instruct-Q4_K_M.gguf
```

## सर्वर विकल्प

### बेसिक सर्वर

```bash
./llama-server \
    -m model.gguf \
    --host 0.0.0.0 \
    --port 8080
```

### पूर्ण GPU ऑफलोड

```bash
./llama-server \
    -m model.gguf \
    --host 0.0.0.0 \
    --port 8080 \
    -ngl 99 \           # GPU लेयर्स (99 = सभी)
    -c 4096 \           # कॉन्टेक्स्ट साइज
    -t 8 \              # CPU थ्रेड्स
    --parallel 4        # समकालिक अनुरोध
```

### सभी विकल्प

```bash
./llama-server \
    -m model.gguf \           # मॉडल फ़ाइल
    --host 0.0.0.0 \          # बाइंड पता
    --port 8080 \             # पोर्ट
    -ngl 35 \                 # GPU लेयर्स
    -c 4096 \                 # कॉन्टेक्स्ट साइज
    -t 8 \                    # थ्रेड्स
    -b 512 \                  # बैच साइज
    --parallel 4 \            # समानांतर अनुरोध
    --mlock \                 # मेमोरी लॉक करें
    --no-mmap \               # mmap अक्षम करें
    --cont-batching \         # सतत बैचिंग
    --flash-attn \            # फ्लैश अटेंशन
    --metrics                 # मेट्रिक्स एंडपॉइंट सक्षम करें
```

## API उपयोग

### चैट कम्पलीशन्स (OpenAI अनुकूल)

```python
import openai

client = openai.OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="not-needed"
)

response = client.chat.completions.create(
    model="llama-3.1-8b",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is machine learning?"}
    ],
    temperature=0.7,
    max_tokens=500
)

print(response.choices[0].message.content)
```

### स्ट्रीमिंग

```python
stream = client.chat.completions.create(
    model="llama-3.1-8b",
    messages=[{"role": "user", "content": "Write a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
```

### टेक्स्ट पूर्णता

```python
response = client.completions.create(
    model="llama-3.1-8b",
    prompt="The future of AI is",
    max_tokens=100,
    temperature=0.8
)

print(response.choices[0].text)
```

### एम्बेडिंग्स

```python
response = client.embeddings.create(
    model="llama-3.1-8b",
    input="Hello, world!"
)

print(f"Embedding: {response.data[0].embedding[:5]}...")
```

## cURL उदाहरण

### चैट

```bash
curl http://localhost:8080/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "llama-3.1-8b",
        "messages": [
            {"role": "user", "content": "Hello!"}
        ]
    }'
```

### पूर्णता

```bash
curl http://localhost:8080/completion \
    -H "Content-Type: application/json" \
    -d '{
        "prompt": "Building a website requires",
        "n_predict": 128,
        "temperature": 0.7
    }'
```

### हेल्थ चेक

```bash
curl http://localhost:8080/health
```

### मेट्रिक्स

```bash
curl http://localhost:8080/metrics
```

## मल्टी-GPU

```bash

# GPUs के बीच विभाजित करें
./llama-server \
    -m model.gguf \
    -ngl 99 \
    --tensor-split 0.5,0.5 \  # 2 GPUs के बीच विभाजन
    --main-gpu 0              # प्राथमिक GPU
```

## मेमोरी अनुकूलन

### सीमित VRAM के लिए

```bash

# आंशिक ऑफलोड
./llama-server -m model.gguf -ngl 20 -c 2048

# छोटे क्वांटाइज़ेशन का उपयोग करें

# Q2_K या Q3_K को Q4_K की बजाय डाउनलोड करें
```

### अधिकतम गति के लिए

```bash
./llama-server \
    -m model.gguf \
    -ngl 99 \
    --flash-attn \
    --cont-batching \
    --parallel 8 \
    -b 1024
```

## मॉडल-विशिष्ट टेम्पलेट्स

### Llama 2 चैट

```bash
./llama-server -m Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf \
    --chat-template llama2
```

### Mistral इंस्ट्रक्ट

```bash
./llama-server -m mistral-7b-instruct.gguf \
    --chat-template mistral
```

### ChatML (कई मॉडल्स)

```bash
./llama-server -m model.gguf \
    --chat-template chatml
```

## Python सर्वर रैपर

```python
import subprocess
import requests
import time

class LlamaCppServer:
    def __init__(self, model_path, port=8080, gpu_layers=35):
        self.port = port
        self.process = subprocess.Popen([
            "./llama-server",
            "-m", model_path,
            "--host", "0.0.0.0",
            "--port", str(port),
            "-ngl", str(gpu_layers),
            "-c", "4096"
        ])
        self._wait_for_ready()

    def _wait_for_ready(self, timeout=60):
        start = time.time()
        while time.time() - start < timeout:
            try:
                r = requests.get(f"http://localhost:{self.port}/health")
                if r.status_code == 200:
                    return
            except:
                pass
            time.sleep(1)
        raise TimeoutError("Server didn't start")

    def chat(self, messages, **kwargs):
        response = requests.post(
            f"http://localhost:{self.port}/v1/chat/completions",
            json={"messages": messages, **kwargs}
        )
        return response.json()

    def stop(self):
        self.process.terminate()

# उपयोग
server = LlamaCppServer("llama-3.1-8b.gguf")
result = server.chat([{"role": "user", "content": "Hello!"}])
print(result["choices"][0]["message"]["content"])
server.stop()
```

## बेंचमार्किंग

```bash

# बिल्ट-इन बेंचमार्क
./llama-bench -m model.gguf -ngl 99

# आउटपुट में शामिल है:

# - प्रति सेकंड टोकन

# - मेमोरी उपयोग

# - लोड समय
```

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

| मॉडल         | GPU      | क्वांटाइज़ेशन | टोकन/सेकंड |
| ------------ | -------- | ------------- | ---------- |
| Llama 3.1 8B | RTX 3090 | Q4\_K\_M      | \~100      |
| Llama 3.1 8B | RTX 4090 | Q4\_K\_M      | \~150      |
| Llama 3.1 8B | RTX 3090 | Q4\_K\_M      | \~60       |
| Mistral 7B   | RTX 3090 | Q4\_K\_M      | \~110      |
| Mixtral 8x7B | A100     | Q4\_K\_M      | \~50       |

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

### CUDA नहीं मिला

```bash

# CUDA के साथ पुनः बनाएँ
make clean
make LLAMA_CUDA=1

# CUDA जांचें
nvidia-smi
```

### आउट ऑफ़ मेमोरी

```bash

# GPU लेयर्स घटाएँ
-ngl 20  # 99 की बजाय

# कॉन्टेक्स्ट घटाएँ
-c 2048  # 4096 की बजाय

# छोटे क्वांट का उपयोग करें

# Q4_K_M की बजाय Q4_K_S
```

### धीमा जनरेशन

```bash

# बैच साइज बढ़ाएँ
-b 1024

# फ्लैश अटेंशन सक्षम करें
--flash-attn

# सतत बैचिंग सक्षम करें
--cont-batching
```

## प्रोडक्शन सेटअप

### Systemd सेवा

```ini

# /etc/systemd/system/llama.service
[Unit]
Description=Llama.cpp Server
After=network.target

[Service]
Type=simple
ExecStart=/opt/llama.cpp/llama-server -m /models/model.gguf -ngl 99 --host 0.0.0.0 --port 8080
Restart=always

[Install]
WantedBy=multi-user.target
```

### nginx के साथ

```nginx
upstream llama {
    server localhost:8080;
}

server {
    listen 80;

    location / {
        proxy_pass http://llama;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}
```

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

सामान्य 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) *वर्तमान दरों के लिए।*

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

* उपयोग करें **स्पॉट** लचीले वर्कलोड के लिए मार्केट (अक्सर 30-50% सस्ता)
* भुगतान करें **CLORE** टोकन के साथ
* विभिन्न प्रदाताओं के बीच कीमतों की तुलना करें

## अगले कदम

* vLLM इन्फरेंस - उच्च थ्रूपुट
* [ExLlamaV2](/guides/guides_v2-hi/language-models/exllamav2-fast.md) - तेज़ इन्फरेंस
* [Text Generation WebUI](/guides/guides_v2-hi/language-models/text-generation-webui.md) - वेब इंटरफ़ेस


---

# 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/language-models/llamacpp-server.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.
