> 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/mistral-rs.md).

# Mistral.rs

**Rust में लिखित बेहद तेज़ LLM इन्फ़रेंस** — GGUF, GGML, SafeTensors समर्थन और OpenAI-संगत API के साथ प्रोडक्शन-रेडी सर्वर।

> 🦀 **Rust में निर्मित** अधिकतम प्रदर्शन के लिए | GGUF और विज़न मॉडल समर्थन | Apache-2.0 लाइसेंस

***

## Mistral.rs क्या है?

Mistral.rs एक उच्च-प्रदर्शन LLM इन्फ़रेंस इंजन है जो पूरी तरह से लिखा गया है **Rust**. मूल रूप से Mistral मॉडलों पर केंद्रित, यह अब आधुनिक LLMs की पूरी दुनिया का समर्थन करता है। Rust की नींव प्रदान करती है:

* **शून्य-लागत अमूर्तताएँ** — इन्फ़रेंस के दौरान कोई garbage collection pause नहीं
* **मेमोरी सुरक्षा** — null pointer exceptions या memory leaks नहीं
* **निर्धारित प्रदर्शन** — JVM/Python overhead के बिना स्थिर latency
* **कंपाइल-समय अनुकूलन** — SIMD, threading, और GPU kernels को build time पर अनुकूलित किया गया

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

* **GGUF समर्थन** — कोई भी quantized model चलाएँ (Q4\_K\_M, Q8\_0, आदि)
* **ISQ (इन-सिटू क्वांटाइज़ेशन)** — load time पर तुरंत quantize करें
* **PagedAttention** — continuous batching के साथ कुशल KV cache
* **विज़न भाषा मॉडल** — LLaVA, Phi-3 Vision, Idefics समर्थन
* **अनुमानात्मक decoding** — draft models के साथ तेज़ इन्फ़रेंस
* **X-LoRA** — स्केलेबल fine-tuned adapter समर्थन
* **OpenAI-संगत REST API** — सीधे-प्रयोग योग्य प्रतिस्थापन

### समर्थित मॉडल परिवार

| परिवार          | फ़ॉर्मेट          | इंजन      |
| --------------- | ----------------- | --------- |
| Llama 2/3       | GGUF, SafeTensors | Rust CUDA |
| Mistral/Mixtral | GGUF, SafeTensors | Rust CUDA |
| Phi-2/3         | GGUF, SafeTensors | Rust CUDA |
| Gemma           | GGUF, SafeTensors | Rust CUDA |
| Qwen 2          | GGUF, SafeTensors | Rust CUDA |
| Starcoder 2     | GGUF              | Rust CUDA |
| LLaVA 1.5/1.6   | SafeTensors       | विज़न     |
| Phi-3 Vision    | SafeTensors       | विज़न     |

***

## Clore.ai पर त्वरित शुरुआत

### चरण 1: एक GPU सर्वर खोजें

