methods
Use Composer speedup methods through algorithm classes, functional helpers, recipes, batch-key routing, and in-place model/optimizer mutations.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- methods
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use Composer speedup methods through algorithm classes, functional helpers, recipes, batch-key routing, and in-place model/optimizer mutations.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/algorithm-catalog.md11.0 KB
- 参考文档references/functional-api.md10.3 KB
- 参考文档references/troubleshooting.md8.2 KB
- 脚本scripts/functional_smoke.py4.0 KB
03 SKILL.md 正文
Composer Methods Router
Use this sub-skill when the task is to add, compose, debug, or translate MosaicML Composer speedup methods from composer.algorithms and composer.functional.
Route first
- For Trainer construction, dataloaders,
ComposerModel, max duration, checkpointing, and optimizer basics, route to../training/SKILL.md. - For loggers, profiling, speed monitors, metric visualization, and throughput diagnosis, route to
../observability/SKILL.md. - For distributed launch, DDP/FSDP setup, multi-node concerns, and backend placement, route to
../distributed/SKILL.md. - For TorchScript/ONNX/export/inference packaging after method application, route to
../inference-export/SKILL.md.
Main decision: algorithm class or functional API
Prefer composer.algorithms classes in Trainer(algorithms=[...]) when the user is already using Composer Trainer or wants a recipe of multiple methods. The Trainer event engine places each algorithm at the relevant event, passes state.optimizers to model-surgery algorithms, handles paired before/after events, and lets batch algorithms use input_key / target_key without changing the dataloader.
Use composer.functional when the user owns a custom PyTorch loop, wants to test one method in isolation, or needs to mutate a model before creating the optimizer. With the functional API, the caller owns exact stage placement, target/loss interpolation, optimizer rebinding after surgery, and any schedule logic.
from composer import Trainer
from composer.algorithms import BlurPool, ChannelsLast, LabelSmoothing, MixUp
algorithms = [
ChannelsLast(),
BlurPool(replace_convs=True, replace_maxpools=True, blur_first=True, min_channels=16),
MixUp(alpha=0.2, interpolate_loss=False, input_key="image", target_key="label"),
LabelSmoothing(smoothing=0.1, target_key="label"),
]
trainer = Trainer(
model=model,
train_dataloader=train_dataloader,
eval_dataloader=eval_dataloader,
optimizers=optimizer,
max_duration="10ep",
algorithms=algorithms,
)
Placement rules
- Image transforms such as
RandAugmentorAugMixbelong in dataset transforms before batching. - Batch methods such as
MixUp,CutMix,ColOut,CutOut, andLabelSmoothingrun after a batch is available and before the forward/loss stage that consumes the modified tensors. - Model surgery such as
BlurPool,SqueezeExcite,Factorize,StochasticDepth,Alibi, low-precision norm replacements, andChannelsLastmutates the model in place. Apply it before optimizer construction, or pass existing optimizers to functional helpers that acceptoptimizers=. Trainer algorithms do this throughstate.optimizers. - Loop and optimizer methods such as
LayerFreezing,ProgressiveResizing,SelectiveBackprop,SeqLengthWarmup,EMA,SWA,SAM, andGradientClippingdepend on event timing or optimizer state. Use algorithm classes unless the user is explicitly maintaining those stages in a custom loop.
Batch key routing
Batch algorithms default to tuple batches: input_key=0, target_key=1. For dict batches, pass string keys instead of rewriting the dataloader:
from composer.algorithms import CutMix, MixUp, LabelSmoothing
algorithms = [
MixUp(alpha=0.2, input_key="image", target_key="label"),
CutMix(alpha=1.0, uniform_sampling=False, input_key="image", target_key="label"),
LabelSmoothing(smoothing=0.1, target_key="label"),
]
For nested or custom batch objects, pass (getter, setter) callables. The getter receives the batch and returns the tensor; the setter receives (batch, value) and returns the updated batch.
References and bundled smoke
references/functional-api.md: function families, stage contracts, batch-key semantics, and custom-loop recipes.references/algorithm-catalog.md: exported Composer method list grouped by taxonomy.references/troubleshooting.md: method-specific failure modes and fixes.scripts/functional_smoke.py: no-download random tensor smoke for a batch method plus functional model surgery.
Run the smoke from this sub-skill directory with:
python scripts/functional_smoke.py
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).