Translate

लोकल LLM Docker आर्किटेक्चर — Local LLM Docker architecture diagram

Updated On : 05-10-2025

Run LLM Locally with Docker — लोकल में LLM मॉडल कैसे चलाएँ

क्या आप बिना क्लाउड API बिल के, अपने डेटा को बाहर भेजे बिना खुद के मशीन पर LLM चलाना चाहते हैं? इस गाइड में हम Docker का उपयोग कर के open-source LLM (जैसे LLaMA, Mistral, OpenChat variants) लोकल पर कैसे डिप्लॉय करें — hardware requirements, Docker images, step-by-step commands, और debugging tips — सब कुछ हिंदी में तकनीकी अंग्रेज़ी शब्दों के साथ समझाएंगे।

क्यों लोकल चलाएँ? (Why run locally)

लोकल में LLM चलाने के प्रमुख फायदे:

  • Privacy: डेटा कभी क्लाउड पर नहीं भेजते — sensitive data on premises रहता है।
  • Cost control: लगातार API calls के बिल से बचते हैं; एक बार hardware पर मॉडल चलाकर predictable खर्च।
  • Latency: लोकल inference अक्सर कम latency देता है, offline scenarios में उपयोगी।
  • Customization: अपने fine-tuned checkpoints या custom tokenizers आसानी से attach कर सकते हैं।

Hardware & Software Requirements

मॉडल और configuration के हिसाब से requirements बदलते हैं। यहाँ सामान्य guideline है:

Hardware (GPU preferred)

  • Minimum: 16 GB RAM (छोटे quantized models के लिए)
  • Recommended GPU: NVIDIA GPU with 12–48 GB VRAM (e.g., RTX 3090/4090 for larger models)
  • For CPU-only: Modern multi-core CPU + lots of RAM (64GB+) — लेकिन performance धीमा होगा।

Software

  • Docker (latest stable)
  • nvidia-docker / NVIDIA Container Toolkit (यदि GPU उपयोग कर रहे हैं)
  • Optional runtimes: text-generation-inference, ggml based containers, Hugging Face Transformers inside container

किस मॉडल को चुनें — LLaMA, Mistral, Vicuna, आदि

मॉडल चुनते समय ध्यान रखें:

  • License: LLaMA derivatives often have specific license terms — check before use.
  • Size vs Capability: 7B मॉडल कम resource लेता है; 13B/70B ज्यादा बेहतर पर resource intensive।
  • Quantized variants: GGML/FP16/INT8 quantized मॉडल कम VRAM में चलते हैं — latency और accuracy tradeoffs समझें।

Popular Docker images & runtimes

कुछ common choices:

  • text-generation-inference (TGI) — Hugging Face का NVIDIA-optimized server for serving models.
  • llama.cpp / ggml based images — CPU/quantized friendly.
  • ggml-webui / auto-gptq containers — community builds for quantized models with web UIs.

Step-by-step: Docker में LLM सेटअप (Hands-on)

1) Docker और NVIDIA toolkit install

// Ubuntu: install Docker


sudo apt update
sudo apt install -y docker.io
sudo systemctl enable --now docker

// NVIDIA container toolkit (for GPU passthrough)
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L [https://nvidia.github.io/nvidia-docker/gpgkey](https://nvidia.github.io/nvidia-docker/gpgkey) | sudo apt-key add -
curl -s -L [https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list](https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list) | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt update
sudo apt install -y nvidia-docker2
sudo systemctl restart docker

2) Example: Run a text-generation-inference container (GPU)

यह एक commonly used HF TGI container का उदाहरण है:

docker run --gpus all -p 8080:8080 \

-v /path/to/models:/models 
ghcr.io/huggingface/text-generation-inference:latest 
--model-id /models/mistral-7b

यह container port 8080 पर server expose करेगा। उसके बाद आप localhost:8080 पर inference requests भेज सकते हैं।

3) Example: llama.cpp / ggml CPU-only (fast setup)

docker run -it --rm \

-v /path/to/ggml-models:/models 
ghcr.io/ggerganov/llama.cpp:latest 
./main -m /models/ggml-model.bin -p "Hello world"

यह छोटा और तेज तरीका है जब आप GPU नहीं रखना चाहते।

4) Expose an API (simple Flask proxy inside container)

FROM python:3.11-slim

RUN pip install fastapi uvicorn requests
COPY server.py /app/server.py
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8080"]

Server proxy मॉडल के inference endpoint को wrap कर सकता है और auth, rate-limiting add कर सकता है।

Optimization: quantization, sharding और GPU tricks

कुछ महत्वपूर्ण optimization कदम:

  • Quantization: FP16/INT8/4-bit quantization से बड़ा मॉडल कम VRAM में चल सकता है। Tools: auto-gptq, ggml.
  • Model sharding: बड़े मॉडल को multiple GPUs पर shard करें (ZeRO / Hugging Face Accelerate, DeepSpeed)।
  • Batching & caching: inference requests batch करें और prompt cache रखें ताकि latency घटे।
  • Use mixed precision: NVIDIA GPUs पर FP16 से memory footprint घटता है।

Security, privacy और licensing मुद्दे

लोकल hosting का मतलब हर चीज सुरक्षित नहीं होती—कुछ ज़रूरी points:

  • Model license पढ़ें — कुछ models商业 उपयोग पर प्रतिबंधित होते हैं।
  • Container network exposure minimal रखें — केवल authenticated proxies को expose करें।
  • Encrypt disk storage जहाँ sensitive checkpoints हैं।
  • Audit logs रखें (access logs, inference inputs) — privacy के लिए redaction policy रखें।

Common issues & troubleshooting

  1. OOM (Out of Memory): model load होते समय OOM। Solution: use quantized model, reduce batch size, use GPU with larger VRAM, or use model sharding.
  2. Docker permissions / nvidia runtime errors: check NVIDIA driver version + nvidia-container-toolkit installation.
  3. Slow CPU inference: use ggml quantized models for acceptable performance or upgrade to GPU.
  4. License / checkpoint missing: ensure model weights are placed in mounted volume and correct path passed to container.

5) Example: Docker Compose Setup (multi-container)

version: '3.9'
services:
  llm-server:
    image: ghcr.io/huggingface/text-generation-inference:latest
    deploy:
      resources:
        reservations:
          devices:
            - capabilities: [gpu]
    volumes:
      - ./models:/models
    ports:
      - "8080:8080"
    command: --model-id /models/mistral-7b
Quick Tip: Reduce batch-size to avoid OOM errors when running on low VRAM GPUs.
Inference Benchmark — Mistral-7B
ModeHardwareTokens/sec
FP16RTX 4090 (24GB)80 tok/s
INT4 QuantizedRTX 3060 (12GB)30 tok/s
CPU-onlyIntel Xeon 64GB RAM5 tok/s

Cloud vs Local LLM Comparison

CriteriaLocal LLM (Docker)Cloud LLM API
Privacy✅ Full control❌ Data leaves system
CostOne-time hardwareRecurring API bills
LatencyLow (LAN)Dependent on network
ScalingLimited by hardwareScalable on demand

📌 Further reading

🧑‍💻 About the Author

Anurag Rai एक टेक ब्लॉगर और नेटवर्किंग विशेषज्ञ हैं जो Accounting, AI, Game, इंटरनेट सुरक्षा और डिजिटल तकनीक पर गहराई से लिखते हैं।

FAQs — अक्सर पूछे जाने वाले प्रश्न

Q1: क्या मैं बिना GPU के बड़े models चला सकता/सकती हूँ?

A: हाँ, पर performance बहुत कम होगी। छोटे quantized models (ggml) CPU पर feasible हैं; पर बड़े 13B+ मॉडल GPU के बिना practical नहीं हैं।

Q2: क्या लोकल मॉडल production-ready होते हैं?

A: छोटे/medium scale deployments के लिए हाँ — पर scale, monitoring, और security के लिए additional infra (autoscaling, logging, auth) चाहिए।

Q3: क्या मैं Hugging Face models Docker में बिना license check के चला सकता/सकती हूँ?

A: नहीं — हर मॉडल का license अलग होता है। हमेशा license और usage restrictions पढ़ें।

Q4: क्या Docker image automatically GPU support detect कर लेता है?

A: नहीं — आपको image run करते समय --gpus all या nvidia runtime configure करना होगा और image में GPU drivers compatible binaries होने चाहिए।

Q5: लोकल inference के लिए best practices क्या हैं?

A: Use quantization where possible; secure your endpoints; limit network exposure; implement rate-limits and monitoring; keep backups of checkpoints.

Post a Comment

Blogger

Your Comment Will be Show after Approval , Thanks

Ads

 
↑ Top