vLLM-Omni 的阶段配置¶
在 vLLM-Omni 中,目标模型被分离成多个阶段,由不同的 LLMEngine、DiffusionEngine 或其他类型的引擎处理。根据不同的阶段类型,例如自回归(AR)阶段或扩散 Transformer(DiT)阶段,每个阶段都可以以插件的方式选择相应的调度器和模型工作器与引擎一起加载。
注意
默认的阶段配置 YAML 文件(例如,vllm_omni/model_executor/stage_configs/qwen2_5_omni.yaml 和 vllm_omni/model_executor/stage_configs/qwen3_omni_moe.yaml)会被打包并自动加载,前提是未提供 stage_configs_path。这些配置已在 1xH100 上针对 Qwen2.5-Omni 和在 2xH100 上针对 Qwen3-Omni 进行了验证。
因此,作为 vLLM-Omni 的核心部分,模型的阶段配置具有几个主要功能:
- 声明
model_executor/models中阶段及其对应的类实现的分区。 - 每个阶段的分离配置以及它们之间的通信拓扑。
- 阶段内每个引擎的引擎参数。
- 每个阶段的输入和输出依赖关系。
- 默认输入参数。
如果用户想修改其中一部分。自定义的 stage_configs 文件可以作为在线和离线模式下的输入参数。如下例所示:
用于离线模式(假设必要的依赖项已导入)
model_name = "Qwen/Qwen2.5-Omni-7B"
omni_llm = OmniLLM(model=model_name, stage_configs_path="/path/to/custom_stage_configs.yaml")
用于在线服务
重要
我们正在积极迭代阶段配置的定义,并欢迎社区用户和开发者的所有反馈,以帮助我们塑造发展方向!
以下是 Qwen2.5-omni 的 stage_configs.yaml 的具体示例。
# stage config for running qwen2.5-omni with architecture of OmniLLM.
stage_args:
- stage_id: 0 # mark the unique id for each stage
runtime: # The disaggregated configuration
process: true # Run this stage in a separate process
devices: "0" # Visible devices for this stage (CUDA_VISIBLE_DEVICES/torch.cuda.set_device)
max_batch_size: 1 # the batch_size for offline inference
engine_args: # Engine arguments for a certain engine
model_stage: thinker
model_arch: Qwen2_5OmniForConditionalGeneration # The model implementation registered in model_executor/models/registry.py
worker_cls: vllm_omni.worker.gpu_ar_worker.GPUARWorker # The specific worker used
scheduler_cls: vllm_omni.core.sched.omni_ar_scheduler.OmniARScheduler # The specific scehduler used
gpu_memory_utilization: 0.8 # The gpu memory allocation for the stage within a single chip
enforce_eager: true # Now we only support eager mode
trust_remote_code: true # Needed by huggingface config parsing
engine_output_type: latent # It claims that the stage will input latent hiddenstates besides token ids
enable_prefix_caching: false # For request with hiddenstates output, the prefix caching is not supported now
is_comprehension: true # If the stage is a text or multimodal comprehension module. If it is, the AsyncOmni will use its tokenizer as default
final_output: true # If the stage has output as part of final outputs. If it is false, which means that the stage only works as a intermediate role.
final_output_type: text # What is the final output type. It can be text and audio now.
default_sampling_params: # sampling parameters for the stage. Their meaning aligns with vLLM.
temperature: 0.0
top_p: 1.0
top_k: -1
max_tokens: 2048
seed: 42
detokenize: True
repetition_penalty: 1.1
- stage_id: 1
runtime:
process: true
devices: "1"
max_batch_size: 3
engine_args:
model_stage: talker
model_arch: Qwen2_5OmniForConditionalGeneration
worker_cls: vllm_omni.worker.gpu_ar_worker.GPUARWorker
scheduler_cls: vllm_omni.core.sched.omni_ar_scheduler.OmniARScheduler
gpu_memory_utilization: 0.8
enforce_eager: true
trust_remote_code: true
enable_prefix_caching: false
engine_output_type: latent
engine_input_source: [0]
custom_process_input_func: vllm_omni.model_executor.stage_input_processors.qwen2_5_omni.thinker2talker
default_sampling_params:
temperature: 0.9
top_p: 0.8
top_k: 40
max_tokens: 2048
seed: 42
detokenize: True
repetition_penalty: 1.05
stop_token_ids: [8294]
- stage_id: 2
runtime:
process: true
devices: "0" # Example: use a different GPU than the previous stage; use "0" if single GPU
max_batch_size: 1
engine_args:
model_stage: code2wav
model_arch: Qwen2_5OmniForConditionalGeneration
worker_cls: vllm_omni.worker.gpu_generation_worker.GPUGenerationWorker
scheduler_cls: vllm_omni.core.sched.omni_generation_scheduler.OmniGenerationScheduler
gpu_memory_utilization: 0.15
enforce_eager: true
trust_remote_code: true
enable_prefix_caching: false
engine_output_type: audio
engine_input_source: [1]
final_output: true
final_output_type: audio
default_sampling_params:
temperature: 0.0
top_p: 1.0
top_k: -1
max_tokens: 2048
seed: 42
detokenize: True
repetition_penalty: 1.1
# Top-level runtime config (concise): default windows and stage edges
runtime:
enabled: true
defaults:
window_size: -1 # Simplified: trigger downstream only after full upstream completion
max_inflight: 1 # Simplified: process serially within each stage
edges:
- from: 0 # thinker → talker: trigger only after receiving full input (-1)
to: 1
window_size: -1
- from: 1 # talker → code2wav: trigger only after receiving full input (-1)
to: 2
window_size: -1
阶段配置参数¶
stage_args 列表中的每个阶段包含以下配置选项:
stage_id¶
多阶段管道中每个阶段的唯一标识符。阶段按顺序从 0 开始编号,此 ID 用于引用阶段间的依赖关系(例如,engine_input_source)。
runtime¶
阶段分离执行的配置,控制阶段的部署和执行方式。
runtime.process¶
是否在此阶段运行单独的进程。设置为 true 时,该阶段将在隔离的进程中执行,从而实现更好的资源隔离和跨不同阶段的并行执行。这对于不同阶段运行在不同设备上的多 GPU 部署至关重要。
默认值:true
runtime.devices¶
此阶段可见的设备,以字符串形式指定。这控制了可用于阶段进程的 GPU 设备,类似于设置 CUDA_VISIBLE_DEVICES 或使用 torch.cuda.set_device()。例如,"0" 使用 GPU 0,"1" 使用 GPU 1,"0,1" 则使 GPU 0 和 1 都可见。
默认值:"0"
runtime.max_batch_size¶
此阶段离线推理的最大批处理大小。这限制了在离线推理操作期间,一次可以同时处理多少个序列。
默认值: 1
engine_args¶
用于配置此阶段使用的 LLM 引擎、扩散引擎或其他引擎类型的引擎参数。
engine_args.model_stage¶
多阶段架构中此模型阶段的名称标识符。这用于内部区分同一模型的不同阶段(例如,Qwen2.5-Omni 中的 "thinker"、"talker"、"code2wav")。
engine_args.model_arch¶
在 model_executor/models/registry.py 中注册的模型架构类名。这指定了此阶段要使用的模型实现。该类必须在模型注册表中注册,vLLM-Omni 才能找到并实例化它。
engine_args.worker_cls¶
此阶段要使用的特定工作器类。这决定了模型计算的执行方式。例如,自回归阶段使用 vllm_omni.worker.gpu_ar_worker.GPUARWorker,扩散阶段使用 vllm_omni.worker.gpu_generation_worker.GPUGenerationWorker。
engine_args.scheduler_cls¶
此阶段要使用的调度器类。调度器负责管理请求队列、批处理和执行顺序。例如,标准阶段使用 vllm_omni.core.sched.omni_ar_scheduler.OmniARScheduler,扩散阶段使用 vllm_omni.core.sched.omni_generation_scheduler.OmniGenerationScheduler。
engine_args.gpu_memory_utilization¶
单个 GPU 芯片中为此阶段分配的 GPU 内存比例。这是一个介于 0.0 和 1.0 之间的值,0.8 表示该阶段将使用 80% 的 GPU 内存。这允许在多个阶段共享同一 GPU 或为其他操作预留内存时,对内存分配进行精细控制。
默认值:0.8
内存配置指南
有关如何计算内存需求和正确配置 gpu_memory_utilization 的详细信息,请参阅GPU 内存计算和配置指南。
engine_args.enforce_eager¶
是否强制执行急切执行模式。设置为 true 时,引擎将在急切模式下运行,不使用 CUDA 图或任何其他编译优化。目前,vLLM-Omni 只支持急切模式。
默认值:true
engine_args.trust_remote_code¶
从 Hugging Face 加载模型时是否信任远程代码。加载使用自定义代码的模型的配置文件时需要此设置。加载需要自定义模型实现的模型时,请设置为 true。
默认值:true
engine_args.engine_output_type¶
指定此阶段引擎产生的输出类型。这决定了什么样的数据流向下游阶段。可能的值包括 latent(隐藏状态)、text(分词后的文本)和 audio(音频波形)。设置为 latent 时,该阶段除了生成 token ID 外,还会输出隐藏状态,这些隐藏状态将被下游阶段使用。
默认值:latent
engine_args.enable_prefix_caching¶
是否为此阶段启用前缀缓存。前缀缓存可以通过缓存常用提示的前缀的 KV 缓存来提高性能。但是,对于输出隐藏状态的请求(当 engine_output_type 为 latent 时),目前不支持前缀缓存,应将其设置为 false。
默认值:false
is_comprehension¶
此阶段是否为文本或多模态理解模块。设置为 true 时,该阶段充当一个处理输入文本或多模态内容的理解模块。如果这是第一个理解阶段,AsyncOmni 将使用其分词器作为整个管道的默认分词器。
默认值:true
final_output¶
此阶段是否产生最终返回给用户的输出。设置为 false 时,该阶段仅作为中间阶段,处理流向下游阶段的数据,但不直接贡献于最终响应。
默认值:true
final_output_type¶
此阶段产生的最终输出类型。这指定了返回给用户的输出格式。当前支持的值有 text(用于文本生成)和 audio(用于音频生成)。
默认值:text
default_sampling_params¶
此阶段的默认采样参数。这些参数控制生成行为,并与 vLLM 的采样参数语义保持一致。当请求中未提供显式采样参数时,将使用这些默认值。
default_sampling_params.temperature¶
用于控制随机性的采样温度。较低的值(例如 0.0)使输出更确定和集中,而较高的值会增加随机性。
默认值:0.0
default_sampling_params.top_p¶
核采样参数。仅考虑累积概率质量不超过 top_p 的 token。这有助于过滤掉低概率的 token,同时保持多样性。
默认值:1.0
default_sampling_params.top_k¶
Top-k 采样参数。仅考虑最有可能的 k 个 token。设置为 -1 可禁用 top-k 过滤并考虑所有 token。
默认值:-1
default_sampling_params.max_tokens¶
此阶段要生成的最大 token 数。这限制了输出序列的长度。
默认值:2048
default_sampling_params.seed¶
用于可复现生成的随机种子。设置后,随机数生成器将使用此种子进行初始化,以确保每次运行结果的一致性。
默认值:42
default_sampling_params.detokenize¶
是否将输出 token 反分词为文本。设置为 true 时,token ID 将被转换回可读的文本字符串。
默认值: True
default_sampling_params.repetition_penalty¶
应用于已在生成序列中出现的 token 的惩罚。大于 1.0 的值会抑制重复,而小于 1.0 的值则会鼓励重复。值为 1.0 时不应用任何惩罚。
默认值:1.1