Skip to content

Add BLAS dispatches and Dot-based lowering for the JIT backend - #2406

Open
jessegrabowski wants to merge 10 commits into
pymc-devs:mainfrom
jessegrabowski:numba-blas-gemm-ger
Open

Add BLAS dispatches and Dot-based lowering for the JIT backend#2406
jessegrabowski wants to merge 10 commits into
pymc-devs:mainfrom
jessegrabowski:numba-blas-gemm-ger

Conversation

@jessegrabowski

Copy link
Copy Markdown
Member

All of this measures netural against pymc-model-catalog. I saw 10-15% speedup in the backward pass of linear layers in pytensor-ml. Rewriting graphs of the form a + B @ C into GEMM isn't perfect, it still requires the user to put parenthesis. We can try to tune it up in follow-up work, but it's not super clear to me it's an obvious win.

Introduce the singledispatch c_funcify registry returning detached CImpl
implementations, resolve CLinker through it, and route OpWiseCLinker, the
VM, and DebugMode to the dispatched C thunk with a Python fallback.
The deleted make_c_gemv_destructive also duplicated a shared AllocEmpty so each Gemv could destroy its own buffer, so test_multiple_inplace fails until the generic replacement lands two commits later.
Without this the rewrite that introduces Ger regresses against the elemwise it replaces, since numba falls back to object mode for it.
Copying the accumulator in and letting BLAS scale it on top touches the output twice, which cost more than the elemwise dot-and-add these ops replace.
@jessegrabowski jessegrabowski added enhancement New feature or request linalg Linear algebra labels Sep 2, 2026
@jessegrabowski jessegrabowski changed the title dd BLAS dispatches and Dot-based lowering for the JIT backe Add BLAS dispatches and Dot-based lowering for the JIT backend Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request linalg Linear algebra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant