Prhub

#47329 [Refactor] Remove multiple dead code

原始 PR 作者 yewentao256 合并时间 2026-07-06 22:54 文件变更 7 提交数 2 评论 0 代码增减 +0 / -186

执行摘要

删除 7 个文件中的未使用函数和类,减少 186 行代码

PR 标题及描述明确为移除死代码(Remove multiple dead code),旨在清理项目中不再使用但仍保留的函数、类和枚举,减少代码体积与后续维护负担。

这是一次标准且安全的死代码清理,值得合入。建议团队定期运行此类清理,并配合扫码工具(如 vulture)自动检测未使用代码。

讨论亮点

该 PR 未产生实质性人工 review 讨论。两位审核者 tlrmchlsmth 和 mgoin 均直接批准(APPROVED),无异议。

实现拆解

按模块划分:

  1. 量化工具函数:在 int8_utils.py 中删除了 apply_w8a8_block_int8_linear 和 input_to_int8 两个函数,它们分别用于 block-wise INT8 线性层前向和 tensor-wise 量化;在 marlin_utils.py 中删除了 apply_awq_marlin_linear,该函数是 AWQ-Marlin 融合线性前向的入口;在 machete_utils.py 中删除了 query_machete_supported_act_types,该函数仅返回 [torch.float16, torch.bfloat16],已无调用者。
  2. FlashInfer MoE 后端枚举:在 flashinfer_utils.py 中删除了 FlashinferMoeBackend 枚举类(定义 CUTLASS、TENSORRT_LLM、CUTEDSL 三种后端)和 is_flashinfer_supporting_global_sf 辅助函数,同时移除不再需要的 from enum import Enum 导入。
  3. Helion kernel 配置管理器:在 config_manager.py 中删除了 ConfigSet.has_config 方法和 ConfigManager.config_exists 方法,前者检查 ConfigSet 内指定平台和键是否存在,后者通过文件读取检查磁盘配置;这些查询逻辑已不被使用。
  4. LayerNormGated 类:在 layernorm_guard.py 中删除了 LayerNormGated 类及其全部方法(__init__、reset_parameters、forward),该类实现带门控的归一化,但当前项目已改用 RMSNormGated。
  5. 构建文件:在 CMakeLists.txt 中删除了 1 行无意义的注释或空行。

所有删除均未引入新的代码,且仓库全局搜索确认这些符号无任何引用,属于安全的死代码清理。

文件 模块 状态 重要度
vllm/model_executor/layers/quantization/utils/int8_utils.py 量化工具 modified 6.57
vllm/model_executor/layers/quantization/utils/marlin_utils.py 量化工具 modified 6.55
vllm/model_executor/layers/quantization/utils/flashinfer_utils.py 量化工具 modified 5.98
vllm/kernels/helion/config_manager.py Helion 配置 modified 5.77
vllm/model_executor/layers/fla/ops/layernorm_guard.py 归一化层 modified 5.5
vllm/model_executor/layers/quantization/utils/machete_utils.py 量化工具 modified 4.48
CMakeLists.txt 构建脚本 modified 0.78

关键符号

apply_w8a8_block_int8_linear input_to_int8 apply_awq_marlin_linear FlashinferMoeBackend is_flashinfer_supporting_global_sf has_config config_exists LayerNormGated query_machete_supported_act_types

关键源码片段

vllm/model_executor/layers/quantization/utils/int8_utils.py data-contract

删除了两个量化函数 `apply_w8a8_block_int8_linear` 和 `input_to_int8`,共 37 行,是该 PR 中单文件删除量最大的文件。

# 以下两个函数被删除,因为它们在仓库中已无任何调用者
​
def apply_w8a8_block_int8_linear(
    input: torch.Tensor,
    weight: torch.Tensor,
    block_size: list[int],
    weight_scale: torch.Tensor,
    input_scale: torch.Tensor | None = None,
    bias: torch.Tensor | None = None,
) -> torch.Tensor:
    # assert input_scale is None
    # 将输入视为 2D 矩阵
    input_2d = input.view(-1, input.shape[-1])
    output_shape = [*input.shape[:-1], weight.shape[0]]
​
    # 对每个 token 组进行 INT8 量化
    q_input, x_scale = per_token_group_quant_int8(input_2d, block_size[1])
    # 执行 W8A8 块量化矩阵乘法
    output = w8a8_block_int8_matmul(
        q_input, weight, x_scale, weight_scale, block_size, output_dtype=input.dtype
    )
​
    if bias is not None:
        output = output + bias
    return output.to(dtype=input.dtype).view(*output_shape)
​
​
def input_to_int8(
    x: torch.Tensor, dtype: torch.dtype = torch.int8
) -> tuple[torch.Tensor, torch.Tensor]:
    """对输入进行 tensor 级别 INT8 量化,返回量化后的 tensor 和 scale。"""
    iinfo = torch.iinfo(dtype)
    min_val, max_val = x.aminmax()
    amax = torch.maximum(min_val.abs(), max_val.abs()).clamp(min=1e-12)
    int8_min, int8_max = iinfo.min, iinfo.max
    scale = int8_max / amax
    x_scl_sat = (x * scale).clamp(min=int8_min, max=int8_max)
    return x_scl_sat.to(dtype).contiguous(), scale.float().reciprocal()

评论区精华

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

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

风险与影响

风险极低。被删除的每个函数/类均在全仓库范围无引用,不存在调用路径。删除后不会影响任何现有功能。但建议将本次删除与后续可能的 quantization 重构或 Helion 配置升级保持同步,避免因代码丢弃导致未来需要时重新实现。

对用户无任何行为性影响。对开发团队而言,代码库体积减小 186 行,减少了不必要的依赖关系和阅读障碍。对系统性能无影响。

删除死代码 低风险

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论