-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Unload unused models from server memory #909
Conversation
I haven't reviewed the code, but as I read the description this would be a big change for anyone using multiple fixed model names under the same project, which seems to be a common practice. |
This only affects the server's in-memory models. The change means the server's You can of course store as many models as you like, but when you switch them (i.e. |
In our use case, and several others I am aware of, we use projects as individual bots and serve multiple models simultaneously from within the project. For example, we may have a pizza bot project and then a model inside for each language English, Spanish, German, etc. We manage our own versions with a version number suffixed to the model name. Just trying to make you aware that what I am describing is a pretty common use case that would have to be re-designed by the implementation of your proposed method. |
thanks for the feedback @wrathagom ! and great that you keep an eye on the issues before we break anything :) the case we're trying to guard against is that if you are continuously running a server and training models, the old ones never get unloaded and Rasa's memory footprint will monotonically increase. I'm sure there's some logic we can implement that supports both use cases, possibly adding an |
I have made some changes that should also accommodate your use case, @wrathagom:
@amn41 I guess we could also consider adding a |
@ricwo @amn41 I understand the need for it, indeed it's been a community request for awhile. Just pointing out that there was an issue open related to this #438 , specifically having to do with exposing endpoints for managing the loading/deleting of models. If I had my way that would still be the solution, but then again we're building platforms on top of Rasa not just individual agents. Maybe my team can take the code from this PR and expand it a bit to add the endpoints and contribute that back. I spoke a bit to soon on our specific use case as ours is actually a hash, which includes among other things the date. |
I think it makes sense to do the following:
|
rasa_nlu/data_router.py
Outdated
# type: (Text, Text) -> Dict[Text] | ||
"""Unload a model from server memory.""" | ||
|
||
project = project or RasaNLUConfig.DEFAULT_PROJECT_NAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use a default here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move this default to the endpoint level
rasa_nlu/data_router.py
Outdated
|
||
try: | ||
unloaded_model = self.project_store[project].unload(model) | ||
return {"unloaded_model": unloaded_model} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine to just return the model without the "unloaded_model"
wrapper, so just return unloaded_model
rasa_nlu/project.py
Outdated
|
||
def _list_loaded_models(self): | ||
return [ | ||
model for model, interpreter in self._models.items() if interpreter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if interpreter is not None
rasa_nlu/server.py
Outdated
request.setHeader('Content-Type', 'application/json') | ||
try: | ||
request.setResponseCode(200) | ||
response = self.data_router.unload_model(params.get('project'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
params.get("project", RasaNLUConfig.DEFAULT_PROJECT_NAME)
rasa_nlu/server.py
Outdated
params.get('model')) | ||
return simplejson.dumps(response) | ||
except Exception as e: | ||
request.setResponseCode(500) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also log to logger
Proposed changes:
Project._models
Project
when a new model is requested by the serverStatus (please check what you already did):