-
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.
* docs * script * dump * desc * import * import * if * norm * t * finished * isort * typing Co-authored-by: Nicki Skafte <[email protected]> * xlabel * pandas * time Co-authored-by: Nicki Skafte <[email protected]>
- Loading branch information
1 parent
1b599ff
commit b16441f
Showing
9 changed files
with
155 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 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 | ||
|
||
BENCHMARK_ROOT = os.path.dirname(__file__) | ||
PROJECT_ROOT = os.path.dirname(BENCHMARK_ROOT) |
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,60 @@ | ||
# 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 matplotlib.pylab as plt | ||
import pandas as pd | ||
|
||
from benchmarks.test_basic_parity import lightning_loop, vanilla_loop | ||
from tests.base.models import ParityModuleMNIST, ParityModuleRNN | ||
|
||
NUM_EPOCHS = 20 | ||
NUM_RUNS = 50 | ||
MODEL_CLASSES = (ParityModuleRNN, ParityModuleMNIST) | ||
PATH_HERE = os.path.dirname(__file__) | ||
FIGURE_EXTENSION = '.png' | ||
|
||
|
||
def _main(): | ||
fig, axarr = plt.subplots(nrows=len(MODEL_CLASSES)) | ||
|
||
for i, cls_model in enumerate(MODEL_CLASSES): | ||
path_csv = os.path.join(PATH_HERE, f'dump-times_{cls_model.__name__}.csv') | ||
if os.path.isfile(path_csv): | ||
df_time = pd.read_csv(path_csv, index_col=0) | ||
else: | ||
vanilla = vanilla_loop(cls_model, num_epochs=NUM_EPOCHS, num_runs=NUM_RUNS) | ||
lightning = lightning_loop(cls_model, num_epochs=NUM_EPOCHS, num_runs=NUM_RUNS) | ||
|
||
df_time = pd.DataFrame({'vanilla PT': vanilla['durations'][1:], 'PT Lightning': lightning['durations'][1:]}) | ||
df_time /= NUM_RUNS | ||
df_time.to_csv(os.path.join(PATH_HERE, f'dump-times_{cls_model.__name__}.csv')) | ||
# todo: add also relative X-axis ticks to see both: relative and absolute time differences | ||
df_time.plot.hist( | ||
ax=axarr[i], | ||
bins=20, | ||
alpha=0.5, | ||
title=cls_model.__name__, | ||
legend=True, | ||
grid=True, | ||
) | ||
axarr[i].set(xlabel='time [seconds]') | ||
|
||
path_fig = os.path.join(PATH_HERE, f'figure-parity-times{FIGURE_EXTENSION}') | ||
fig.tight_layout() | ||
fig.savefig(path_fig) | ||
|
||
|
||
if __name__ == '__main__': | ||
_main() |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
Benchmark with vanilla PyTorch | ||
============================== | ||
|
||
In this section we set grounds for comparison between vanilla PyTorch and PT Lightning for most common scenarios. | ||
|
||
Time comparison | ||
--------------- | ||
|
||
We have set regular benchmarking against PyTorch vanilla training loop on with RNN and simple MNIST classifier as per of out CI. | ||
In average for simple MNIST CNN classifier we are only about 0.06s slower per epoch, see detail chart bellow. | ||
|
||
.. figure:: _images/benchmarks/figure-parity-times.png | ||
:alt: Speed parity to vanilla PT, created on 2020-12-16 | ||
:width: 500 |
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 |
---|---|---|
|
@@ -17,3 +17,4 @@ pre-commit>=1.0 | |
|
||
cloudpickle>=1.3 | ||
nltk>=3.3 | ||
pandas # needed in benchmarks |
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