पर [clore.ai](https://clore.ai) मार्केटप्लेस:

* **न्यूनतम:** 8GB VRAM (7B Q4 मॉडलों के लिए)
* **अनुशंसित:** बड़े मॉडलों के लिए RTX 3090/4090 (24GB)
* CUDA 11.8+ आवश्यक है

### चरण 2: Mistral.rs Docker परिनियोजित करें

```
Docker इमेज: ghcr.io/ericlbuehler/mistral.rs:cuda
```

**पोर्ट मैपिंग:**

| कंटेनर पोर्ट | उद्देश्य       |
| ------------ | -------------- |
| `22`         | SSH पहुँच      |
| `8080`       | REST API सर्वर |

**उपलब्ध इमेज वेरिएंट:**

```bash
# CUDA (अधिकांश Clore.ai सर्वर)
ghcr.io/ericlbuehler/mistral.rs:cuda

# केवल CPU
ghcr.io/ericlbuehler/mistral.rs:cpu

# Metal (Apple Silicon - Clore.ai के लिए नहीं)
ghcr.io/ericlbuehler/mistral.rs:metal
```

### चरण 3: कनेक्ट करें और सत्यापित करें

```bash
ssh root@<clore-node-ip> -p <ssh-port>

# mistral.rs बाइनरी जाँचें
mistralrs-server --help
```

***

## सर्वर चलाना

### GGUF मॉडल के साथ त्वरित शुरुआत

```bash
# HuggingFace से सीधे GGUF मॉडल सर्व करें
mistralrs-server \\
  --port 8080 \\
  --log info \\
  gguf \\
  -m TheBloke/Llama-2-7B-Chat-GGUF \\
  -f llama-2-7b-chat.Q4_K_M.gguf
```

### Mistral 7B (SafeTensors) सर्व करें

```bash
mistralrs-server \\
  --port 8080 \\
  plain \\
  -m mistralai/Mistral-7B-Instruct-v0.3 \\
  --isq Q4K
```

### इन-सिटू क्वांटाइज़ेशन (ISQ) के साथ सर्व करें

ISQ मॉडल को load time पर quantize करता है — पहले से quantized मॉडल की आवश्यकता नहीं:

```bash
# Llama 3 8B लोड करें और तुरंत Q4K में quantize करें
mistralrs-server \\
  --port 8080 \\
  plain \\
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K

# उपलब्ध ISQ विकल्प:
# Q4_0, Q4_1, Q5_0, Q5_1, Q8_0
# Q2K, Q3K, Q4K, Q5K, Q6K, Q8K
# HQQ4, HQQ8 (Half-Quadratic Quantization)
```

### विज़न भाषा मॉडल

```bash
mistralrs-server \\
  --port 8080 \\
  vision-plain \\
  -m llava-hf/llava-1.5-7b-hf \\
  --isq Q4K
```

### अनुमानात्मक decoding

```bash
# जनरेशन तेज़ करने के लिए एक छोटा draft model उपयोग करें
mistralrs-server \\
  --port 8080 \\
  speculative \\
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K \\
  -d meta-llama/Meta-Llama-3-1B-Instruct \\
  --draft-isq Q4K \\
  -n 5  # Speculative tokens
```

{% hint style="success" %}
**अनुमानात्मक decoding** प्रदान कर सकता है **2–3x गति वृद्धि** अधिकांश संवादात्मक वर्कलोड के लिए, जहाँ छोटा draft model अगले टोकनों की सही भविष्यवाणी करता है।
{% endhint %}

***

## API उपयोग

### OpenAI-संगत एंडपॉइंट

| एंडपॉइंट                 | विधि | विवरण                                   |
| ------------------------ | ---- | --------------------------------------- |
| `/v1/chat/completions`   | POST | चैट पूर्णताएँ                           |
| `/v1/completions`        | POST | पाठ पूर्णताएँ                           |
| `/v1/models`             | GET  | मॉडल सूची                               |
| `/v1/images/generations` | POST | छवि निर्माण (VLMs)                      |
| `/v1/re_isq`             | POST | लोड किए गए मॉडल को पुनः क्वांटाइज़ करें |
| `/health`                | GET  | स्वास्थ्य जाँच                          |

### Python उदाहरण

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://<clore-node-ip>:<api-port>/v1",
    api_key="none"  # डिफ़ॉल्ट रूप से कोई प्रमाणीकरण आवश्यक नहीं
)

