pymc-devs / pymc-devs/pytensor

Does `destroy_map` need to specify which output destroys which input?

Open
#1,377 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

graph objects memory opt needs info
Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

Description

This seems focused on single output Ops. It's the application of the node that destroys the input, not the computation of a specific output. For instance, in LU_factor which outputs both LU, and p we artificially specify that destroy_map is {1: [0]}, because {0: [0], 1: [0]} is not allowed (we get a mulitple destroyers error when introducing the inplace during rewrites).

We should check if anything in the codebase relies on a strict map from input to output. If not, our Ops could simply have a tuple for destroy_map indicating which inputs are being destroied, and not a dict from outputs to inputs like we have now.

Some Ops may be overloading this functionality to know for instance which of multiple outputs in being computed inplace of an input (such as in Elemwise) but this is information that could be stored elsewhere.

Otherwise, if this mapping is actually needed for something, we may need to extend the inplace consistency check to at least allow multiple outputs from the same node to destroy the same input.

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 tracing destroy_map usage and the inplace consistency check, then compare the LU_factor and Elemwise cases described in the issue. Determine whether any code relies on a strict output-to-input mapping or whether multiple outputs may destroy one input. Done means the required representation and consistency behavior are agreed and the affected cases are covered.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.