Library version mismatches declared not safe
2 min read
Content
Learning
Always, always, always match the python package versions used during model development with the ones available on inference infrastructure, especially for critical applications. Personally inspect that pre-processing code in production matches with the one used during model development. Empower Scientists and Developers to jointly own inference infrastructure.
Problem
I trained a model, but the inference infrastructure doesn’t load it.
Root-causing
Models trained with transformers v4.37.2 produce the package:
model.safetensors
(line 4) is preferred due to higher security, lower memory footprint (zero-copy) and faster loading speed. The earlier pickle format pytorch_model.bin
can be target to a security vulnerability. From pickle documentation:
Simple Fix
A simple workaround — load model.safetensors
in a model object and then re-save to old format. Delete or move the model.safetensors
file.
Create a final deployment-ready package that looks like:
Smaller Packaging
The training script might also save a optimizer file in the model package. This is not required for inference and can be deleted to reduce the size of the model package.