Deploying GLM 5.2 with Docker: Self-Hosting and vLLM API Setup
Jul 21, 2026

Deploying GLM 5.2 with Docker: Self-Hosting and vLLM API Setup

GLM 5.2's MIT license allows full self-hosting on your own GPU infrastructure. Here is how to containerize a GLM 5.2 API server using Docker and vLLM, with memory requirements and production configuration.

GLM 5.2's MIT open-weight license is one of its biggest advantages — it gives you the legal right to run the full 753B-parameter model on your own infrastructure, with no usage restrictions and no calls back to any external service. That matters enormously for air-gapped environments, data-residency compliance, and high-volume production workloads. The honest caveat: GLM 5.2 is a 753B-parameter mixture-of-experts model with 40B active parameters per forward pass, and the hardware bar to self-host it is genuinely extreme. For most engineering teams, the Z.ai cloud API at $1.40/M input and $4.40/M output tokens will be far more practical. This guide walks through both the Docker setup for teams that do have the hardware, and the realistic numbers you need to decide which path makes sense.

Hardware Requirements

GLM 5.2 uses a sparse MoE architecture, which reduces compute per inference but does not reduce the VRAM needed to load all parameters. Here is what you are looking at across quantization levels:

QuantizationModel VRAMMinimum GPU ConfigPractical?
BF16 (full precision)~1,500 GB19+ H100 80GBResearch / enterprise only
INT8~750 GB10 H100 80GBLarge enterprise clusters
Q4_K_M (4-bit)~380 GB5 H100 80GBMinimum practical config
GLM-4-9B (BF16)~18 GB1x RTX 4090 or A100Accessible to most teams

If you are working with a single workstation or a small GPU cluster, GLM-4-9B on Hugging Face is a much more practical target. For the full GLM 5.2, you need a multi-node GPU cluster, which is why the cloud API exists.

Docker Setup with vLLM

vLLM is the recommended serving framework for large models. It provides an OpenAI-compatible REST API, efficient paged attention for long contexts, and straightforward tensor parallelism across multiple GPUs. The official Docker image bundles everything you need.

First, pull the image:

docker pull vllm/vllm-openai:latest

Then launch the server. The command below assumes 8 GPUs and limits the context window to 32,768 tokens, which is a practical cap for most workloads and avoids KV cache memory spikes at the full 1,048,576-token context length:

docker run --gpus all \
  --shm-size=8g \
  -p 8000:8000 \
  -e HUGGING_FACE_HUB_TOKEN=your_hf_token_here \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  vllm/vllm-openai:latest \
  --model THUDM/GLM-5.2 \
  --tensor-parallel-size 8 \
  --max-model-len 32768 \
  --dtype bfloat16

The --shm-size=8g flag is required for inter-GPU shared memory when using tensor parallelism. Increase --tensor-parallel-size to match your GPU count. The model weights download automatically from Hugging Face on first run — plan for several hours depending on your connection, as the full checkpoint is hundreds of gigabytes.

API Configuration

Once the container is running, vLLM exposes an OpenAI-compatible API at http://localhost:8000. You can point any OpenAI SDK client at this endpoint with no other changes:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="not-required"  # vLLM does not enforce API keys by default
)

response = client.chat.completions.create(
    model="THUDM/GLM-5.2",
    messages=[
        {"role": "user", "content": "Explain mixture-of-experts architecture."}
    ],
    max_tokens=512,
    temperature=0.7
)

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

To verify the server is healthy before sending requests:

curl http://localhost:8000/health
curl http://localhost:8000/v1/models

Production Configuration

For production deployments, use a docker-compose.yml file to manage GPU allocation, environment variables, volume mounts, and health checks:

version: '3.8'

services:
  glm52-api:
    image: vllm/vllm-openai:latest
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    shm_size: '8gb'
    ports:
      - "8000:8000"
    environment:
      - HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
      - VLLM_WORKER_MULTIPROC_METHOD=spawn
    volumes:
      - huggingface_cache:/root/.cache/huggingface
    command: >
      --model THUDM/GLM-5.2
      --tensor-parallel-size 8
      --max-model-len 32768
      --dtype bfloat16
      --max-num-seqs 16
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 600s
    restart: unless-stopped

volumes:
  huggingface_cache:

Set your Hugging Face token in a .env file next to the compose file (HF_TOKEN=hf_...). The start_period: 600s health check delay is important — the model takes several minutes to load into VRAM before it can serve requests. --max-num-seqs 16 limits concurrent sequences to avoid OOM errors under load; tune this based on your available memory headroom.

Quantization Options

If your hardware falls short of the Q4 requirements for the full 753B model, llama.cpp running inside Docker offers a lighter-weight alternative using GGUF quantized files. This is the practical path for teams with 4–8 consumer GPUs:

docker run --gpus all \
  -p 8080:8080 \
  -v /path/to/models:/models \
  ghcr.io/ggerganov/llama.cpp:server \
  -m /models/glm-5.2.Q4_K_M.gguf \
  --host 0.0.0.0 \
  --port 8080 \
  -ngl 99 \
  --ctx-size 8192

The -ngl 99 flag offloads all layers to GPU. GGUF files for GLM 5.2 are available from the community on Hugging Face once quantization is finalized. The llama.cpp server also exposes an OpenAI-compatible API at port 8080, so your client code works unchanged.

When Self-Hosting Makes Sense

At Z.ai's pricing of $1.40/M input and $4.40/M output tokens, the cost of cloud API access is very low for most workloads. The break-even calculation for self-hosting depends almost entirely on throughput.

A 10-GPU H100 cluster on a major cloud provider costs roughly $30–35 per hour. At $4.40/M output tokens, you would need to generate approximately 7 million output tokens per hour — sustained, around the clock — before self-hosting becomes cheaper than the API. That is roughly 2,000 tokens per second of output, which requires significant concurrent traffic.

Self-hosting makes economic sense if you are running one of these scenarios:

  • Air-gapped or compliance environments where data cannot leave your network, regardless of cost
  • Very high-volume inference (tens of millions of tokens per day, consistently), where you own the hardware rather than rent it
  • Research or fine-tuning where you need direct model access and the ability to modify weights

For everything else — prototyping, production apps with moderate traffic, or teams without GPU cluster experience — the Z.ai API is faster to set up and cheaper to operate.

Frequently Asked Questions

What is the absolute minimum hardware to run GLM 5.2? Five H100 80GB GPUs (400GB combined VRAM) with Q4 quantization. Below that, you cannot load the full 753B parameter model. For smaller hardware, use GLM-4-9B, which fits in ~18GB VRAM on a single A100 or high-end consumer GPU.

Does self-hosting deliver lower latency than the cloud API? Not necessarily. Z.ai's infrastructure is optimized for GLM 5.2 and runs at 158 tokens per second. A self-hosted cluster with less optimized networking and fewer GPUs may actually be slower, especially at lower batch sizes. Latency depends heavily on your cluster configuration.

Does the MIT license allow commercial use? Yes. The MIT license places no restrictions on commercial use, fine-tuning, redistribution, or modification. You must retain the license notice but are otherwise free to use the model in any product or service.

Can I run GLM 5.2 on consumer GPUs? The full 753B model, no. Even with aggressive quantization, you need professional-grade multi-GPU infrastructure. If you are working with consumer hardware (RTX 4090, for example), use GLM-4-9B instead — it runs in ~18GB and is significantly capable.

Is llama.cpp a viable alternative to vLLM for production? For smaller models or teams without deep ML infrastructure experience, yes. llama.cpp is simpler to set up and supports more quantization formats. vLLM has higher throughput and better concurrency for production traffic at scale, but requires more VRAM and more complex configuration.

What happens if I exceed the 32,768 token context window I set in the Docker command? vLLM will reject the request with an error. You can increase --max-model-len up to 1,048,576 — GLM 5.2's full context — but each increase raises KV cache memory requirements significantly. Start conservative and tune upward based on your actual workload.

Bottom Line

GLM 5.2 is legally and technically self-hostable thanks to its MIT license, and vLLM with Docker gives you a clean path to an OpenAI-compatible API on your own infrastructure. The hardware bar is extreme: you need at minimum five H100 80GB GPUs just to load the quantized weights, and a more realistic production cluster costs tens of thousands of dollars per month to rent. For the vast majority of teams, the Z.ai cloud API at $1.40/M input and $4.40/M output tokens is the right starting point — self-hosting only becomes worth the operational complexity for air-gapped environments, strict data-residency requirements, or very large sustained inference volumes.

Try GLM 5.2 — no API key needed: glm5.app/chat

Sources

Begynn å bruke GLM 5 i dag

Prøv GLM 5 gratis — resonnering, koding, agenter og bildegenerering i én plattform.