2026-04-25 20:49:19 +08:00
|
|
|
# GLM-Image Offline Inference
|
2026-02-27 17:28:35 +08:00
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
GLM-Image is a 2-stage image generation model (AR + Diffusion) supported by vLLM-Omni's
|
|
|
|
|
declarative config system. The pipeline topology and stage structure are declared in
|
|
|
|
|
`vllm_omni/model_executor/models/glm_image/pipeline.py`; deployment knobs live in
|
|
|
|
|
`vllm_omni/deploy/glm_image.yaml`.
|
2026-02-27 17:28:35 +08:00
|
|
|
|
|
|
|
|
## Architecture
|
|
|
|
|
|
|
|
|
|
```
|
2026-04-25 20:49:19 +08:00
|
|
|
Stage 0 (AR Model) Stage 1 (Diffusion)
|
|
|
|
|
┌───────────────────┐ ┌─────────────────────┐
|
|
|
|
|
│ vLLM-optimized │ prior │ GlmImagePipeline │
|
|
|
|
|
│ GlmImageFor │──tokens──►│ ┌───────────────┐ │
|
|
|
|
|
│ Conditional │ │ │ DiT Denoiser │ │
|
|
|
|
|
│ Generation │ │ └───────┬───────┘ │
|
|
|
|
|
│ (9B AR model) │ │ ▼ │
|
|
|
|
|
└───────────────────┘ │ ┌───────────────┐ │
|
|
|
|
|
▲ │ │ VAE Decode │──┼──► Image
|
|
|
|
|
│ │ └───────────────┘ │
|
|
|
|
|
Text / Image └─────────────────────┘
|
|
|
|
|
Input
|
2026-02-27 17:28:35 +08:00
|
|
|
```
|
|
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
## Text-to-Image
|
2026-02-27 17:28:35 +08:00
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
```python
|
|
|
|
|
from vllm_omni.entrypoints.omni import Omni
|
2026-07-13 23:59:42 +08:00
|
|
|
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
2026-02-27 17:28:35 +08:00
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
omni = Omni(model="zai-org/GLM-Image")
|
|
|
|
|
outputs = omni.generate(
|
|
|
|
|
"A photorealistic mountain landscape at sunset",
|
2026-07-13 23:59:42 +08:00
|
|
|
sampling_params_list=[
|
|
|
|
|
omni.default_sampling_params_list[0],
|
|
|
|
|
OmniDiffusionSamplingParams(
|
|
|
|
|
height=1024,
|
|
|
|
|
width=1024,
|
|
|
|
|
num_inference_steps=50,
|
|
|
|
|
guidance_scale=1.5,
|
|
|
|
|
seed=42,
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-04-25 20:49:19 +08:00
|
|
|
)
|
2026-08-15 07:07:28 +08:00
|
|
|
outputs[0].images[0].save("output.png")
|
2026-02-27 17:28:35 +08:00
|
|
|
```
|
|
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
## Image-to-Image (Image Editing)
|
2026-02-27 17:28:35 +08:00
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
```python
|
|
|
|
|
from vllm_omni.entrypoints.omni import Omni
|
2026-07-13 23:59:42 +08:00
|
|
|
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
2026-04-25 20:49:19 +08:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
omni = Omni(model="zai-org/GLM-Image")
|
|
|
|
|
outputs = omni.generate(
|
|
|
|
|
{
|
|
|
|
|
"prompt": "Convert this image to watercolor style",
|
|
|
|
|
"multi_modal_data": {
|
|
|
|
|
"image": "input.png",
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-07-13 23:59:42 +08:00
|
|
|
sampling_params_list=[
|
|
|
|
|
omni.default_sampling_params_list[0],
|
|
|
|
|
OmniDiffusionSamplingParams(
|
|
|
|
|
height=1024,
|
|
|
|
|
width=1024,
|
|
|
|
|
num_inference_steps=50,
|
|
|
|
|
guidance_scale=1.5,
|
|
|
|
|
seed=42,
|
|
|
|
|
),
|
|
|
|
|
],
|
2026-04-25 20:49:19 +08:00
|
|
|
)
|
2026-08-15 07:07:28 +08:00
|
|
|
outputs[0].images[0].save("output.png")
|
2026-02-27 17:28:35 +08:00
|
|
|
```
|
|
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
## Generation Parameters
|
2026-02-27 17:28:35 +08:00
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
| Parameter | Type | Default | Description |
|
|
|
|
|
| --------------------- | ----- | ------- | ----------------------------------- |
|
|
|
|
|
| `height` | int | 1024 | Image height in pixels |
|
|
|
|
|
| `width` | int | 1024 | Image width in pixels |
|
|
|
|
|
| `num_inference_steps` | int | 50 | Number of diffusion denoising steps |
|
|
|
|
|
| `guidance_scale` | float | 1.5 | Classifier-free guidance scale |
|
|
|
|
|
| `seed` | int | None | Optional random seed |
|
|
|
|
|
| `negative_prompt` | str | None | Negative prompt |
|
2026-02-27 17:28:35 +08:00
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
## VRAM Requirements
|
2026-02-27 17:28:35 +08:00
|
|
|
|
2026-04-25 20:49:19 +08:00
|
|
|
| Stage | VRAM |
|
|
|
|
|
| :---------------- | :--------------------- |
|
|
|
|
|
| Stage-0 (AR) | **~18 GiB + KV Cache** |
|
|
|
|
|
| Stage-1 (DiT+VAE) | **~20 GiB** |
|
|
|
|
|
| Total | **~38 GiB + KV Cache** |
|