-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for legacy checkpoints (#5223)
* wip * generate * clean * tests * copy * download * download * download * download * download * download * download * download * download * download * download * flake8 * extend * aws * extension * pull * pull * pull * pull * pull * pull * pull * try * try * try * got it * Apply suggestions from code review (cherry picked from commit 72525f0)
- Loading branch information
Showing
16 changed files
with
286 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,4 @@ prune temp* | |
prune test* | ||
prune benchmark* | ||
prune dockers | ||
prune legacy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# Sample call: | ||
# bash generate_checkpoints.sh 1.0.2 1.0.3 1.0.4 | ||
|
||
LEGACY_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" | ||
|
||
echo $LEGACY_PATH | ||
# install some PT version here so it does not need to reinstalled for each env | ||
pip install virtualenv "torch==1.5" --quiet --no-cache-dir | ||
|
||
ENV_PATH="$LEGACY_PATH/vEnv" | ||
|
||
# iterate over all arguments assuming that each argument is version | ||
for ver in "$@" | ||
do | ||
echo "processing version: $ver" | ||
# mkdir "$LEGACY_PATH/$ver" | ||
|
||
# create local env | ||
echo $ENV_PATH | ||
virtualenv $ENV_PATH --system-site-packages | ||
# activate and install PL version | ||
source "$ENV_PATH/bin/activate" | ||
pip install "pytorch_lightning==$ver" --quiet -U --no-cache-dir | ||
|
||
python --version | ||
pip --version | ||
pip list | grep torch | ||
|
||
python "$LEGACY_PATH/zero_training.py" | ||
cp "$LEGACY_PATH/zero_training.py" ${LEGACY_PATH}/checkpoints/${ver} | ||
|
||
mv ${LEGACY_PATH}/checkpoints/${ver}/lightning_logs/version_0/checkpoints/*.ckpt ${LEGACY_PATH}/checkpoints/${ver}/ | ||
rm -rf ${LEGACY_PATH}/checkpoints/${ver}/lightning_logs | ||
|
||
deactivate | ||
# clear env | ||
rm -rf $ENV_PATH | ||
|
||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Copyright The PyTorch Lightning team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
|
||
import torch | ||
from torch.utils.data import Dataset | ||
|
||
import pytorch_lightning as pl | ||
|
||
PATH_LEGACY = os.path.dirname(__file__) | ||
|
||
|
||
class RandomDataset(Dataset): | ||
def __init__(self, size, length: int = 100): | ||
self.len = length | ||
self.data = torch.randn(length, size) | ||
|
||
def __getitem__(self, index): | ||
return self.data[index] | ||
|
||
def __len__(self): | ||
return self.len | ||
|
||
|
||
class DummyModel(pl.LightningModule): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.layer = torch.nn.Linear(32, 2) | ||
|
||
def forward(self, x): | ||
return self.layer(x) | ||
|
||
def _loss(self, batch, prediction): | ||
# An arbitrary loss to have a loss that updates the model weights during `Trainer.fit` calls | ||
return torch.nn.functional.mse_loss(prediction, torch.ones_like(prediction)) | ||
|
||
def _step(self, batch, batch_idx): | ||
output = self.layer(batch) | ||
loss = self._loss(batch, output) | ||
return loss | ||
|
||
def training_step(self, batch, batch_idx): | ||
return self._step(batch, batch_idx) | ||
|
||
def validation_step(self, batch, batch_idx): | ||
self._step(batch, batch_idx) | ||
|
||
def test_step(self, batch, batch_idx): | ||
self._step(batch, batch_idx) | ||
|
||
def configure_optimizers(self): | ||
optimizer = torch.optim.SGD(self.layer.parameters(), lr=0.1) | ||
lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1) | ||
return [optimizer], [lr_scheduler] | ||
|
||
def train_dataloader(self): | ||
return torch.utils.data.DataLoader(RandomDataset(32, 64)) | ||
|
||
def val_dataloader(self): | ||
return torch.utils.data.DataLoader(RandomDataset(32, 64)) | ||
|
||
def test_dataloader(self): | ||
return torch.utils.data.DataLoader(RandomDataset(32, 64)) | ||
|
||
|
||
def main_train(dir_path, max_epochs: int = 5): | ||
|
||
trainer = pl.Trainer( | ||
default_root_dir=dir_path, | ||
checkpoint_callback=True, | ||
max_epochs=max_epochs, | ||
) | ||
|
||
model = DummyModel() | ||
trainer.fit(model) | ||
|
||
|
||
if __name__ == '__main__': | ||
path_dir = os.path.join(PATH_LEGACY, 'checkpoints', str(pl.__version__)) | ||
main_train(path_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.