pymc-devs / pymc-devs/pytensor

Remove BatchedDot and provide C implementation for batched matmul that uses numpy C-API

Open
#1,357 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-backend vectorization
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

Description

Numpy has this function we can probably use for the Blockwise of Dot (Matmul) https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_MatrixProduct2 to replace

This also makes the BatchedOp redundant, so we can save a lot of code: https://github.com/pymc-devs/pytensor/blob/f10a6036ab0c24149565f469946d46f4d4922672/pytensor/tensor/blas.py#L1314-L1711

Including some rewrites that try to introduce it. May want to have a look at https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_InnerProduct for the respective Blockwise Dot

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pytensor/tensor/blas.py, especially the BatchedOp code at lines 1314–1711, then read NumPy's PyArray_MatrixProduct2 and PyArray_InnerProduct C-API documentation. Trace the proposed rewrites and determine how Blockwise Dot and batched matmul should use the C implementation; done means BatchedDot is removed and the rewrites support the intended operations.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, numpy, python
Domain
backend, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.