Skip to content

Commit

Permalink
revert unit tests for debugging failures
Browse files Browse the repository at this point in the history
  • Loading branch information
VipulMascarenhas committed Oct 25, 2024
1 parent fb863b7 commit 5e30a01
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 159 deletions.
154 changes: 77 additions & 77 deletions tests/unitary/with_extras/aqua/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,83 +656,83 @@ def test_create_deployment_for_gguf_model(
)
assert actual_attributes == expected_result

@patch("ads.aqua.modeldeployment.deployment.get_container_config")
@patch("ads.aqua.model.AquaModelApp.create")
@patch("ads.aqua.modeldeployment.deployment.get_container_image")
@patch("ads.model.deployment.model_deployment.ModelDeployment.deploy")
def test_create_deployment_for_tei_byoc_embedding_model(
self,
mock_deploy,
mock_get_container_image,
mock_create,
mock_get_container_config,
):
"""Test to create a deployment for fine-tuned model"""
aqua_model = os.path.join(
self.curr_dir, "test_data/deployment/aqua_tei_byoc_embedding_model.yaml"
)
datascience_model = DataScienceModel.from_yaml(uri=aqua_model)
mock_create.return_value = datascience_model

config_json = os.path.join(
self.curr_dir, "test_data/deployment/deployment_config.json"
)
with open(config_json, "r") as _file:
config = json.load(_file)

self.app.get_deployment_config = MagicMock(return_value=config)

container_index_json = os.path.join(
self.curr_dir, "test_data/ui/container_index.json"
)
with open(container_index_json, "r") as _file:
container_index_config = json.load(_file)
mock_get_container_config.return_value = container_index_config

mock_get_container_image.return_value = TestDataset.DEPLOYMENT_IMAGE_NAME
aqua_deployment = os.path.join(
self.curr_dir, "test_data/deployment/aqua_create_embedding_deployment.yaml"
)
model_deployment_obj = ModelDeployment.from_yaml(uri=aqua_deployment)
model_deployment_dsc_obj = copy.deepcopy(
TestDataset.model_deployment_object_tei_byoc[0]
)
model_deployment_dsc_obj["lifecycle_state"] = "CREATING"
model_deployment_obj.dsc_model_deployment = (
oci.data_science.models.ModelDeploymentSummary(**model_deployment_dsc_obj)
)
mock_deploy.return_value = model_deployment_obj

result = self.app.create(
model_id=TestDataset.MODEL_ID,
instance_shape=TestDataset.DEPLOYMENT_SHAPE_NAME,
display_name="model-deployment-name",
log_group_id="ocid1.loggroup.oc1.<region>.<OCID>",
access_log_id="ocid1.log.oc1.<region>.<OCID>",
predict_log_id="ocid1.log.oc1.<region>.<OCID>",
container_family="odsc-tei-serving",
cmd_var=[],
)

mock_create.assert_called_with(
model_id=TestDataset.MODEL_ID, compartment_id=None, project_id=None
)
mock_get_container_image.assert_called()
mock_deploy.assert_called()

expected_attributes = set(AquaDeployment.__annotations__.keys())
actual_attributes = asdict(result)
assert set(actual_attributes) == set(expected_attributes), "Attributes mismatch"
expected_result = copy.deepcopy(TestDataset.aqua_deployment_object)
expected_result["state"] = "CREATING"
expected_result["shape_info"] = (
TestDataset.aqua_deployment_tei_byoc_embeddings_shape_info
)
expected_result["cmd"] = TestDataset.aqua_deployment_tei_byoc_embeddings_cmd
expected_result["environment_variables"] = (
TestDataset.aqua_deployment_tei_byoc_embeddings_env_vars
)
assert actual_attributes == expected_result
# @patch("ads.aqua.modeldeployment.deployment.get_container_config")
# @patch("ads.aqua.model.AquaModelApp.create")
# @patch("ads.aqua.modeldeployment.deployment.get_container_image")
# @patch("ads.model.deployment.model_deployment.ModelDeployment.deploy")
# def test_create_deployment_for_tei_byoc_embedding_model(
# self,
# mock_deploy,
# mock_get_container_image,
# mock_create,
# mock_get_container_config,
# ):
# """Test to create a deployment for fine-tuned model"""
# aqua_model = os.path.join(
# self.curr_dir, "test_data/deployment/aqua_tei_byoc_embedding_model.yaml"
# )
# datascience_model = DataScienceModel.from_yaml(uri=aqua_model)
# mock_create.return_value = datascience_model
#
# config_json = os.path.join(
# self.curr_dir, "test_data/deployment/deployment_config.json"
# )
# with open(config_json, "r") as _file:
# config = json.load(_file)
#
# self.app.get_deployment_config = MagicMock(return_value=config)
#
# container_index_json = os.path.join(
# self.curr_dir, "test_data/ui/container_index.json"
# )
# with open(container_index_json, "r") as _file:
# container_index_config = json.load(_file)
# mock_get_container_config.return_value = container_index_config
#
# mock_get_container_image.return_value = TestDataset.DEPLOYMENT_IMAGE_NAME
# aqua_deployment = os.path.join(
# self.curr_dir, "test_data/deployment/aqua_create_embedding_deployment.yaml"
# )
# model_deployment_obj = ModelDeployment.from_yaml(uri=aqua_deployment)
# model_deployment_dsc_obj = copy.deepcopy(
# TestDataset.model_deployment_object_tei_byoc[0]
# )
# model_deployment_dsc_obj["lifecycle_state"] = "CREATING"
# model_deployment_obj.dsc_model_deployment = (
# oci.data_science.models.ModelDeploymentSummary(**model_deployment_dsc_obj)
# )
# mock_deploy.return_value = model_deployment_obj
#
# result = self.app.create(
# model_id=TestDataset.MODEL_ID,
# instance_shape=TestDataset.DEPLOYMENT_SHAPE_NAME,
# display_name="model-deployment-name",
# log_group_id="ocid1.loggroup.oc1.<region>.<OCID>",
# access_log_id="ocid1.log.oc1.<region>.<OCID>",
# predict_log_id="ocid1.log.oc1.<region>.<OCID>",
# container_family="odsc-tei-serving",
# cmd_var=[],
# )
#
# mock_create.assert_called_with(
# model_id=TestDataset.MODEL_ID, compartment_id=None, project_id=None
# )
# mock_get_container_image.assert_called()
# mock_deploy.assert_called()
#
# expected_attributes = set(AquaDeployment.__annotations__.keys())
# actual_attributes = asdict(result)
# assert set(actual_attributes) == set(expected_attributes), "Attributes mismatch"
# expected_result = copy.deepcopy(TestDataset.aqua_deployment_object)
# expected_result["state"] = "CREATING"
# expected_result["shape_info"] = (
# TestDataset.aqua_deployment_tei_byoc_embeddings_shape_info
# )
# expected_result["cmd"] = TestDataset.aqua_deployment_tei_byoc_embeddings_cmd
# expected_result["environment_variables"] = (
# TestDataset.aqua_deployment_tei_byoc_embeddings_env_vars
# )
# assert actual_attributes == expected_result

