fix(mm): check for presence of invoker before emitting model load event

The model loader emits events. During testing, it doesn't have access to a fully-mocked events service, so the test fails when attempting to call a nonexistent method. There was a check for this previously, but I accidentally removed it. Restored.
This commit is contained in:
psychedelicious 2024-03-14 18:51:06 +11:00
parent 500a733d79
commit 20db93b901

View File

@ -58,7 +58,10 @@ class ModelLoadService(ModelLoadServiceBase):
:param submodel: For main (pipeline models), the submodel to fetch.
"""
self._invoker.services.events.emit_model_load_started(model_config, submodel_type)
# We don't have an invoker during testing
# TODO(psyche): Mock this method on the invoker in the tests
if hasattr(self, "_invoker"):
self._invoker.services.events.emit_model_load_started(model_config, submodel_type)
implementation, model_config, submodel_type = self._registry.get_implementation(model_config, submodel_type) # type: ignore
loaded_model: LoadedModel = implementation(
@ -68,6 +71,7 @@ class ModelLoadService(ModelLoadServiceBase):
convert_cache=self._convert_cache,
).load_model(model_config, submodel_type)
self._invoker.services.events.emit_model_load_started(model_config, submodel_type)
if hasattr(self, "_invoker"):
self._invoker.services.events.emit_model_load_started(model_config, submodel_type)
return loaded_model