# चैट पूर्णता
response = client.chat.completions.create(
    model="llama-3-8b",  # मॉडल नाम लचीला है
    messages=[
        {"role": "system", "content": "आप एक मददगार कोडिंग सहायक हैं।"},
        {"role": "user", "content": "एक लिंक्ड लिस्ट को उलटने के लिए Python फ़ंक्शन लिखें"}
    ],
    temperature=0.1,  # कोड जनरेशन के लिए कम तापमान
    max_tokens=1024
)
print(response.choices[0].message.content)
```

### स्ट्रीमिंग प्रतिक्रिया

```python
with client.chat.completions.create(
    model="llama-3-8b",
    messages=[{"role": "user", "content": "एक रोबोट के बारे में एक कहानी सुनाइए।"}],
    stream=True,
    max_tokens=512
) as stream:
    for chunk in stream:
        delta = chunk.choices[0].delta
        if hasattr(delta, 'content') and delta.content:
            print(delta.content, end="", flush=True)
print()
```

### विज़न/छवि इनपुट

```python
import base64
from pathlib import Path

# छवि लोड करें
image_data = base64.b64encode(Path("photo.jpg").read_bytes()).decode()

response = client.chat.completions.create(
    model="llava-1.5-7b",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{image_data}"
                    }
                },
                {
                    "type": "text",
                    "text": "आप इस छवि में क्या देखते हैं?"
                }
            ]
        }
    ]
)
print(response.choices[0].message.content)
```

### cURL उदाहरण

```bash
# बुनियादी चैट
curl http://localhost:8080/v1/chat/completions \\
  -H "Content-Type: application/json" \
  -d '{
    "model": "mistral-7b",
    "messages": [{"role": "user", "content": "Rust क्या है?"}],
    "temperature": 0.7,
    "max_tokens": 256
  }'

# मॉडल सूचीबद्ध करें
curl http://localhost:8080/v1/models

# हेल्थ चेक
curl http://localhost:8080/health
```

***

## कॉन्फ़िगरेशन विकल्प

### सर्वर फ़्लैग

```bash
mistralrs-server \\
  --port 8080 \\                    # API पोर्ट (डिफ़ॉल्ट: 1234)
  --host 0.0.0.0 \\                 # बाइंड पता
  --log info \\                     # लॉग स्तर: off/error/warn/info/debug/trace
  --token-source env:HF_TOKEN \\    # HuggingFace टोकन स्रोत
  --max-seqs 16 \\                  # समकालिक sequences की अधिकतम संख्या
  --no-paged-attn \\                # PagedAttention अक्षम करें (debugging के लिए उपयोग करें)
  --prefix-cache-n 16 \\            # Prefix cache प्रविष्टियाँ
  plain \\                          # मॉडल प्रकार सबकमांड
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K
```

### ISQ क्वांटाइज़ेशन संदर्भ

| ISQ विकल्प | बिट्स | गुणवत्ता | VRAM (7B) |
| ---------- | ----- | -------- | --------- |
| `Q2K`      | 2     | ★★☆☆☆    | \~2.5GB   |
| `Q3K`      | 3     | ★★★☆☆    | \~3.5GB   |
| `Q4_0`     | 4     | ★★★★☆    | \~4.5GB   |
| `Q4K`      | 4     | ★★★★☆    | \~4.5GB   |
| `Q5K`      | 5     | ★★★★★    | \~5.5GB   |
| `Q6K`      | 6     | ★★★★★    | \~6.5GB   |
| `Q8_0`     | 8     | ★★★★★    | \~8GB     |
| `HQQ4`     | 4     | ★★★★☆    | \~4.5GB   |
| `HQQ8`     | 8     | ★★★★★    | \~8GB     |

{% hint style="info" %}
**HQQ (Half-Quadratic Quantization)** अक्सर समान बिट स्तर पर GGUF Q4 की तुलना में बेहतर गुणवत्ता देता है, खासकर निर्देश-पालन कार्यों के लिए।
{% endhint %}

***

## उन्नत सुविधाएँ

### X-LoRA (LoRA एडाप्टरों का मिश्रण)

प्रति टोकन गतिशील रूप से चुने गए कई fine-tuned adapters चलाएँ:

```bash
mistralrs-server \\
  --port 8080 \\
  x-lora-plain \\
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K \\
  -x ./xlora-config.json
