core-api
Use TorchMetrics core APIs for import checks, metric lifecycle, custom Metric state, device/DDP behavior, persistence, and Lightning logging.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- core-api
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use TorchMetrics core APIs for import checks, metric lifecycle, custom Metric state, device/DDP behavior, persistence, and Lightning logging.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/core-api.md9.0 KB
- 参考文档references/custom-metrics-lightning-ddp.md10.3 KB
- 参考文档references/troubleshooting.md6.7 KB
- 脚本scripts/core_metric_smoke.py7.3 KB
03 SKILL.md 正文
TorchMetrics Core API
Use this sub-skill when a task is about the TorchMetrics base API rather than a specific metric family: choosing functional versus module metrics, accumulating batches, writing a custom Metric, moving metrics across devices, synchronizing distributed state, saving metric state, or logging metrics from PyTorch Lightning.
Route map
- Read references/core-api.md when you need import sanity checks, functional-vs-module selection,
update/compute/forward/resetsemantics,MetricCollection, device/dtype rules, or state persistence. - Read references/custom-metrics-lightning-ddp.md when implementing
Metricsubclasses withadd_state, list states,dist_reduce_fx, cache behavior, DDP controls, or Lightningself.log/self.log_dictpatterns. - Read references/troubleshooting.md when you see install/import errors, unexpected keyword arguments, stale computed values, device mismatches, unregistered metrics, Lightning logging failures, or DDP synchronization surprises.
- Run scripts/core_metric_smoke.py to verify that the installed package can instantiate and execute
Accuracy,MeanSquaredError,MetricCollection, and a small custom list-state metric without downloads.
Quick usage policy
- Use functional metrics for one-shot tensor-in/tensor-out calculations that do not need accumulation, object registration, state persistence, or built-in distributed synchronization.
- Use module metrics for training/evaluation loops, multi-batch accumulation, Lightning logging,
MetricCollection, device moves, or DDP-aware synchronization. - Register module metrics as
nn.Modulechildren: direct attributes,nn.ModuleList,nn.ModuleDict, orMetricCollection; do not hide metrics inside plain Python containers. - Keep separate metric instances for train/validation/test and for each dataloader whose state must not mix.
- Route detailed domain metric catalogs to sibling domain sub-skills; route wrappers and plotting to
collections-wrappers-plotting; route metrics that may download models tomodel-based-metrics.
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).