pymc-devs / pymc-devs/pytensor

Use numpy C-API einsum for unoptimized Einsum

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

Nobody has claimed this yet.

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

Description

Description

When Einsum can't be optimized (because we don't know the static shapes) it stays as an OpFromGraph. We could replace it by a COp (as a cxx_only rewrite) in this case, that calls the numpy C function:

https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_EinsteinSum

https://github.com/pymc-devs/pytensor/blob/f25a624a42849374807368d6b056c254a4ea2044/pytensor/tensor/rewriting/einsum.py#L39-L53

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 by reading the einsum rewrite in pytensor/tensor/rewriting/einsum.py, especially lines 39-53, and review NumPy's PyArray_EinsteinSum C-API documentation. Determine how the unoptimized OpFromGraph can be replaced by a cxx_only COp. Done means the unoptimized case calls the NumPy C function while preserving the einsum behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
compilers, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.