{
  "hf_id": "zai-org/GLM-Image",
  "meta": {
    "title": "GLM-Image",
    "slug": "glm-image",
    "provider": "GLM (Z-AI)",
    "description": "Hybrid autoregressive + diffusion image generation model — text-to-image and image-to-image with strong text rendering and knowledge-intensive generation",
    "date_added": "2026-01-26",
    "date_updated": "2026-04-17",
    "tasks": [
      "omni"
    ],
    "performance_headline": "9B AR generator + 7B DiT decoder, state-of-the-art text rendering in generated images",
    "related_recipes": [],
    "hardware": {
      "h100": "verified"
    }
  },
  "model": {
    "model_id": "zai-org/GLM-Image",
    "min_vllm_version": "0.11.0",
    "architecture": "dense",
    "parameter_count": "16B",
    "active_parameters": "16B",
    "context_length": 4096,
    "base_args": [
      "--trust-remote-code"
    ],
    "base_env": {},
    "install": {
      "pip": {
        "command": "uv venv\nsource .venv/bin/activate\nuv pip install -U vllm --torch-backend auto"
      },
      "docker": {
        "command": "docker pull vllm/vllm-openai:latest"
      },
      "extras": [
        {
          "note": "vllm-omni provides the diffusion decoder path",
          "command": "uv pip install vllm-omni"
        },
        {
          "note": "transformers from source (GLM-Image tokenizer)",
          "command": "uv pip install git+https://github.com/huggingface/transformers.git"
        },
        {
          "note": "diffusers from source — required for the DiT decoder",
          "command": "uv pip install git+https://github.com/huggingface/diffusers.git"
        }
      ]
    }
  },
  "omni": {
    "tasks": [
      "t2i",
      "i2i"
    ]
  },
  "features": {},
  "opt_in_features": [],
  "variants": {
    "default": {
      "precision": "bf16",
      "vram_minimum_gb": 38,
      "description": "Single-GPU deployment (~33 GB for model weights, plus activation headroom)"
    }
  },
  "hardware_overrides": {},
  "guide": "## Overview\n\nGLM-Image is an image generation model with a hybrid architecture:\n\n- **Autoregressive Generator (9B):** initialized from GLM-4-9B-0414 with an expanded\n  vocabulary for visual tokens. Produces a compact encoding (~256 tokens), then\n  expands to 1K–4K tokens corresponding to 1K–2K resolution images.\n- **Diffusion Decoder (7B):** single-stream DiT that decodes latents into pixels.\n  Includes a Glyph Encoder text module for accurate in-image text rendering.\n\nServed via vLLM-Omni for OpenAI-compatible online inference.\n\n### Key Capabilities\n\n- Text-to-image and image-to-image (editing, style transfer, identity-preserving)\n- Exceptional text rendering inside generated images\n- Strong knowledge-intensive generation\n\n## Prerequisites\n\n- **vLLM version:** latest (with `vllm-omni` extension)\n- **Transformers:** >= 5.0.0 (use source install for latest)\n- **Hardware:** single H100-class GPU (approx. 33 GB for weights)\n\n### Install Dependencies\n\n```bash\nuv venv --python 3.12 --seed\nsource .venv/bin/activate\n\nuv pip install -U vllm --torch-backend auto\nuv pip install vllm-omni\n\npip install git+https://github.com/huggingface/transformers.git\npip install git+https://github.com/huggingface/diffusers.git\n```\n\n## Online Serving\n\n```bash\nvllm serve zai-org/GLM-Image --omni\n```\n\n## Client Usage\n\n### OpenAI SDK (Text-to-Image)\n\n```python\nimport base64\nfrom openai import OpenAI\n\nclient = OpenAI(base_url=\"http://localhost:8000/v1\", api_key=\"EMPTY\")\n\nresponse = client.chat.completions.create(\n    model=\"zai-org/GLM-Image\",\n    messages=[{\"role\": \"user\", \"content\": \"A beautiful landscape painting with mountains and a lake at sunset\"}],\n)\n\nimage_url = response.choices[0].message.content[0].image_url.url\nimage_data = base64.b64decode(image_url.split(\",\")[1])\nwith open(\"output.png\", \"wb\") as f:\n    f.write(image_data)\n```\n\n### cURL (Text-to-Image)\n\n```bash\ncurl -s http://localhost:8000/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"messages\": [{\"role\": \"user\", \"content\": \"A beautiful landscape painting\"}]\n  }' | jq -r '.choices[0].message.content[0].image_url.url' | cut -d',' -f2- | base64 -d > output.png\n```\n\n### Image-to-Image\n\n```python\nimport base64\nfrom openai import OpenAI\n\nclient = OpenAI(base_url=\"http://localhost:8000/v1\", api_key=\"EMPTY\")\n\nwith open(\"input.png\", \"rb\") as f:\n    image_base64 = base64.b64encode(f.read()).decode(\"utf-8\")\n\nresponse = client.chat.completions.create(\n    model=\"zai-org/GLM-Image\",\n    messages=[{\n        \"role\": \"user\",\n        \"content\": [\n            {\"type\": \"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{image_base64}\"}},\n            {\"type\": \"text\", \"text\": \"Replace the background with a sunset beach scene\"}\n        ]\n    }],\n)\n\nimage_url = response.choices[0].message.content[0].image_url.url\nimage_data = base64.b64decode(image_url.split(\",\")[1])\nwith open(\"output.png\", \"wb\") as f:\n    f.write(image_data)\n```\n\n## Offline Inference\n\n```bash\n# Text to Image\ncd examples/offline_inference/text_to_image\npython3 text_to_image.py --model zai-org/GLM-Image --output t2i_output.png\n\n# Image to Image\ncd examples/offline_inference/image_to_image\nwget https://vllm-public-assets.s3.us-west-2.amazonaws.com/omni-assets/qwen-bear.png\npython3 image_to_image.py --model zai-org/GLM-Image --image qwen-bear.png --output i2i_output.png\n```\n\n## Troubleshooting\n\n- **Resolution errors:** Target image dimensions must be divisible by 32.\n- **Text rendering:** Wrap text that should appear in the image with quotation marks\n  in the prompt.\n- **Output stability:** Default `temperature=0.9`, `top_p=0.75`. Higher temperature\n  gives more diverse outputs but may reduce stability.\n- **Transformers version:** Requires `transformers >= 5.0.0`.\n\n## References\n\n- [Model card](https://huggingface.co/zai-org/GLM-Image)\n- [Technical blog](https://z.ai/blog/glm-image)\n- [GitHub repo](https://github.com/zai-org/GLM-Image)\n",
  "source": {
    "source": "vllm-omni",
    "repo": "vllm-project/vllm-omni",
    "ref": "main",
    "sha": "cda4a1ef83b295ba332146a7709e6277725edc9f",
    "path": "recipes/models/zai-org/GLM-Image.yaml",
    "edit_url": "https://github.com/vllm-project/vllm-omni/edit/main/recipes/models/zai-org/GLM-Image.yaml",
    "overlays": []
  }
}