2020-12-17 11:03:45 +00:00
|
|
|
# Copyright The Lightning AI 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
|
|
|
|
|
2022-06-15 22:10:49 +00:00
|
|
|
from tests_pytorch.helpers.advanced_models import ParityModuleMNIST, ParityModuleRNN
|
2020-12-17 11:03:45 +00:00
|
|
|
|
ruff: replace isort with ruff +TPU (#17684)
* ruff: replace isort with ruff
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixing & imports
* lines in warning test
* docs
* fix enum import
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixing
* import
* fix lines
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* type ClusterEnvironment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-09-26 15:54:55 +00:00
|
|
|
from parity_pytorch.measure import measure_loops
|
|
|
|
|
2020-12-17 11:03:45 +00:00
|
|
|
NUM_EPOCHS = 20
|
|
|
|
NUM_RUNS = 50
|
|
|
|
MODEL_CLASSES = (ParityModuleRNN, ParityModuleMNIST)
|
|
|
|
PATH_HERE = os.path.dirname(__file__)
|
2021-07-26 11:37:35 +00:00
|
|
|
FIGURE_EXTENSION = ".png"
|
2020-12-17 11:03:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _main():
|
2021-12-01 19:58:18 +00:00
|
|
|
import matplotlib.pylab as plt
|
|
|
|
import pandas as pd
|
|
|
|
|
2020-12-17 11:03:45 +00:00
|
|
|
fig, axarr = plt.subplots(nrows=len(MODEL_CLASSES))
|
|
|
|
|
|
|
|
for i, cls_model in enumerate(MODEL_CLASSES):
|
2021-07-26 11:37:35 +00:00
|
|
|
path_csv = os.path.join(PATH_HERE, f"dump-times_{cls_model.__name__}.csv")
|
2020-12-17 11:03:45 +00:00
|
|
|
if os.path.isfile(path_csv):
|
|
|
|
df_time = pd.read_csv(path_csv, index_col=0)
|
|
|
|
else:
|
2020-12-23 19:38:57 +00:00
|
|
|
# todo: kind="Vanilla PT" -> use_lightning=False
|
|
|
|
vanilla = measure_loops(cls_model, kind="Vanilla PT", num_epochs=NUM_EPOCHS, num_runs=NUM_RUNS)
|
|
|
|
lightning = measure_loops(cls_model, kind="PT Lightning", num_epochs=NUM_EPOCHS, num_runs=NUM_RUNS)
|
2020-12-17 11:03:45 +00:00
|
|
|
|
2021-07-26 11:37:35 +00:00
|
|
|
df_time = pd.DataFrame({"vanilla PT": vanilla["durations"][1:], "PT Lightning": lightning["durations"][1:]})
|
2020-12-17 11:03:45 +00:00
|
|
|
df_time /= NUM_RUNS
|
2021-07-26 11:37:35 +00:00
|
|
|
df_time.to_csv(os.path.join(PATH_HERE, f"dump-times_{cls_model.__name__}.csv"))
|
2020-12-17 11:03:45 +00:00
|
|
|
# todo: add also relative X-axis ticks to see both: relative and absolute time differences
|
2021-07-26 11:37:35 +00:00
|
|
|
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}")
|
2020-12-17 11:03:45 +00:00
|
|
|
fig.tight_layout()
|
|
|
|
fig.savefig(path_fig)
|
|
|
|
|
|
|
|
|
2021-07-26 11:37:35 +00:00
|
|
|
if __name__ == "__main__":
|
2020-12-17 11:03:45 +00:00
|
|
|
_main()
|