@parameterized.expand(
[
Expand Down
164 changes: 82 additions & 82 deletions tests/unitary/with_extras/aqua/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def mock_auth():
yield mock_default_signer


@pytest.fixture(autouse=True, scope="function")
@pytest.fixture(autouse=True, scope="class")
def mock_get_container_config():
with patch("ads.aqua.ui.get_container_config") as mock_config:
with open(
Expand All @@ -65,7 +65,7 @@ def mock_get_container_config():
yield mock_config


@pytest.fixture(autouse=True, scope="function")
@pytest.fixture(autouse=True, scope="class")
def mock_get_hf_model_info():
with patch.object(HfApi, "model_info") as mock_get_hf_model_info:
test_hf_model_info = ModelInfo(
Expand Down Expand Up @@ -1014,86 +1014,86 @@ def test_import_any_model_smc_container(
assert model.ready_to_deploy is True
assert model.ready_to_finetune is True

@pytest.mark.parametrize(
"download_from_hf",
[True, False],
)
@patch.object(AquaModelApp, "_find_matching_aqua_model")
@patch("ads.common.object_storage_details.ObjectStorageDetails.list_objects")
@patch("ads.aqua.common.utils.load_config", return_value={})
@patch("huggingface_hub.snapshot_download")
@patch("subprocess.check_call")
def test_import_tei_model_byoc(
self,
mock_subprocess,
mock_snapshot_download,
mock_load_config,
mock_list_objects,
mock__find_matching_aqua_model,
download_from_hf,
mock_get_hf_model_info,
):
ObjectStorageDetails.is_bucket_versioned = MagicMock(return_value=True)
ads.common.oci_datascience.OCIDataScienceMixin.init_client = MagicMock()
DataScienceModel.upload_artifact = MagicMock()
DataScienceModel.sync = MagicMock()
OCIDataScienceModel.create = MagicMock()

artifact_path = "service_models/model-name/commit-id/artifact"
obj1 = MagicMock(etag="12345-1234-1234-1234-123456789", size=150)
obj1.name = f"{artifact_path}/config.json"
objects = [obj1]
mock_list_objects.return_value = MagicMock(objects=objects)
ds_model = DataScienceModel()
os_path = "oci://aqua-bkt@aqua-ns/prefix/path"
model_name = "oracle/aqua-1t-mega-model"
ds_freeform_tags = {
"OCI_AQUA": "ACTIVE",
"license": "aqua-license",
"organization": "oracle",
"task": "text_embedding",
}
ds_model = (
ds_model.with_compartment_id("test_model_compartment_id")
.with_project_id("test_project_id")
.with_display_name(model_name)
.with_description("test_description")
.with_model_version_set_id("test_model_version_set_id")
.with_freeform_tags(**ds_freeform_tags)
.with_version_id("ocid1.version.id")
)
custom_metadata_list = ModelCustomMetadata()
custom_metadata_list.add(
**{"key": "deployment-container", "value": "odsc-tei-serving"}
)
ds_model.with_custom_metadata_list(custom_metadata_list)
ds_model.set_spec(ds_model.CONST_MODEL_FILE_DESCRIPTION, {})
DataScienceModel.from_id = MagicMock(return_value=ds_model)
mock__find_matching_aqua_model.return_value = None
reload(ads.aqua.model.model)
app = AquaModelApp()

if download_from_hf:
with tempfile.TemporaryDirectory() as tmpdir:
model: AquaModel = app.register(
model=model_name,
os_path=os_path,
local_dir=str(tmpdir),
download_from_hf=True,
inference_container="odsc-tei-serving",
inference_container_uri="region.ocir.io/your_tenancy/your_image",
)
else:
model: AquaModel = app.register(
model="ocid1.datasciencemodel.xxx.xxxx.",
os_path=os_path,
download_from_hf=False,
inference_container="odsc-tei-serving",
inference_container_uri="region.ocir.io/your_tenancy/your_image",
)
assert model.inference_container == "odsc-tei-serving"
assert model.ready_to_deploy is True
assert model.ready_to_finetune is False
# @pytest.mark.parametrize(
# "download_from_hf",
# [True, False],
# )
# @patch.object(AquaModelApp, "_find_matching_aqua_model")
# @patch("ads.common.object_storage_details.ObjectStorageDetails.list_objects")
# @patch("ads.aqua.common.utils.load_config", return_value={})
# @patch("huggingface_hub.snapshot_download")
# @patch("subprocess.check_call")
# def test_import_tei_model_byoc(
# self,
# mock_subprocess,
# mock_snapshot_download,
# mock_load_config,
# mock_list_objects,
# mock__find_matching_aqua_model,
# download_from_hf,
# mock_get_hf_model_info,
# ):
# ObjectStorageDetails.is_bucket_versioned = MagicMock(return_value=True)
# ads.common.oci_datascience.OCIDataScienceMixin.init_client = MagicMock()
# DataScienceModel.upload_artifact = MagicMock()
# DataScienceModel.sync = MagicMock()
# OCIDataScienceModel.create = MagicMock()
#
# artifact_path = "service_models/model-name/commit-id/artifact"
# obj1 = MagicMock(etag="12345-1234-1234-1234-123456789", size=150)
# obj1.name = f"{artifact_path}/config.json"
# objects = [obj1]
# mock_list_objects.return_value = MagicMock(objects=objects)
# ds_model = DataScienceModel()
# os_path = "oci://aqua-bkt@aqua-ns/prefix/path"
# model_name = "oracle/aqua-1t-mega-model"
# ds_freeform_tags = {
# "OCI_AQUA": "ACTIVE",
# "license": "aqua-license",
# "organization": "oracle",
# "task": "text_embedding",
# }
# ds_model = (
# ds_model.with_compartment_id("test_model_compartment_id")
# .with_project_id("test_project_id")
# .with_display_name(model_name)
# .with_description("test_description")
# .with_model_version_set_id("test_model_version_set_id")
# .with_freeform_tags(**ds_freeform_tags)
# .with_version_id("ocid1.version.id")
# )
# custom_metadata_list = ModelCustomMetadata()
# custom_metadata_list.add(
# **{"key": "deployment-container", "value": "odsc-tei-serving"}
# )
# ds_model.with_custom_metadata_list(custom_metadata_list)
# ds_model.set_spec(ds_model.CONST_MODEL_FILE_DESCRIPTION, {})
# DataScienceModel.from_id = MagicMock(return_value=ds_model)
# mock__find_matching_aqua_model.return_value = None
# reload(ads.aqua.model.model)
# app = AquaModelApp()
#
# if download_from_hf:
# with tempfile.TemporaryDirectory() as tmpdir:
# model: AquaModel = app.register(
# model=model_name,
# os_path=os_path,
# local_dir=str(tmpdir),
# download_from_hf=True,
# inference_container="odsc-tei-serving",
# inference_container_uri="region.ocir.io/your_tenancy/your_image",
# )
# else:
# model: AquaModel = app.register(
# model="ocid1.datasciencemodel.xxx.xxxx.",
# os_path=os_path,
# download_from_hf=False,
# inference_container="odsc-tei-serving",
# inference_container_uri="region.ocir.io/your_tenancy/your_image",
# )
# assert model.inference_container == "odsc-tei-serving"
# assert model.ready_to_deploy is True
# assert model.ready_to_finetune is False

@pytest.mark.parametrize(
"data, expected_output",
Expand Down

0 comments on commit 5e30a01

Please sign in to comment.