AGENT SKILL

sonnet

Use DeepMind Sonnet for TensorFlow 2 modules, layers, training loops, functional transforms, serialization, and distribution workflows.

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

01 前言 Front Matter

name
sonnet
license
Apache 2.0
metadata
{ "disco-role": "operating" }
description
Use DeepMind Sonnet for TensorFlow 2 modules, layers, training loops, functional transforms, serialization, and distribution workflows.
disable-model-invocation
true

02 资源文件 5

03 SKILL.md 正文

Sonnet Repo Skill

Use this repo skill when a task involves DeepMind Sonnet (dm-sonnet, imported as sonnet or snt) for TensorFlow 2 neural-network research code: custom modules, built-in layers and nets, manual training loops, RNNs, functional transforms, checkpoints, SavedModel export, mixed precision, or TensorFlow distribution helpers.

Sonnet is intentionally small and unopinionated. It provides composable Module objects, built-in module families, and optimizers, but it does not provide a full training framework, dataset pipeline, experiment runner, or serving stack.

Quick install and import check

python -m pip install tensorflow dm-sonnet
import tensorflow as tf
import sonnet as snt
print("TensorFlow", tf.__version__)
print("Sonnet", snt.__version__)
print(snt.nets.MLP([16, 4])(tf.ones([2, 8])).shape)

Run scripts/check_sonnet_install.py when you need a no-download smoke check for importability, device visibility, lazy variables, a tiny optimizer step, and basic RNN construction.

Route by task

If the task asks about... Read this sub-skill Why
Custom snt.Module classes, @snt.once, lazy variables, names, Sequential, Deferred, BatchApply, or snt.build sub-skills/module-authoring/SKILL.md Owns Sonnet's core module programming model and composition contracts.
Built-in layers, normalization, initializers, metrics, regularizers, snt.nets.MLP, ResNet, Cifar10ConvNet, or VQ-VAE modules sub-skills/layers-and-nets/SKILL.md Owns constructor signatures, shape rules, state behavior, and layer/net smoke checks.
tf.GradientTape training loops, snt.optimizers.*, optimizer.apply, tiny local training checks, or metric accumulation sub-skills/training-and-optimization/SKILL.md Owns object-oriented Sonnet optimization and safe training-loop recipes.
RNNCore, LSTM, GRU, DeepRNN, dynamic_unroll, static_unroll, trainable state, or ConvLSTM sub-skills/sequence-and-rnn/SKILL.md Owns sequence shape/state conventions and recurrent troubleshooting.
snt.functional.variables, transform, transform_with_state, grad, value_and_grad, jit, device_put/get, or functional optimizers sub-skills/functional-transforms/SKILL.md Owns Sonnet's TensorFlow-based Haiku/JAX-like functional API.
TensorFlow checkpoints, SavedModel export/load, Keras/pickle caveats, XLA, mixed precision, snt.distribute.Replicator, TPU, or cross-replica BatchNorm sub-skills/serialization-and-distribution/SKILL.md Owns persistence, export, distribution, and backend limitations.

Root references

Operating checklist

  1. Import public symbols from sonnet (import sonnet as snt), not private implementation modules.
  2. Build modules once with representative inputs before inspecting variables, exporting, or passing parameters to optimizers.
  3. Assert small shapes at module boundaries: final feature dimension for Linear, channel dimension for convolution/normalization, and time-major sequence layout for RNN unroll helpers.
  4. Use tf.GradientTape plus optimizer.apply(gradients, variables) for object-oriented Sonnet training loops, or use snt.functional only when the task explicitly wants stateless-style init/apply workflows.
  5. Treat CUDA, TPU, XLA, and distributed execution as environment-specific. Do not claim accelerator verification unless the current TensorFlow runtime has been probed and the sub-skill's backend guidance is satisfied.

When not to use this skill

  • The user is asking for general TensorFlow or Keras usage with no Sonnet API, module, optimizer, or distribution helper involved.
  • The user wants to edit or maintain the Sonnet repository itself rather than use Sonnet as a package; route to a repository-maintenance workflow instead.
  • The user needs a full experiment framework, trainer, data pipeline, model zoo, or serving platform that Sonnet does not provide.

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