[ConfigRefactor] GLM-Image (#2977)
Signed-off-by: JaredforReal <w13431838023@gmail.com> Signed-off-by: Jared Wen <w13431838023@gmail.com> Co-authored-by: SYLAR <125541396+lishunyang12@users.noreply.github.com>
This commit is contained in:
1 parent
e1cdd0c23b
commit
554233208f
16 files changed
+142
-1491
No files matched your search
@@ -1,3 +1,16 @@
|
||||
from .glm_image_ar import GlmImageForConditionalGeneration
|
||||
def __getattr__(name: str):
|
||||
"""Lazy import to avoid importing transformers.models.glm_image at module init.
|
||||
|
||||
The AR model depends on ``transformers.models.glm_image`` which is only
|
||||
available when the model weights are present. Importing it eagerly in
|
||||
``__init__.py`` breaks the pipeline registry lookup for environments that
|
||||
don't have this custom transformers extension installed.
|
||||
"""
|
||||
if name == "GlmImageForConditionalGeneration":
|
||||
from .glm_image_ar import GlmImageForConditionalGeneration
|
||||
|
||||
return GlmImageForConditionalGeneration
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
|
||||
__all__ = ["GlmImageForConditionalGeneration"]
|
||||
@@ -0,0 +1,47 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""GLM-Image pipeline topologies (frozen).
|
||||
Two-stage (default):
|
||||
Stage 0: AR — multimodal understanding + token_ids generation
|
||||
Stage 1: DiT — diffusion image generation
|
||||
"""
|
||||
|
||||
from vllm_omni.config.stage_config import (
|
||||
PipelineConfig,
|
||||
StageExecutionType,
|
||||
StagePipelineConfig,
|
||||
)
|
||||
|
||||
GLM_IMAGE_PIPELINE = PipelineConfig(
|
||||
model_type="glm_image",
|
||||
model_arch="GlmImageForConditionalGeneration",
|
||||
hf_architectures=("GlmImageForConditionalGeneration",),
|
||||
diffusers_class_name="GlmImagePipeline",
|
||||
stages=(
|
||||
StagePipelineConfig(
|
||||
stage_id=0,
|
||||
model_stage="ar",
|
||||
execution_type=StageExecutionType.LLM_AR,
|
||||
requires_multimodal_data=True,
|
||||
input_sources=(),
|
||||
final_output=False,
|
||||
owns_tokenizer=True,
|
||||
model_arch="GlmImageForConditionalGeneration",
|
||||
engine_output_type="token_ids",
|
||||
model_subdir="vision_language_encoder",
|
||||
tokenizer_subdir="processor",
|
||||
),
|
||||
StagePipelineConfig(
|
||||
stage_id=1,
|
||||
model_stage="dit",
|
||||
execution_type=StageExecutionType.DIFFUSION,
|
||||
input_sources=(0,),
|
||||
requires_multimodal_data=True,
|
||||
final_output=True,
|
||||
final_output_type="image",
|
||||
model_arch="GlmImagePipeline",
|
||||
custom_process_input_func="vllm_omni.model_executor.stage_input_processors.glm_image.ar2diffusion",
|
||||
omni_kv_config={"need_recv_cache": False},
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -1,74 +0,0 @@
|
||||
# Stage config for running GLM-Image with 2-stage architecture
|
||||
# Stage 0: AR Model (vLLM implementation) - generates prior_token_ids
|
||||
# Stage 1: Diffusion (DiT + VAE) - denoising and image decoding
|
||||
|
||||
stage_args:
|
||||
# Stage 0: AR Model (GlmImageForConditionalGeneration)
|
||||
# This stage uses the vLLM-optimized AR model to generate prior tokens
|
||||
# for conditioning the diffusion process.
|
||||
- stage_id: 0
|
||||
stage_type: llm
|
||||
runtime:
|
||||
process: true
|
||||
devices: "0"
|
||||
requires_multimodal_data: true # Required for i2i mode to receive source images
|
||||
engine_args:
|
||||
model_stage: ar
|
||||
max_num_seqs: 1
|
||||
model_arch: GlmImageForConditionalGeneration
|
||||
model_subdir: vision_language_encoder # AR model config.json is in this subdirectory
|
||||
tokenizer_subdir: processor # Use processor's tokenizer (not ByT5 from tokenizer/)
|
||||
worker_cls: vllm_omni.worker.gpu_ar_worker.GPUARWorker
|
||||
scheduler_cls: vllm_omni.core.sched.omni_ar_scheduler.OmniARScheduler
|
||||
gpu_memory_utilization: 0.6
|
||||
enforce_eager: false
|
||||
trust_remote_code: true
|
||||
engine_output_type: token_ids # Output prior_token_ids for diffusion stage
|
||||
distributed_executor_backend: "mp"
|
||||
enable_prefix_caching: false
|
||||
max_num_batched_tokens: 32768
|
||||
final_output: false # AR is not the final output
|
||||
is_comprehension: true
|
||||
default_sampling_params:
|
||||
temperature: 0.9 # From model's generation_config.json
|
||||
top_p: 0.75 # From model's generation_config.json
|
||||
top_k: 16512 # vision_vocab_size from generation_config.json
|
||||
stop_token_ids: [16385] # eos_token_id from generation_config.json
|
||||
seed: 42
|
||||
detokenize: false
|
||||
|
||||
# Stage 1: Diffusion (DiT + VAE)
|
||||
# This stage receives prior_token_ids from AR and performs denoising + VAE decode
|
||||
- stage_id: 1
|
||||
stage_type: diffusion
|
||||
runtime:
|
||||
process: true
|
||||
devices: "1" # Can use different GPU, or same GPU if memory allows
|
||||
requires_multimodal_data: true # Required for i2i mode to pass condition images
|
||||
engine_args:
|
||||
model_stage: dit
|
||||
max_num_seqs: 1
|
||||
model_arch: GlmImagePipeline # Required for diffusion model class resolution
|
||||
# Diffusion-specific parameters
|
||||
num_gpus: 1
|
||||
enforce_eager: true
|
||||
trust_remote_code: true
|
||||
distributed_executor_backend: "mp"
|
||||
engine_input_source: [0] # Input from AR stage
|
||||
custom_process_input_func: vllm_omni.model_executor.stage_input_processors.glm_image.ar2diffusion
|
||||
final_output: true
|
||||
final_output_type: image
|
||||
default_sampling_params:
|
||||
# Diffusion-specific parameters only (no LLM params like temperature/top_p/top_k)
|
||||
seed: 42
|
||||
num_inference_steps: 50
|
||||
guidance_scale: 1.5
|
||||
height: 1024
|
||||
width: 1024
|
||||
|
||||
# Top-level runtime config
|
||||
runtime:
|
||||
enabled: true
|
||||
edges:
|
||||
- from: 0 # AR → Diffusion: trigger after AR completes
|
||||
to: 1
|
||||
@@ -1,87 +0,0 @@
|
||||
# Stage config for running GLM-Image with 2-stage architecture (MultiConnector version)
|
||||
# Stage 0: AR Model (vLLM implementation) - generates prior_token_ids
|
||||
# Stage 1: Diffusion (DiT + VAE) - denoising and image decoding
|
||||
#
|
||||
# This config uses OmniConnectors for inter-stage communication,
|
||||
# enabling efficient tensor transfer between stages on different processes/nodes.
|
||||
|
||||
stage_args:
|
||||
# Stage 0: AR Model (GlmImageForConditionalGeneration)
|
||||
# This stage uses the vLLM-optimized AR model to generate prior tokens
|
||||
# for conditioning the diffusion process.
|
||||
- stage_id: 0
|
||||
stage_type: llm
|
||||
runtime:
|
||||
process: true
|
||||
devices: "0"
|
||||
requires_multimodal_data: true # Required for i2i mode to receive source images
|
||||
engine_args:
|
||||
model_stage: ar
|
||||
max_num_seqs: 1
|
||||
model_arch: GlmImageForConditionalGeneration
|
||||
worker_cls: vllm_omni.worker.gpu_ar_worker.GPUARWorker
|
||||
scheduler_cls: vllm_omni.core.sched.omni_ar_scheduler.OmniARScheduler
|
||||
gpu_memory_utilization: 0.6
|
||||
enforce_eager: false
|
||||
trust_remote_code: true
|
||||
engine_output_type: token_ids # Output prior_token_ids for diffusion stage
|
||||
distributed_executor_backend: "mp"
|
||||
enable_prefix_caching: false
|
||||
max_num_batched_tokens: 32768
|
||||
hf_config_name: vision_language_encoder # Subfolder in model path
|
||||
final_output: false # AR is not the final output
|
||||
is_comprehension: true
|
||||
default_sampling_params:
|
||||
temperature: 0.9 # From model's generation_config.json
|
||||
top_p: 0.75 # From model's generation_config.json
|
||||
top_k: 16512 # vision_vocab_size from generation_config.json
|
||||
stop_token_ids: [16385] # eos_token_id from generation_config.json
|
||||
seed: 42
|
||||
detokenize: false
|
||||
|
||||
# Stage 1: Diffusion (DiT + VAE)
|
||||
# This stage receives prior_token_ids from AR and performs denoising + VAE decode
|
||||
- stage_id: 1
|
||||
stage_type: diffusion
|
||||
runtime:
|
||||
process: true
|
||||
devices: "1" # Use separate GPU for diffusion
|
||||
requires_multimodal_data: true # Required for i2i mode to pass condition images
|
||||
engine_args:
|
||||
model_stage: dit
|
||||
max_num_seqs: 1
|
||||
# Diffusion-specific parameters
|
||||
num_gpus: 1
|
||||
enforce_eager: true
|
||||
trust_remote_code: true
|
||||
distributed_executor_backend: "mp"
|
||||
engine_input_source: [0] # Input from AR stage
|
||||
custom_process_input_func: vllm_omni.model_executor.stage_input_processors.glm_image.ar2diffusion
|
||||
final_output: true
|
||||
final_output_type: image
|
||||
default_sampling_params:
|
||||
seed: 42
|
||||
num_inference_steps: 50
|
||||
guidance_scale: 1.5
|
||||
height: 1024
|
||||
width: 1024
|
||||
|
||||
# Top-level runtime config with MultiConnector support
|
||||
runtime:
|
||||
enabled: true
|
||||
edges:
|
||||
- from: 0 # AR → Diffusion
|
||||
to: 1
|
||||
|
||||
# OmniConnector configuration for efficient inter-stage tensor transfer
|
||||
connectors:
|
||||
- type: tensor_transfer
|
||||
source_stage: 0
|
||||
target_stage: 1
|
||||
# Transfer prior_token_ids efficiently between stages
|
||||
fields:
|
||||
- name: prior_token_ids
|
||||
dtype: int64
|
||||
- name: prior_token_image_ids
|
||||
dtype: int64
|
||||
optional: true
|
||||
Reference in new issue
Block a user