vLLM-Omni 运行 ByteDance Lance:统一 AR + 扩散多模态 3B 模型的离线推理与在线服务实战
发布时间:2026/9/18 3:50:48 作者:尧图编辑部 阅读量:1,286

vLLM-Omni 运行 ByteDance Lance统一 AR 扩散多模态 3B 模型的离线推理与在线服务实战【免费下载链接】vllm-omniA framework for efficient model inference with omni-modality models项目地址: https://gitcode.com/GitHub_Trending/vl/vllm-omni本文基于仓库 recipes/ByteDance/Lance.md 编写。Lance 是字节跳动开源的 3B 统一自回归AR 扩散多模态模型在 Qwen2.5-VL 骨干上同时支持文生图、图生图、文生视频、视频编辑以及图像/视频理解六类单阶段任务。通过本文你可以掌握在 vLLM-Omni 中完成 Lance 的环境准备、六类任务的离线推理命令、采样与扩散参数调优以及基于 OpenAI 兼容 API 的在线服务部署与客户端调用并了解其背后复用 BAGEL 变换器核心、特化 ViT/VAE/检查点布局的实现原理。一、Lance 模型是什么Lancebytedance-research/Lance是一个3B 规模的统一自回归 扩散多模态模型采用 Qwen2.5-VL 骨干backbone一次加载即可覆盖文本、图像、视频三类模态的生成与理解任务text2img文生图text2video文生视频img2imgimage edit图生图 / 图像编辑video2videovideo edit视频编辑img2textimage understanding图像理解caption / VQAvideo2textvideo understanding视频理解在 vLLM-Omni 中Lance 属于BAGEL 血缘BAGEL-lineage模型其发布的检查点与 BAGEL 使用相同的*_moe_genMixture-of-TransformersMoT权重布局因此 vLLM-Omni 直接复用 BAGEL 的变换器核心仅针对三处做特化视觉编码器ViT改用 Qwen2.5-VL 视觉塔而非 BAGEL 的 SigLIP变分自编码器VAE改用 Wan2.2Wan2.2_VAE.pth而非 BAGEL 自带的 autoencoder检查点布局适配 HuggingFace 仓库内多子目录的打包结构。从源码看vllm_omni/diffusion/models/lance/pipeline_lance.py中的LancePipeline直接继承自BagelPipeline其文档字符串明确指出只有模型构建过程不同且仅局限于三个位置——检查点布局、理解用 ViT、VAE。生成/前向机制整体原样复用 BAGEL这也是整个集成能快速落地的基础。模型仓库结构HuggingFace 仓库bytedance-research/Lance将全部权重打包在一个仓库内无需额外下载Lance_3B/图像路径对应的 LLM 检查点Lance_3B_Video/视频路径所需的 LLM 检查点含 3-Dlatent_pos_embed位置嵌入表Qwen2.5-VL-ViT/图像/视频理解所需的视觉塔vit.safetensorsWan2.2_VAE.pthWan2.2 VAE 权重。与 BAGEL 不同Lance 的 HuggingFaceconfig.json只是描述性元数据没有model_type字段加载器无法仅凭模型目录自动探测管线类型因此 vLLM-Omni 通过部署配置显式指定pipeline: lance见下文在线服务一节。检查点与管线形态六类单阶段任务在Lance_3B检查点上全部支持text2video 与 video2video额外需要Lance_3B_Video子检查点用于加载 3-Dlatent_pos_embed表形状(126976, 2048)两阶段 AR DiT 拓扑AR thinker diffusion transformer当前暂未启用需要LanceConfig/LanceProcessor在vllm包中完成注册属于独立的上游 PR。二、硬件与运行环境操作系统LinuxPython3.12驱动 / 运行时CUDA ≥ 12.4vLLM-Omni 版本0.18.x.devGPU单卡 16 GB 显存BF16即可运行Lance_3B官方验证环境为 NVIDIA B300 / A100 80GB显存占用参考BF16LLM Qwen2.5-VL ViT Wan2.2 VAE 合计约7 GB单卡 16 GB 以上即可舒适运行Lance_3B。三、离线推理六类任务的完整命令离线推理统一入口是 examples/offline_inference/lance/end2end.py通过--modality切换任务类型。脚本内部会用render_lance_prompt按 Qwen chat 模板包装提示词并用|vision_start||video_pad||vision_end|视觉块占位构造Omni引擎单阶段扩散无需 deploy YAMLpipeline、enforce_eager、trust_remote_code、max_num_seqs1等以平铺 kwargs 传入将--steps、--cfg-text-scale、--timestep-shift等写入扩散采样参数调用omni.generate(...)图像输出保存为 PNG视频输出编码为 MP4fps参数控制帧率默认 12与上游 Lance 的save_fps12一致MP4 编码失败时回退为逐帧 PNG 落盘。3.1 文生图text2img默认python examples/offline_inference/lance/end2end.py \ --model bytedance-research/Lance \ --prompts a corgi astronaut on the moon, cinematic \ --steps 30 --cfg-text-scale 4.0 --timestep-shift 3.5 \ --height 1024 --width 1024 \ --seed 42 --output ./out默认值与上游inference_lance.sh保持一致30 步去噪、timestep-shift 3.5、文本 CFG 4.0、seed 42、1024×1024。可通过--height/--width覆盖分辨率--height/--width未指定时默认取max_hw1024。3.2 图像编辑img2imgpython examples/offline_inference/lance/end2end.py \ --model bytedance-research/Lance --modality img2img \ --image-path /path/to/input.png \ --prompts Convert this into a vibrant cartoon-style illustration \ --steps 30 --cfg-text-scale 4.0 --timestep-shift 3.5 \ --output ./out关键原理Lance 原生 VAE prefill 会把 Wan2.2 潜变量latents散列scatter进 LLM 的 query 序列无需额外的独立图像编码器。输入图片经 PIL 打开为 RGB 后通过multi_modal_data: {img2img: img}传入提示词以image_edit任务渲染。3.3 文生视频text2videopython examples/offline_inference/lance/end2end.py \ --model bytedance-research/Lance/Lance_3B_Video --modality text2video \ --num-frames 25 --video-height 480 --video-width 768 \ --prompts a cat playing piano, cinematic \ --steps 30 --fps 8 --output ./out--num-framesRGB 帧数默认 25上限 121--video-height/--video-width视频帧分辨率默认 480×768。任何视频路径都必须显式指定Lance_3B_Video子检查点以加载 3-Dlatent_pos_embed表。若仅指向顶层仓库vllm-omni 会静默加载图像版表形状(4096, 2048)一旦t_lat 1立即越界报错。离线脚本对此做了防御当--modality为text2video/video2video/video2text/image2video时若模型路径不以Lance_3B_Video结尾且本地存在该子目录会自动改写模型路径。3.4 图像 / 视频理解img2text / video2text# Image → textcaption / VQA python examples/offline_inference/lance/end2end.py \ --model bytedance-research/Lance --modality img2text \ --image-path /path/to/photo.jpg \ --prompts Describe this image in detail. \ --do-sample --text-temperature 0.8 # Video → text python examples/offline_inference/lance/end2end.py \ --model bytedance-research/Lance --modality video2text \ --video-path /path/to/clip.mp4 \ --prompts What is happening in this video?理解路径默认开启采样--do-sample默认True--text-temperature 0.8。原因在源码注释中写得很清楚Lance 的贪心解码器对许多提示词会立即输出 EOS温度低于约 0.7 时同样容易提前结束0.8 是一个可靠默认值。可用--no-sample关闭采样贪心解码用--max-text-tokens默认 512控制生成文本最大 token 数。理解路径的system_prompt可通过--system-prompt覆盖。源码指出x2t 路径默认使用 caption 风格的系统提示Generate a detailed and accurate description of the image/video...如果不提供 system prompt模型会倾向于描述而非按指令回答例如希望模型回答具体问题时可传入Look at the image carefully and answer the question.之类的 per-example QA 指令。3.5 额外能力image2video 与 video2video离线脚本还支持image2video图像 文本 → 长视频与video2video视频编辑# 图像生成视频不锁首帧图片作为 1 帧参考VAEViT prefill 后生成全新多帧视频 python examples/offline_inference/lance/end2end.py \ --model bytedance-research/Lance/Lance_3B_Video --modality image2video \ --image-path /path/to/image.png \ --prompts a corgi walking on the moon \ --num-frames 25 --video-height 480 --video-width 768 \ --output ./outimage2video通过multi_modal_data: {first_frame: img}传入参考帧提示词以i2v任务渲染复用 t2v 的系统提示词池video2video通过multi_modal_data: {video: video_path}传入源视频以video_edit任务渲染。3.6 提示词渲染机制源码视角vllm_omni/diffusion/models/lance/prompts.py 定义了与上游 Lance 训练分布完全一致的提示词格式每个任务有专属系统提示词SYSTEM_PROMPTS字典描述应关注的内容要素颜色、数量、文字、形状、尺寸、纹理、物体与背景的空间关系、运动/镜头移动等提示词按 Qwen chat 模板包装|im_start|system\n…|im_end|\n|im_start|user\n…|im_end|\n|im_start|assistant\n视觉内容占位符为|vision_start||video_pad||vision_end|——与直觉相反即使输入是图像上游 Lance 默认也使用|video_pad|除非设置force_video_padFalsevLLM-Omni 忠实复刻了这一行为。四、在线服务OpenAI 兼容 APILance 的所有单阶段模态均通过 OpenAI 兼容的/v1/chat/completionsAPI 提供在线服务。4.1 启动服务一键启动脚本为 examples/online_serving/lance/run_server.shbash examples/online_serving/lance/run_server.sh # 或带覆盖参数 MODELbytedance-research/Lance \ DEPLOY_CONFIGvllm_omni/deploy/lance.yaml \ PORT8091 \ bash examples/online_serving/lance/run_server.sh脚本内部执行的是vllm serve $MODEL --omni --deploy-config $DEPLOY_CONFIG --port $PORT。三个环境变量的默认值分别为MODELbytedance-research/Lance、DEPLOY_CONFIGvllm_omni/deploy/lance.yaml、PORT8091。若运行text2video/video2video设置MODELbytedance-research/Lance/Lance_3B_Video。4.2 部署配置解读vllm_omni/deploy/lance.yaml 是单阶段扩散管线选择器全文如下# LanceByteDance— single-stage diffusion pipeline selector. pipeline: lance async_chunk: false stages: - stage_id: 0 max_num_batched_tokens: 32768 max_num_seqs: 1 enforce_eager: true trust_remote_code: true enable_prefix_caching: false devices: 0 default_sampling_params: seed: 42关键点pipeline: lance因为 Lance 的 HFconfig.json无model_type加载器无法自动探测必须显式声明使用 Lance 管线单阶段、无多阶段编排max_num_batched_tokens: 32768与max_num_seqs: 1单序列大 batch 的扩散推理特征enforce_eager: true禁用图编译配合扩散模型动态形状trust_remote_code: true允许加载远程代码enable_prefix_caching: false、async_chunk: false单条请求场景下关闭前缀缓存与异步分块。值得注意的是E2E 测试 tests/e2e/online_serving/test_lance.py 选择不依赖 YAML而是把这些引擎旋钮作为 CLI 参数直接传入vllm-omni serve等效命令为vllm-omni serve bytedance-research/Lance --omni \ --pipeline lance --enforce-eager --trust-remote-code --port 8091 \ --max-num-batched-tokens 32768 --max-num-seqs 1 \ --no-enable-prefix-caching --no-async-chunk两种方式等价——deploy YAML 或平铺 CLI 参数都会由create_default_diffusion物化为 stage 配置。4.3 发送请求客户端为 examples/online_serving/lance/openai_chat_client.py与 BAGEL 共用同一套 OpenAI 消息格式与modalities/num_inference_steps/seed/height/width旋钮# 文生图 python examples/online_serving/lance/openai_chat_client.py \ --prompt A cute corgi astronaut on the moon, cinematic \ --modality text2img --output corgi.png # 图像编辑 python examples/online_serving/lance/openai_chat_client.py \ --prompt Convert this into a vibrant cartoon-style illustration \ --modality img2img --image-url path/to/photo.png \ --output edited.png # 图像理解 python examples/online_serving/lance/openai_chat_client.py \ --prompt Describe this image \ --modality img2text --image-url photo.jpg客户端实现要点源码可见提示词以|im_start|prompt|im_end|包裹本地图片自动 base64 编码为data:image/jpeg;base64,...远程 URL 直接透传modalities字段置于 payload 顶层[image]或[text]num_inference_steps、seed、height、width、negative_prompt同样置于顶层——注释明确说明 vLLM 会忽略extra_body参数必须直接放在 payload 中响应解析先遍历所有choices查找image_url类型的图像输出base64 解码落盘再回退提取文本输出理解任务客户端默认参数--height/--width 512、--steps 25、--seed 42若需要与离线推理默认一致请显式传--steps 30 --height 1024 --width 1024。五、验证与测试在线服务的端到端验证可直接运行仓库测试pytest -s -v tests/e2e/online_serving/test_lance.py该测试tests/e2e/online_serving/test_lance.py验证test_lance_text2img_onlinetext2img 请求经 OpenAI 兼容 API 返回 base64 图像test_lance_img2img_onlineimg2img 请求渲染image_edit提示词 base64 图像消息返回编辑后图像。测试内部使用render_lance_prompt构造与上游一致的提示词并显式设置VLLM_WORKER_MULTIPROC_METHODspawnstage_init_timeout300秒。注意测试标有hardware_test标记需要真实 GPU 环境。六、实现原理与位置编码细节6.1 三处特化 vs BAGEL 复用vllm_omni/diffusion/models/lance/lance_transformer.py 承载了模型层特化LanceBagel继承 BAGEL 的vae2llm/llm2vae/time_embedder/latent_pos_embed连接器布局仅调整模型构建LanceQwen2_5_VLNaViTWrapperLanceZeroVitPosEmbed接入 Qwen2.5-VL 视觉塔使用 Qwen2-VL 图像处理器 no-op 连接器 /vit_pos_embedLanceIdentityConnector身份连接器LancePositionEmbedding3D3-D 潜在位置嵌入视频路径LanceWanVAEwan_vae.py封装 Wan2.2 VAE含decode_video多帧解码路径。6.2 mRoPE 位置编码rope_scaling {type: mrope, mrope_section: [16, 24, 24]}通过BagelRotaryEmbedding贯通BagelRotaryEmbedding现在会按rope_type自动分派text2img 使用标量位置 id与 BAGEL 等价img2text / video / 编辑路径按轴传递 3-D 位置 idper-axis 3-D position ids。从 pipeline_lance.py 的构建逻辑看若 LLM config 未带rope_scaling会写入默认值{rope_type: mrope, mrope_section: [16, 24, 24]}。图像版latent_pos_embed形状为(4096, 2048)对应max_latent_size 64视频版为(126976, 2048)对应max_num_frames × max_latent_size²。6.3 已知限制与注意事项按仓库文档与源码记录以下事实需在实操中留意video_edit 在同等分辨率下质量偏抽象不如 text2video已知存在 VAE-prefill 与 gen-latent 块之间的 position-id 偏移问题但功能上端到端正确理解路径的贪心 EOS 问题务必使用默认采样温度 0.8否则可能得到空输出flash attention 更贴近上游数值离线脚本默认设置DIFFUSION_ATTENTION_BACKENDFLASH_ATTN上游使用flash_attn_varlen_funcSDPA 在 36 层 Qwen2 栈上会积累约 5 倍数值漂移B300 上尤为明显除非显式指定其他后端两阶段 AR DiT 拓扑暂未接入当前仅单阶段管线可用视频路径务必使用Lance_3B_Video子检查点否则 3-D 位置表缺失会导致越界错误HuggingFace 仓库已捆绑全部子检查点Lance_3B/、Lance_3B_Video/、Qwen2.5-VL-ViT/、Wan2.2_VAE.pth无需单独下载。七、快速参考常用参数一览参数默认值说明--modalitytext2imgtext2img/img2text/text2video/video2text/img2img/video2video/image2video--steps30去噪步数上游默认--cfg-text-scale4.0文本 CFG 强度--timestep-shift3.5Flow-match 时间步偏移--seed42随机种子--height/--width1024×1024图像分辨率t2i--num-frames25视频 RGB 帧数上限 121--video-height/--video-width480×768视频分辨率--fps12输出 MP4 帧率与上游save_fps12一致--max-text-tokens512理解路径最大生成 token 数--do-sample/--no-sample采样开理解路径采样开关贪心易触发即时 EOS--text-temperature0.8理解路径采样温度--system-prompt无覆盖任务系统提示词问答场景必用--negative-prompt无负向提示词--txt-prompts无从文件逐行读取提示词八、相关资源索引Recipe 文档recipes/ByteDance/Lance.md离线推理示例examples/offline_inference/lance/end2end.py、README、gradio_demo.py在线服务示例examples/online_serving/lance/run_server.sh、openai_chat_client.py、README部署配置vllm_omni/deploy/lance.yaml管线实现pipeline_lance.py、lance_transformer.py、prompts.py、wan_vae.pyE2E 测试tests/e2e/online_serving/test_lance.py【免费下载链接】vllm-omniA framework for efficient model inference with omni-modality models项目地址: https://gitcode.com/GitHub_Trending/vl/vllm-omni创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考