Skip to content

Commit

Permalink
feat!: remove automatic loading of deprecated deepaas-test model
Browse files Browse the repository at this point in the history
Fixes: #132
  • Loading branch information
alvarolopez committed Jun 12, 2024
1 parent 242e02e commit 376b0f9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 44 deletions.
4 changes: 4 additions & 0 deletions deepaas/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@

class ModuleNotFoundError(Exception):
"""Module not found error."""


class NoModelsAvailable(Exception):
"""No models are available in the system."""
23 changes: 3 additions & 20 deletions deepaas/model/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from deepaas import config
from deepaas import exceptions
from deepaas.model import loading
from deepaas.model.v2 import test
from deepaas.model.v2 import wrapper

LOG = log.getLogger(__name__)
Expand Down Expand Up @@ -54,14 +53,8 @@ def register_models(app):
LOG.error("Model not found: %s", CONF.model_name)
raise
except Exception as e:
# We do not raise here, as we have not yet removed the deprecated loading of the
# test module... but we should remove it as soon as the code below is deprecated
LOG.warning("Error loading models: %s", e)
warnings.warn(
"Error loading models, using test model. This will be deprecated soon.",
DeprecationWarning,
stacklevel=2,
)
raise e

if MODELS:
if len(MODELS) > 1:
Expand All @@ -74,16 +67,6 @@ def register_models(app):
return

if not MODELS:
# Raise deprecation warning
warn_msg = (
"Using the built-in test model is deprecated, if you are testing the "
"API, please use the demo_app instead. "
"Check https://github.com/deephdc/demo_app for more information.",
)
warnings.warn(warn_msg, DeprecationWarning, stacklevel=2)
LOG.info("No models found in V2, loading test model")
LOG.warning(warn_msg)
MODELS["deepaas-test"] = wrapper.ModelWrapper(
"deepaas-test", test.TestModel(), app
)
LOG.error("No models found in V2, loading test model")
raise exceptions.NoModelsAvailable()
MODELS_LOADED = True
5 changes: 2 additions & 3 deletions deepaas/tests/fake_v2_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class TestModel(base.BaseModel):

name = "deepaas-test"

# FIXME(aloga): document this
schema = {
"date": fields.Date(),
"labels": fields.List(
Expand Down Expand Up @@ -135,7 +134,7 @@ def get_predict_args(self):
"accept": fields.Str(
metadata={
"description": (
"Media type(s) that is/are acceptable for the " "response."
"Media type(s) that is/are acceptable for the response."
),
"location": "headers",
},
Expand All @@ -151,7 +150,7 @@ def get_train_args(self):
required=True,
metadata={
"descripton": (
"This is a integer parameter, and it is " "a required one."
"This is a integer parameter, and it is a required one."
),
},
),
Expand Down
33 changes: 19 additions & 14 deletions deepaas/tests/test_v2_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
from webargs import fields

import deepaas
from deepaas import exceptions
import deepaas.model.v2
from deepaas.model.v2 import base as v2_base
from deepaas.model.v2 import test as v2_test
from deepaas.model.v2 import wrapper as v2_wrapper
from deepaas.tests import base
from deepaas.tests import fake_v2_model


class TestV2Model(base.TestCase):
Expand Down Expand Up @@ -131,7 +132,7 @@ class Model(object):
)

def test_dummy_model(self):
m = v2_test.TestModel()
m = fake_v2_model.TestModel()
pred = m.predict()
pred.pop("data")
self.assertDictEqual(
Expand All @@ -152,7 +153,7 @@ def test_dummy_model(self):
@mock.patch("deepaas.model.v2.wrapper.ModelWrapper._setup_cleanup")
@test_utils.unittest_run_loop
async def test_dummy_model_with_wrapper(self, m_clean):
w = v2_wrapper.ModelWrapper("foo", v2_test.TestModel(), self.app)
w = v2_wrapper.ModelWrapper("foo", fake_v2_model.TestModel(), self.app)
task = w.predict()
await task
ret = task.result()["output"]
Expand Down Expand Up @@ -203,30 +204,34 @@ async def test_model_with_not_implemented_attributes_and_wrapper(self, m_clean):

@mock.patch("deepaas.model.v2.wrapper.ModelWrapper._setup_cleanup")
@mock.patch("deepaas.model.loading.get_available_models")
async def test_loading_ok(self, mock_loading, m_clean):
def test_loading_ok(self, mock_loading, m_clean):
app = self.get_application()

mock_loading.return_value = {uuid.uuid4().hex: "bar"}
deepaas.model.v2.register_models(self.app)

deepaas.model.v2.register_models(app)
mock_loading.assert_called()
for m in deepaas.model.v2.MODELS.values():
self.assertIsInstance(m, v2_wrapper.ModelWrapper)

@mock.patch("deepaas.model.v2.wrapper.ModelWrapper._setup_cleanup")
@mock.patch("deepaas.model.loading.get_available_models")
async def test_loading_ok_singleton(self, mock_loading, m_clean):
def test_loading_ok_singleton(self, mock_loading, m_clean):
app = self.get_application()

mock_loading.return_value = {uuid.uuid4().hex: "bar"}
deepaas.model.v2.register_models(self.app)
deepaas.model.v2.register_models(self.app)
deepaas.model.v2.register_models(app)
deepaas.model.v2.register_models(app)
mock_loading.assert_called_once()
for m in deepaas.model.v2.MODELS.values():
self.assertIsInstance(m, v2_wrapper.ModelWrapper)

@mock.patch("deepaas.model.v2.wrapper.ModelWrapper._setup_cleanup")
@mock.patch("deepaas.model.loading.get_available_models")
async def test_loading_error(self, mock_loading, m_clean):
def test_loading_error(self, mock_loading, m_clean):
app = self.get_application()
mock_loading.return_value = {}
deepaas.model.v2.register_models(self.app)
self.assertRaises(
exceptions.NoModelsAvailable, deepaas.model.v2.register_models, app
)
mock_loading.assert_called()
self.assertIn("deepaas-test", deepaas.model.v2.MODELS)
m = deepaas.model.v2.MODELS.pop("deepaas-test")
self.assertIsInstance(m, v2_wrapper.ModelWrapper)
self.assertIsInstance(m.model_obj, v2_test.TestModel)
7 changes: 0 additions & 7 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,3 @@ Model wrapper
.. automodule:: deepaas.model.v2
:members:
:inherited-members:

V2 test model
#############

.. automodule:: deepaas.model.v2.test
:members:
:inherited-members:
5 changes: 5 additions & 0 deletions releasenotes/notes/deprecation-removals-1f43c9301633ac76.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
upgrade:
- |
Removed deprecated loading of "deepaas-test" model. If you wish to develop
or debug your model, use the "demo-app" instead: https://github.com/ai4os-hub/ai4os-demo-app

0 comments on commit 376b0f9

Please sign in to comment.