Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/safetensors_doc/en/speed.ipynb
Views: 2542
Speed Comparison
Safetensors
is really fast. Let's compare it against PyTorch
by loading gpt2 weights. To run the GPU benchmark, 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:
Let's start by importing all the packages that will be used:
Download safetensors & torch weights for gpt2:
CPU benchmark
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 pure pytorch. The currently shown speedup was gotten on:
OS: Ubuntu 18.04.6 LTS
CPU: Intel(R) Xeon(R) CPU @ 2.00GHz
GPU benchmark
The speedup works because this library is able to skip unecessary 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