Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak pm.Data to create or auto-replace by TensorConstant #5105

Closed
michaelosthege opened this issue Oct 26, 2021 · 1 comment · Fixed by #5295
Closed

Tweak pm.Data to create or auto-replace by TensorConstant #5105

michaelosthege opened this issue Oct 26, 2021 · 1 comment · Fixed by #5295

Comments

@michaelosthege
Copy link
Member

Background

pm.Data is often used to track data in the model, making it end up in the InferenceData and so on.

Right now this always creates shared variables, but in the vast majority of applications one doesn't actually use the shared variable features.

Generally there are three (?) flavors of data variables:

  • constant (could be a TensorConstant instead)
  • shared with constant shape
  • shared with flexible shape (constant ndim)

AFAIK Aesara does not distinguish between shared variables that can, or cannot be resized.

Motivation

But the difference between TensorConstant and SharedVariable is a thing, and sometimes also costly.
For example see #3818

Potential solution

  • Additional kwargs to pm.Data through which one can constrain the flexibility (creating TensorConstant instead).
  • Automatically replacing all SharedVariables in the graph with TensorConstant before starting MCMC.

Versions and main components

  • PyMC/PyMC3 Version: main
@michaelosthege michaelosthege changed the title Add pm.Data options to create constant data variables Tweak pm.Data to create or auto-replace by TensorConstant Oct 26, 2021
@ricardoV94
Copy link
Member

ricardoV94 commented Oct 27, 2021

Automatically replacing all SharedVariables in the graph with TensorConstant before starting MCMC.

I implemented this for other reasons here:

def replace_shared_variables(graph: List[TensorVariable]) -> List[TensorVariable]:

Should be possible. Perhaps a more flexible version that just skips Variables with default updates instead of raising an Error would be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants