Speed Comparison
Last updated
Last updated
Safetensors
is really fast. Let’s compare it against PyTorch
by loading weights. To run the , make sure your machine has GPU or you have selected GPU runtime
if you are using Google Colab.
Before you begin, make sure you have all the necessary libraries installed:
Copied
Let’s start by importing all the packages that will be used:
Copied
Download safetensors & torch weights for gpt2:
Copied
Copied
OS: Ubuntu 18.04.6 LTS
CPU: Intel(R) Xeon(R) CPU @ 2.00GHz
Copied
The speedup works because this library is able to skip unnecessary CPU allocations. It is unfortunately not replicable in pure pytorch as far as we know. The library works by memory mapping the file, creating the tensor empty with pytorch and calling cudaMemcpy
directly to move the tensor directly on the GPU. The currently shown speedup was gotten on:
OS: Ubuntu 18.04.6 LTS.
GPU: Tesla T4
Driver Version: 460.32.03
CUDA Version: 11.2
This speedup is due to the fact that this library avoids unnecessary copies by mapping the file directly. It is actually possible to do on . The currently shown speedup was gotten on: