losses-and-metrics
Operate MedicalZooPytorch loss and metric APIs for segmentation criteria, shape contracts, tuple returns, and safe smoke checks.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- losses-and-metrics
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Operate MedicalZooPytorch loss and metric APIs for segmentation criteria, shape contracts, tuple returns, and safe smoke checks.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/api-reference.md12.7 KB
- 参考文档references/troubleshooting.md5.9 KB
- 脚本scripts/smoke_losses.py7.0 KB
03 SKILL.md 正文
losses-and-metrics
Use this sub-skill when the task is to select, instantiate, debug, or smoke-test MedicalZooPytorch loss objects exposed through lib.losses3D.
Route first
- For exact constructor names, accepted shapes, return types, one-hot expansion, and criterion-selection rules, open references/api-reference.md.
- For assertion failures, unsupported loss names, singleton-batch 2D Dice quirks, device mismatches, or pixel-weight issues, open references/troubleshooting.md.
- For model creation, trainer wiring, writer updates, checkpoints, full training loops, and inference, hand off to the sibling route segmentation-workflows. Bring only the selected criterion and its return contract from this sub-skill.
- For how dataset loaders produce target tensors and labels, hand off to data-loading-preprocessing.
Fast operating rules
- Standard 3D semantic segmentation criteria expect logits shaped
[N, C, D, H, W]and integer label targets shaped[N, D, H, W]unless the API reference says a raw PyTorch loss requires same-shaped targets. - Dice-family MedicalZoo losses expand class-index targets to one-hot internally and normalize logits internally. Match the loss
classesargument to the model output channel count. - The built-in 3D trainer route expects
criterion(output, target)to return(loss_tensor, per_channel_dice_like).DiceLoss,GeneralizedDiceLoss,BCEDiceLoss, andDiceLoss2Dsatisfy that shape of contract; scalar-only losses require a trainer adaptation owned bysegmentation-workflows. create_loss(name, ...)is case-sensitive and does not expose every constructor option. Instantiate classes directly when class count,skip_index_after, tag coefficients, contrastive embeddings, or 2D Dice behavior matters.- Keep targets integer-valued and on the same device as logits. Move criterion modules that carry weight buffers to the target device before CUDA checks.
Bundled smoke check
Run the bundled deterministic smoke check after making the MedicalZooPytorch package importable:
python sub-skills/losses-and-metrics/scripts/smoke_losses.py
python sub-skills/losses-and-metrics/scripts/smoke_losses.py --cuda
The script uses tiny synthetic tensors, validates tuple versus scalar return contracts, exercises representative factory/manual loss paths, and confirms unsupported factory names fail with guidance.
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).