Skip to content

import pytorch_lightning is too slow #16090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
junsoo-ha-unknot opened this issue Dec 16, 2022 · 2 comments
Closed

import pytorch_lightning is too slow #16090

junsoo-ha-unknot opened this issue Dec 16, 2022 · 2 comments
Labels
duplicate This issue or pull request already exists performance

Comments

@junsoo-ha-unknot
Copy link

junsoo-ha-unknot commented Dec 16, 2022

Bug description

import pytorch_lightning takes about 2 seconds (~1 second when import torch has been executed before), which is relatively ~30x slower than import numpy, and ~15x slower than import pandas.

While ~2 second latency could be considered negligible for a computation-heavy applications, it becomes annoying, for example, when you try to build a CLI tool with autocompletion features. User wants quick response, but a simple tab completion would take at least ~2 seconds, just because of the slow import statement.

How to reproduce the bug

import time
start = time.time()
import numpy
np_end = time.time()
import pandas
pd_end = time.time()
import torch
torch_end = time.time()
import pytorch_lightning
pl_end = time.time()


print(f"np: {np_end - start}")
print(f"pd: {pd_end - np_end}")
print(f"torch: {torch_end - pd_end}")
print(f"pl: {pl_end - torch_end}")

Error messages and logs

np: 0.06890726089477539
pd: 0.12215876579284668
torch: 0.7145488262176514
pl: 0.9180386066436768

Environment

Current environment
* CUDA:
        - GPU:
                - NVIDIA A30
                - NVIDIA A30
                - NVIDIA A30
                - NVIDIA A30
                - NVIDIA A30
                - NVIDIA A30
                - NVIDIA A30
                - NVIDIA A30
        - available:         True
        - version:           11.7
* Lightning:
        - pytorch-lightning: 1.6.3
        - torch:             1.13.0
        - torchmetrics:      0.7.3
        - torchtyping:       0.1.4
        - torchvision:       0.14.0
