Skip to content

fix(instrumentor): skip meta-var injection in Triton-decorated functions - #9

Merged
Jayden-Xu merged 1 commit into
OrderLab:mainfrom
Jayden-Xu:fix/skip-triton-meta
Nov 15, 2026
Merged

Jayden-Xu merged 1 commit into
OrderLab:mainfrom
Jayden-Xu:fix/skip-triton-meta

Conversation

@Jayden-Xu

Copy link
Copy Markdown
Collaborator

Problem

auto_meta_var_injector.py inserts update_meta(...) after every assignment to a
DEFAULT_META_VARS name in every function of an instrumented file, including Triton kernels.
Triton cannot compile calls to arbitrary Python functions, so a kernel line such as vLLM's
batch_idx = tl.program_id(0) fails with
RuntimeError: Unsupported function referenced: <function update_meta ...>, and the instrumented
program cannot run even in eager mode. trace_robust.py always passes meta_var_names=None,
so this cannot be turned off from the official flow.

Fix

  • Do not descend into any function with a Triton decorator: visit_FunctionDef returns False,
    so the body and nested functions are skipped.
  • A decorator counts as Triton if, after resolving import aliases collected from the whole module,
    any dotted segment equals triton. This covers @triton.jit(...), autotune, heuristics,
    stacked decorators, from triton import jit as tjit, import triton as tr,
    from triton import *, and re-exports such as vLLM's from vllm.triton_utils import triton.
  • The rule is static and deterministic. Meta values are part of the alignment key, so the same
    source must always be instrumented the same way.
  • It errs toward skipping: wrongly skipping a function only loses its meta values, while missing a
    kernel breaks compilation.
  • instrument_file_auto_meta_vars reports the number of skipped functions in a new
    skipped_functions field; existing fields are unchanged.

Testing

  • New tests/test_auto_meta_var_injector.py (29 tests): 23 fail on 339e225 and all pass with this
    change, including a GPU smoke test that compiles and launches a real kernel
    (RTX 3090, torch 2.13, triton 3.7.1).
  • Differential check (static, no imports): ran the injector at 339e225 and with this change over
    all 2879 vLLM files plus OpGuard's own examples/ and tests/. The only differences are inside
    Triton-decorated functions (46 → 0 injections there); injections outside them are unchanged
    (116 → 116 in vLLM, per file and in total), and files whose only injections were in kernels are
    now left byte-identical.
  • The CONTRIBUTING.md pytest suites: 95 passed. Harness unittests: 47 OK.

Out of scope

  • 35 @cute.jit (CuTe DSL) functions in vLLM are still injected. This is the same class of
    problem; a follow-up can extend the rule to other JIT decorators (including torch.jit.script).
  • Non-decorator wrapping such as kernel = triton.jit(fn) is not detected.
  • tests/test_instrumentor.py, tests/test_meta_vars.py and tests/test_trace_with_meta.py
    already fail on main due to stale imports, independently of this change.

@Jayden-Xu
Jayden-Xu merged commit 74b6807 into OrderLab:main Nov 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant