pymc-devs / pymc-devs/pytensor
Reconsider handlig of constants in numba backend
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Description
In the numba backend (and all Jitted backends), we massage constants into global variables of the codegen function.
This poses has a couple of issues for the Numba backend:
- Functions with large arrays can't be cached
- The number of cached functions grows with small differences in the global arrays, but otherwise identical structure (not sure how common)
- Functions with more esoteric constant types can't be compiled: SparseVariables, RandomGenerator, TypedLists (see failures in #1676 and #811)
We could adopt the approach that the C-backend takes, which is to just use pointers to the storage list created by PyTensor function, for these constants. We only inline scalars in the C-backend codegen. This would work-around all the issues listed above.
On the downside, I'm not sure how hard it would make things for nutpie. CC @aseyboldt
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the Numba and other jitted backends turn constants into codegen-function globals, then compare that path with the C-backend's pointer-based handling. Review the failures referenced in #1676 and #811, and consider the stated interaction with nutpie. Done means large arrays can be cached without unnecessary cache growth and the listed constant types compile successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100