执行摘要
重构 LTX2.3 代码,清理冗余逻辑并统一接口。
PR body 未提供具体动机,但从标题和变更内容推断,旨在清理 LTX2.3 相关代码,减少冗余、统一接口并改进结构,属于常规维护性重构。
建议核心开发人员精读 ltx_2_denoising.py 和 ltx_2_pipeline.py,关注数据类设计和 LoRA 切换重构,这些设计决策有助于提升模块化和可测试性。
无 review 评论,变更由作者直接合并,表明团队内部可能已达成共识或变更较小。
PR body 未提供具体动机,但从标题和变更内容推断,旨在清理 LTX2.3 相关代码,减少冗余、统一接口并改进结构,属于常规维护性重构。
建议核心开发人员精读 ltx_2_denoising.py 和 ltx_2_pipeline.py,关注数据类设计和 LoRA 切换重构,这些设计决策有助于提升模块化和可测试性。
无 review 评论,变更由作者直接合并,表明团队内部可能已达成共识或变更较小。
ltx_2_denoising.py 中移除了 init_logger 导入,改为从 server_args 导入 is_ltx2_two_stage_pipeline_name,简化依赖关系。LTX2ModelInputs 和 LTX2GuidancePassSpec 数据类,集中管理去噪阶段的输入参数和引导配置,提高代码可读性。ltx_2_pipeline.py 中,将 switch_lora_phase 方法拆分为 _can_short_circuit_lora_switch 和 _build_lora_switch_spec,使逻辑更模块化并便于测试。server_args.py 中添加 is_ltx2_two_stage_pipeline_name 函数和 _is_ltx23_two_stage_pipeline 方法,替代硬编码字符串比较,增强可维护性。denoising_av.py 和 latent_preparation_av.py 以使用新接口,并更新 perf_baselines.json 测试基准数据,确保测试覆盖。| 文件 | 模块 | 状态 | 重要度 |
|---|---|---|---|
python/sglang/multimodal_gen/runtime/pipelines_core/stages/ltx_2_denoising.py |
多模态生成 | modified | 8.86 |
python/sglang/multimodal_gen/runtime/pipelines/ltx_2_pipeline.py |
多模态生成 | modified | 7.98 |
python/sglang/multimodal_gen/runtime/server_args.py |
多模态生成 | modified | 6.71 |
python/sglang/multimodal_gen/runtime/pipelines_core/stages/denoising_av.py |
多模态生成 | modified | 6.03 |
python/sglang/multimodal_gen/runtime/pipelines_core/stages/latent_preparation_av.py |
多模态生成 | modified | 5.21 |
python/sglang/multimodal_gen/test/server/perf_baselines.json |
性能基准 | modified | 4.3 |
python/sglang/multimodal_gen/runtime/pipelines_core/stages/ltx_2_denoising.py
dependency-wiring
核心去噪阶段实现,新增数据类并调整逻辑,影响扩散模型推理路径。
@dataclass(slots=True)
class LTX2ModelInputs:
"""统一封装 LTX-2 模型的输入参数,用于去噪阶段。"""
latent_model_input: torch.Tensor # 视频潜在表示输入
audio_latent_model_input: torch.Tensor # 音频潜在表示输入
audio_num_frames_latent: int # 音频潜在帧数
video_coords: torch.Tensor | None # 视频坐标(可选)
audio_coords: torch.Tensor | None # 音频坐标(可选)
timestep_video: torch.Tensor # 视频去噪时间步
timestep_audio: torch.Tensor # 音频去噪时间步
prompt_timestep_video: torch.Tensor | None # 视频提示时间步(可选)
prompt_timestep_audio: torch.Tensor | None # 音频提示时间步(可选)
video_self_attention_mask: torch.Tensor | None # 视频自注意力掩码
audio_self_attention_mask: torch.Tensor | None # 音频自注意力掩码
a2v_cross_attention_mask: torch.Tensor | None # 音频到视频交叉注意力掩码
v2a_cross_attention_mask: torch.Tensor | None # 视频到音频交叉注意力掩码
@dataclass(slots=True)
class LTX2GuidancePassSpec:
"""定义引导传递的配置,支持跳过特定注意力块以优化计算。"""
name: str # 引导传递名称
encoder_hidden_states: torch.Tensor # 编码器隐藏状态
audio_encoder_hidden_states: torch.Tensor # 音频编码器隐藏状态
encoder_attention_mask: torch.Tensor | None # 编码器注意力掩码(可选)
skip_video_self_attn_blocks: tuple[int, ...] = () # 跳过的视频自注意力块索引
skip_audio_self_attn_blocks: tuple[int, ...] = () # 跳过的音频自注意力块索引
disable_a2v_cross_attn: bool = False # 禁用音频到视频交叉注意力
disable_v2a_cross_attn: bool = False # 禁用视频到音频交叉注意力
当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。
风险较低,主要为回归风险:重构涉及核心去噪和管道逻辑(如 ltx_2_denoising.py 和 ltx_2_pipeline.py),但变更主要是结构优化而非行为修改。需注意 _should_shard_ltx23_legacy_one_stage_audio_latents 等方法被移除,可能影响分布式 sharding 逻辑,但已通过其他方式集成。
对用户无直接影响,属于内部代码改进。对系统:提升代码可读性和可维护性,可能减少未来 bug。对团队:简化 LTX2.3 相关代码的维护工作,便于后续扩展。
当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。
参与讨论