Skip to content
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

[BUG] graspologic takes 33 seconds to import #1035

Open
loftusa opened this issue May 21, 2023 · 9 comments
Open

[BUG] graspologic takes 33 seconds to import #1035

loftusa opened this issue May 21, 2023 · 9 comments
Labels
enhancement New feature or request not planned by core Not planned to be worked on by core team, welcome to propose a plan of action

Comments

@loftusa
Copy link
Collaborator

loftusa commented May 21, 2023

Problem

Graspologic is taking an extremely long time to import for me. This is after a fresh pip install --upgrade graspologic. (Also had to pip install --upgrade numba and pip install --upgrade numpy to get it to import)

I timed it and it looks like it takes around 33 seconds, and importing it also gives some strange umap numba warning.

Screenshot 2023-05-20 at 9 19 02 PM

Example Code

Please see How to create a Minimal, Reproducible example for some guidance on creating the best possible example of the problem

from time import time
start = time()
import graspologic
end = time()

print(end - start)

Full Traceback

/usr/local/lib/python3.9/site-packages/umap_learn-0.5.3-py3.9.egg/umap/distances.py:1063: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  @numba.jit()
/usr/local/lib/python3.9/site-packages/umap_learn-0.5.3-py3.9.egg/umap/distances.py:1071: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  @numba.jit()
/usr/local/lib/python3.9/site-packages/umap_learn-0.5.3-py3.9.egg/umap/distances.py:1086: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  @numba.jit()
/usr/local/lib/python3.9/site-packages/umap_learn-0.5.3-py3.9.egg/umap/umap_.py:660: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  @numba.jit()
/usr/local/lib/python3.9/site-packages/graspologic/models/edge_swaps.py:215: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  _edge_swap_numba = nb.jit(_edge_swap)

Your Environment

  • Python version: 3.9.13
  • graspologic version: 3.0.0

Additional Details

This is in the graphstatsbook docker container with 7 cpus allocated and about 2/3 of my RAM on a 2022 macbook air with m2 chip.

@loftusa loftusa added the bug Something isn't working label May 21, 2023
@bdpedigo bdpedigo added enhancement New feature or request and removed bug Something isn't working labels May 22, 2023
@bdpedigo
Copy link
Collaborator

I don't plan on working on this, but if anyone wants to speed things up, go for it.

I'd also just note that importing a specific function or class is usually pretty quick

@bdpedigo bdpedigo added the not planned by core Not planned to be worked on by core team, welcome to propose a plan of action label May 22, 2023
@loftusa
Copy link
Collaborator Author

loftusa commented May 23, 2023

I did some light profiling on this with python -X importtime -c 'import graspologic -- here's what came up.
import_times.txt

@loftusa
Copy link
Collaborator Author

loftusa commented Dec 7, 2023

@bdpedigo I looked at this a bit more just now using tuna.
here's the import profile for graspologic:

Screenshot 2023-12-07 at 9 18 44 AM

appears to be mainly the umap import in graspologic.layouts.auto and ot in graspologic.align.seedless_procrustes

@bdpedigo
Copy link
Collaborator

bdpedigo commented Dec 7, 2023

that's interesting! and a cool tool/visualization

im open to discussing proposed fixes, i just dont really know what could be done here, since those other libraries are out of our controll

i can tell you that i dont think we use anything under ot.backend.tensorflow ot ot.backend.torch... so if there's some way to turn off those imports perhaps that could be a big save?

@bdpedigo
Copy link
Collaborator

bdpedigo commented Dec 7, 2023

i wonder why the load time is so much shorter for tuna than you, though?

@loftusa
Copy link
Collaborator Author

loftusa commented Dec 11, 2023

i wonder why the load time is so much shorter for tuna than you, though?

no clue, I noticed that too, how long does it take for you?

that's interesting! and a cool tool/visualization

im open to discussing proposed fixes, i just dont really know what could be done here, since those other libraries are out of our controll

i can tell you that i dont think we use anything under ot.backend.tensorflow ot ot.backend.torch... so if there's some way to turn off those imports perhaps that could be a big save?

throw imports inside of functions maybe? makes those functions take "longer" to run, but shorter for anybody who just wants to import the package

@bdpedigo
Copy link
Collaborator

bdpedigo commented Dec 11, 2023

PythonOT/POT#516 i wonder to what extent your issue is related to this? what version of POT are you on? it sounds like the root cause is tensorflow, do you have tensorflow installed in this environment?

@bdpedigo
Copy link
Collaborator

i guess another question - is there a reason you are needing to import all of graspologic, if you're saying you dont want some of these functions? might be much faster to just import the function(s) you need

@daxpryce
Copy link
Contributor

i wonder why the load time is so much shorter for tuna than you, though?

no clue, I noticed that too, how long does it take for you?

that's interesting! and a cool tool/visualization
im open to discussing proposed fixes, i just dont really know what could be done here, since those other libraries are out of our controll
i can tell you that i dont think we use anything under ot.backend.tensorflow ot ot.backend.torch... so if there's some way to turn off those imports perhaps that could be a big save?

throw imports inside of functions maybe? makes those functions take "longer" to run, but shorter for anybody who just wants to import the package

does this import stick around? are you paying the cost only the first time? if so, this seems totally reasonable to me, but if you add 33 seconds every time you try to save your graph layout, it's going to be a bit wonky. doesn't mean there won't be other ways to fix it, just that this specific one may not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request not planned by core Not planned to be worked on by core team, welcome to propose a plan of action
Projects
None yet
Development

No branches or pull requests

3 participants