AGENT SKILL

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

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 selected pyro.ops utilities, 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.block or 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 with infer_discrete, or debug enum dimensions";
  • "apply AutoReparam, LocScaleReparam, TransformReparam, StableReparam, LinearHMMReparam, SplitReparam, NeuTraReparam, or related config";
  • "use Vindex, plated pyro.ops.contract.einsum, HMM Gaussian contractions, or pyro.ops.stats diagnostics where they support inference code".

Boundaries And Reroutes

  • Beginner model authoring, pyro.sample/pyro.param introductions, parameter-store lifecycle, pyro.plate basics, validation, RNG, or PyroModule: 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.funsor workflows, 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

  1. 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.
  2. 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.
  3. For traces, call trace.compute_log_prob() before reading per-site log_prob; use trace.format_shapes() in every shape/debug answer.
  4. For enumeration, set max_plate_nesting to the number of nested vectorized plates around enumerated/observed sites, then allocate enum dimensions to the left with first_available_dim = -1 - max_plate_nesting.
  5. 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.
  6. For indexed parameters under enumerated variables, prefer pyro.ops.indexing.Vindex or broadcasting-safe tensor code; do not branch on a parallel-enumerated tensor value.
  7. 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

VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

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).

★ 351