Hello, Recently we created a metaflow extension f...
# ask-metaflow
p
Hello, Recently we created a metaflow extension for our internal use cases (It has a Pytorch dependency) but then when we try to bootstrap the environment, it starts consuming memory like crazy. Does anyone know why this is happening? We suspect that it is because of the PyTorch dependency but maybe there are other reasons. Thanks!
d
it’s hard for me to answer this without more information. What do you mean “it has a pytorch dependency”. When is it consuming memory?
p
the extension has code that uses Pytorch, so it is a dependency of the extension
and when trying to bootstrap the virtual environment is when we are having problem with the memory
then when looking at the activity monitor we can see a lot of python processes that start to suck up memory
d
so your extension is doing
import pytorch
somewhere?
p
yes it is
g
Just a bit of extra context, we are creating a metaflow extension to share code across our company (following a suggestion in this same Slack channel) The code we are sharing has multiple dependencies (e.g. pytorch, transformers, numpy, pandas). When we run metaflow with our extension the amount of resources consumed skyrockets. By monitoring the resources we noticed that there's a bunch of python processes being executed during the Virtual Environment Bootstrapping step (previous to the execution of the flow). We suspect that it might have to do with the aforementioned dependencies making the Metaflow environment too large during the Virtual Env Bootstrapping process.
d
Sorry for the delay. If you are loading massive libraries that actually do something when loading, I could see that happening. Metaflow can launch multiple processes and if each process is loading the extension you wrote which INCLUDES large stuff, it may increase resource usage. I would suggest, for large libraries, to delay import until use (ie: the extension, instead of always loading Pytorch, loads it when the function that needs it is called). That may help a bit.
g
We ended up coming up with the same solution! We took the large libraries and lazy loaded them and that fixed the issue 🙂
d
cool. Sorry for being late tot he party 😞
g
Don't worry! Thank you for your help! It was really insightful 🙂