Skip to content

Commit 426be16

Browse files
committed
apply autotuner fix
中文:应用 AutoTuner non-Tensor 输入保护修复。
1 parent 2aba6ed commit 426be16

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

benchmarks/single_node/fixed_seq_len/minimaxm3_fp4_b300.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#
88
# At runtime the recipe swaps the image's FlashInfer for the first pinned
99
# nightly containing the upstream SM100 low-M MXFP8 split-K kernel
10-
# (flashinfer-ai/flashinfer#3847).
10+
# (flashinfer-ai/flashinfer#3847), then backports the AutoTuner non-Tensor guard
11+
# fix from flashinfer-ai/flashinfer#3918.
1112

1213
source "$(dirname "$0")/../../benchmark_lib.sh"
1314

@@ -23,7 +24,7 @@ check_env_vars \
2324
RANDOM_RANGE_RATIO \
2425
RESULT_FILENAME
2526

26-
# --- FlashInfer nightly ------------------------------------------------------
27+
# --- FlashInfer nightly + AutoTuner non-Tensor guard patch ------------------
2728
FLASHINFER_VERSION=0.6.15.dev20260710
2829
FLASHINFER_NIGHTLY_TAG=nightly-v0.6.15-20260710
2930
FLASHINFER_RELEASE_URL="https://github.com/flashinfer-ai/flashinfer/releases/download/${FLASHINFER_NIGHTLY_TAG}"
@@ -36,6 +37,20 @@ python3 -m pip install \
3637
"${FLASHINFER_RELEASE_URL}/flashinfer_jit_cache-${FLASHINFER_VERSION}+cu130-cp39-abi3-manylinux_2_28_$(uname -m).whl" \
3738
|| { echo "FlashInfer nightly install failed" >&2; exit 1; }
3839

40+
# The pinned nightly predates flashinfer-ai/flashinfer#3918. Apply only its
41+
# runtime fix; the upstream test change is intentionally not backported.
42+
FLASHINFER_PATCH="$(dirname "$0")/patches/flashinfer-autotuner-non-tensor-guard.patch"
43+
if ! command -v patch >/dev/null 2>&1; then
44+
apt-get update -y && apt-get install -y --no-install-recommends patch \
45+
|| { echo "Failed to install patch(1)" >&2; exit 1; }
46+
fi
47+
SITE_PACKAGES=$(dirname "$(python3 -c "import importlib.util; print(importlib.util.find_spec('flashinfer').submodule_search_locations[0])")") \
48+
|| { echo "Could not locate the installed flashinfer package" >&2; exit 1; }
49+
patch --dry-run -p1 -d "${SITE_PACKAGES}" < "${FLASHINFER_PATCH}" >/dev/null \
50+
|| { echo "FlashInfer AutoTuner non-Tensor guard patch does not apply" >&2; exit 1; }
51+
patch -p1 -d "${SITE_PACKAGES}" < "${FLASHINFER_PATCH}" \
52+
|| { echo "FlashInfer AutoTuner non-Tensor guard patch failed" >&2; exit 1; }
53+
3954
# -----------------------------------------------------------------------------
4055

4156
if [[ -n "${MODEL_PATH:-}" ]]; then
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
diff --git a/flashinfer/autotuner/autotuner.py b/flashinfer/autotuner/autotuner.py
2+
index 54b90a0..76443ca 100644
3+
--- a/flashinfer/autotuner/autotuner.py
4+
+++ b/flashinfer/autotuner/autotuner.py
5+
@@ -2074,14 +2074,19 @@ class AutoTuner:
6+
def _prepare_input_tensors_with_batches(
7+
self,
8+
- inputs: list[torch.Tensor],
9+
+ inputs: list[Any],
10+
tuning_config: TuningConfig,
11+
- ) -> list[list[torch.Tensor]]:
12+
+ ) -> list[list[Any]]:
13+
"""Create multiple input copies to flush the L2 cache between profiling iterations."""
14+
if not tuning_config.use_cold_l2_cache:
15+
return [inputs]
16+
17+
- one_buffer_bytes = sum(input.numel() * input.element_size() for input in inputs)
18+
+ one_buffer_bytes = sum(
19+
+ input.numel() * input.element_size()
20+
+ if isinstance(input, torch.Tensor)
21+
+ else 0
22+
+ for input in inputs
23+
+ )
24+
if one_buffer_bytes <= 0:
25+
logger.debug(
26+
"[Autotuner] No tensor inputs or zero-sized tensors; falling back to single-batch profiling."
27+
)
28+
@@ -2093,7 +2098,9 @@ class AutoTuner:
29+
30+
inputs_list = [inputs]
31+
for _ in range(num_buffers - 1):
32+
- inputs_list.append(list(t.clone() for t in inputs))
33+
+ inputs_list.append(
34+
+ [t.clone() if isinstance(t, torch.Tensor) else t for t in inputs]
35+
+ )
36+
37+
logger.debug(
38+
f"[Autotuner] use_cold_l2_cache={tuning_config.use_cold_l2_cache}, use {num_buffers} different tensors for profiling"

0 commit comments

Comments
 (0)