executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
inference-exportExport Composer or PyTorch models for inference with TorchScript or ONNX, including checkpoint loading, export callbacks, and HuggingFace integration caveats.
Independent GitHub snapshot · Automated classification · Original documentation governs
Use this sub-skill when a user asks to make a Composer or PyTorch model ready for inference through TorchScript, ONNX, checkpoint-backed export, ExportForInferenceCallback, or optional HuggingFace/PEFT integration.
load_path and optional load_object_store.ExportForInferenceCallback so export happens at the end of training.Trainer.export_for_inference from an already-constructed Trainer.sample_input, dynamic_axes, input_names, and output_names.surgery_algs, transforms, or quantize_dynamic before export.../training/SKILL.md.../observability/SKILL.md.../distributed/SKILL.md.../methods/SKILL.md, then return here for artifact generation.mosaicml[nlp], PEFT, tokenizer/config/embedding caveats, and checkpoint metadata.save_format="torchscript" for a self-contained scripted/traced artifact.save_format="onnx" when the target runtime expects ONNX and you can provide a representative sample_input.load_path when the model object needs weights from a Composer checkpoint before export.surgery_algs for pre-load model surgery and transforms for post-load export-time transforms.quantize_dynamic only when the target model layers and runtime support dynamic quantization.from composer.utils import export_for_inference, quantize_dynamic
export_for_inference(
model=model,
save_format="torchscript",
save_path="model.pt",
sample_input=example_batch,
transforms=[quantize_dynamic],
)
For ONNX, provide sample_input and usually explicit names or dynamic axes:
export_for_inference(
model=model,
save_format="onnx",
save_path="model.onnx",
sample_input=(inputs,),
input_names=["input"],
output_names=["logits"],
dynamic_axes={"input": {0: "batch"}, "logits": {0: "batch"}},
)
Use ExportForInferenceCallback when export should be part of the training lifecycle:
from composer.callbacks import ExportForInferenceCallback
from composer import Trainer
trainer = Trainer(
model=model,
train_dataloader=train_loader,
max_duration="1ep",
callbacks=[ExportForInferenceCallback(save_format="torchscript", save_path="model.pt")],
)
trainer.fit()
For ONNX callbacks, pass sample_input or allow the callback to capture a batch after the dataloader runs.
load_strict=False is the export utility default; choose strictness intentionally when loading changed heads or adapter-only weights.HuggingFaceModel.allow_embedding_resizing=True.Run from this sub-skill directory:
python scripts/export_torchscript_smoke.py
The script exports a tiny CPU model to a temporary TorchScript file, reloads it, and compares outputs.
onnx/onnxruntime are not available and validation is required.