pymc-devs / pymc-devs/pytensor

Simplify dots with 1

Open
#638 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

beginner friendly graph rewriting
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

Description

We have a local_0_dot_x that removes useless dots with zero'd inputs. We don't seem to have anything for dots with ones as reported in https://github.com/pymc-devs/pytensor/discussions/637#discussioncomment-8405862

import pytensor
import pytensor.tensor as pt
from pytensor.compile.mode import get_default_mode

x = tn.col('x')
f = x @ [[1.]]
with pytensor.config.change_flags(optimizer_verbose=True):
    fn = pytensor.function([x], f, mode=get_default_mode().excluding("BlasOpt"))

pytensor.dprint(fn)
dot [id A] 0
 ├─ x [id B]
 └─ [[1.]] [id C]

I excluded the BlasOpt just to have a simpler graph, but it will still not rewrite it away with those, just add the more complex Blas Op.

https://github.com/pymc-devs/pytensor/blob/d3dd34e7ea78eb1f125dd771d06436d49bf2ce5d/pytensor/tensor/rewriting/math.py#L155-L190

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 the existing zero-input dot rewrite in pytensor/tensor/rewriting/math.py at the linked section, then run the reproduction using x @ [[1.]] with BlasOpt excluded. Done means the resulting graph no longer contains the redundant dot operation for one-valued inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.