AGENT SKILL

mcmc-and-sampling

Use ZhuSuan for HMC, SGLD, PSGLD, SGHMC, SGNHT, annealed importance sampling, and posterior-sampling diagnostics.

License 许可
MIT
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
mcmc-and-sampling
license
MIT
metadata
{ "disco-role": "operating" }
description
Use ZhuSuan for HMC, SGLD, PSGLD, SGHMC, SGNHT, annealed importance sampling, and posterior-sampling diagnostics.
disable-model-invocation
true

02 资源文件 4

03 SKILL.md 正文

MCMC and Sampling

Use this sub-skill when the task is about posterior sampling or sampling-based estimation rather than variational training.

Read this when

  • the user names HMC, SGLD, PSGLD, SGHMC, SGNHT, AIS, or effective_sample_size
  • the task is about sampling latent variables, posterior chains, or sampling diagnostics
  • the request mentions toy posterior examples, topic models, or matrix factorization examples that use HMC or stochastic-gradient MCMC

What this sub-skill owns

  • HMC.sample(...) and the HMC adaptation knobs
  • stochastic-gradient MCMC classes: SGLD, PSGLD, SGHMC, SGNHT
  • AIS for annealed importance sampling over a sequence of temperatures
  • effective_sample_size diagnostics for chain quality
  • toy examples and heavier sampling workflows such as PMF and topic models

What this sub-skill does not own

  • core Bayesian-network construction
  • ELBO / IWAE / VIMCO / REINFORCE / flow-based variational workflows
  • generic training code that does not use a ZhuSuan sampler

Start here

  1. Read references/mcmc-workflows.md for the sampler map and example matrix.
  2. Read references/api-reference.md for exact constructor and sample signatures.
  3. Read references/troubleshooting.md for adaptation, acceptance, and chain shape issues.
  4. Run scripts/mcmc_smoke.py after environment setup to confirm a short HMC chain, sampler instantiation, and ESS calculation.

Common tasks

Run HMC

  • Build a log_joint function or pass a MetaBayesianNet.
  • Create TensorFlow Variable objects to hold the latent state.
  • Instantiate zs.HMC(...) with a small step size and a handful of leapfrog steps.
  • Call sample(meta_bn, observed, latent) once per sampler instance.
  • Turn adaptation on only during burn-in.

Run stochastic-gradient MCMC

  • Use zs.SGLD, zs.SGHMC, or zs.SGNHT when the gradient is minibatch- based.
  • Keep the latent variables in Variable objects and feed minibatches into the observed data placeholders.
  • For SGHMC and SGNHT, watch the kinetic-energy / friction diagnostics.

Evaluate a chain

  • Flatten the chain to a 2-D matrix when using effective_sample_size.
  • For multiple chains or latent dimensions, keep track of the axis ordering so the diagnostic matches the intended latent dimension.

Good entry points

  • zhusuan/hmc.py
  • zhusuan/sgmcmc.py
  • zhusuan/evaluation.py for AIS
  • zhusuan/diagnostics.py
  • scripts/mcmc_smoke.py

Routing hints

  • If the request is about a Bayesian model but not about sampling, route to modeling-primitives.
  • If the request is about a variational posterior or a lower bound, route to variational-inference.
  • If the user asks about a plotting-heavy toy example, treat it as a workflow reference rather than a required verification target unless the user explicitly wants the demo run.

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