Skip to content

Commit 720551f

Browse files
committed
backmerged with latest
2 parents 6b3bdc4 + 8c5866e commit 720551f

File tree

9 files changed

+67
-13
lines changed

9 files changed

+67
-13
lines changed

ads/feature_store/dataset.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ def with_model_details(self, model_details: ModelDetails) -> "Dataset":
500500
"The argument `model_details` has to be of type `ModelDetails`"
501501
"but is of type: `{}`".format(type(model_details))
502502
)
503+
503504
return self.set_spec(self.CONST_MODEL_DETAILS, model_details.to_dict())
504505

505506
@property
@@ -549,9 +550,20 @@ def add_models(self, model_details: ModelDetails) -> "Dataset":
549550
if existing_model_details and existing_model_details.items:
550551
items = existing_model_details["items"]
551552
for item in items:
552-
model_details.items.append(item)
553+
if item not in model_details.items:
554+
model_details.items.append(item)
553555
self.with_model_details(model_details)
554-
return self.update()
556+
try:
557+
return self.update()
558+
except Exception as ex:
559+
logger.error(
560+
f"Dataset update Failed with : {type(ex)} with error message: {ex}"
561+
)
562+
if existing_model_details:
563+
self.with_model_details(ModelDetails().with_items(existing_model_details["items"]))
564+
else:
565+
self.with_model_details(ModelDetails().with_items([]))
566+
return self
555567

