For most Sparsify Experiments, you will need to provide a base model to create a sparse model from. Due to the varied ML pipelines and implementations, Sparsify standardizes on a few popular formats for models. You will need to make sure that your model is formatted properly according to the standards listed below.
For image classification tasks, Sparsify relies on the PTH format generated from SparseML.
Specifically, the PTH format generated from the ModuleExporter
class in SparseML.
This will save a model in the PTH format with the following structure:
{
"state_dict": model.state_dict(),
"optimizer": optimizer.state_dict(),
"recipe": recipe,
"epoch": epoch,
"arch_key": arch_key,
}
from sparseml.pytorch.image_classification.utils import ModuleExporter
from torchvision.models import resnet18
model = resnet18()
exporter = ModuleExporter(model, "./")
exporter.export_pytorch(
optimizer=None,
epoch=-1,
recipe=None,
name=f"{model}.pth",
arch_key="resnet18",
)
For object detection tasks, Sparsify utilizes the YOLO format for models. This is the same format used by Ultralytics YOLOv5/YOLOv8 This is the default format that is saved from training within the YOLOv5 or YOLOv8 repos.
More information on the YOLO format can be found here.
For image segmentation tasks, Sparsify utilizes the YOLO format for models. This is the same format used by Ultralytics YOLOv5/YOLOv8 This is the default format that is saved from training within the YOLOv5 or YOLOv8 repos.
More information on the YOLO format can be found here.
For NLP tasks, Sparsify utilizes the HuggingFace Models format and expectations. This includes the standard tokenizer.json, config.json, and bin files. If using any of the standard transformers pathways externally or through SparseML, then this is the default format models are saved in.
More information on the HuggingFace Models format can be found here.
For One-Shot Experiments, Sparsify utilizes the .ONNX
format for models.
In the future, more formats will be added for support with One-Shot Experiments.
For more information on the ONNX format, see the ONNX website. For more information on exporting to the ONNX format, see our docs page here.