forked from awslabs/s3-connector-for-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckpoint_reading.py
31 lines (22 loc) · 917 Bytes
/
checkpoint_reading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# // SPDX-License-Identifier: BSD
from lightning import Trainer
from lightning.pytorch.demos import WikiText2, LightningTransformer
from torch.utils.data import DataLoader
from s3torchconnector.lightning import S3LightningCheckpoint
def main(region: str, checkpoint_path: str):
dataset = WikiText2()
dataloader = DataLoader(dataset, num_workers=3)
model = LightningTransformer(vocab_size=dataset.vocab_size)
s3_lightning_checkpoint = S3LightningCheckpoint(region)
trainer = Trainer(
plugins=[s3_lightning_checkpoint],
min_epochs=4,
max_epochs=5,
max_steps=3,
)
# Load the checkpoint in `ckpt_path` before training
trainer.fit(model, dataloader, ckpt_path=checkpoint_path)
if __name__ == "__main__":
import os
main(os.getenv("REGION"), os.getenv("CHECKPOINT_PATH"))