```

### रनटाइम पर पुनः-क्वांटाइज़ करें

```bash
# पुनः आरंभ किए बिना quantization बदलें
curl http://localhost:8080/v1/re_isq \\
  -H "Content-Type: application/json" \
  -d '{"isq_type": "Q8_0"}'
```

### अनुरोध लॉगिंग

```bash
# फ़ाइल में अनुरोध लॉगिंग सक्षम करें
mistralrs-server \\
  --port 8080 \\
  --log info \\
  --request-logging-file ./requests.jsonl \\
  plain \\
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K
```

***

## प्रदर्शन ट्यूनिंग

### थ्रूपुट के लिए अनुकूलित करें

```bash
# समकालिक अनुरोधों के लिए अधिक max-seqs
mistralrs-server \\
  --port 8080 \\
  --max-seqs 32 \\
  plain \\
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K
```

### कम latency के लिए अनुकूलित करें

```bash
# कम max-seqs, prefix cache sharing अक्षम करें
mistralrs-server \\
  --port 8080 \\
  --max-seqs 4 \\
  --prefix-cache-n 0 \\
  plain \\
  -m meta-llama/Meta-Llama-3-8B-Instruct \\
  --isq Q4K
```

### प्रदर्शन मॉनिटर करें

```bash
# इन्फ़रेंस के दौरान GPU उपयोग देखें
watch -n 1 nvidia-smi

# nvtop के साथ प्रोफ़ाइल करें
apt-get install nvtop && nvtop
```

***

## Docker Compose

```yaml
version: '3.8'
services:
  mistral-rs:
    image: ghcr.io/ericlbuehler/mistral.rs:cuda
    runtime: nvidia
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - HF_TOKEN=${HUGGING_FACE_HUB_TOKEN}
    ports:
      - "8080:8080"
    volumes:
      - hf-cache:/root/.cache/huggingface
    command: >
      mistralrs-server
      --port 8080
      --host 0.0.0.0
      --log info
      --max-seqs 16
      --token-source env:HF_TOKEN
      plain
      -m meta-llama/Meta-Llama-3-8B-Instruct
      --isq Q4K
    restart: unless-stopped

volumes:
  hf-cache:
```

***

## स्रोत से बिल्ड करना

यदि Docker image आपकी CUDA version से मेल नहीं खाती:

```bash
# Rust इंस्टॉल करें
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env

# क्लोन करें और बिल्ड करें
git clone https://github.com/EricLBuehler/mistral.rs.git
cd mistral.rs

# CUDA समर्थन के साथ बिल्ड करें
cargo build --release --features cuda

# बाइनरी का स्थान
./target/release/mistralrs-server --help
```

{% hint style="warning" %}
**बिल्ड समय:** Rust संकलन धीमा है। पूर्ण बिल्ड में 10–20 मिनट लगने की उम्मीद करें। उपयोग करें `sccache` इन्क्रिमेंटल बिल्ड को तेज़ करने के लिए: `cargo install sccache && RUSTC_WRAPPER=sccache cargo build --release --features cuda`
{% endhint %}

***

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

### CUDA लाइब्रेरी नहीं मिली

```bash
# CUDA लाइब्रेरी जाँचें
ldconfig -p | grep libcuda
ls /usr/local/cuda/lib64/

# लाइब्रेरी पाथ सेट करें
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
```

### मॉडल डाउनलोड विफल

```bash
# HuggingFace टोकन सेट करें
export HF_TOKEN=your_token_here

# या --token-source फ़्लैग का उपयोग करें
mistralrs-server \\
  --token-source env:HF_TOKEN \\
  ...

# या पहले मैन्युअल रूप से डाउनलोड करें
huggingface-cli download meta-llama/Meta-Llama-3-8B-Instruct --local-dir ./llama3-8b
mistralrs-server ... plain -m ./llama3-8b --isq Q4K
```

### पोर्ट 8080 उपयोग में है

```bash
# प्रक्रिया खोजें और समाप्त करें
fuser -k 8080/tcp

