Prhub

#49745 [Refactor] Remove dead code in multiple files

原始 PR 作者 yewentao256 合并时间 2026-07-28 03:58 文件变更 22 提交数 3 评论 0 代码增减 +0 / -519

执行摘要

删除 22 个文件中 519 行未使用代码

仓库中存在大量不再被调用的私有方法和冗余导入,增加了代码阅读和维护负担。本 PR 系统性识别并移除这些死代码,提升代码库整洁度。

建议精读涉及的核心文件(如 minimax_m3.pyradio.pymodelopt.py)以了解仓库中废弃代码的典型模式,并作为后续清理工作的参考。

讨论亮点

无实质性 review 讨论。sfeng33 直接批准,claude[bot] 自动评论未触发人工深入审核。

实现拆解

  1. 识别死代码:逐个文件检查未被引用的私有方法(如 _prune_video_tokens_load_embed_shuffle_weights_for_trtllm 等)和不再需要的 import。
  2. 删除函数定义:移除这些方法及其内部辅助函数,同时清理相关的 import 语句(例如移除 regexswap_w13_to_w31defaultdict 等)。
  3. 调整模块结构:部分文件删除后,后续类和方法的层次自然收紧(如 minimax_m3.py__init__ 后直接 __call__)。
  4. 保留接口:所有删除的函数均未在仓库剩余代码中有任何引用点,保证不会破坏现有逻辑。无测试变更。
文件 模块 状态 重要度
vllm/transformers_utils/processors/minimax_m3.py 处理器 modified 8.12
vllm/model_executor/models/radio.py 视觉模型 modified 7.86
vllm/model_executor/layers/quantization/modelopt.py 量化层 modified 7.83
vllm/model_executor/models/qwen3_omni_moe_thinker.py MoE 模型 modified 7.51
vllm/model_executor/models/hyperclovax_vision.py 视觉模型 modified 7.33
vllm/model_executor/models/idefics3.py 视觉模型 modified 7.19

关键符号

_prune_video_tokens is_timestamp extract_timestamp _load_embed _load_projection _shuffle_weights_for_trtllm _get_raw_input_ids _prepare_multimodal_kwargs _get_resize_output_image_size _rope_scaling_validation _prepare_attention_mask _safe_get_token_id _safe_get_token_str _copy_missing_attrs _e2m1_lookup _pop_unallowed_keys_and_warn

关键源码片段

vllm/transformers_utils/processors/minimax_m3.py dependency-wiring

移除视频令牌修剪函数 _prune_video_tokens 及其内部辅助函数 is_timestamp/extract_timestamp,同时清理 regex 导入,是本次删除量最大的文件(80 行)。

# 删除 _prune_video_tokens 后,__init__ 方法直接衔接 __call__ 方法
class MiniMaxM3VLProcessor(ProcessorMixin):
    # ... __init__ 方法(裁剪后)
    def __init__(self, image_processor=None, tokenizer=None, video_processor=None, **kwargs):
        self.image_token_id = tokenizer.convert_tokens_to_ids(self.IMAGE_TOKEN)
        self.video_token_id = tokenizer.convert_tokens_to_ids(self.VIDEO_TOKEN)
        super().__init__(image_processor, tokenizer, video_processor)
        self.vision_start_token_id = tokenizer.convert_tokens_to_ids(
            self.VISION_START_TOKEN
        )
        self.vision_end_token_id = tokenizer.convert_tokens_to_ids(
            self.VISION_END_TOKEN
        )
​
    def __call__(self, images=None, text=None, videos=None, **kwargs):
        # 原先此处有 _prune_video_tokens 方法定义,现已清除
        # 方法体直接处理输入
        ...
vllm/model_executor/models/radio.py data-contract

移除嵌入投影加载方法 _load_embed 和 _load_projection,简化 RADIO 视觉模型类。

# 删除 _load_embed 和 _load_projection 后,属性之后直接是 embed_patches 方法
class RADIOPatchEmbeddings(nn.Module):
    @property
    def num_skip(self):
        return self.num_cls_tokens + self.num_registers
​
    # 原先 _load_embed 和 _load_projection 定义在此
    def embed_patches(self, x: torch.Tensor) -> torch.Tensor:
        patches = self.im_to_patches(x)
        patches = self.embedder(patches)
        return patches
vllm/model_executor/layers/quantization/modelopt.py data-contract

移除 TRTLLM 权重重排方法 _shuffle_weights_for_trtllm 并清理关联导入(swap_w13_to_w31),涉及 MXFP8 的废弃路径。

# 删除 _shuffle_weights_for_trtllm 后,_check_weight_dtypes 后直接是新方法 _dequant_mxfp8_weights_to_bf16
class ModeloptFp8Config(QuantizationConfig):
    @staticmethod
    def _check_weight_dtypes(layer: torch.nn.Module) -> None:
        # ... 验证逻辑
​
    # 原先 _shuffle_weights_for_trtllm 定义在此(约 90 行),现已移除
    def _dequant_mxfp8_weights_to_bf16(self, layer: RoutedExperts) -> None:
        """One-time MXFP8->BF16 weight dequant for the emulation path."""
        ...

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

极低风险。所有删除的函数均通过全局搜索确认无外部调用点,且模块单元测试持续通过。唯一潜在风险是极少数间接动态引用(如 getattr)未覆盖,但鉴于这些函数均为私有方法且命名不通用,概率很小。

对用户无功能影响,对系统无性能变化。显著减少代码行数,提升可维护性和可读性,尤其对后续开发者降低困惑。

低风险 无功能变更 误删可能低

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论