A library for persisting PyTorch program state
Project description
torchsnapshot
This library is currently in Alpha and currently does not have a stable release. The API may change and may not be backward compatible. If you have suggestions for improvements, please open a GitHub issue. We'd love to hear your feedback.
A light-weight library for adding fault tolerance to large-scale PyTorch distributed training workloads.
Install
Requires Python >= 3.7 and PyTorch >= 1.11
From pip:
pip install --pre torchsnapshot-nightly
From source:
git clone https://github.com/facebookresearch/torchsnapshot
cd torchsnapshot
pip install -r requirements.txt
python setup.py install
Concepts
- Stateful object - an object that whose state can be obtained via
.state_dict()
and restored via.load_state_dict()
. Most PyTorch components (e.g.Module
,Optimizer
,LRScheduler
) already implement this protocol. - App state - the application state described using multiple stateful objects.
- Snapshot - the persisted app state.
Basic Usage
Describing the application state with multiple stateful objects:
app_state = {"model": model, "optimizer": optimizer}
Taking a snapshot of the application state:
from torchsnapshot import Snapshot
# File System
snapshot = Snapshot.take(path="/foo/bar/baz", app_state=app_state)
# S3
snapshot = Snapshot.take(path="s3://foo/bar", app_state=app_state)
# Google Cloud Storage
snapshot = Snapshot.take(path="gcs://foo/bar", app_state=app_state)
Referencing an existing snapshot:
snapshot = Snapshot(path="foo/bar/baz")
Restoring the application state from a snapshot:
snapshot.restore(app_state=app_state)
See the example directory for more examples.
License
torchsnapshot is BSD licensed, as found in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for torchsnapshot-nightly-2022.6.17.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9775f522cfba6c8da479e5b96a92f46846f5f290ad46d56490266e9e7b1db2b7 |
|
MD5 | 1bc0aaf5eb0ea7a2173545b3c6ddcaf4 |
|
BLAKE2b-256 | 57e3b8058423c5fec048623b14d96939d93bee9df142222532dff5b42339a16b |
Hashes for torchsnapshot_nightly-2022.6.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef9acd6025deef54db37403915d0740b99d8419e37248ebeaad8d47fc7ec8ffe |
|
MD5 | 063717aa89add7391530bfe0fd24fd91 |
|
BLAKE2b-256 | 94d46a5bfedf2f3a066cf5689a66ec187911ac1cc90f5ac480489ba2c7c01fc4 |