diff --git a/caikit/core/__init__.py b/caikit/core/__init__.py index f9f7edc16..d4cbb3814 100644 --- a/caikit/core/__init__.py +++ b/caikit/core/__init__.py @@ -30,8 +30,7 @@ _warnings.filterwarnings("ignore") # Local -from . import blocks, data_model, module, module_config, resources, toolkit, workflows -from .blocks.base import BlockBase, block +from . import data_model, module, module_config, resources, toolkit, workflows from .data_model import DataObjectBase, dataobject from .model_manager import * from .module import * diff --git a/caikit/core/blocks/__init__.py b/caikit/core/blocks/__init__.py deleted file mode 100644 index 049dbde08..000000000 --- a/caikit/core/blocks/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright The Caikit Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -"""The `blocks` within the `caikit.core` library are essentially the conduits of algorithms. -Each block follows sets of principles about how they work including `.__init__()`, `.load()`, -`.run()`, `.save()`, and `.train()`. Blocks often require each other as inputs and support many -models. -""" - -################# -## Core Blocks ## -################# - -# Local -from .base import BlockSaver, block diff --git a/caikit/core/blocks/base.py b/caikit/core/blocks/base.py deleted file mode 100644 index ca78b4d17..000000000 --- a/caikit/core/blocks/base.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright The Caikit Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -"""This contains the `base` class from which ALL blocks inherit. This class is not for direct use -and most methods are, in fact, abstract. -""" - -# Standard -import threading - -# First Party -import alog - -# Local -from .. import module as mod -from ..module_type import module_type -from ..toolkit.errors import error_handler - -log = alog.use_channel("BLBASE") -error = error_handler.get(log) - - -@module_type("block") -# pylint: disable=abstract-method -class BlockBase(mod.ModuleBase): - """Abstract base class for creating Blocks. Inherits from ModuleBase.""" - - # This mutex is shared among TensorFlow / Keras models to use around model loading. - # In TensorFlow 1.x, model loading was *not* thread safe and this was required. - # We need to verify whether or not model loading operations are thread safe in TensorFlow 2.x - tensorflow_graph_mutex = threading.Lock() - - -# Hoist the @block decorator -block = BlockBase.block - - -class BlockSaver(mod.ModuleSaver): - """DEPRECATED. Use ModuleSaver directly""" diff --git a/caikit/runtime/service_generation/rpcs.py b/caikit/runtime/service_generation/rpcs.py index ffaf8a869..aefeab7ea 100644 --- a/caikit/runtime/service_generation/rpcs.py +++ b/caikit/runtime/service_generation/rpcs.py @@ -168,9 +168,9 @@ def _module_class_to_req_name(self) -> str: """Helper function to convert from the name of a module to the name of the request RPC message - Example: self.clz._module__ = sample_lib.blocks.sample_task.sample_implementation + Example: self.clz._module__ = sample_lib.modules.sample_task.sample_implementation - return: BlocksSampleTaskSampleBlockTrainRequest + return: BlocksSampleTaskSampleModuleTrainRequest """ module_split = self.clz.__module__.split(".") diff --git a/caikit/runtime/servicers/global_train_servicer.py b/caikit/runtime/servicers/global_train_servicer.py index bc6ba9e33..b6c8b6f9d 100644 --- a/caikit/runtime/servicers/global_train_servicer.py +++ b/caikit/runtime/servicers/global_train_servicer.py @@ -114,8 +114,8 @@ def Train(self, request, *_, **__) -> TrainingJob: try: with alog.ContextLog(log.debug, outer_scope_name): - # BlocksSampleTaskSampleBlockTrainRequest - # getattr(importlib.import_module("sample_lib.blocks.sample_task"), "SampleBlock") + # BlocksSampleTaskSampleModuleTrainRequest + # getattr(importlib.import_module("sample_lib.modules.sample_task"), "SampleModule") # TODO: fixme - temporary workaround for now desc_name = desc_name.replace("TrainRequest", "") split = re.split("(?<=.)(?=[A-Z])", desc_name) diff --git a/examples/text-sentiment/models/text_sentiment/config.yml b/examples/text-sentiment/models/text_sentiment/config.yml index 9ea463dfa..cd1315092 100644 --- a/examples/text-sentiment/models/text_sentiment/config.yml +++ b/examples/text-sentiment/models/text_sentiment/config.yml @@ -13,5 +13,5 @@ # limitations under the License. block_id: 8f72161-c0e4-49b0-8fd0-7587b3017a35 -name: HuggingFaceSentimentBlock +name: HuggingFaceSentimentModule version: 0.0.1 diff --git a/examples/text-sentiment/text_sentiment/runtime_model/__init__.py b/examples/text-sentiment/text_sentiment/runtime_model/__init__.py index 3b1bd68a7..7adad323d 100644 --- a/examples/text-sentiment/text_sentiment/runtime_model/__init__.py +++ b/examples/text-sentiment/text_sentiment/runtime_model/__init__.py @@ -13,4 +13,4 @@ # limitations under the License. # # Local # Local -from .hf_block import HuggingFaceSentimentBlock +from .hf_module import HuggingFaceSentimentModule diff --git a/examples/text-sentiment/text_sentiment/runtime_model/hf_block.py b/examples/text-sentiment/text_sentiment/runtime_model/hf_module.py similarity index 93% rename from examples/text-sentiment/text_sentiment/runtime_model/hf_block.py rename to examples/text-sentiment/text_sentiment/runtime_model/hf_module.py index af626a744..ba4b41de6 100644 --- a/examples/text-sentiment/text_sentiment/runtime_model/hf_block.py +++ b/examples/text-sentiment/text_sentiment/runtime_model/hf_module.py @@ -19,7 +19,7 @@ from transformers import pipeline # Local -from caikit.core import BlockBase, ModuleLoader, ModuleSaver, block +from caikit.core import ModuleBase, ModuleLoader, ModuleSaver, module from text_sentiment.data_model.classification import ( ClassificationPrediction, ClassInfo, @@ -27,8 +27,8 @@ ) -@block("8f72161-c0e4-49b0-8fd0-7587b3017a35", "HuggingFaceSentimentBlock", "0.0.1") -class HuggingFaceSentimentBlock(BlockBase): +@module("8f72161-c0e4-49b0-8fd0-7587b3017a35", "HuggingFaceSentimentModule", "0.0.1") +class HuggingFaceSentimentModule(ModuleBase): """Class to wrap sentiment analysis pipeline from HuggingFace""" def __init__(self, model_path) -> None: diff --git a/tests/core/blocks/__init__.py b/tests/core/blocks/__init__.py deleted file mode 100644 index 2068258bf..000000000 --- a/tests/core/blocks/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright The Caikit Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/tests/core/blocks/test_base.py b/tests/core/blocks/test_base.py deleted file mode 100644 index f74c4ac15..000000000 --- a/tests/core/blocks/test_base.py +++ /dev/null @@ -1,302 +0,0 @@ -# Copyright The Caikit Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Standard -import os -import shutil -import tempfile - -# Local -from caikit.config import get_config -from caikit.core.blocks import block -from caikit.core.blocks.base import BlockSaver -from caikit.core.toolkit.serializers import JSONSerializer - -# pylint: disable=import-error -from sample_lib.blocks.sample_task import SampleBlock -from sample_lib.data_model.sample import SampleInputType, SampleTask - -# Unit Test Infrastructure -from tests.base import TestCaseBase -import caikit.core - - -class TestBlockBase(TestCaseBase): - @classmethod - def setUpClass(cls): - cls.dummy_block_class = SampleBlock - - def setUp(self): - self.base_block_instance = caikit.core.BlockBase() - self.dummy_model_path = os.path.join(self.fixtures_dir, "dummy_block") - self.dummy_block_instance = self.dummy_block_class(self.dummy_model_path) - - def test_init_available(self): - model = caikit.core.BlockBase() - self.assertIsInstance(model, caikit.core.BlockBase) - - def test_load_not_implemented(self): - with self.assertRaises(NotImplementedError): - caikit.core.BlockBase.load() - - def test_run_not_implemented(self): - with self.assertRaises(NotImplementedError): - self.base_block_instance.run() - - def test_save_not_implemented(self): - with self.assertRaises(NotImplementedError): - self.base_block_instance.save("dummy_path") - - def test_train_not_implemented(self): - with self.assertRaises(NotImplementedError): - caikit.core.BlockBase.train() - - def test_timed_run_seconds(self): - # with seconds - num_seconds = 0.01 - time_passed, iterations_passed, _ = self.dummy_block_instance.timed_run( - sample_input=SampleInputType(name="Gabe"), num_seconds=num_seconds - ) - self.assertIsInstance(time_passed, float) - self.assertLess(num_seconds, time_passed) - self.assertIsInstance(iterations_passed, int) - - def test_timed_run_iterations(self): - # with iterations - num_iterations = 1 - time_passed, iterations_passed, _ = self.dummy_block_instance.timed_run( - sample_input=SampleInputType(name="Gabe"), num_iterations=num_iterations - ) - self.assertIsInstance(time_passed, float) - self.assertIsInstance(iterations_passed, int) - self.assertEqual(num_iterations, iterations_passed) - - def test_timed_load(self): - time_passed, model = self.dummy_block_class.timed_load( - module_path=self.dummy_model_path - ) - self.assertIsInstance(time_passed, float) - self.assertIsInstance(model, self.dummy_block_class) - - -class TestBlockAnnotation(TestCaseBase): - def test_block_annotation_adds_metadata_to_class(self): - # Declare a new dummy block - @block("12345", "MyNewBlock", "0.0.1", SampleTask) - class MyNewBlock(caikit.core.BlockBase): - # pylint: disable=no-method-argument,super-init-not-called - def __init__(): - pass - - self.assertEqual(MyNewBlock.BLOCK_ID, "12345") - self.assertEqual(MyNewBlock.MODULE_ID, "12345") - self.assertEqual(MyNewBlock.BLOCK_NAME, "MyNewBlock") - self.assertEqual(MyNewBlock.BLOCK_VERSION, "0.0.1") - self.assertEqual( - MyNewBlock.BLOCK_CLASS, - MyNewBlock.__module__ + "." + MyNewBlock.__qualname__, - ) - self.assertIsNotNone(MyNewBlock.PRODUCER_ID) - self.assertEqual(MyNewBlock.PRODUCER_ID.name, "MyNewBlock") - self.assertEqual(MyNewBlock.PRODUCER_ID.version, "0.0.1") - - def test_block_annotation_registers_block_in_module_registry(self): - # Declare a new dummy block - @block("12345-A", "MyNewBlock2", "0.0.2", SampleTask) - # pylint: disable=unused-variable - class MyNewBlock2(caikit.core.BlockBase): - # pylint: disable=no-method-argument,super-init-not-called - def __init__(): - pass - - self.assertIsNotNone(caikit.core.MODULE_REGISTRY.get("12345-A")) - - def test_block_annotation_registers_block_in_block_registry(self): - # Declare a new dummy block - @block("12345-B", "MyNewBlock3", "0.0.2", SampleTask) - # pylint: disable=unused-variable - class MyNewBlock3(caikit.core.BlockBase): - # pylint: disable=no-method-argument,super-init-not-called - def __init__(): - pass - - self.assertIsNotNone(caikit.core.BLOCK_REGISTRY.get("12345-B")) - - def test_block_annotation_registers_will_not_register_duplicate_block_ids(self): - # Declare a new dummy block - def declare_block(): - @block("12345-C", "MyNewBlock4", "0.0.2", SampleTask) - # pylint: disable=unused-variable - class MyNewBlock4(caikit.core.BlockBase): - # pylint: disable=no-method-argument,super-init-not-called - def __init__(): - pass - - declare_block() # Should succeed - - # Verify the fist block declaration is in the registry - self.assertIsNotNone(caikit.core.MODULE_REGISTRY.get("12345-C")) - - with self.assertRaises(RuntimeError): - declare_block() # Should fail (block was already registered) - - -class TestBlockSaver(TestCaseBase): - @classmethod - def setUpClass(cls): - cls.dummy_block = SampleBlock() - - def test_block_saver_attribs(self): - # make sure the saver has the desired config attrs - with tempfile.TemporaryDirectory() as tempdir: - with BlockSaver( - self.dummy_block, - model_path=tempdir, - ) as block_saver: - # name - self.assertIsInstance(block_saver.config.get("name"), str) - self.assertEqual( - block_saver.config.get("name"), self.dummy_block.BLOCK_NAME - ) - - # block version - self.assertIsInstance(block_saver.config.get("version"), str) - self.assertEqual( - block_saver.config.get("version"), self.dummy_block.BLOCK_VERSION - ) - - # block class - self.assertIsInstance(block_saver.config.get("block_class"), str) - self.assertEqual( - block_saver.config.get("block_class"), self.dummy_block.BLOCK_CLASS - ) - - # block id - self.assertIsInstance(block_saver.config.get("block_id"), str) - self.assertEqual( - block_saver.config.get("block_id"), self.dummy_block.BLOCK_ID - ) - - # sample_lib_version - self.assertIsInstance(block_saver.config.get("sample_lib_version"), str) - self.assertEqual( - block_saver.config.get("sample_lib_version"), - "1.2.3", - ) - - # creation date - self.assertIsInstance(block_saver.config.get("created"), str) - - # and that the config gets written - self.assertTrue(os.path.isfile(os.path.join(tempdir, "config.yml"))) - - def test_add_dir(self): - with tempfile.TemporaryDirectory() as tempdir: - with BlockSaver( - self.dummy_block, - model_path=tempdir, - ) as block_saver: - # add a directory called `a` - a_rel, a_abs = block_saver.add_dir("a") - self.assertEqual(os.path.normpath(a_rel), os.path.basename(a_abs)) - self.assertTrue(os.path.isdir(a_abs)) - - # add `b/c` inside `a` - bc_rel, bc_abs = block_saver.add_dir("b/c", "a") - self.assertTrue(os.path.isdir(bc_abs)) - self.assertTrue(bc_abs.endswith(bc_rel)) - - # verify `a/b/c` was created - self.assertTrue(os.path.isdir(os.path.join(tempdir, "a/b/c"))) - - def test_update_config(self): - # verify that we can add some config options with `saver.update_config` - with tempfile.TemporaryDirectory() as tempdir: - with BlockSaver( - self.dummy_block, - model_path=tempdir, - ) as block_saver: - block_saver.update_config( - { - "training_mode": "stochastic", - "training_epochs": 1000, - } - ) - - self.assertEqual(block_saver.config.get("training_mode"), "stochastic") - self.assertEqual(block_saver.config.get("training_epochs"), 1000) - - def test_copy_file(self): - # verify that we can copy a file into the model with `saver.copy_file` - with tempfile.TemporaryDirectory() as tempdir: - with BlockSaver( - self.dummy_block, - model_path=tempdir, - ) as block_saver: - block_saver.copy_file( - os.path.join(self.fixtures_dir, "linux.txt"), "artifacts" - ) - self.assertTrue( - os.path.isfile(os.path.join(tempdir, "artifacts/linux.txt")) - ) - - def test_remove_on_error(self): - # we cannot use `TemporaryDirectory` context manager because the model saver will - # remove it in the middle of the test - tempdir = tempfile.mkdtemp() - - try: - # verify that exceptions are re-raised from the context manager - with self.assertRaises(RuntimeError): - with BlockSaver( - self.dummy_block, - model_path=tempdir, - ) as block_saver: - block_saver.add_dir("artifacts") - raise RuntimeError("test") - - # verify that our error caused the model tree to be removed - self.assertFalse(os.path.exists(os.path.join(tempdir, "config.yml"))) - self.assertFalse(os.path.exists(os.path.join(tempdir, "artifacts"))) - - finally: - shutil.rmtree(tempdir, ignore_errors=True) - - def test_save_object_saves_a_json_object_to_model_root_dir(self): - with tempfile.TemporaryDirectory() as tempdir: - with BlockSaver( - self.dummy_block, - model_path=tempdir, - ) as block_saver: - serializer = JSONSerializer() - - block_saver.save_object({"foo": "bar"}, "test.json", serializer) - - self.assertTrue(os.path.exists(os.path.join(tempdir, "test.json"))) - - def test_save_object_saves_a_json_object_to_model_sub_dir(self): - with tempfile.TemporaryDirectory() as tempdir: - with BlockSaver( - self.dummy_block, - model_path=tempdir, - ) as block_saver: - serializer = JSONSerializer() - - block_saver.save_object( - {"foo": "bar"}, "test.json", serializer, "artifacts" - ) - - self.assertTrue( - os.path.exists(os.path.join(tempdir, "artifacts/test.json")) - ) diff --git a/tests/core/data_model/streams/test_data_stream.py b/tests/core/data_model/streams/test_data_stream.py index 86bcb8b7b..25e920870 100644 --- a/tests/core/data_model/streams/test_data_stream.py +++ b/tests/core/data_model/streams/test_data_stream.py @@ -18,7 +18,7 @@ # Local from caikit.core import data_model as core_dm from caikit.core.augmentors import AugmentorBase -from sample_lib.blocks.sample_task.sample_implementation import SampleBlock +from sample_lib.modules.sample_task.sample_implementation import SampleModule from sample_lib.data_model.sample import SampleInputType, SampleOutputType # Unit Test Infrastructure diff --git a/tests/core/test_model_manager.py b/tests/core/test_model_manager.py index 8eed0fbb1..a8823f31f 100644 --- a/tests/core/test_model_manager.py +++ b/tests/core/test_model_manager.py @@ -27,7 +27,7 @@ from caikit.core.module_backends.base import SharedLoadBackendBase # Unit Test Infrastructure -from sample_lib.blocks.sample_task import SampleBlock +from sample_lib.modules.sample_task import SampleModule from sample_lib.data_model import SampleTask from tests.base import TestCaseBase from tests.conftest import temp_config @@ -207,10 +207,10 @@ def setup_saved_model(mock_backend_class): backend_types.register_backend_type(LocalBackend) - @caikit.core.blocks.block( + @caikit.core.modules.module( id=DUMMY_MODULE_ID, name="dummy base", version="0.0.1", task=SampleTask ) - class DummyFoo(caikit.core.blocks.base.BlockBase): + class DummyFoo(caikit.core.ModuleBase): @classmethod def load(cls, *args, **kwargs): return cls() @@ -218,8 +218,8 @@ def load(cls, *args, **kwargs): # Register backend type backend_types.register_backend_type(mock_backend_class) - @caikit.core.blocks.block(base_module=DummyFoo, backend_type=backend_types.MOCK) - class DummyBar(caikit.core.blocks.base.BlockBase): + @caikit.core.modules.module(base_module=DummyFoo, backend_type=backend_types.MOCK) + class DummyBar(caikit.core.ModuleBase): SUPPORTED_LOAD_BACKENDS = [backend_types.MOCK, backend_types.LOCAL] @classmethod @@ -229,10 +229,10 @@ def load(self, *args, **kwargs): return DummyFoo, DummyBar -@caikit.core.blocks.block( +@caikit.core.modules.module( id="non-distributed", name="non distributed mod", version="0.0.1", task=SampleTask ) -class NonDistributedBlock(caikit.core.blocks.base.BlockBase): +class NonDistributedBlock(caikit.core.ModuleBase): @classmethod def load(cls, *args, **kwargs): return cls() @@ -480,8 +480,8 @@ def stop(self): backend_types.register_backend_type(MockBackend2) - @caikit.core.blocks.block(base_module=DummyFoo, backend_type=backend_types.MOCK2) - class DummyBaz(caikit.core.blocks.base.BlockBase): + @caikit.core.modules.module(base_module=DummyFoo, backend_type=backend_types.MOCK2) + class DummyBaz(caikit.core.ModuleBase): SUPPORTED_LOAD_BACKENDS = [backend_types.MOCK, backend_types.MOCK2] @classmethod @@ -508,7 +508,7 @@ def test_load_must_return_model(): """ @caikit.core.block("00110203-baad-beef-0809-0a0b0c0d0e0f", "FunkyBlock", "0.0.1") - class _FunkyModel(SampleBlock): + class _FunkyModel(SampleModule): @classmethod def load(cls, model_path): return (super().load(model_path), "something else") @@ -592,7 +592,7 @@ def register_config(self, config): def load(self, model_path, *args, **kwargs): """This load function doesn't read from model_path, so it definitely does not read the config.yml file""" - return SampleBlock() + return SampleModule() backend_types.register_backend_type(NoYamlLoader) @@ -607,4 +607,4 @@ def load(self, model_path, *args, **kwargs): ): configure() model = caikit.core.load(tmpdir) - assert isinstance(model, SampleBlock) + assert isinstance(model, SampleModule) diff --git a/tests/core/test_module.py b/tests/core/test_module.py index 2e2f31ee5..7dd0d1121 100644 --- a/tests/core/test_module.py +++ b/tests/core/test_module.py @@ -17,7 +17,6 @@ import io import os import tempfile -import uuid # Third Party import pytest @@ -66,17 +65,17 @@ def configure_alternate_backend_impl(): """Function to register a new backend type and register a module implementation of existing caikit.core module""" - @caikit.core.blocks.block( + @caikit.core.modules.module( id=DUMMY_MODULE_ID, name="dummy base", version="0.0.1", task=SampleTask ) - class DummyFoo(caikit.core.blocks.base.BlockBase): + class DummyFoo(caikit.core.ModuleBase): pass # Register backend type backend_types.register_backend_type(MockBackend) - @caikit.core.blocks.block(base_module=DummyFoo, backend_type=backend_types.MOCK) - class DummyBar(caikit.core.blocks.base.BlockBase): + @caikit.core.modules.module(base_module=DummyFoo, backend_type=backend_types.MOCK) + class DummyBar(caikit.core.ModuleBase): def test_fetching_backend(self): return [ backend @@ -303,8 +302,8 @@ def test_duplicate_registration_raises(reset_globals): DummyFoo, _ = configure_alternate_backend_impl() with pytest.raises(AssertionError): - @caikit.core.blocks.block(base_module=DummyFoo, backend_type=backend_types.MOCK) - class DummyBat(caikit.core.blocks.base.BlockBase): + @caikit.core.modules.module(base_module=DummyFoo, backend_type=backend_types.MOCK) + class DummyBat(caikit.core.ModuleBase): pass @@ -314,7 +313,7 @@ def test_backend_impl_inheritance_error(reset_globals): DummyFoo, DummyBar = configure_alternate_backend_impl() with pytest.raises(TypeError): - @caikit.core.blocks.block(backend_type=backend_types.MOCK) + @caikit.core.modules.module(backend_type=backend_types.MOCK) class DummyBat(DummyFoo): pass @@ -366,10 +365,10 @@ def test_override_load_supported_backend(reset_globals): """Test if the class can successfully define its own backends that it supports load from""" - @caikit.core.blocks.block( + @caikit.core.modules.module( id=DUMMY_MODULE_ID, name="dummy base", version="0.0.1", task=SampleTask ) - class DummyFoo(caikit.core.blocks.base.BlockBase): + class DummyFoo(caikit.core.ModuleBase): pass class BazBackend(BackendBase): @@ -383,8 +382,8 @@ class FooBackend(BackendBase): supported_backends = [backend_types.BAZ, backend_types.FOO] - @caikit.core.blocks.block(base_module=DummyFoo, backend_type=backend_types.BAZ) - class DummyBaz(caikit.core.blocks.base.BlockBase): + @caikit.core.modules.module(base_module=DummyFoo, backend_type=backend_types.BAZ) + class DummyBaz(caikit.core.ModuleBase): SUPPORTED_LOAD_BACKENDS = supported_backends assert hasattr(DummyBaz, SUPPORTED_LOAD_BACKENDS_VAR_NAME) @@ -404,20 +403,20 @@ class FooBackend(BackendBase): backend_types.register_backend_type(BazBackend) backend_types.register_backend_type(FooBackend) - @caikit.core.blocks.block( + @caikit.core.modules.module( id=DUMMY_MODULE_ID, name="dummy base", version="0.0.1", task=SampleTask ) - class DummyLocal(caikit.core.blocks.base.BlockBase): + class DummyLocal(caikit.core.ModuleBase): pass - @caikit.core.blocks.block(backend_type=backend_types.BAZ, base_module=DummyLocal) - class DummyBaz(caikit.core.blocks.base.BlockBase): + @caikit.core.modules.module(backend_type=backend_types.BAZ, base_module=DummyLocal) + class DummyBaz(caikit.core.ModuleBase): pass - @caikit.core.blocks.block( + @caikit.core.modules.module( backend_type=backend_types.FOO, base_module=DummyLocal.MODULE_ID ) - class DummyFoo(caikit.core.blocks.base.BlockBase): + class DummyFoo(caikit.core.ModuleBase): pass assert DummyLocal in list(caikit.core.MODULE_REGISTRY.values()) diff --git a/tests/core/test_module_metadata.py b/tests/core/test_module_metadata.py index e132b31d6..9af0b5de2 100644 --- a/tests/core/test_module_metadata.py +++ b/tests/core/test_module_metadata.py @@ -29,7 +29,7 @@ from caikit.core import toolkit # pylint: disable=import-error -from sample_lib.blocks.sample_task import SampleBlock +from sample_lib.modules.sample_task import SampleModule # pylint: disable=import-error from sample_lib.data_model import SampleTask @@ -100,7 +100,7 @@ def test_loaded_modules_have_metadata(sample_model_path): """Make sure a model has metadata after being loaded""" expected_metadata = _load_model_metadata(sample_model_path) model_loaded_with_core = caikit.core.load(sample_model_path) - model_directly_loaded = SampleBlock.load(sample_model_path) + model_directly_loaded = SampleModule.load(sample_model_path) # TODO: figure out "module_id" and "model_path" as well... @@ -121,7 +121,7 @@ def test_block_has_saved_field(): the "saved" field should track each timestamp when you save, and should be different """ with tempfile.TemporaryDirectory() as tempdir: - model1 = SampleBlock() + model1 = SampleModule() path1 = os.path.join(tempdir, "test1") model1.save(path1) resaved_metadata1 = _load_model_metadata(path1) @@ -138,7 +138,7 @@ def test_block_has_saved_field(): def test_block_has_tracking_id_field(): with tempfile.TemporaryDirectory() as tempdir: - model1 = SampleBlock() + model1 = SampleModule() path1 = os.path.join(tempdir, "test1") model1.save(path1) resaved_metadata1 = _load_model_metadata(path1) @@ -171,7 +171,7 @@ def test_block_metadata_is_saved_into_a_workflow(sample_model_path): resaved_metadata = _load_model_metadata(os.path.join(tempdir, "dummy_model")) # assert resaved_metadata == initial_metadata - fields_to_not_check = {"saved", "SampleBlock_version", "train"} + fields_to_not_check = {"saved", "SampleModule_version", "train"} _check_dicts_equal(resaved_metadata, initial_metadata, fields_to_not_check) @@ -181,7 +181,7 @@ def test_load_can_be_called_directly_with_non_standard_kwargs(sample_model_path) # note that # - no positional arguments given # - path is `model_path` not `module_path` - model = SampleBlock.load(foo="bar", test_kw="arg", model_path=sample_model_path) + model = SampleModule.load(foo="bar", test_kw="arg", model_path=sample_model_path) assert len(model.metadata) > 0 _check_dicts_equal(initial_metadata, model.metadata, {"module_id", "model_path"}) @@ -190,7 +190,7 @@ def test_load_can_be_called_directly_with_non_standard_kwargs(sample_model_path) @caikit.core.block( "00110203-0809-beef-baad-0a0b0c0d0e0f", "FunkyBlock", "0.0.1", SampleTask ) - class _FunkyModel(SampleBlock): + class _FunkyModel(SampleModule): @classmethod def load(cls, some_really_odd_param_name): return super().load(some_really_odd_param_name) @@ -204,14 +204,14 @@ def load(cls, some_really_odd_param_name): def test_parent_class_loads_work(sample_model_path): """This test ensures that our metadata injector works on blocks that inherit from other classes""" - model = SampleBlock.load(sample_model_path) + model = SampleModule.load(sample_model_path) - assert isinstance(model, SampleBlock) + assert isinstance(model, SampleModule) def test_workflows_save_correct_module_paths(): with tempfile.TemporaryDirectory() as tempdir: - SampleWorkflow(SampleBlock()).save(tempdir) + SampleWorkflow(SampleModule()).save(tempdir) workflow = caikit.core.load(tempdir) # Should only be the path to the one block diff --git a/tests/core/test_module_type.py b/tests/core/test_module_type.py index 1e963cf5f..4938db1f1 100644 --- a/tests/core/test_module_type.py +++ b/tests/core/test_module_type.py @@ -12,7 +12,7 @@ # Local from caikit.core import module from caikit.core.module_type import module_type -from sample_lib.blocks.sample_task import SampleBlock +from sample_lib.modules.sample_task import SampleModule from sample_lib.data_model.sample import SampleTask import caikit.core @@ -96,7 +96,7 @@ def test_module_no_reused_ids(TestModBase): with pytest.raises(RuntimeError): @TestModBase.testmod( - id=SampleBlock.MODULE_ID, + id=SampleModule.MODULE_ID, name="Sample tesmod", version="1.2.3", task=SampleTask, @@ -109,7 +109,7 @@ class SampleTestmod(TestModBase): def test_intermediate_metabase(): """Make sure that an abc.ABC can be declared that derives from ModuleBase""" - class Intermediate(caikit.core.blocks.base.BlockBase, abc.ABC): + class Intermediate(caikit.core.ModuleBase, abc.ABC): """Sample intermediate base class""" @abc.abstractmethod diff --git a/tests/core/test_task.py b/tests/core/test_task.py index 9ceeab40b..dcebce6e2 100644 --- a/tests/core/test_task.py +++ b/tests/core/test_task.py @@ -7,7 +7,7 @@ # Local from caikit.core import TaskBase, task -from sample_lib import SampleBlock +from sample_lib import SampleModule from sample_lib.data_model.sample import SampleInputType, SampleOutputType, SampleTask import caikit.core @@ -51,16 +51,16 @@ class SampleTask(TaskBase): def test_task_is_set_on_module_classes(): - assert hasattr(SampleBlock, "TASK_CLASS") - assert SampleBlock.TASK_CLASS == SampleTask + assert hasattr(SampleModule, "TASK_CLASS") + assert SampleModule.TASK_CLASS == SampleTask def test_task_can_be_inferred_from_parent_block(): - @caikit.core.blocks.block(id="foobar", name="Stuff", version="0.0.1") - class Stuff(SampleBlock): + @caikit.core.modules.module(id="foobar", name="Stuff", version="0.0.1") + class Stuff(SampleModule): pass - assert Stuff.TASK_CLASS == SampleBlock.TASK_CLASS + assert Stuff.TASK_CLASS == SampleModule.TASK_CLASS def test_task_cannot_conflict_with_parent_block(): @@ -73,16 +73,16 @@ class SomeTask(TaskBase): with pytest.raises(TypeError, match="but superclass has"): - @caikit.core.blocks.block( + @caikit.core.modules.module( id=str(uuid.uuid4()), name="Stuff", version="0.0.1", task=SomeTask ) - class Stuff(SampleBlock): + class Stuff(SampleModule): pass def test_task_is_not_required_for_blocks(): - @caikit.core.blocks.block(id=str(uuid.uuid4()), name="Stuff", version="0.0.1") - class Stuff(caikit.core.blocks.base.BlockBase): + @caikit.core.modules.module(id=str(uuid.uuid4()), name="Stuff", version="0.0.1") + class Stuff(caikit.core.ModuleBase): pass assert Stuff.TASK_CLASS is None diff --git a/tests/core/workflows/test_base.py b/tests/core/workflows/test_base.py index f796056c9..0081a2ed5 100644 --- a/tests/core/workflows/test_base.py +++ b/tests/core/workflows/test_base.py @@ -21,7 +21,7 @@ from caikit.core.workflows.base import WorkflowLoader, WorkflowSaver # pylint: disable=import-error -from sample_lib.blocks.sample_task import SampleBlock +from sample_lib.modules.sample_task import SampleModule from sample_lib.data_model.sample import SampleInputType, SampleTask from sample_lib.workflows.sample_task import SampleWorkflow @@ -183,7 +183,7 @@ def test_missing_module_key(self): def test_module_load(self): self.assertIsInstance( self.loader.load_module("dummy_model"), - SampleBlock, + SampleModule, ) def test_module_load_list_invalid(self): @@ -199,7 +199,7 @@ def test_module_load_list(self): self.assertIsInstance(loaded_modules, list) for module in loaded_modules: - self.assertIsInstance(module, SampleBlock) + self.assertIsInstance(module, SampleModule) class TestWorkflowSaver(TestCaseBase): diff --git a/tests/fixtures/dummy_block/config.yml b/tests/fixtures/dummy_block/config.yml index 1669059c9..135ade099 100644 --- a/tests/fixtures/dummy_block/config.yml +++ b/tests/fixtures/dummy_block/config.yml @@ -2,7 +2,7 @@ # note: this config is not actually loadable since there is no DummyBlock # but we *can* use it to create a config object for testing block_id: "00110203-0405-0607-0809-0a0b02dd0e0f" -block_class: "sample_lib.blocks.sample_task.sample_implementation.SampleBlock" +block_class: "sample_lib.modules.sample_task.sample_implementation.SampleModule" name: "Dummy config file." version: "4.0.2" description': "dummy model for testing" diff --git a/tests/fixtures/dummy_block_singleton/config.yml b/tests/fixtures/dummy_block_singleton/config.yml index 5b201cacf..f98b9bbaf 100644 --- a/tests/fixtures/dummy_block_singleton/config.yml +++ b/tests/fixtures/dummy_block_singleton/config.yml @@ -2,7 +2,7 @@ # note: this config is not actually loadable since there is no DummyBlock # but we *can* use it to create a config object for testing block_id: "00110203-0405-0607-0809-0a0b02dd0e0f" -block_class: "sample_lib.blocks.sample_task.sample_implementation.SampleBlock" +block_class: "sample_lib.modules.sample_task.sample_implementation.SampleModule" name: "Dummy config file." version: "4.0.2" diff --git a/tests/fixtures/dummy_workflow/dummy_block/config.yml b/tests/fixtures/dummy_workflow/dummy_block/config.yml index fa730ee10..1b0ca12b1 100644 --- a/tests/fixtures/dummy_workflow/dummy_block/config.yml +++ b/tests/fixtures/dummy_workflow/dummy_block/config.yml @@ -2,7 +2,7 @@ # note: this config is not actually loadable since there is no DummyBlock # but we *can* use it to create a config object for testing block_id: "00110203-0405-0607-0809-0a0b02dd0e0f" -block_class: "sample_lib.blocks.sample_task.sample_implementation.SampleBlock" +block_class: "sample_lib.modules.sample_task.sample_implementation.SampleModule" name: "Dummy config file." version: "4.0.2" diff --git a/tests/fixtures/models/bar/config.yml b/tests/fixtures/models/bar/config.yml index a091af907..bd34d6abd 100644 --- a/tests/fixtures/models/bar/config.yml +++ b/tests/fixtures/models/bar/config.yml @@ -1,7 +1,7 @@ -block_class: sample_lib.blocks.other_task.other_implementation.OtherBlock +block_class: sample_lib.modules.other_task.other_implementation.OtherModule block_id: 33221100-0405-0607-0809-0a0b02dd0e0f created: "2023-03-28 16:34:58.720898" -name: OtherBlock +name: OtherModule sample_lib_version: 1.2.3 saved: "2023-03-28 16:34:58.720929" tracking_id: 4ee84742-79f3-40da-8465-26c48c77968c diff --git a/tests/fixtures/models/foo/config.yml b/tests/fixtures/models/foo/config.yml index 7e0a36251..51e000734 100644 --- a/tests/fixtures/models/foo/config.yml +++ b/tests/fixtures/models/foo/config.yml @@ -1,7 +1,7 @@ -block_class: sample_lib.blocks.sample_task.sample_implementation.SampleBlock +block_class: sample_lib.modules.sample_task.sample_implementation.SampleModule block_id: 00110203-0405-0607-0809-0a0b02dd0e0f created: "2023-03-14 11:24:58.720898" -name: SampleBlock +name: SampleModule sample_lib_version: 1.2.3 saved: "2023-03-14 11:24:58.720929" tracking_id: 0676cc24-1823-4a31-a3ff-96a45b316699 diff --git a/tests/fixtures/sample_block/config.yml b/tests/fixtures/sample_block/config.yml index b2668a887..3fe2c6988 100644 --- a/tests/fixtures/sample_block/config.yml +++ b/tests/fixtures/sample_block/config.yml @@ -1,7 +1,7 @@ -block_class: sample_lib.blocks.sample_task.sample_implementation.SampleBlock +block_class: sample_lib.modules.sample_task.sample_implementation.SampleModule block_id: 00110203-0405-0607-0809-0a0b02dd0e0f created: "2022-11-21 21:51:18.761485" -name: SampleBlock +name: SampleModule saved: "2022-11-21 21:51:18.761501" tracking_id: 0fc3c53c-37f3-44bf-b90e-5135871ba1bf train: diff --git a/tests/fixtures/sample_lib/__init__.py b/tests/fixtures/sample_lib/__init__.py index d13c4c8cd..a55978236 100644 --- a/tests/fixtures/sample_lib/__init__.py +++ b/tests/fixtures/sample_lib/__init__.py @@ -2,8 +2,8 @@ import os # Local -from . import blocks, data_model, workflows -from .blocks import InnerBlock, OtherBlock, SampleBlock, SamplePrimitiveBlock +from . import modules, data_model, workflows +from .modules import InnerModule, OtherModule, SampleModule, SamplePrimitiveModule from .workflows import SampleWorkflow from caikit.config import configure diff --git a/tests/fixtures/sample_lib/blocks/__init__.py b/tests/fixtures/sample_lib/blocks/__init__.py deleted file mode 100644 index f80a3c879..000000000 --- a/tests/fixtures/sample_lib/blocks/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# Local -from .other_task import OtherBlock -from .sample_task import InnerBlock, SampleBlock, SamplePrimitiveBlock diff --git a/tests/fixtures/sample_lib/blocks/other_task/__init__.py b/tests/fixtures/sample_lib/blocks/other_task/__init__.py deleted file mode 100644 index 9cedbd600..000000000 --- a/tests/fixtures/sample_lib/blocks/other_task/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# Local -from . import other_implementation -from .other_implementation import OtherBlock diff --git a/tests/fixtures/sample_lib/blocks/sample_task/__init__.py b/tests/fixtures/sample_lib/blocks/sample_task/__init__.py deleted file mode 100644 index a66887179..000000000 --- a/tests/fixtures/sample_lib/blocks/sample_task/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# Local -from .inner_block import InnerBlock -from .list_implementation import ListBlock -from .primitive_party_implementation import SamplePrimitiveBlock -from .sample_implementation import SampleBlock diff --git a/tests/fixtures/sample_lib/modules/__init__.py b/tests/fixtures/sample_lib/modules/__init__.py new file mode 100644 index 000000000..baf38ed63 --- /dev/null +++ b/tests/fixtures/sample_lib/modules/__init__.py @@ -0,0 +1,3 @@ +# Local +from .other_task import OtherModule +from .sample_task import InnerModule, SampleModule, SamplePrimitiveModule diff --git a/tests/fixtures/sample_lib/modules/other_task/__init__.py b/tests/fixtures/sample_lib/modules/other_task/__init__.py new file mode 100644 index 000000000..a533b07ab --- /dev/null +++ b/tests/fixtures/sample_lib/modules/other_task/__init__.py @@ -0,0 +1,3 @@ +# Local +from . import other_implementation +from .other_implementation import OtherModule diff --git a/tests/fixtures/sample_lib/blocks/other_task/other_implementation.py b/tests/fixtures/sample_lib/modules/other_task/other_implementation.py similarity index 92% rename from tests/fixtures/sample_lib/blocks/other_task/other_implementation.py rename to tests/fixtures/sample_lib/modules/other_task/other_implementation.py index e8b4e6761..a823d4b51 100644 --- a/tests/fixtures/sample_lib/blocks/other_task/other_implementation.py +++ b/tests/fixtures/sample_lib/modules/other_task/other_implementation.py @@ -12,9 +12,9 @@ @caikit.core.block( - "33221100-0405-0607-0809-0a0b02dd0e0f", "OtherBlock", "0.0.1", OtherTask + "33221100-0405-0607-0809-0a0b02dd0e0f", "OtherModule", "0.0.1", OtherTask ) -class OtherBlock(caikit.core.BlockBase): +class OtherModule(caikit.core.BlockBase): def __init__(self, batch_size=64, learning_rate=0.0015): super().__init__() self.batch_size = batch_size @@ -52,7 +52,7 @@ def train( training_data: DataStream[int], sample_input: Union[SampleInputType, str], batch_size: int = 64, - ) -> "OtherBlock": + ) -> "OtherModule": """Sample training method that produces a trained model""" # Barf if we were incorrectly passed data not in datastream format assert type(training_data) == DataStream diff --git a/tests/fixtures/sample_lib/modules/sample_task/__init__.py b/tests/fixtures/sample_lib/modules/sample_task/__init__.py new file mode 100644 index 000000000..065b6f675 --- /dev/null +++ b/tests/fixtures/sample_lib/modules/sample_task/__init__.py @@ -0,0 +1,5 @@ +# Local +from .inner_block import InnerModule +from .list_implementation import ListBlock +from .primitive_party_implementation import SamplePrimitiveModule +from .sample_implementation import SampleModule diff --git a/tests/fixtures/sample_lib/blocks/sample_task/inner_block.py b/tests/fixtures/sample_lib/modules/sample_task/inner_block.py similarity index 81% rename from tests/fixtures/sample_lib/blocks/sample_task/inner_block.py rename to tests/fixtures/sample_lib/modules/sample_task/inner_block.py index bc7544510..33f2182b9 100644 --- a/tests/fixtures/sample_lib/blocks/sample_task/inner_block.py +++ b/tests/fixtures/sample_lib/modules/sample_task/inner_block.py @@ -7,9 +7,9 @@ @caikit.core.block( - "00110203-baad-beef-0809-0a0b02dd0e0f", "SampleBlock", "0.0.1", SampleTask + "00110203-baad-beef-0809-0a0b02dd0e0f", "SampleModule", "0.0.1", SampleTask ) -class InnerBlock(caikit.core.BlockBase): +class InnerModule(caikit.core.BlockBase): def __init__(self, batch_size=64, learning_rate=0.0015): super().__init__() self.batch_size = batch_size diff --git a/tests/fixtures/sample_lib/blocks/sample_task/list_implementation.py b/tests/fixtures/sample_lib/modules/sample_task/list_implementation.py similarity index 100% rename from tests/fixtures/sample_lib/blocks/sample_task/list_implementation.py rename to tests/fixtures/sample_lib/modules/sample_task/list_implementation.py diff --git a/tests/fixtures/sample_lib/blocks/sample_task/primitive_party_implementation.py b/tests/fixtures/sample_lib/modules/sample_task/primitive_party_implementation.py similarity index 89% rename from tests/fixtures/sample_lib/blocks/sample_task/primitive_party_implementation.py rename to tests/fixtures/sample_lib/modules/sample_task/primitive_party_implementation.py index d98d54ce2..310e3522e 100644 --- a/tests/fixtures/sample_lib/blocks/sample_task/primitive_party_implementation.py +++ b/tests/fixtures/sample_lib/modules/sample_task/primitive_party_implementation.py @@ -11,9 +11,9 @@ @caikit.core.block( - "00112233-0405-0607-0809-0a0b02dd0e0f", "SampleBlock", "0.0.1", SampleTask + "00112233-0405-0607-0809-0a0b02dd0e0f", "SampleModule", "0.0.1", SampleTask ) -class SamplePrimitiveBlock(caikit.core.BlockBase): +class SamplePrimitiveModule(caikit.core.BlockBase): def __init__(self): super().__init__() diff --git a/tests/fixtures/sample_lib/blocks/sample_task/sample_implementation.py b/tests/fixtures/sample_lib/modules/sample_task/sample_implementation.py similarity index 94% rename from tests/fixtures/sample_lib/blocks/sample_task/sample_implementation.py rename to tests/fixtures/sample_lib/modules/sample_task/sample_implementation.py index 130b09332..84e4a9377 100644 --- a/tests/fixtures/sample_lib/blocks/sample_task/sample_implementation.py +++ b/tests/fixtures/sample_lib/modules/sample_task/sample_implementation.py @@ -17,9 +17,9 @@ @caikit.core.block( - "00110203-0405-0607-0809-0a0b02dd0e0f", "SampleBlock", "0.0.1", SampleTask + "00110203-0405-0607-0809-0a0b02dd0e0f", "SampleModule", "0.0.1", SampleTask ) -class SampleBlock(caikit.core.BlockBase): +class SampleModule(caikit.core.BlockBase): POISON_PILL_NAME = "Bob Marley" POISON_PILL_BATCH_SIZE = 999 @@ -71,7 +71,7 @@ def train( training_data: DataStream[SampleTrainingType], batch_size: int = 64, oom_exit: bool = False, - ) -> "SampleBlock": + ) -> "SampleModule": """Sample training method that produces a trained model""" if oom_exit: diff --git a/tests/fixtures/sample_lib/workflows/sample_task/sample_implementation.py b/tests/fixtures/sample_lib/workflows/sample_task/sample_implementation.py index 5ad77551d..2fecc4cce 100644 --- a/tests/fixtures/sample_lib/workflows/sample_task/sample_implementation.py +++ b/tests/fixtures/sample_lib/workflows/sample_task/sample_implementation.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # Local -from ...blocks.sample_task.sample_implementation import SampleBlock +from ...modules.sample_task.sample_implementation import SampleModule from ...data_model import SampleInputType, SampleOutputType, SampleTask from caikit.core.workflows import WorkflowLoader, WorkflowSaver import caikit.core @@ -22,7 +22,7 @@ "A34E68FA-E5E6-41BD-BAAE-77A880EB6877", "SampleWorkflow", "0.0.1", SampleTask ) class SampleWorkflow(caikit.core.WorkflowBase): - def __init__(self, sample_block: SampleBlock = SampleBlock()): + def __init__(self, sample_block: SampleModule = SampleModule()): super().__init__() self.block = sample_block @@ -43,5 +43,5 @@ def save(self, model_path): saver.save_module(self.block, "dummy_model") @classmethod - def train(cls, sample_block: SampleBlock) -> "SampleWorkflow": + def train(cls, sample_block: SampleModule) -> "SampleWorkflow": return cls(sample_block) diff --git a/tests/runtime/metrics/test_rpc_meter.py b/tests/runtime/metrics/test_rpc_meter.py index fac6f30f1..bfaa553f5 100644 --- a/tests/runtime/metrics/test_rpc_meter.py +++ b/tests/runtime/metrics/test_rpc_meter.py @@ -29,8 +29,8 @@ def setUp(self): """This method runs before each test begins to run""" self.rpc_meter = RPCMeter() # Note: These are not real classes in sample_lib - self.another_widget_type = "" - self.another_fidget_type = "" + self.another_widget_type = "" + self.another_fidget_type = "" def test_update_metrics(self): pool = ThreadPool(1000) diff --git a/tests/runtime/model_management/test_batcher.py b/tests/runtime/model_management/test_batcher.py index fe60878ee..609347aee 100644 --- a/tests/runtime/model_management/test_batcher.py +++ b/tests/runtime/model_management/test_batcher.py @@ -50,7 +50,7 @@ @caikit.core.block( "7464f684-58e3-4e99-9a58-1c5bc085472b", "slow sample block", "0.0.1", SampleTask ) -class SlowSampleBlock(caikit.core.blocks.base.BlockBase): +class SlowSampleModule(caikit.core.ModuleBase): """This block is just a wrapper around another module that will inject a sleep """ @@ -78,7 +78,7 @@ def run_batch(self, *args, **kwargs): "0.0.1", SampleTask, ) -class StubBlock(caikit.core.blocks.base.BlockBase): +class StubBlock(caikit.core.ModuleBase): # NOTE: The initial implementation had "num_bobs" which expected an int. # This led to the discovery of the fact that lists of ints are not # considered "expandable iterables" in the default run_batch impl. @@ -179,7 +179,7 @@ def test_single_request(): def test_multi_request_batch(): """Make sure that batches of size > 1 can be run""" - model = SlowSampleBlock(caikit.core.load(DUMMY_MODEL)) + model = SlowSampleModule(caikit.core.load(DUMMY_MODEL)) batch_size = 10 wrapped_model = Batcher("test-model", model, batch_size) threads = {str(i): ModelRunThread(wrapped_model, i) for i in range(2 * batch_size)} @@ -202,7 +202,7 @@ def test_multi_request_batch(): def test_stop_in_flight_batch(): """Make sure that setting the stop event will preempt running a batch""" model_delay = 0.001 - model = SlowSampleBlock(caikit.core.load(DUMMY_MODEL), model_delay) + model = SlowSampleModule(caikit.core.load(DUMMY_MODEL), model_delay) batch_size = 10 wrapped_model = Batcher("test-model", model, batch_size, model_delay * 2) threads = {str(i): ModelRunThread(wrapped_model, i) for i in range(2 * batch_size)} @@ -306,7 +306,7 @@ def test_invalid_req_after_valid_req(): processed and the invalid request is rejected. """ - model = SlowSampleBlock(StubBlock()) + model = SlowSampleModule(StubBlock()) batch_size = 5 wrapped_model = Batcher("stub-model", model, batch_size) threads = { @@ -340,7 +340,7 @@ def test_valid_req_after_invalid_req(): defaults, the previous invalid requests are rejected. """ - model = SlowSampleBlock(StubBlock()) + model = SlowSampleModule(StubBlock()) batch_size = 5 wrapped_model = Batcher("stub-model", model, batch_size) threads = { @@ -372,7 +372,7 @@ def test_batch_collect_delay(): """Make sure that with the batch delay, multiple sequential calls end up in the same batchg even when not presented concurrently """ - model = SlowSampleBlock(StubBlock()) + model = SlowSampleModule(StubBlock()) batch_size = 5 batch_collect_delay = 0.01 wrapped_model = Batcher("stub-model", model, batch_size, batch_collect_delay) diff --git a/tests/runtime/model_management/test_model_loader.py b/tests/runtime/model_management/test_model_loader.py index e2f4ee10d..c7275469c 100644 --- a/tests/runtime/model_management/test_model_loader.py +++ b/tests/runtime/model_management/test_model_loader.py @@ -29,7 +29,7 @@ from caikit.runtime.model_management.batcher import Batcher from caikit.runtime.model_management.model_loader import ModelLoader from caikit.runtime.types.caikit_runtime_exception import CaikitRuntimeException -from sample_lib.blocks.sample_task import SampleBlock +from sample_lib.modules.sample_task import SampleModule from sample_lib.data_model import SampleInputType, SampleOutputType from tests.conftest import random_test_id, temp_config from tests.core.helpers import MockBackend @@ -245,11 +245,11 @@ def test_load_distributed_impl(): ): @block( - base_module=SampleBlock, + base_module=SampleModule, backend_type=backend_types.MOCK, backend_config_override={"bar1": 1}, ) - class DistributedGadget(caikit.core.blocks.base.BlockBase): + class DistributedGadget(caikit.core.ModuleBase): """An alternate implementation of a Gadget""" SUPPORTED_LOAD_BACKENDS = [ @@ -272,7 +272,7 @@ def load(cls, model_load_path) -> "DistributedGadget": with tempfile.TemporaryDirectory() as model_path: # Create and save the model directly with the local impl - SampleBlock().save(model_path) + SampleModule().save(model_path) model_type = "gadget" diff --git a/tests/runtime/service_generation/signature_parsing/test_parsers.py b/tests/runtime/service_generation/signature_parsing/test_parsers.py index cedb9002c..eb097ab13 100644 --- a/tests/runtime/service_generation/signature_parsing/test_parsers.py +++ b/tests/runtime/service_generation/signature_parsing/test_parsers.py @@ -67,51 +67,51 @@ def test_get_output_type_name(): empty_sign = inspect.Signature(return_annotation=inspect.Signature.empty) assert ( get_output_type_name( - module_class=sample_lib.blocks.sample_task.SampleBlock, + module_class=sample_lib.modules.sample_task.SampleModule, fn_signature=empty_sign, - fn=sample_lib.blocks.sample_task.SampleBlock.run, + fn=sample_lib.modules.sample_task.SampleModule.run, ) == sample_lib.data_model.SampleOutputType ) # Test that we use type annotation to deduct output type inner_block_run_method_ptr = getattr( - sample_lib.blocks.sample_task.InnerBlock, "run" + sample_lib.modules.sample_task.InnerModule, "run" ) fn_sign = inspect.signature(inner_block_run_method_ptr) assert ( get_output_type_name( - module_class=sample_lib.blocks.sample_task.InnerBlock, + module_class=sample_lib.modules.sample_task.InnerModule, fn_signature=fn_sign, - fn=sample_lib.blocks.sample_task.InnerBlock.run, + fn=sample_lib.modules.sample_task.InnerModule.run, ) == sample_lib.data_model.SampleOutputType ) # Test that we use type annotation to deduct output type is return annotation is a string - def _run(self, some_input: str) -> "InnerBlock": + def _run(self, some_input: str) -> "InnerModule": pass fn_sign = inspect.signature(_run) assert ( get_output_type_name( - module_class=sample_lib.blocks.sample_task.InnerBlock, + module_class=sample_lib.modules.sample_task.InnerModule, fn_signature=fn_sign, - fn=sample_lib.blocks.sample_task.InnerBlock.run, + fn=sample_lib.modules.sample_task.InnerModule.run, ) - == sample_lib.blocks.sample_task.InnerBlock + == sample_lib.modules.sample_task.InnerModule ) # Test that we return None if type annotation as a string that doesn't match module class name - def _run2(self, some_input: str) -> "AStringThatsNotInnerBlock": + def _run2(self, some_input: str) -> "AStringThatsNotInnerModule": pass fn_sign = inspect.signature(_run2) assert ( get_output_type_name( - module_class=sample_lib.blocks.sample_task.InnerBlock, + module_class=sample_lib.modules.sample_task.InnerModule, fn_signature=fn_sign, - fn=sample_lib.blocks.sample_task.InnerBlock.run, + fn=sample_lib.modules.sample_task.InnerModule.run, ) == None ) @@ -119,9 +119,9 @@ def _run2(self, some_input: str) -> "AStringThatsNotInnerBlock": # User doesn't provide any type annotation or docstring, return None assert ( get_output_type_name( - module_class=sample_lib.blocks.sample_task.InnerBlock, + module_class=sample_lib.modules.sample_task.InnerModule, fn_signature=empty_sign, - fn=sample_lib.blocks.sample_task.InnerBlock.run, + fn=sample_lib.modules.sample_task.InnerModule.run, ) == None ) @@ -130,9 +130,9 @@ def _run2(self, some_input: str) -> "AStringThatsNotInnerBlock": with patch("docstring_parser.parse", side_effect=ParseError("mocked error")): assert ( get_output_type_name( - module_class=sample_lib.blocks.sample_task.InnerBlock, + module_class=sample_lib.modules.sample_task.InnerModule, fn_signature=empty_sign, - fn=sample_lib.blocks.sample_task.InnerBlock.run, + fn=sample_lib.modules.sample_task.InnerModule.run, ) == None ) @@ -141,7 +141,7 @@ def _run2(self, some_input: str) -> "AStringThatsNotInnerBlock": def test_get_argument_types_with_real_block(): """Quick check that we get the right type for our sample block""" assert ( - get_argument_types(sample_lib.blocks.sample_task.SampleBlock.run)[ + get_argument_types(sample_lib.modules.sample_task.SampleModule.run)[ "sample_input" ] == sample_lib.data_model.SampleInputType @@ -150,7 +150,7 @@ def test_get_argument_types_with_real_block(): # Test that if a ParseError was raised with docstring.parsers, we could still parse from type annotation with patch("docstring_parser.parse", side_effect=ParseError("mocked error")): assert ( - get_argument_types(sample_lib.blocks.sample_task.SampleBlock.run)[ + get_argument_types(sample_lib.modules.sample_task.SampleModule.run)[ "sample_input" ] == sample_lib.data_model.SampleInputType diff --git a/tests/runtime/service_generation/test_create_service.py b/tests/runtime/service_generation/test_create_service.py index 52513e6ce..edc170865 100644 --- a/tests/runtime/service_generation/test_create_service.py +++ b/tests/runtime/service_generation/test_create_service.py @@ -21,8 +21,8 @@ ## Setup ######################################################################## -widget_class = sample_lib.blocks.sample_task.SampleBlock -untrainable_module_class = sample_lib.blocks.sample_task.SamplePrimitiveBlock +widget_class = sample_lib.modules.sample_task.SampleModule +untrainable_module_class = sample_lib.modules.sample_task.SamplePrimitiveModule ## Tests ######################################################################## @@ -46,42 +46,42 @@ def test_create_inference_rpcs(): def test_create_inference_rpcs_for_multiple_modules_of_same_type(): module_list = [ - sample_lib.blocks.sample_task.SampleBlock, - sample_lib.blocks.sample_task.SamplePrimitiveBlock, - sample_lib.blocks.other_task.OtherBlock, + sample_lib.modules.sample_task.SampleModule, + sample_lib.modules.sample_task.SamplePrimitiveModule, + sample_lib.modules.other_task.OtherModule, ] rpcs = create_inference_rpcs(module_list) # only 2 RPCs, Widget and Gadget because SampleWidget and AnotherWidget are of the same module type Widget assert len(rpcs) == 2 - assert sample_lib.blocks.sample_task.SampleBlock in rpcs[0].module_list - assert sample_lib.blocks.sample_task.SamplePrimitiveBlock in rpcs[0].module_list - assert sample_lib.blocks.other_task.OtherBlock in rpcs[1].module_list + assert sample_lib.modules.sample_task.SampleModule in rpcs[0].module_list + assert sample_lib.modules.sample_task.SamplePrimitiveModule in rpcs[0].module_list + assert sample_lib.modules.other_task.OtherModule in rpcs[1].module_list def test_create_inference_rpcs_with_block_and_workflow(): module_list = [ - sample_lib.blocks.sample_task.SampleBlock, + sample_lib.modules.sample_task.SampleModule, sample_lib.workflows.sample_task.SampleWorkflow, ] rpcs = create_inference_rpcs(module_list) # only 1 RPC assert len(rpcs) == 1 - assert sample_lib.blocks.sample_task.SampleBlock in rpcs[0].module_list + assert sample_lib.modules.sample_task.SampleModule in rpcs[0].module_list assert sample_lib.workflows.sample_task.SampleWorkflow in rpcs[0].module_list def test_create_inference_rpcs_remove_non_primitive_modules(): # NOTE: This requires Gadget to be in config since other modules do not have methods - TODO fix? module_list = [ - sample_lib.blocks.sample_task.SampleBlock, # is a primitive module - sample_lib.blocks.sample_task.InnerBlock, # not a primitive module + sample_lib.modules.sample_task.SampleModule, # is a primitive module + sample_lib.modules.sample_task.InnerModule, # not a primitive module ] rpcs = create_inference_rpcs(module_list) # only 1 RPC, fidget is not valid assert len(rpcs) == 1 - assert sample_lib.blocks.sample_task.SampleBlock in rpcs[0].module_list + assert sample_lib.modules.sample_task.SampleModule in rpcs[0].module_list ### create_training_rpcs tests ################################################# diff --git a/tests/runtime/service_generation/test_type_helpers.py b/tests/runtime/service_generation/test_type_helpers.py index 1bb503bdb..cd2f2df46 100644 --- a/tests/runtime/service_generation/test_type_helpers.py +++ b/tests/runtime/service_generation/test_type_helpers.py @@ -35,5 +35,5 @@ def test_data_stream_helpers(): def test_model_type_helpers(): - assert is_model_type(sample_lib.blocks.sample_task.SampleBlock) - assert is_model_type(Union[str, sample_lib.blocks.sample_task.SampleBlock]) + assert is_model_type(sample_lib.modules.sample_task.SampleModule) + assert is_model_type(Union[str, sample_lib.modules.sample_task.SampleModule]) diff --git a/tests/runtime/servicers/test_global_predict_servicer_impl.py b/tests/runtime/servicers/test_global_predict_servicer_impl.py index 6b9a79ec9..c317ae5d6 100644 --- a/tests/runtime/servicers/test_global_predict_servicer_impl.py +++ b/tests/runtime/servicers/test_global_predict_servicer_impl.py @@ -27,7 +27,7 @@ # Local from caikit.runtime.servicers.global_predict_servicer import GlobalPredictServicer from caikit.runtime.types.caikit_runtime_exception import CaikitRuntimeException -from sample_lib.blocks.sample_task import SampleBlock +from sample_lib.modules.sample_task import SampleModule from sample_lib.data_model import SampleInputType, SampleOutputType from tests.fixtures import Fixtures import sample_lib @@ -40,7 +40,7 @@ def test_calling_predict_should_raise_if_block_raises( sample_inference_service, sample_predict_servicer, loaded_model_id ): with pytest.raises(CaikitRuntimeException) as context: - # SampleBlocks will raise a RuntimeError if the throw flag is set + # SampleModules will raise a RuntimeError if the throw flag is set request = sample_inference_service.messages.SampleTaskRequest( sample_input=HAPPY_PATH_INPUT, throw=True ) @@ -56,9 +56,9 @@ def test_invalid_input_to_a_valid_caikit_core_class_method_raises( ): """Test that a caikit.core block that gets an unexpected input value errors in an expected way""" with pytest.raises(CaikitRuntimeException) as context: - # SampleBlocks will raise a ValueError if the poison pill name is given + # SampleModules will raise a ValueError if the poison pill name is given request = sample_inference_service.messages.SampleTaskRequest( - sample_input=SampleInputType(name=SampleBlock.POISON_PILL_NAME).to_proto(), + sample_input=SampleInputType(name=SampleModule.POISON_PILL_NAME).to_proto(), ) sample_predict_servicer.Predict( request, Fixtures.build_context(loaded_model_id) @@ -167,7 +167,7 @@ def test_metering_predict_rpc_counter(sample_inference_service, loaded_model_id) assert data[0]["batch_size"] == 20 assert len(data[0]["model_type_counters"]) == 1 assert data[0]["model_type_counters"] == { - "": 20 + "": 20 } finally: sample_predict_servicer.rpc_meter.end_writer_thread() @@ -213,7 +213,7 @@ def test_metering_write_to_metrics_file_twice( assert data[0]["batch_size"] == 1 assert len(data[0]["model_type_counters"]) == 1 assert data[0]["model_type_counters"] == { - "": 1 + "": 1 } finally: sample_predict_servicer.rpc_meter.end_writer_thread() diff --git a/tests/runtime/servicers/test_global_train_servicer_impl.py b/tests/runtime/servicers/test_global_train_servicer_impl.py index 3d55b2f95..b2af7b3a3 100644 --- a/tests/runtime/servicers/test_global_train_servicer_impl.py +++ b/tests/runtime/servicers/test_global_train_servicer_impl.py @@ -22,7 +22,7 @@ # Local from caikit.runtime.servicers.global_train_servicer import GlobalTrainServicer from caikit.runtime.types.caikit_runtime_exception import CaikitRuntimeException -from sample_lib.blocks.sample_task.sample_implementation import SampleBlock +from sample_lib.modules.sample_task.sample_implementation import SampleModule from sample_lib.data_model.sample import ( OtherOutputType, SampleInputType, @@ -88,7 +88,7 @@ def test_global_train_sample_task( ).to_proto() model_name = random_test_id() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=model_name, batch_size=42, training_data=training_data, @@ -106,7 +106,7 @@ def test_global_train_sample_task( assert result.batch_size == 42 assert ( result.BLOCK_CLASS - == "sample_lib.blocks.sample_task.sample_implementation.SampleBlock" + == "sample_lib.modules.sample_task.sample_implementation.SampleModule" ) # give the trained model time to load @@ -140,7 +140,7 @@ def test_global_train_other_task( batch_size = 42 stream_type = caikit.interfaces.common.data_model.DataStreamSourceInt training_data = stream_type(jsondata=stream_type.JsonData(data=[1])).to_proto() - train_request = sample_train_service.messages.BlocksOtherTaskOtherBlockTrainRequest( + train_request = sample_train_service.messages.BlocksOtherTaskOtherModuleTrainRequest( model_name="Other block Training", training_data=training_data, sample_input=SampleInputType(name="Gabe").to_proto(), @@ -158,7 +158,7 @@ def test_global_train_other_task( assert result.batch_size == batch_size assert ( result.BLOCK_CLASS - == "sample_lib.blocks.other_task.other_implementation.OtherBlock" + == "sample_lib.modules.other_task.other_implementation.OtherModule" ) # give the trained model time to load @@ -241,7 +241,7 @@ def test_run_train_job_works_with_wait( jsondata=stream_type.JsonData(data=[SampleTrainingType(1)]) ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), batch_size=42, training_data=training_data, @@ -251,7 +251,7 @@ def test_run_train_job_works_with_wait( with TemporaryDirectory() as tmp_dir: training_response = servicer.run_training_job( train_request, - SampleBlock, + SampleModule, training_id="dummy-training-id", training_output_dir=tmp_dir, wait=True, @@ -280,7 +280,7 @@ def test_run_train_job_works_with_no_autoload(sample_train_service): jsondata=stream_type.JsonData(data=[SampleTrainingType(1)]) ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=str(uuid.uuid4()), batch_size=42, training_data=training_data, @@ -293,7 +293,7 @@ def test_run_train_job_works_with_no_autoload(sample_train_service): with TemporaryDirectory() as tmp_dir: training_response = servicer.run_training_job( train_request, - SampleBlock, + SampleModule, training_id="dummy-training-id", training_output_dir=tmp_dir, wait=True, @@ -309,7 +309,7 @@ def test_run_train_job_works_with_autoload(sample_train_service): jsondata=stream_type.JsonData(data=[SampleTrainingType(1)]) ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=str(uuid.uuid4()), batch_size=42, training_data=training_data, @@ -322,7 +322,7 @@ def test_run_train_job_works_with_autoload(sample_train_service): with TemporaryDirectory() as tmp_dir: training_response = servicer.run_training_job( train_request, - SampleBlock, + SampleModule, training_id="dummy-training-id-2", training_output_dir=tmp_dir, wait=True, @@ -367,7 +367,7 @@ def test_global_train_Edge_Case_Widget_should_raise_when_error_surfaces_from_blo jsondata=stream_type.JsonData(data=[SampleTrainingType(1)]) ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), batch_size=999, training_data=training_data, @@ -392,7 +392,7 @@ def test_global_train_returns_exit_code_with_oom( jsondata=stream_type.JsonData(data=[SampleTrainingType(1)]) ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), batch_size=42, training_data=training_data, diff --git a/tests/runtime/test_grpc_server.py b/tests/runtime/test_grpc_server.py index 89530ccb1..4dea3d07c 100644 --- a/tests/runtime/test_grpc_server.py +++ b/tests/runtime/test_grpc_server.py @@ -139,7 +139,7 @@ def test_model_train(runtime_grpc_server): assert ( result.BLOCK_CLASS - == "sample_lib.blocks.sample_task.sample_implementation.SampleBlock" + == "sample_lib.modules.sample_task.sample_implementation.SampleModule" ) # Fields with defaults have expected values assert result.batch_size == 64 @@ -184,7 +184,7 @@ def test_train_fake_block_ok_response_and_can_predict_with_trained_model( sample_train_service, sample_inference_service, ): - """Test RPC CaikitRuntime.BlocksSampleTaskSampleBlockTrain successful response""" + """Test RPC CaikitRuntime.BlocksSampleTaskSampleModuleTrain successful response""" stream_type = caikit.interfaces.common.data_model.DataStreamSourceSampleTrainingType training_data = stream_type( jsondata=stream_type.JsonData( @@ -193,11 +193,11 @@ def test_train_fake_block_ok_response_and_can_predict_with_trained_model( ).to_proto() model_name = random_test_id() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=model_name, training_data=training_data ) ) - actual_response = train_stub.BlocksSampleTaskSampleBlockTrain(train_request) + actual_response = train_stub.BlocksSampleTaskSampleModuleTrain(train_request) is_good_train_response(actual_response, HAPPY_PATH_TRAIN_RESPONSE, model_name) # give the trained model time to load @@ -256,20 +256,20 @@ def test_train_fake_block_does_not_change_another_instance_model_of_block( sample_train_service, sample_inference_service, ): - """This test: original "stock" OtherBlock model has batch size 42 (see fixtures/models/bar.yml), - we then train a custom OtherBlock model with batch size 100, + """This test: original "stock" OtherModule model has batch size 42 (see fixtures/models/bar.yml), + we then train a custom OtherModule model with batch size 100, then we make a predict to each, they should have the correct batch size""" - # Train an OtherBlock with batch size 100 + # Train an OtherModule with batch size 100 stream_type = caikit.interfaces.common.data_model.DataStreamSourceInt training_data = stream_type( file=stream_type.File(filename=sample_int_file) ).to_proto() - train_request = sample_train_service.messages.BlocksOtherTaskOtherBlockTrainRequest( + train_request = sample_train_service.messages.BlocksOtherTaskOtherModuleTrainRequest( model_name="Bar Training", batch_size=100, training_data=training_data ) - actual_response = train_stub.BlocksOtherTaskOtherBlockTrain(train_request) + actual_response = train_stub.BlocksOtherTaskOtherModuleTrain(train_request) is_good_train_response(actual_response, HAPPY_PATH_TRAIN_RESPONSE, "Bar Training") # give the trained model time to load @@ -288,7 +288,7 @@ def test_train_fake_block_does_not_change_another_instance_model_of_block( ).to_proto() assert trained_inference_response == expected_trained_inference_response - # make sure the previously loaded OtherBlock model still has batch size 42 + # make sure the previously loaded OtherModule model still has batch size 42 original_inference_response = inference_stub.OtherTaskPredict( predict_request, metadata=[("mm-model-id", other_loaded_model_id)] ) @@ -302,7 +302,7 @@ def test_train_fake_block_does_not_change_another_instance_model_of_block( def test_train_fake_block_ok_response_with_datastream_jsondata( train_stub, inference_stub, sample_train_service, sample_inference_service ): - """Test RPC CaikitRuntime.BlocksSampleTaskSampleBlockTrainRequest successful response with training data json type""" + """Test RPC CaikitRuntime.BlocksSampleTaskSampleModuleTrainRequest successful response with training data json type""" stream_type = caikit.interfaces.common.data_model.DataStreamSourceSampleTrainingType training_data = stream_type( jsondata=stream_type.JsonData( @@ -311,14 +311,14 @@ def test_train_fake_block_ok_response_with_datastream_jsondata( ).to_proto() model_name = random_test_id() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=model_name, batch_size=42, training_data=training_data, ) ) - actual_response = train_stub.BlocksSampleTaskSampleBlockTrain(train_request) + actual_response = train_stub.BlocksSampleTaskSampleModuleTrain(train_request) is_good_train_response(actual_response, HAPPY_PATH_TRAIN_RESPONSE, model_name) # give the trained model time to load @@ -342,20 +342,20 @@ def test_train_fake_block_ok_response_with_datastream_csv_file( sample_inference_service, sample_csv_file, ): - """Test RPC CaikitRuntime.BlocksSampleTaskSampleBlockTrainRequest successful response with training data file type""" + """Test RPC CaikitRuntime.BlocksSampleTaskSampleModuleTrainRequest successful response with training data file type""" stream_type = caikit.interfaces.common.data_model.DataStreamSourceSampleTrainingType training_data = stream_type( file=stream_type.File(filename=sample_csv_file) ).to_proto() model_name = random_test_id() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=model_name, training_data=training_data, ) ) - actual_response = train_stub.BlocksSampleTaskSampleBlockTrain(train_request) + actual_response = train_stub.BlocksSampleTaskSampleModuleTrain(train_request) is_good_train_response(actual_response, HAPPY_PATH_TRAIN_RESPONSE, model_name) # give the trained model time to load @@ -728,7 +728,7 @@ def test_metrics_stored_after_server_interrupt( assert data[0]["batch_size"] == 1 assert len(data[0]["model_type_counters"]) == 1 assert data[0]["model_type_counters"] == { - "": 1 + "": 1 } diff --git a/tests/runtime/test_service_factory.py b/tests/runtime/test_service_factory.py index c3cceb911..654036297 100644 --- a/tests/runtime/test_service_factory.py +++ b/tests/runtime/test_service_factory.py @@ -208,7 +208,7 @@ def test_get_and_filter_modules_respects_excluded_task_type(): def test_get_and_filter_modules_respects_excluded_modules(): - assert "InnerBlock" in str(MODULE_LIST) + assert "InnerModule" in str(MODULE_LIST) with temp_config( { "runtime": { @@ -218,15 +218,15 @@ def test_get_and_filter_modules_respects_excluded_modules(): } } } - } # excluding InnerBlock + } # excluding InnerModule ) as cfg: clean_modules = ServicePackageFactory._get_and_filter_modules(cfg, "sample_lib") - assert "InnerBlock" not in str(clean_modules) + assert "InnerModule" not in str(clean_modules) def test_get_and_filter_modules_respects_excluded_modules_and_excluded_task_type(): - assert "InnerBlock" in str(MODULE_LIST) + assert "InnerModule" in str(MODULE_LIST) with temp_config( { "runtime": { @@ -237,12 +237,12 @@ def test_get_and_filter_modules_respects_excluded_modules_and_excluded_task_type "task_types": {"excluded": ["other_task"]}, } } - } # excluding InnerBlock and OtherBlock + } # excluding InnerModule and OtherModule ) as cfg: clean_modules = ServicePackageFactory._get_and_filter_modules(cfg, "sample_lib") - assert "InnerBlock" not in str(clean_modules) - assert "OtherBlock" not in str(clean_modules) + assert "InnerModule" not in str(clean_modules) + assert "OtherModule" not in str(clean_modules) assert "other_task" not in str(clean_modules) @@ -257,13 +257,13 @@ def test_get_and_filter_modules_respects_included_modules_and_included_task_type "task_types": {"included": ["other_task"]}, } } - } # only want InnerBlock and OtherBlock + } # only want InnerModule and OtherModule ) as cfg: clean_modules = ServicePackageFactory._get_and_filter_modules(cfg, "sample_lib") assert len(clean_modules) == 2 - assert "InnerBlock" in str(clean_modules) - assert "OtherBlock" in str(clean_modules) + assert "InnerModule" in str(clean_modules) + assert "OtherModule" in str(clean_modules) assert "ListBlock" not in str(clean_modules) @@ -280,14 +280,14 @@ def test_get_and_filter_modules_respects_included_modules(): }, } } - } # only want InnerBlock and ListBlock + } # only want InnerModule and ListBlock ) as cfg: clean_modules = ServicePackageFactory._get_and_filter_modules(cfg, "sample_lib") assert len(clean_modules) == 2 - assert "InnerBlock" in str(clean_modules) + assert "InnerModule" in str(clean_modules) assert "ListBlock" in str(clean_modules) - assert "OtherBlock" not in str(clean_modules) + assert "OtherModule" not in str(clean_modules) def test_get_and_filter_modules_respects_included_task_types(): @@ -302,8 +302,8 @@ def test_get_and_filter_modules_respects_included_task_types(): ) as cfg: clean_modules = ServicePackageFactory._get_and_filter_modules(cfg, "sample_lib") - assert "InnerBlock" in str(clean_modules) - assert "OtherBlock" not in str(clean_modules) + assert "InnerModule" in str(clean_modules) + assert "OtherModule" not in str(clean_modules) def test_get_and_filter_modules_respects_included_task_types_and_excluded_modules(): @@ -321,5 +321,5 @@ def test_get_and_filter_modules_respects_included_task_types_and_excluded_module ) as cfg: clean_modules = ServicePackageFactory._get_and_filter_modules(cfg, "sample_lib") - assert "InnerBlock" in str(clean_modules) + assert "InnerModule" in str(clean_modules) assert "ListBlock" not in str(clean_modules) diff --git a/tests/runtime/utils/test_servicer_util.py b/tests/runtime/utils/test_servicer_util.py index d706e12c8..f7df37757 100644 --- a/tests/runtime/utils/test_servicer_util.py +++ b/tests/runtime/utils/test_servicer_util.py @@ -220,7 +220,7 @@ def test_global_predict_build_caikit_library_request_dict_creates_caikit_core_ru sample_inference_service.messages.SampleTaskRequest( sample_input=HAPPY_PATH_INPUT ), - sample_lib.blocks.sample_task.SampleBlock().run, + sample_lib.modules.sample_task.SampleModule().run, ) # No self or "throw", throw was not set and the throw parameter contains a default value @@ -239,7 +239,7 @@ def test_global_predict_build_caikit_library_request_dict_strips_invalid_run_kwa sample_inference_service.messages.SampleTaskRequest( sample_input=HAPPY_PATH_INPUT, int_type=5, bool_type=True ), - sample_lib.blocks.sample_task.SampleBlock().run, + sample_lib.modules.sample_task.SampleModule().run, ) expected_arguments = {"sample_input"} @@ -253,7 +253,7 @@ def test_global_predict_build_caikit_library_request_dict_strips_empty_list_from """Global predict build_caikit_library_request_dict strips empty list from request""" request_dict = build_caikit_library_request_dict( sample_inference_service.messages.SampleTaskRequest(int_type=5, list_type=[]), - sample_lib.blocks.sample_task.SamplePrimitiveBlock().run, + sample_lib.modules.sample_task.SamplePrimitiveModule().run, ) assert "list_type" not in request_dict.keys() @@ -343,14 +343,14 @@ def test_global_train_build_caikit_library_request_dict_creates_caikit_core_run_ """Global train build_caikit_library_request_dict creates block run kwargs from RPC msg and if not passed in request, it creates the fields with default values""" train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id() # not having batch_size, and training_data ) ) caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) expected_arguments = {"training_data"} @@ -373,14 +373,14 @@ def test_global_train_build_caikit_library_request_dict_strips_empty_list_from_r stream_type = caikit.interfaces.common.data_model.DataStreamSourceSampleTrainingType training_data = stream_type(jsondata=stream_type.JsonData(data=[])).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), training_data=training_data ) ) caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) # model_name is not expected to be passed through @@ -404,7 +404,7 @@ def test_global_train_build_caikit_library_request_dict_works_for_repeated_field caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.ListBlock().train, + sample_lib.modules.sample_task.ListBlock().train, ) # model_name is not expected to be passed through @@ -424,16 +424,16 @@ def test_global_train_build_caikit_library_request_dict_ok_with_DataStreamSource jsondata=stream_type.JsonData(data=[100, 120]) ).to_proto() - train_request = sample_train_service.messages.BlocksOtherTaskOtherBlockTrainRequest( + train_request = sample_train_service.messages.BlocksOtherTaskOtherModuleTrainRequest( model_name="Bar Training", batch_size=100, training_data=training_data ) caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.other_task.OtherBlock().train, + sample_lib.modules.other_task.OtherModule().train, ) expected_arguments = set( - sample_lib.blocks.other_task.OtherBlock().train.__code__.co_varnames + sample_lib.modules.other_task.OtherModule().train.__code__.co_varnames ) expected_arguments.remove("cls") @@ -450,7 +450,7 @@ def test_global_train_build_caikit_library_request_dict_ok_with_data_stream_file file=stream_type.File(filename=sample_csv_file) ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), training_data=training_data, ) @@ -458,7 +458,7 @@ def test_global_train_build_caikit_library_request_dict_ok_with_data_stream_file caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) # model_name is not expected to be passed through @@ -483,7 +483,7 @@ def test_global_train_build_caikit_library_request_dict_ok_with_training_data_as caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.ListBlock().train, + sample_lib.modules.sample_task.ListBlock().train, ) # model_name is not expected to be passed through @@ -514,7 +514,7 @@ def test_build_caikit_library_request_dict_works_when_data_stream_directory_incl directory=stream_type.Directory(dirname=tempdir, extension="json") ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), training_data=training_data, ) @@ -523,7 +523,7 @@ def test_build_caikit_library_request_dict_works_when_data_stream_directory_incl # no error because at least 1 json file exists within the provided dir caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) @@ -538,7 +538,7 @@ def test_build_caikit_library_request_dict_raises_invalid_data_stream_source_fil stream_type = caikit.interfaces.common.data_model.DataStreamSourceSampleTrainingType training_data = stream_type(file=stream_type.File(filename="abc.blah")).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), training_data=training_data, ) @@ -547,7 +547,7 @@ def test_build_caikit_library_request_dict_raises_invalid_data_stream_source_fil with pytest.raises(CaikitRuntimeException) as e: caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) assert "Invalid .blah data source file" in e.value.message @@ -566,7 +566,7 @@ def test_build_caikit_library_request_dict_raises_invalid_data_stream_source_fil ) training_data = stream_type(file=stream_type.File(filename=fname)).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name="Foo Bar Training", training_data=training_data, ) @@ -575,7 +575,7 @@ def test_build_caikit_library_request_dict_raises_invalid_data_stream_source_fil with pytest.raises(CaikitRuntimeException) as e: caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) assert "Extension not supported" in e.value.message @@ -591,7 +591,7 @@ def test_build_caikit_library_request_dict_raises_when_data_stream_file_passes_a directory=stream_type.Directory(dirname=sample_csv_file) ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name="Foo Bar Training", training_data=training_data, ) @@ -600,7 +600,7 @@ def test_build_caikit_library_request_dict_raises_when_data_stream_file_passes_a with pytest.raises(CaikitRuntimeException) as e: caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) assert "Invalid json directory source file" in e.value.message @@ -623,7 +623,7 @@ def test_build_caikit_library_request_dict_raises_when_data_stream_directory_pas directory=stream_type.Directory(dirname=tempdir, extension="txt") ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), training_data=training_data, ) @@ -632,7 +632,7 @@ def test_build_caikit_library_request_dict_raises_when_data_stream_directory_pas with pytest.raises(CaikitRuntimeException) as e: caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) # TODO: change this message once it's implemented @@ -656,7 +656,7 @@ def test_build_caikit_library_request_dict_raises_when_data_stream_directory_pas directory=stream_type.Directory(dirname=tempdir, extension="json") ).to_proto() train_request = ( - sample_train_service.messages.BlocksSampleTaskSampleBlockTrainRequest( + sample_train_service.messages.BlocksSampleTaskSampleModuleTrainRequest( model_name=random_test_id(), training_data=training_data, ) @@ -665,7 +665,7 @@ def test_build_caikit_library_request_dict_raises_when_data_stream_directory_pas with pytest.raises(CaikitRuntimeException) as e: caikit.core_request = build_caikit_library_request_dict( train_request, - sample_lib.blocks.sample_task.SampleBlock().train, + sample_lib.modules.sample_task.SampleModule().train, ) assert "contains no source files with extension" in e.value.message