Persistent Volumes
A readable and writable data store that will persist across tasks
Beam allows you to create persistent volumes that can be used across tasks. You might use persistent volumes for things like storing model artifacts created during training, or caching model weights to avoid having to download them each time your function is invoked.
Mounting a Persistent Volume
To setup a persistent volume, first mount in your app definition file. The path is relative to the files in your workspace.
Reading and Writing Files
You can read and write to the persistent volume like an ordinary Python file:
Example: Caching Model Weights
A good use case for Persistent Volumes is caching your ML model in order to avoid downloading it each time you make a prediction.
If you’re using a Huggingface model, you can set the Huggingface cache location in app.py
.
Example: Saving Pickle Files
You can manually save files to the Persistent Volume. First, mount the volume in app.py
.
After mounting the volume, you can read and write to it from anywhere in your app, and the contents will be persisted between runs.