Environment:Pyro ppl Pyro Funsor Backend
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Probabilistic_Programming |
| Last Updated | 2026-02-09 09:00 GMT |
Overview
Optional Funsor backend environment providing an alternative inference engine for discrete variable enumeration and the AutoGaussian guide family.
Description
Funsor is a tensor-based functional programming library that provides an alternative backend for Pyro's discrete enumeration and Gaussian guide computations. It is pinned to an exact version (0.4.4) to ensure compatibility. Funsor is required specifically for `CollapseMessenger` (experimental collapsed inference), the `AutoGaussianFunsor` guide, and the `contrib.funsor` enumeration backend.
Usage
Use this environment when using the AutoGaussian guide with funsor backend, CollapseMessenger for collapsed inference, or the contrib.funsor enumeration backend for discrete variable models.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Python | >= 3.8 | Same as core Pyro requirement |
| Hardware | CPU (minimum) | Same as core environment |
Dependencies
Python Packages
- `funsor[torch]` == 0.4.4 (exactly pinned)
Credentials
No credentials required.
Quick Install
# Install Pyro with Funsor backend
pip install pyro-ppl[funsor]
# This installs funsor[torch]==0.4.4
Code Evidence
Exact version pin from `setup.py:143-145`:
"funsor": [
"funsor[torch]==0.4.4",
],
Funsor import guard in `pyro/poutine/collapse_messenger.py:17-28`:
# TODO Remove import guard once funsor is a required dependency.
try:
import funsor
from funsor.cnf import Contraction
from funsor.delta import Delta
from funsor.terms import Funsor, Variable
except ImportError:
# Create fake types for singledispatch.
Contraction = type("Contraction", (), {})
Delta = type("Delta", (), {})
Funsor = type("Funsor", (), {})
Variable = type("Variable", (), {})
AutoGaussian funsor import with helpful error from `pyro/infer/autoguide/gaussian.py:616-625`:
def _import_funsor():
try:
import funsor
except ImportError as e:
raise ImportError(
'AutoGaussian(..., backend="funsor") requires funsor. '
"Try installing via: pip install pyro-ppl[funsor]"
) from e
funsor.set_backend("torch")
return funsor
Conditional registration in `pyro/contrib/__init__.py:35-42`:
try:
import funsor as funsor_ # noqa: F401
from pyro.contrib import funsor
__all__ += ["funsor"]
except ImportError:
pass
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ImportError: AutoGaussian(..., backend="funsor") requires funsor` | Funsor not installed | `pip install pyro-ppl[funsor]` |
| Version conflict with funsor | Wrong funsor version | Must use exactly `funsor[torch]==0.4.4`; uninstall and reinstall if needed |
| `ImportError` in CollapseMessenger | Funsor not available for collapsed inference | `pip install pyro-ppl[funsor]`; feature is experimental |
Compatibility Notes
- Exact version pin: Funsor is pinned to exactly 0.4.4; other versions are not guaranteed to work
- Experimental: CollapseMessenger with Funsor is marked experimental (note the TODO comment about making funsor a required dependency)
- Backend initialization: Funsor must be initialized with `funsor.set_backend("torch")` before use; Pyro handles this internally