in src/edge/run.py [0:0]
def load_model(name, version):
"""Loads the model into the edge agent and unloads previous versions if any."""
global models_loaded
version = str(version)
# Create a model name string as a concatenation of name and version
identifier = "%s-%s" % (name, version.replace('.', '-'))
# Check if previous version of this model was loaded already and unload it
matching_model_dict = next((m for m in models_loaded if m['name'] == name), None)
if matching_model_dict:
logging.info('Previous version of new model found: %s' % matching_model_dict)
# Check if version is higher
if float(version) <= float(matching_model_dict['version']):
logging.info('New model version is not higher than previous version. Not loading incoming model.')
return
logging.info('Loading model into edge agent: %s' % identifier)
resp = edge_agent.load_model(identifier, os.path.join(SM_EDGE_MODEL_PATH, name, version))
if resp is None:
logging.error('It was not possible to load the model. Is the agent running?')
return
else:
models_loaded.append({'name': name, 'version': version, 'identifier': identifier})
logging.info('Sucessfully loaded new model version into agent')
if matching_model_dict:
logging.info('Unloading previous model version')
edge_agent.unload_model(matching_model_dict['identifier'])
models_loaded.remove(matching_model_dict)