Skip to content

Commit

Permalink
Make Buildable fields instance variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
n8mellis committed Oct 26, 2023
1 parent 25bb390 commit 39034bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/chassisml/src/chassis/builder/buildable.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ class Buildable(metaclass=abc.ABCMeta):
[chassis.runtime.constants][].
"""

packaged = False
metadata = ModelMetadata.default()
requirements: set[str] = set()
apt_packages: set[str] = set()
additional_files: set[str] = set()
python_modules: dict = {}
def __init__(self):
self.packaged = False
self.metadata = ModelMetadata.default()
self.requirements: set[str] = set()
self.apt_packages: set[str] = set()
self.additional_files: set[str] = set()
self.python_modules: dict = {}

def merge_package(self, package: Buildable):
"""
Expand Down
1 change: 1 addition & 0 deletions packages/chassisml/src/chassisml/v1/chassis_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, process_fn: PredictFunction, batch_size: int = 1,
legacy_predict_fn: For internal backwards-compatibility use only.
chassis_client: For internal backwards-compatibility use only.
"""
super().__init__()
self.runner = ModelRunner(process_fn, batch_size=batch_size,
is_legacy_fn=legacy_predict_fn)
self.python_modules[PYTHON_MODEL_KEY] = self.runner
Expand Down
18 changes: 18 additions & 0 deletions packages/chassisml/tests/test_chassis_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,22 @@ def test_adding_pip_requirements_from_conda_env(echo_predict_function):
model.parse_conda_env(env)
assert len(model.requirements.symmetric_difference(["scikit-learn", "numpy", "chassisml"])) == 0


def test_each_model_instance_has_own_default_values(echo_predict_function):
model = ChassisModel(echo_predict_function)
assert model.metadata.model_name == ""
assert model.metadata.model_version == ""
assert model.metadata.has_inputs() is False
model.metadata.model_name = "Test Model"
model.metadata.model_version = "1.0.1"
model.metadata.add_input("input", ["text/plain"])
assert model.metadata.model_name == "Test Model"
assert model.metadata.model_version == "1.0.1"
assert model.metadata.has_inputs() is True

model2 = ChassisModel(echo_predict_function)
assert model2.metadata.model_name == ""
assert model2.metadata.model_version == ""
assert model2.metadata.has_inputs() is False

# Verify that the fields in the metadata are updated based on the values provided during `prepare_context`.

0 comments on commit 39034bf

Please sign in to comment.