Skip to content

fix(thirdparty/triton_kernels): tolerate upstream module rename#277

Closed
qywu wants to merge 1 commit into
mainfrom
fix/triton-kernels-import-compat
Closed

fix(thirdparty/triton_kernels): tolerate upstream module rename#277
qywu wants to merge 1 commit into
mainfrom
fix/triton-kernels-import-compat

Conversation

@qywu
Copy link
Copy Markdown
Collaborator

@qywu qywu commented May 27, 2026

Summary

tokenspeed_kernel/thirdparty/triton_kernels/__init__.py pre-imports a list of triton_kernels submodules under the redirected-triton context. The pre-imports were unconditional, so any naming difference between the locally-installed triton_kernels and the names hard-coded here broke every downstream tokenspeed.runtime import with:

ModuleNotFoundError: No module named 'triton_kernels.matmul'

Upstream openai/triton's triton_kernels renamed matmulmatmul_ogs (and matmul_detailsmatmul_ogs_details) at some point between 0.x and 1.x. PyPI's triton_kernels==0.1.0 already has the new layout; older builds shipped through other channels still have the old layout.

Real call sites in tokenspeed_kernel/ops/moe/triton_kernels.py already guard their actual usages with try/except ImportError, so the only thing actually broken was the eager pre-import.

Change

Wrap each __import__ individually. List both naming conventions so either flavour of the installed package works.

Test plan

  • python -c "from tokenspeed.runtime.entrypoints.engine import Engine" succeeds against the new layout (triton_kernels==0.1.0 PyPI build, has matmul_ogs). ✅ verified locally.
  • Same against an older install that still has matmul (will still work via the first half of the alternation list).
  • MoE path that depends on triton_kernels.matmul_ogs is unaffected (no behaviour change to call sites, only to the pre-import shim).

Related

Encountered while verifying #272 / #273 / #274 / #275 end-to-end on H100.

Older releases of upstream openai/triton's ``triton_kernels`` package
shipped ``matmul`` and ``matmul_details``; newer releases (currently the
one resolved when ``pip install triton_kernels`` runs against PyPI's
``triton_kernels==0.1.0``, and other channels' newer 1.x builds) rename
them to ``matmul_ogs`` / ``matmul_ogs_details``.

The unconditional pre-imports in this shim's ``__init__`` raised
``ModuleNotFoundError: No module named 'triton_kernels.matmul'`` whenever
the installed package only had the new layout, breaking every downstream
import of ``tokenspeed.runtime`` even though the actual consumers in
``tokenspeed_kernel.ops.moe.triton_kernels`` already guard their usages
with ``try/except ImportError`` fallbacks.

Wrap each submodule import individually so a missing one no longer breaks
the chain. The list covers both naming conventions so either flavour of
the installed package works.

Signed-off-by: Qingyang Wu <willqywu@gmail.com>
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