-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Mmap model shared between process , memory use is not stable #2883
Comments
As this is likely some behavior specific to your use, and not necessarily a bug in gensim, it'd be better to discuss at the discussion list, unless/until some bug/feature-request emerges. But, a few thoughts:
|
Another lead is just plain memory fragmentation from Python. The large numpy array will only live in RAM once (assuming nothing went wrong with So even if you managed to fork processes after loading the object, so that you have just one TL;DR: Make sure you're actually mmaping, so the big array is in RAM just once. Then check where the extra memory is creeping in from. You can use my smaps.py script, for example. |
Hi thanks for your answers , yes the keyedVector is loaded before to fork I tried to use gc.freeze() after the preload in gunicorn but it's not better. [2020-09-10 09:08:28,409] INFO in serve: Starting serving predict
[2020-09-10 09:08:31,831] INFO in utils: loading Word2VecKeyedVectors object from /opt/ml/model/keyedvector
[2020-09-10 09:08:31,959] INFO in utils: setting ignored attribute vectors_norm to None
[2020-09-10 09:08:31,959] INFO in utils: loaded /opt/ml/model/keyedvector
[2020-09-10 09:08:31,959] INFO in keyedvectors: precomputing L2-norms of word weight vectors
[2020-09-10 09:08:32,058] INFO in predictor: Keyed Vectors loaded.
[2020-09-10 09:08:32,059] INFO in predictor: Loading Annoy Index...
[2020-09-10 09:08:32,059] INFO in patch_annoy: Custom Annoy loader : prefault=True
[2020-09-10 09:08:32,063] INFO in predictor: Annoy Index loaded.
[2020-09-10 09:08:32,105] INFO in predictor: Warm index
[2020-09-10 09:08:34 +0000] [46] [INFO] Starting gunicorn 20.0.4
[2020-09-10 09:08:34 +0000] [46] [INFO] Listening at: unix:/tmp/gunicorn.sock (46)
[2020-09-10 09:08:34 +0000] [46] [INFO] Using worker: sync
Objects frozen in perm gen: 165434
[2020-09-10 09:08:34 +0000] [56] [INFO] Booting worker with pid: 56
[2020-09-10 09:08:34 +0000] [57] [INFO] Booting worker with pid: 57
[2020-09-10 09:08:34 +0000] [58] [INFO] Booting worker with pid: 58
[2020-09-10 09:08:34 +0000] [59] [INFO] Booting worker with pid: 59 |
As noted in my response, you might get more-assured mmap-sharing by loading the KeyedVectors into each separate process. It's hard to understand your logging without more of your full code - what code is loading the vectors & index that's not wholly-before the The way the increase happens after loading, gradually over use, means it could easily be other code (including your unshown "monkey patch" to the |
@gojomo again big thank for your help. So I tried without the Sorry for my wrong interpretations. |
Problem description
I'm exposing a word2vec model with Gunicorn sync workers.
(and I run this gunicorn process inside one docker container )
With 1 worker there is no problem. But with multiples workers ( forks from the main gunicorn process and with preload activated ) :
mmap work well at statup , the memory use is almost the same than if I'm using only one process.
But when I start to query the API ( each call execute a
indexer.model.wv.most_similar
) with a loadtest program, the memory usage grow until it stabilize.This is with 8 sync workers (memory is growing):
with only one worker the lines stay perfectly flat :
Steps/code/corpus to reproduce
Load a word2vec Gensim model with mmap activated and fork N times , then query the model in each subprocesses.
The problem is already in stackoverflow , but no solution proposed :
https://stackoverflow.com/questions/51616074/sharing-memory-for-gensims-keyedvectors-objects-between-docker-containers/51722607#51722607
What I tried :
This is the loading code of the model
Also i get this message when I load the previously normalized (
init_sims(replace=True)
) model is :setting ignored attribute vectors_norm to None
Versions
The text was updated successfully, but these errors were encountered: