components
Routes PyTorch Metric Learning questions about losses, miners, distances, reducers, regularizers, self-supervised wrappers, and custom component implementations.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- components
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Routes PyTorch Metric Learning questions about losses, miners, distances, reducers, regularizers, self-supervised wrappers, and custom component implementations.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/losses-miners-and-customization.md6.5 KB
- 参考文档references/troubleshooting.md3.1 KB
- 脚本scripts/smoke_components.py1.9 KB
03 SKILL.md 正文
Components
Use this sub-skill when the user needs to choose, combine, or customize the metric-learning primitives that sit below training and evaluation.
Typical triggers
- "Which loss should I use for triplets, pairs, proxies, or self-supervision?"
- "How do I pick a miner for this batch?"
- "How do I swap the distance, reducer, or regularizer?"
- "Why does this loss need labels, a miner output, or
indices_tuple?" - "How do I write a custom loss or miner?"
- "Why am I getting no valid triplets, a distance-compatibility error, or a shape error?"
In scope
- Distances:
LpDistance,CosineSimilarity,DotProductSimilarity,SNRDistance, andBatchedDistance. - Reducers:
MeanReducer,AvgNonZeroReducer,ThresholdReducer,DivisorReducer,PerAnchorReducer,MultipleReducers,DoNothingReducer,SumReducer,ClassWeightedReducer. - Regularizers:
LpRegularizer,CenterInvariantRegularizer,RegularFaceRegularizer,SparseCentersRegularizer,ZeroMeanRegularizer. - Miners:
TripletMarginMiner,MultiSimilarityMiner,BatchHardMiner,BatchEasyHardMiner,DistanceWeightedMiner,PairMarginMiner,AngularMiner,HDCMiner,UniformHistogramMiner,EmbeddingsAlreadyPackagedAsTriplets. - Loss families and wrappers:
TripletMarginLoss,ContrastiveLoss,MultiSimilarityLoss,NTXentLoss,AngularLoss,ArcFaceLoss,CosFaceLoss,NormalizedSoftmaxLoss,ProxyAnchorLoss,ProxyNCALoss,SelfSupervisedLoss,CrossBatchMemory,MultipleLosses,SmoothAPLoss,VICRegLoss, and related metric/classification losses. - Custom component authoring with
BaseMetricLossFunction,BaseMiner,loss_and_miner_utils, andTorchInitWrapper.
Out of scope
- Trainer setup, hooks, logging, and checkpointing belong in
training. - Accuracy calculators, testers, and nearest-neighbor inference belong in
evaluation. - Dataset download and sampler configuration belong in
data.
How to use this sub-skill
- Start with
references/losses-miners-and-customization.mdfor the compact component catalog and compatibility rules. - Run
scripts/smoke_components.pyon toy tensors when you need a quick sanity check for a component stack or a custom extension. - Read
references/troubleshooting.mdwhen the failure mentions labels,indices_tuple, no valid tuples, or an incompatible distance/reducer/regularizer. - For custom loss/miner implementations, follow the distilled extension patterns and use the bundled
loss_and_miner_utilshelpers instead of re-deriving tuple conversion logic.
Common routing decisions
- If the user asks which loss or miner to use, stay here.
- If the user asks why a component rejects labels, margins, or tuple shapes, stay here.
- If the user asks how to wire the chosen component into a trainer or tester, route to
trainingorevaluationafter the component choice is settled.
Useful public facts
- Most metric losses and miners accept a
distanceobject. - Some losses can be called with
indices_tupleinstead of labels when the tuple has already been mined. - Classification-style losses typically need
num_classesandembedding_size, and some require an optimizer for their class weights. CrossBatchMemorywraps another loss and adds queue behavior;SelfSupervisedLossadapts a pair or tuple loss to two views.MultipleLossesandMultipleReducersrequire matching keys or parallel lists.
Read next
references/losses-miners-and-customization.mdfor the component catalog and extension notes.references/troubleshooting.mdfor predictable component-level failures.scripts/smoke_components.pyfor a tiny direct smoke check.
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).