effect-handlers-and-enumeration
Use Pyro poutine effect handlers, traces, discrete enumeration, reparameterizers, and inference-tied tensor ops.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- effect-handlers-and-enumeration
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use Pyro poutine effect handlers, traces, discrete enumeration, reparameterizers, and inference-tied tensor ops.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/effect-handler-workflows.md12.2 KB
- 参考文档references/enumeration-and-reparameterization.md19.9 KB
- 参考文档references/troubleshooting.md13.6 KB
- 脚本scripts/enumeration_trace_smoke.py5.1 KB
03 SKILL.md 正文
Effect Handlers And Enumeration
Use this sub-skill when the task involves Pyro's poutine stack, trace/replay/
condition/block/scale/mask/seed/substitute/reparam handlers, discrete latent
variable enumeration, posterior decoding with infer_discrete, TraceEnum_ELBO
or Tensor Monte Carlo setup, reparameterizers, or inference-adjacent pyro.ops
utilities such as Vindex, plated einsum, HMM contraction helpers, and stats.
This guidance targets the pyro-ppl 1.9.1 API family imported as pyro. It is
self-contained; do not rely on the source checkout, original notebooks, or
example scripts at runtime.
Route First
- For poutine handler semantics, handler ordering, trace node inspection, condition/replay posterior workflows, and masking/scaling compositions, read references/effect-handler-workflows.md.
- For
TraceEnum_ELBO,config_enumerate,infer_discrete,max_plate_nesting,first_available_dim, TMC/funsor caveats, reparameterizer config patterns, and selectedpyro.opsutilities, read references/enumeration-and-reparameterization.md. - For recovery steps after duplicate names, enum dimension allocation failures,
missing
funsor, JIT warnings, trace shape errors, handler order surprises, or reparameterizer failures, read references/troubleshooting.md. - To confirm that the active package can run a tiny CPU enumeration plus trace
workflow without the original checkout, run
scripts/enumeration_trace_smoke.py.
Start with
python scripts/enumeration_trace_smoke.py --help; defaults are intentionally short and deterministic.
Best-Fit Tasks
Use this sub-skill for requests like:
- "trace this model and inspect sample/param sites, log probabilities, masks,
scales, or
cond_indep_stack"; - "condition the model on posterior samples, replay a guide trace through a model, or trace deterministic return sites";
- "hide sites from an autoguide with
poutine.blockor expose only selected sample/param sites"; - "scale or mask part of a likelihood, minibatch objective, prior term, or ragged time-series likelihood";
- "enumerate a discrete latent variable, use
TraceEnum_ELBO, compute MAP or sampled discrete states withinfer_discrete, or debug enum dimensions"; - "apply
AutoReparam,LocScaleReparam,TransformReparam,StableReparam,LinearHMMReparam,SplitReparam,NeuTraReparam, or related config"; - "use
Vindex, platedpyro.ops.contract.einsum, HMM Gaussian contractions, orpyro.ops.statsdiagnostics where they support inference code".
Boundaries And Reroutes
- Beginner model authoring,
pyro.sample/pyro.paramintroductions, parameter-store lifecycle,pyro.platebasics, validation, RNG, orPyroModule: route to../modeling-basics/. - Distribution selection, support constraints,
.to_event(), batch/event shape algebra, HMM distribution constructors, and generic shape debugging: route to../distributions-and-shapes/. - Ordinary SVI loops, autoguide choice, ELBO choice outside enumeration,
optimizer wrappers, or PyTorch optimizer loops: route to
../svi-and-autoguides/after the enumeration/handler contract is clear. - HMC/NUTS/MCMC loops, initialization strategies, MCMC diagnostics, and
Predictive: route to../mcmc-and-prediction/, using this sub-skill only for conditioning/replay/reparameterizer details. - Domain-specific contributed examples,
pyro.contrib.funsorworkflows, Horovod/Lightning/Graphviz/torchvision/pandas/scanpy extras, and long HMM demos: route to../contrib-and-domain-workflows/. Treat them as optional or unverified unless the active user environment proves support.
High-Value Checks Before Answering
- Confirm whether the user needs a handler composition, a traced diagnostic, a discrete enumeration algorithm, or a reparameterization. These look similar in code but have different ordering and shape rules.
- For poutine composition, reason from the execution stack: handlers process messages from the innermost wrapper first and postprocess from the outermost wrapper first. If values are unexpectedly overwritten, inspect handler order.
- For traces, call
trace.compute_log_prob()before reading per-sitelog_prob; usetrace.format_shapes()in every shape/debug answer. - For enumeration, set
max_plate_nestingto the number of nested vectorized plates around enumerated/observed sites, then allocate enum dimensions to the left withfirst_available_dim = -1 - max_plate_nesting. - For model-side enumeration, use only
infer={"enumerate": "parallel"}; model-side sequential enumeration is not implemented. Guide-side sequential enumeration is supported but can multiply execution count. - For indexed parameters under enumerated variables, prefer
pyro.ops.indexing.Vindexor broadcasting-safe tensor code; do not branch on a parallel-enumerated tensor value. - Treat
funsor, CUDA, Horovod, Lightning, Graphviz, torchvision, pandas, and scanpy as optional/unverified in the minimum environment unless the current runtime explicitly imports them.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).