* Packages:
        - absl-py:           0.15.0
        - aiohttp:           3.8.1
        - aiosignal:         1.2.0
        - ansible:           6.5.0
        - ansible-core:      2.13.5
        - anyio:             3.6.2
        - appdirs:           1.4.4
        - argon2-cffi:       21.3.0
        - argon2-cffi-bindings: 21.2.0
        - asttokens:         2.2.0
        - async-timeout:     4.0.2
        - attrs:             21.4.0
        - babel:             2.11.0
        - backcall:          0.2.0
        - backports.functools-lru-cache: 1.6.4
        - bcrypt:            4.0.1
        - beautifulsoup4:    4.11.1
        - bleach:            5.0.1
        - blinker:           1.4
        - boto3:             1.24.96
        - botocore:          1.27.96
        - bottleneck:        1.3.5
        - brotlipy:          0.7.0
        - cachecontrol:      0.12.11
        - cached-property:   1.5.2
        - cachetools:        4.2.2
        - cachy:             0.3.0
        - certifi:           2022.9.24
        - cffi:              1.15.1
        - cfgv:              3.3.1
        - charset-normalizer: 2.0.4
        - chart-studio:      1.1.0
        - click:             8.1.3
        - click-default-group: 1.2.2
        - clikit:            0.6.2
        - coloredlogs:       15.0.1
        - conda-lock:        1.2.1
        - contourpy:         1.0.5
        - crashtest:         0.3.1
        - cryptography:      37.0.1
        - cycler:            0.11.0
        - debugpy:           1.6.3
        - decorator:         5.1.1
        - deepdiff:          6.2.1
        - defusedxml:        0.7.1
        - distlib:           0.3.6
        - docker-pycreds:    0.4.0
        - docstring-to-markdown: 0.10
        - einops:            0.4.1
        - ensureconda:       1.4.3
        - entrypoints:       0.4
        - exceptiongroup:    1.0.2
        - exchange-calendars: 4.2.3
        - execnet:           1.9.0
        - executing:         1.2.0
        - fancycompleter:    0.9.1
        - fastjsonschema:    2.16.2
        - filelock:          3.8.0
        - fire:              0.4.0
        - flake8:            5.0.4
        - flatbuffers:       2.0
        - flit-core:         3.8.0
        - fonttools:         4.37.4
        - frozenlist:        1.2.0
        - fsspec:            2022.7.1
        - future:            0.18.2
        - gitdb:             4.0.9
        - gitpython:         3.1.29
        - gmpy2:             2.1.2
        - google-auth:       2.6.0
        - google-auth-oauthlib: 0.4.4
        - greenlet:          1.1.3.post0
        - grpcio:            1.42.0
        - h5py:              3.6.0
        - html5lib:          1.1
        - humanfriendly:     10.0
        - hurst:             0.0.5
        - identify:          2.5.6
        - idna:              3.4
        - importlib-metadata: 4.11.3
        - importlib-resources: 5.10.0
        - iniconfig:         1.1.1
        - ipdb:              0.13.9
        - ipykernel:         6.16.1
        - ipython:           8.7.0
        - ipython-genutils:  0.2.0
        - ipywidgets:        8.0.2
        - jaraco.classes:    3.2.3
        - jedi:              0.18.2
        - jedi-language-server: 0.37.0
        - jeepney:           0.8.0
        - jinja2:            3.1.2
        - jmespath:          1.0.1
        - json5:             0.9.5
        - jsonschema:        4.17.3
        - jupyter:           1.0.0
        - jupyter-client:    7.4.3
        - jupyter-console:   6.4.4
        - jupyter-core:      5.1.0
        - jupyter-server:    1.23.3
        - jupyterlab:        3.5.0
        - jupyterlab-pygments: 0.2.2
        - jupyterlab-server: 2.16.3
        - jupyterlab-vim:    0.15.1
        - jupyterlab-widgets: 3.0.3
        - keyring:           23.9.3
        - kiwisolver:        1.4.4
        - korean-lunar-calendar: 0.2.1
        - llvmlite:          0.38.0
        - lockfile:          0.12.2
        - markdown:          3.3.4
        - markupsafe:        2.1.1
        - matplotlib:        3.6.0
        - matplotlib-inline: 0.1.6
        - mccabe:            0.7.0
        - mistune:           2.0.4
        - mkl-fft:           1.3.1
        - mkl-random:        1.2.2
        - mkl-service:       2.4.0
        - more-itertools:    9.0.0
        - mpmath:            1.2.1
        - msgpack:           1.0.4
        - multidict:         6.0.2
        - namegenerator:     1.0.6
        - nbclassic:         0.4.8
        - nbclient:          0.7.2
        - nbconvert:         7.2.5
        - nbformat:          5.7.0
        - neovim:            0.3.1
        - nest-asyncio:      1.5.6
        - nodeenv:           1.7.0
        - notebook:          6.5.2
        - notebook-shim:     0.2.2
        - numba:             0.55.1
        - numexpr:           2.8.3
        - numpy:             1.21.5
        - nvidia-cublas-cu11: 11.10.3.66
        - nvidia-cuda-nvrtc-cu11: 11.7.99
        - nvidia-cuda-runtime-cu11: 11.7.99
        - nvidia-cudnn-cu11: 8.5.0.96
        - oauthlib:          3.2.1
        - onnxruntime:       1.12.1
        - ordered-set:       4.1.0
        - packaging:         21.3
        - pandas:            1.4.4
        - pandas-market-calendars: 4.1.0
        - pandocfilters:     1.5.0
        - paramiko:          2.12.0
        - parso:             0.8.3
        - pastel:            0.2.1
        - pathtools:         0.1.2
        - patsy:             0.5.3
        - pdbpp:             0.10.3
        - pexpect:           4.8.0
        - pickleshare:       0.7.5
        - pillow:            9.3.0
        - pip:               21.0.1
        - pkginfo:           1.8.3
        - pkgutil-resolve-name: 1.3.10
        - platformdirs:      2.5.2
        - plotly:            5.11.0
        - pluggy:            1.0.0
        - pre-commit:        2.20.0
        - prettytable:       3.5.0
        - prometheus-client: 0.15.0
        - promise:           2.3
        - prompt-toolkit:    3.0.33
        - protobuf:          3.20.1
        - psutil:            5.9.3
        - ptyprocess:        0.7.0
        - pudb:              2022.1.3
        - pure-eval:         0.2.2
        - py:                1.11.0
        - pyasn1:            0.4.8
        - pyasn1-modules:    0.2.8
        - pycodestyle:       2.9.1
        - pycparser:         2.21
        - pydantic:          1.9.2
        - pydeprecate:       0.3.2
        - pyflakes:          2.5.0
        - pygls:             0.12.2
        - pygments:          2.13.0
        - pyjwt:             2.4.0
        - pylev:             1.4.0
        - pyluach:           2.0.2
        - pynacl:            1.5.0
        - pynvim:            0.4.3
        - pyopenssl:         22.0.0
        - pyparsing:         3.0.9
        - pyrepl:            0.9.0
        - pyrsistent:        0.18.1
        - pysocks:           1.7.1
        - pytest:            7.2.0
        - pytest-forked:     1.4.0
        - pytest-xdist:      3.0.2
        - python-box:        6.1.0
        - python-dateutil:   2.8.2
        - pytorch-lightning: 1.6.3
        - pytz:              2022.1
        - pyyaml:            6.0
        - pyzmq:             24.0.1
        - qtconsole:         5.3.2
        - qtpy:              2.2.1
        - requests:          2.28.1
        - requests-oauthlib: 1.3.0
        - resolvelib:        0.8.1
        - retrying:          1.3.4
        - rsa:               4.7.2
        - ruamel.yaml:       0.17.21
        - ruamel.yaml.clib:  0.2.7
        - s3transfer:        0.6.0
        - scipy:             1.9.1
        - seaborn:           0.12.1
        - secretstorage:     3.3.3
        - send2trash:        1.8.0
        - sentry-sdk:        1.10.0
        - setproctitle:      1.3.2
        - setuptools:        58.0.4
        - shortuuid:         1.0.9
        - six:               1.16.0
        - slackclient:       2.9.4
        - smmap:             5.0.0
        - sniffio:           1.3.0
        - soupsieve:         2.3.2.post1
        - stack-data:        0.6.2
        - statsmodels:       0.13.5
        - sympy:             1.10.1
        - tenacity:          8.1.0
        - tensorboard:       2.9.0
        - tensorboard-data-server: 0.6.0
        - tensorboard-plugin-wit: 1.8.1
        - termcolor:         2.1.0
        - terminado:         0.17.0
        - tinycss2:          1.2.1
        - toml:              0.10.2
        - tomli:             2.0.1
        - tomlkit:           0.11.5
        - toolz:             0.12.0
        - torch:             1.13.0
        - torchmetrics:      0.7.3
        - torchtyping:       0.1.4
        - torchvision:       0.14.0
        - tornado:           6.2
        - tqdm:              4.64.1
        - traitlets:         5.6.0
        - typeguard:         2.13.3
        - typing-extensions: 4.3.0
        - urllib3:           1.26.12
        - urwid:             2.1.2
        - urwid-readline:    0.13
        - virtualenv:        20.16.5
        - wandb:             0.13.5
        - wcwidth:           0.2.5
        - webencodings:      0.5.1
        - websocket-client:  1.4.2

More info

No response

cc @Borda

@junsoo-ha-unknot junsoo-ha-unknot added the needs triage Waiting to be triaged by maintainers label Dec 16, 2022
@semaphore-egg
Copy link
Contributor

Version 1.7.x is faster.

@awaelchli
Copy link
Contributor

Hi @junsoo-ha-unknot
We already have some work started here: #12786
Lots of imports have already been refactored to load lazily.
Closing it because it's a duplicate. Thanks for reporting it!

@awaelchli awaelchli closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2022
@awaelchli awaelchli added duplicate This issue or pull request already exists performance and removed needs triage Waiting to be triaged by maintainers labels Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists performance
Projects
None yet
Development

No branches or pull requests

3 participants