556568
def remove_models(self, model_details: ModelDetails) -> "Dataset":
557569
"""remove model details from the dataset, remove from the existing dataset model id list

ads/feature_store/docs/source/dataset.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Use the ``show()`` method on the ``Dataset`` instance to visualize the lineage o
306306

307307
The ``show()`` method takes the following optional parameter:
308308

309-
- ``rankdir: (str, optional)``. Defaults to ``LR``. The allowed values are ``TB`` or ``LR``. This parameter is applicable only for ``graph`` mode and it renders the direction of the graph as either top to bottom (TB) or left to right (LR).
309+
- ``rankdir: (str, optional)``. Defaults to ``LR``. The allowed values are ``TB`` or ``LR``. This parameter is applicable only for ``graph`` mode and it renders the direction of the graph as either top to bottom (TB) or left to right (LR).
310310

311311

312312
.. code-block:: python3
@@ -317,3 +317,16 @@ Below is an example of the output.
317317

318318
.. figure:: figures/dataset_lineage.png
319319
:width: 400
320+
321+
322+
Add Model Details
323+
=================
324+
325+
You can call the ``add_models()`` method of the Dataset instance to add model ids to dataset.
326+
The ``.add_models()`` method takes the following parameter:
327+
328+
- ``model_details: ModelDetails``. ModelDetails takes ``items: List[str]`` as parameter and model ids to be passed as items.
329+
330+
.. code-block:: python3
331+
332+
dataset.add_models(ModelDetails().with_items([<ocid1.datasciencemodel..<unique_id>]))

ads/feature_store/docs/source/notebook.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ Notebook Examples
2424
- `Big data operations with feature store <https://objectstorage.us-ashburn-1.oraclecloud.com/p/hh2NOgFJbVSg4amcLM3G3hkTuHyBD-8aE_iCsuZKEvIav1Wlld-3zfCawG4ycQGN/n/ociodscdev/b/oci-feature-store/o/beta/notebook/feature-store-big-data-ingestion-and-querying.ipynb>`__
2525
- | 1. Ingestion of data using spark magic
2626
| 2. Querying and exploration of data using spark magic
27+
28+
* - `Schema enforcement and schema evolution <https://objectstorage.us-ashburn-1.oraclecloud.com/p/hh2NOgFJbVSg4amcLM3G3hkTuHyBD-8aE_iCsuZKEvIav1Wlld-3zfCawG4ycQGN/n/ociodscdev/b/oci-feature-store/o/beta/notebook/feature_store_flights_schema_evolution.html>`__
29+
- `Schema enforcement and schema evolution <https://objectstorage.us-ashburn-1.oraclecloud.com/p/hh2NOgFJbVSg4amcLM3G3hkTuHyBD-8aE_iCsuZKEvIav1Wlld-3zfCawG4ycQGN/n/ociodscdev/b/oci-feature-store/o/beta/notebook/feature_store_flights_schema_evolution.ipynb>`__
30+
- | 1. Schema evolution is a feature that allows users to easily change a table's current schema to accommodate data that is changing over time.
31+
| 2. Schema enforcement, also known as schema validation, is a safeguard in Delta Lake that ensures data quality by rejecting writes to a table that do not match the table's schema.

ads/feature_store/docs/source/quickstart.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ Background reading to understand the concepts of Feature Store and OCI Data Scie
5555
compartment_id = "ocid1.compartment.<unique_id>"
5656
metastore_id = "ocid1.datacatalogmetastore.oc1.iad.<unique_id>"
5757
api_gateway_endpoint = "https://**.{region}.oci.customer-oci.com/20230101"
58+
os.environ["OCI_FS_SERVICE_ENDPOINT"] = api_gateway_endpoint
5859
59-
ads.set_auth(auth="user_principal", client_kwargs={"service_endpoint": api_gateway_endpoint})
60+
ads.set_auth(auth="api_key")
6061

6162
# step1: Create feature store
6263
feature_store_resource = (

ads/feature_store/feature_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def with_primary_keys(self, primary_keys: List[str]) -> "FeatureGroup":
323323
self.CONST_PRIMARY_KEYS,
324324
{
325325
self.CONST_ITEMS: [
326-
{self.CONST_NAME: primary_key} for primary_key in primary_keys
326+
{self.CONST_NAME: primary_key} for primary_key in primary_keys or []
327327
]
328328
},
329329
)

ads/feature_store/mixin/oci_feature_store.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66

77
from ads.common.oci_mixin import OCIModelMixin
88
import oci.feature_store
9+
import os
910

1011

1112
class OCIFeatureStoreMixin(OCIModelMixin):
1213
@classmethod
1314
def init_client(
1415
cls, **kwargs
1516
) -> oci.feature_store.feature_store_client.FeatureStoreClient:
17+
# TODO: Getting the endpoint from authorizer
18+
fs_service_endpoint = os.environ.get("OCI_FS_SERVICE_ENDPOINT")
19+
if fs_service_endpoint:
20+
kwargs = {"service_endpoint": fs_service_endpoint}
21+
1622
client = cls._init_client(
1723
client=oci.feature_store.feature_store_client.FeatureStoreClient, **kwargs
1824
)

ads/model/generic_model.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from ads.evaluations import EvaluatorMixin
3535
from ads.feature_engineering import ADSImage
3636
from ads.feature_engineering.schema import Schema
37+
from ads.feature_store.model_details import ModelDetails
3738
from ads.model.artifact import ModelArtifact
3839
from ads.model.common.utils import (
3940
_extract_locals,
@@ -65,7 +66,7 @@
6566
Framework,
6667
ModelCustomMetadata,
6768
ModelProvenanceMetadata,
68-
ModelTaxonomyMetadata,
69+
ModelTaxonomyMetadata, MetadataCustomCategory,
6970
)
7071
from ads.model.model_metadata_mixin import MetadataMixin
7172
from ads.model.model_properties import ModelProperties
@@ -1825,6 +1826,7 @@ def save(
18251826
remove_existing_artifact: Optional[bool] = True,
18261827
model_version_set: Optional[Union[str, ModelVersionSet]] = None,
18271828
version_label: Optional[str] = None,
1829+
featurestore_dataset=None,
18281830
**kwargs,
18291831
) -> str:
18301832
"""Saves model artifacts to the model catalog.
@@ -1856,6 +1858,8 @@ def save(
18561858
The model version set OCID, or model version set name, or `ModelVersionSet` instance.
18571859
version_label: (str, optional). Defaults to None.
18581860
The model version lebel.
1861+
featurestore_dataset: (Dataset, optional).
1862+
The feature store dataset
18591863
kwargs:
18601864
project_id: (str, optional).
18611865
Project OCID. If not specified, the value will be taken either
@@ -1937,6 +1941,15 @@ def save(
19371941
# variables in case of saving model in context of model version set.
19381942
model_version_set_id = _extract_model_version_set_id(model_version_set)
19391943

1944+
if featurestore_dataset:
1945+
dataset_details = {
1946+
"dataset-id": featurestore_dataset.id,
1947+
"dataset-name": featurestore_dataset.name
1948+
}
1949+
self.metadata_custom.add("featurestore.dataset", value=str(dataset_details),
1950+
category=MetadataCustomCategory.TRAINING_AND_VALIDATION_DATASETS,
1951+
description="feature store dataset", replace=True)
1952+
19401953
self.dsc_model = (
19411954
self.dsc_model.with_compartment_id(self.properties.compartment_id)
19421955
.with_project_id(self.properties.project_id)
@@ -1965,6 +1978,10 @@ def save(
19651978
.with_infrastructure(ModelDeploymentInfrastructure())
19661979
.with_runtime(ModelDeploymentContainerRuntime())
19671980
)
1981+
# Add the model id to the feature store dataset
1982+
if featurestore_dataset:
1983+
model_details = ModelDetails().with_items([self.model_id])
1984+
featurestore_dataset.add_models(model_details)
19681985

19691986
return self.model_id
19701987

tests/integration/feature_store/test_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ads.feature_store.input_feature_detail import FeatureDetail
2020
from ads.feature_store.statistics_config import StatisticsConfig
2121

22+
2223
client_kwargs = dict(
2324
retry_strategy=oci.retry.NoneRetryStrategy,
2425
service_endpoint=os.getenv("service_endpoint"),
@@ -48,7 +49,7 @@ def transformation_with_kwargs(data_frame, **kwargs):
4849

4950
class FeatureStoreTestCase:
5051
# networks compartment in feature store
51-
TIME_NOW = str.format("{}_{}", datetime.utcnow().strftime("%Y_%m_%d_%H_%M_%S"), int(random() * 1000))
52+
TIME_NOW = str.format("{}_{}",datetime.utcnow().strftime("%Y_%m_%d_%H_%M_%S"),int(random()*1000))
5253
TENANCY_ID = "ocid1.tenancy.oc1..aaaaaaaa462hfhplpx652b32ix62xrdijppq2c7okwcqjlgrbknhgtj2kofa"
5354
COMPARTMENT_ID = "ocid1.tenancy.oc1..aaaaaaaa462hfhplpx652b32ix62xrdijppq2c7okwcqjlgrbknhgtj2kofa"
5455
METASTORE_ID = "ocid1.datacatalogmetastore.oc1.iad.amaaaaaabiudgxyap7tizm4gscwz7amu7dixz7ml3mtesqzzwwg3urvvdgua"
@@ -378,11 +379,10 @@ def create_transformation_resource(self, feature_store) -> "Transformation":
378379
transformation = feature_store.create_transformation(source_code_func=transformation_with_kwargs,
379380
display_name="transformation_with_kwargs",
380381
transformation_mode=TransformationMode.PANDAS)
381-
382382
return transformation
383383

384384
def define_feature_group_resource(
385-
self, entity_id, feature_store_id
385+
self, entity_id, feature_store_id
386386
) -> "FeatureGroup":
387387
feature_group_resource = (
388388
FeatureGroup()
@@ -400,7 +400,7 @@ def define_feature_group_resource(
400400
return feature_group_resource
401401

402402
def define_dataset_resource(
403-
self, entity_id, feature_store_id, feature_group_name
403+
self, entity_id, feature_store_id, feature_group_name
404404
) -> "Dataset":
405405
name = self.get_name("petals_ds")
406406
dataset_resource = (
@@ -470,6 +470,7 @@ def clean_up_feature_group(feature_group):
470470
except Exception as ex:
471471
print("Failed to delete feature group: ", str(ex))
472472
exit(1)
473+
473474
@staticmethod
474475
def clean_up_transformation(transformation):
475476
try:

tests/integration/feature_store/test_dataset_validations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ def test_dataset_model_details(self):
9191
assert dataset.oci_dataset.id
9292

9393
dataset.materialise()
94-
updated_dataset = dataset.add_models(ModelDetails().with_items(["model_ocid"]))
95-
updated_dataset.show()
96-
assert updated_dataset.model_details is not None
94+
dataset.add_models(ModelDetails().with_items(["model_ocid_invalid"]))
95+
assert len(dataset.model_details.get("items")) == 0
9796
self.clean_up_dataset(dataset)
9897
self.clean_up_feature_group(fg)
9998
self.clean_up_entity(entity)

0 commit comments

Comments
 (0)