技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
training【数据与研究】Build and debug Composer Trainer workflows, model/data contracts, time units, checkpoint save/load, manual resume, autoresume, evaluation, prediction, and basic CPU/GPU precision choices.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task is to create, run, resume, or debug a MosaicML Composer training workflow with Trainer, ComposerModel, ComposerClassifier, DataSpec, Evaluator, State, Time, Timestamp, optimizers, schedulers, devices, precision, and checkpoints.
The public package install for examples is:
pip install mosaicml
Import the runtime module as composer.
Trainer(model=..., train_dataloader=..., max_duration=..., optimizers=...) for CPU or single-process GPU experiments.ComposerClassifier or subclass ComposerModel.DataLoader objects, DataSpec objects, or Evaluator objects to training and validation.trainer.fit(), trainer.eval(), or trainer.predict() and inspect trainer.state after the run.max_duration, duration, eval_interval, save_interval, or scheduler milestones using Composer time strings.save_folder, save_filename, save_latest_filename, and save_interval.load_path or configure autoresume=True with stable run_name and save_folder.load_weights_only, load_strict_model_weights, and load_ignore_keys.device and precision choices such as CPU plus fp32 or GPU plus AMP.../methods/SKILL.md.../observability/SKILL.md.../distributed/SKILL.md.../inference-export/SKILL.md.ComposerClassifier(module, num_classes=...) when batches are (inputs, targets) and the module maps inputs -> logits.ComposerModel and implement forward(batch) plus loss(outputs, batch).torch.utils.data.DataLoader first.
If Composer cannot infer samples, tokens, transforms, or microbatch splitting, wrap it in DataSpec.torch.optim.AdamW(model.parameters(), lr=...).max_duration using a Composer time string such as "2ba", "1ep", "100sp", or "2048tok".device="cpu" and precision="fp32"; switch to device="gpu" and AMP only after CPU logic works.run_name stable when checkpoints or external logs must be grouped across restarts.trainer.fit() and validate trainer.state.timestamp, trainer.state.train_metrics, and trainer.saved_checkpoints.trainer.eval() for standalone validation, and trainer.predict(dataloader) when batch outputs are needed.Keep examples small and explicit before adding algorithms, distributed launchers, or loggers:
from composer import Trainer
from composer.models import ComposerClassifier
import torch
model = ComposerClassifier(module=torch.nn.Linear(8, 3), num_classes=3)
optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3)
trainer = Trainer(
model=model,
train_dataloader=train_loader,
eval_dataloader=eval_loader,
optimizers=optimizer,
max_duration="10ba",
device="cpu",
precision="fp32",
run_name="debug-run",
)
trainer.fit()
trainer.eval()
Use references/trainer-workflows.md when the task needs complete construction patterns.
ComposerModel.forward(batch) consumes the dataloader batch, not just tensors already unpacked from the batch.ComposerModel.loss(outputs, batch) returns the loss tensor that the trainer backpropagates.ComposerModel.eval_forward(batch, outputs=None) defaults to outputs or forward(batch); override it for custom eval behavior.ComposerModel.get_metrics(is_train) returns a dictionary of TorchMetrics; Composer deep-copies metrics per split.ComposerModel.update_metric(batch, outputs, metric) must update each metric with the same batch/output schema.ComposerClassifier expects (input, target) batches and can infer or receive num_classes for default accuracy metrics.DataSpec owns batch transforms, microbatch transforms, splitting, sample counting, token counting, and epoch sizing.Evaluator(label=..., dataloader=..., metric_names=...) when multiple eval loaders or selected metric names are needed.Use references/model-and-data-contracts.md for custom batch schemas, token counting, metrics, and eval/predict contracts.
Time.from_timestring(...) when validating user input.iter, ep, ba, sp, tok, dur, and sec; max_duration cannot use circular duration or wall-clock seconds.Timestamp tracks total and in-epoch counts such as batch, sample, token, batch_in_epoch, and token_in_epoch.save_folder, save_filename, save_latest_filename, save_interval, and save_overwrite.trainer.saved_checkpoints or the latest symlink/name to choose a manual load_path.max_duration is the total target, not the additional duration.load_weights_only=True; add non-strict or ignored keys only when needed.autoresume=True requires stable run_name, save_folder, and save_latest_filename so Composer can find the latest checkpoint.Use references/checkpointing-and-time.md for save/load/autoresume recipes and validation steps.
device="cpu", precision="fp32", a tiny synthetic dataloader, and max_duration="1ba".ComposerModel and that one batch can pass through forward, loss, eval_forward, and metrics.DataSpec and provide counting/splitting functions.trainer.state.timestamp for unexpected epochs, batches, samples, or tokens.trainer.state.eval_metrics by evaluator label when validation appears missing.run_name, save_folder, latest filename, and whether a latest checkpoint actually exists.references/troubleshooting.md to map common error messages to fixes.Run these from this sub-skill directory in any environment with mosaicml installed:
python scripts/train_smoke.py --batches 2 --eval-batches 1 --predict
python scripts/checkpoint_smoke.py --mode both
The scripts use only random CPU tensors and temporary directories; they do not download datasets or models.