docs: guide to PyTensor compilation for PyMC users [first draft / RFC] - #2220
Closed
drbenvincent wants to merge 4 commits into
Closed
docs: guide to PyTensor compilation for PyMC users [first draft / RFC]#2220drbenvincent wants to merge 4 commits into
drbenvincent wants to merge 4 commits into
Conversation
Add an opinionated User Guide page explaining PyTensor's two-stage compilation pipeline (graph rewriting then backend linking) from the perspective of a PyMC user, including a Mermaid system diagram covering the Numba/C/JAX/PyTorch/MLX/VM backends and the runtime logp+gradient callable consumed by samplers (PyMC NUTS, nutpie). Enable the sphinxcontrib-mermaid extension (and render plain ```mermaid fences via myst_fence_as_directive) so the diagram renders in the docs build, on GitHub, and in editor previews. Co-authored-by: Cursor <cursoragent@cursor.com>
Rework the PyMC-user compilation guide to be readable without prior PyTensor knowledge: explain each Stage 1 rewrite pass (merge/useless, canonicalize, stabilize, specialize/fusion, backend-specific + in-place) and each Stage 2 backend in plain language with analogies, and move precise module/function references into collapsible "Under the hood" notes. Clarify how the backend (backend= / compile_kwargs / config.linker) and the sampler (nuts_sampler=: pymc/nutpie/numpyro/blackjax) are chosen, and make the PyTensor/sampler boundary explicit in the diagram. Co-authored-by: Cursor <cursoragent@cursor.com>
Member
|
sounds like a PyMC documentation not PyTensor. There's already one doc answering the "graph" approach part https://www.pymc.io/projects/docs/en/stable/learn/core_notebooks/pymc_pytensor.html |
Contributor
Author
|
Thanks @ricardoV94 — agreed, this belongs in the PyMC docs alongside the existing PyMC and PyTensor notebook rather than here. I've moved it over and reframed it as a companion to that notebook (placed right after it in the core-notebooks toctree): pymc-devs/pymc#8326. Closing this one in favour of that PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Putting this up early to get first impressions and direction before I invest in polishing. Feedback on scope, framing, and accuracy is more useful than wording at this stage; I'm happy to restructure significantly.
Summary
A new user-guide page, "Understanding PyTensor compilation (a guide for PyMC users)", for people who reach PyTensor through PyMC rather than using it directly. It builds a mental model of the compilation pipeline and answers two recurring PyMC questions: "why does sampling take a while to start?" (compilation) and "why is the first run slow but later runs faster?" (caching).
What's included
backend=/compile_kwargs/config.linker) vs. how the sampler is chosen (nuts_sampler=: pymc/nutpie/numpyro/blackjax), and why they're mostly-independent choices.sphinx-design,sphinxcontrib-mermaid) andconf.pymermaid config.Open questions for reviewers
Notes
python -m sphinx -b html ./doc ./html; cross-references (FunctionGraph, Mode, jax.jit, torch.compile) resolve and the Mermaid diagram + collapsible notes render.Made with Cursor