modeling-primitives
Use ZhuSuan's distributions, BayesianNet, MetaBayesianNet, and stochastic tensor primitives to build and inspect probabilistic models.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- modeling-primitives
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use ZhuSuan's distributions, BayesianNet, MetaBayesianNet, and stochastic tensor primitives to build and inspect probabilistic models.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-reference.md1.5 KB
- 参考文档references/modeling-concepts.md2.1 KB
- 参考文档references/troubleshooting.md1.4 KB
- 脚本scripts/core_smoke.py1.3 KB
03 SKILL.md 正文
Modeling Primitives
Use this sub-skill when the task is about ZhuSuan's core probabilistic-modeling surface rather than a specific inference algorithm.
Read this when
- the user names
BayesianNet,MetaBayesianNet,StochasticTensor,meta_bayesian_net,reuse_variables,cond_log_prob,log_joint,query, orget - the task is about distributions, observed nodes, latent nodes, node naming,
group_ndims,n_samples, or shape semantics - the user wants to understand how to build a model graph before training or sampling
- the request is about compatibility or migration from the deprecated legacy wrappers
What this sub-skill owns
zhusuan.distributionsand theBayesianNet.<distribution>helpersBayesianNet,StochasticTensor,MetaBayesianNet, andmeta_bayesian_net- observed-vs-latent node handling, deterministic nodes, and custom
log_joint - tensor-like behavior of stochastic nodes and shape checking rules
- safe use of
get,query,cond_log_prob, andlog_joint
What this sub-skill does not own
- ELBO/IWAE/VIMCO/RWS, importance sampling likelihoods, or flows
- HMC, SGMCMC, AIS, or sampling diagnostics
- dataset downloads, example training loops, or plotting utilities
Start here
- Read
references/modeling-concepts.mdfor the modeling rules and shape semantics. - Read
references/api-reference.mdwhen you need exact constructor or method signatures. - Read
references/troubleshooting.mdfor dtype, shape, and deprecation issues. - Run
scripts/core_smoke.pyafter environment setup to confirm the core package can build a tiny model and evaluate an ELBO.
Common tasks
Build a probabilistic model
- Create a
BayesianNet. - Add stochastic nodes with distribution helpers such as
normal,bernoulli,categorical,dirichlet, ormultivariate_normal_cholesky. - Use deterministic TensorFlow ops for hidden calculations and optionally wrap
them with
bn.deterministic(...)when you want the node name tracked.
Reuse a model with different observations
- Wrap the model builder with
@zs.meta_bayesian_net(scope=..., reuse_variables=True)when repeated observation patterns should share TensorFlow variables. - Call
model.observe(...)to instantiate a concreteBayesianNetwith a specific observation map.
Inspect a network
- Use
bn.get(...)to fetch nodes by name. - Use
bn.cond_log_prob(...)to inspect per-node conditional log probabilities. - Use
bn.log_joint()for the overall joint log probability. - Use
bn.query(..., outputs=True, local_log_prob=True)only when maintaining older code that still expects the deprecated tuple return.
Good entry points
zhusuan/framework/bn.pyzhusuan/framework/meta_bn.pyzhusuan/distributions/base.pyzhusuan/distributions/univariate.pyzhusuan/distributions/multivariate.pyscripts/core_smoke.py
Routing hints
- If the request is really about training a VAE/BNN or estimating posterior
bounds, route to
variational-inference. - If the request is about HMC, SGHMC, SGNHT, or posterior sampling, route to
mcmc-and-sampling. - If the request is only about a generic TensorFlow model unrelated to probabilistic nodes or Bayesian inference, a different repo skill is likely a better fit.
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).