inception-project / inception-external-recommender

Get annotation suggestions for the INCEpTION text annotation platform from spaCy, Sentence BERT, scikit-learn and more. Runs as a web-service compatible with the external recommender API of INCEpTION.
Apache License 2.0
40 stars 17 forks source link

Lazy loading and discarding of unused models #22

Open reckart opened 3 years ago

reckart commented 3 years ago

It might be interesting if there were an option initialize classifiers lazily and to free their resources if unused for a while:

Not sure if this is something that should/could be implemented as part of this framework or if it would rather be something to handle at the level of the production server (e.g. gunicorn).

jcklie commented 3 years ago

If you do not save the model in the classifier itself as a member variable, it should do what you want, does it not?. Just load models when you need the weights, then save them e.g. on disk.

reckart commented 3 years ago

If I see it correctly, then e.g. the spacy classifiers load the model in the constructor of the classifier and the constructor is called when the classifier is added to the server - so every worker keeps the spacy models in memory even if during actual use it may seldomly be called.

jcklie commented 3 years ago

Yes, but it prevents you nothing from doing it differently. I read this issue as if you want your own recommender to be able to be lazy, not changing existing ones.

reckart commented 3 years ago

I was suggesting to implement something that extracts this aspect of lazy endpoint management from the classifiers into the framework so that the implementors of classifiers do not need to worry about it or can easily add it e.g. by adding a decorator, wrapping the classifier in some kind of LazyClassifier or extending some kind of base class. Just an idea. Feel free to discard it.