Files
vLLM/vllm/triton_utils/force_first_config.py
MOVZXandHinata 61fbe0b865 [Mini-VLLM] Remove unreferenced definitions found by static scan
A symbol scan over every tracked file found 123 top-level definitions in
vllm/ with zero references, including references inside strings. All of
them came from features this fork deleted earlier.

- Delete dead attention helpers: MLADCPManager, split_prefill_chunks, the
  reshape helpers, compute_varlen_chunk_metadata, the LINEAR backend's
  unused BailingLinearAttentionBackend, and the sparse flash-attn entry
  points.
- Delete the CPU and AMX op wrappers from _custom_ops.py: cpu_mla_decode,
  cpu_mla_extend, cpu_mla_get_scheduler_metadata,
  gather_mla_context_cache_cpu.
- Delete dead quantization helpers: awq_pack, gptq_pack,
  gptq_quantize_weights, get_and_maybe_dequant_weights,
  marlin_quant_fp8_torch, the rand_marlin_weight_*_like pair,
  ocp_mx_weight_dtype_and_rows, get_fp8_block_weight_scale,
  input_to_float8.
- Delete dead model helpers: resolve_visual_encoder_outputs,
  run_dp_sharded_vision_model, fast_topk, get_layer_index,
  is_pp_missing_parameter, skip_spec_layers, KimiK3MergedQKVGateLinear,
  selective_scan_fn, causal_conv1d_update_torch.
- Delete dead utils: format_kib, format_mib, chunk_list, prev_power_of_2,
  split_host_port, join_host_port, make_zmq_path, make_async_with_semaphore,
  is_meta_module, is_non_overlapping_and_dense, supports_xpu_graph,
  create_kv_caches_with_random*, and the unused has_* capability probes.
- Delete the unreachable deep-gemm mega-MoE warmup path, which imported
  vllm.models.deepseek_v4.nvidia.model and vllm.models.kimi_k3.nvidia.model,
  neither of which exists anymore.
- Drop the imports and the two now-empty guards left behind.

Verified statically: every changed file compiles, no unused import
remains, and no deleted name is referenced in vllm, tests or csrc. The
runtime gates still need the Python environment rebuilt.

Co-authored-by: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
2026-10-19 21:39:56 +07:00

88 lines
3.1 KiB
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Skip Triton autotuning under VLLM_TRITON_FORCE_FIRST_CONFIG."""
from vllm.logger import init_logger
from vllm.triton_utils.importing import HAS_TRITON
logger = init_logger(__name__)
_installed: bool = False
def install() -> None:
"""Install the Autotuner.run replacement."""
global _installed
if _installed:
return
if not HAS_TRITON:
return
import importlib
autotuner_mod = importlib.import_module("triton.runtime.autotuner")
Autotuner = autotuner_mod.Autotuner
from triton.compiler.errors import CompileTimeAssertionFailure
from triton.runtime.errors import OutOfResources, PTXASError
_invalid_config_errors = (OutOfResources, CompileTimeAssertionFailure, PTXASError)
_picked_cache: dict[tuple, int] = {}
seen_kernels: set[str] = set()
def _run_first_valid_config(self, *args, **kwargs):
if not self.configs:
return self.fn(*args, **kwargs)
key_vals = tuple(kwargs[name] for name in self.keys if name in kwargs)
cache_key = (id(self), key_vals)
kernel_name = getattr(self.base_fn, "__name__", repr(self.fn))
cached_idx = _picked_cache.get(cache_key)
candidate_indices = (
[cached_idx] if cached_idx is not None else list(range(len(self.configs)))
)
last_exc: Exception | None = None
for idx in candidate_indices:
config = self.configs[idx]
if config.pre_hook is not None:
full_nargs = {
**dict(zip(self.arg_names, args)),
**kwargs,
**config.all_kwargs(),
}
config.pre_hook(full_nargs)
# Prefer self.fn.run(...) — the kernel-launch entrypoint for both
# JITFunction and Heuristics. Calling JITFunction(...) directly
# raises "Cannot call @triton.jit'd outside of the scope of a
# kernel". Fall back to plain call only if .run is missing.
launch = getattr(self.fn, "run", self.fn)
try:
result = launch(*args, **kwargs, **config.all_kwargs())
except _invalid_config_errors as e:
last_exc = e
continue
if cached_idx is None:
_picked_cache[cache_key] = idx
self.best_config = config
if kernel_name not in seen_kernels:
seen_kernels.add(kernel_name)
logger.info(
"[triton-autotune-disabled] kernel=%s configs=%d "
"picked_index=%d picked=%s",
kernel_name,
len(self.configs),
idx,
config,
)
return result
raise RuntimeError(
f"No valid config for kernel "
f"{kernel_name} key={key_vals} (tried {len(self.configs)} configs)"
) from last_exc
Autotuner.run = _run_first_valid_config
_installed = True