# अलग पोर्ट का उपयोग करें
mistralrs-server --port 9090 ...
```

### क्वांटाइज़ेशन के दौरान मेमोरी समाप्त

```bash
# ISQ GPU पर quantize करता है — पहले अन्य GPU उपयोग कम करें
# या GGUF पर स्विच करें (पहले से quantized, कम peak memory)
mistralrs-server \\
  gguf \\
  -m TheBloke/Llama-2-7B-Chat-GGUF \\
  -f llama-2-7b-chat.Q4_K_M.gguf
```

{% hint style="danger" %}
**ISQ बनाम GGUF:** ISQ load time पर GPU मेमोरी का उपयोग करके quantize करता है (अस्थायी स्पाइक)। यदि आपके पास VRAM कम है, तो TheBloke या इसी तरह के pre-quantized GGUF files उपयोग करें — वे लोडिंग के दौरान कम peak memory लेते हैं।
{% endhint %}

***

## Clore.ai GPU अनुशंसाएँ

Mistral.rs एक Rust-native इंजन है — इसका कम overhead मतलब Python-based servers की तुलना में आपको प्रति GPU डॉलर अधिक throughput मिलता है।

| GPU       | VRAM  | Clore.ai मूल्य                            | अनुशंसित उपयोग                               | थ्रूपुट (Mistral 7B Q4) |
| --------- | ----- | ----------------------------------------- | -------------------------------------------- | ----------------------- |
| RTX 3090  | 24 GB | $0.07–0.21/hr                             | सबसे अच्छा बजट विकल्प — 7B Q4/Q8, विज़न मॉडल | \~120 tok/s             |
| RTX 4090  | 24 GB | $0.14–0.42/hr                             | उच्च-थ्रूपुट 7B–34B, speculative decoding    | \~200 tok/s             |
| A100 40GB | 40 GB | [bare metal](https://clore.ai/bare-metal) | प्रोडक्शन 34B–70B Q4 सर्विंग                 | \~160 tok/s             |
| A100 80GB | 80 GB | [bare metal](https://clore.ai/bare-metal) | पूर्ण-परिशुद्धता 70B, multi-model            | \~185 tok/s             |

**यहाँ RTX 3090 क्यों उत्कृष्ट है:** Mistral.rs के Rust CUDA kernels Python GIL overhead और garbage collection pauses से बचते हैं, जो Python servers को नुकसान पहुँचाते हैं। Mistral 7B Q4\_K\_M चलाने वाला RTX 3090 लगभग \~120 tok/s देता है — वही hardware पर vLLM के बराबर, लेकिन लागत का एक अंश ($0.07–0.21/घंटा बनाम cloud providers द्वारा $0.07–0.21/घंटा)।

**अनुमानात्मक decoding:** एक बड़े मॉडल (34B) को एक छोटे draft model (3B) के साथ जोड़ें ताकि गुणवत्ता में कोई कमी बिना 2–3× गति वृद्धि मिले। RTX 4090 इस पैटर्न के लिए आदर्श है।

***

## संसाधन

* 🐙 **GitHub:** [github.com/EricLBuehler/mistral.rs](https://github.com/EricLBuehler/mistral.rs)
* 📦 **कंटेनर रजिस्ट्री:** [ghcr.io/ericlbuehler/mistral.rs](https://ghcr.io/ericlbuehler/mistral.rs)
* 📚 **दस्तावेज़ीकरण:** [ericlbuehler.github.io/mistral.rs](https://ericlbuehler.github.io/mistral.rs/mistralrs/)
* 💬 **Discord:** [discord.gg/SZrecqK8qw](https://discord.gg/SZrecqK8qw)
* 🤗 **GGUF मॉडल:** [huggingface.co/TheBloke](https://huggingface.co/TheBloke)


---

# 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/mistral-rs.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.
