oracle-ads 2.13.9rc0__py3-none-any.whl → 2.13.10rc0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ads/aqua/__init__.py +40 -0
- ads/aqua/app.py +507 -0
- ads/aqua/cli.py +96 -0
- ads/aqua/client/__init__.py +3 -0
- ads/aqua/client/client.py +836 -0
- ads/aqua/client/openai_client.py +305 -0
- ads/aqua/common/__init__.py +5 -0
- ads/aqua/common/decorator.py +125 -0
- ads/aqua/common/entities.py +274 -0
- ads/aqua/common/enums.py +134 -0
- ads/aqua/common/errors.py +109 -0
- ads/aqua/common/utils.py +1295 -0
- ads/aqua/config/__init__.py +4 -0
- ads/aqua/config/container_config.py +247 -0
- ads/aqua/config/evaluation/__init__.py +4 -0
- ads/aqua/config/evaluation/evaluation_service_config.py +147 -0
- ads/aqua/config/utils/__init__.py +4 -0
- ads/aqua/config/utils/serializer.py +339 -0
- ads/aqua/constants.py +116 -0
- ads/aqua/data.py +14 -0
- ads/aqua/dummy_data/icon.txt +1 -0
- ads/aqua/dummy_data/oci_model_deployments.json +56 -0
- ads/aqua/dummy_data/oci_models.json +1 -0
- ads/aqua/dummy_data/readme.md +26 -0
- ads/aqua/evaluation/__init__.py +8 -0
- ads/aqua/evaluation/constants.py +53 -0
- ads/aqua/evaluation/entities.py +186 -0
- ads/aqua/evaluation/errors.py +70 -0
- ads/aqua/evaluation/evaluation.py +1814 -0
- ads/aqua/extension/__init__.py +42 -0
- ads/aqua/extension/aqua_ws_msg_handler.py +76 -0
- ads/aqua/extension/base_handler.py +90 -0
- ads/aqua/extension/common_handler.py +121 -0
- ads/aqua/extension/common_ws_msg_handler.py +36 -0
- ads/aqua/extension/deployment_handler.py +381 -0
- ads/aqua/extension/deployment_ws_msg_handler.py +54 -0
- ads/aqua/extension/errors.py +30 -0
- ads/aqua/extension/evaluation_handler.py +129 -0
- ads/aqua/extension/evaluation_ws_msg_handler.py +61 -0
- ads/aqua/extension/finetune_handler.py +96 -0
- ads/aqua/extension/model_handler.py +390 -0
- ads/aqua/extension/models/__init__.py +0 -0
- ads/aqua/extension/models/ws_models.py +145 -0
- ads/aqua/extension/models_ws_msg_handler.py +50 -0
- ads/aqua/extension/ui_handler.py +300 -0
- ads/aqua/extension/ui_websocket_handler.py +130 -0
- ads/aqua/extension/utils.py +133 -0
- ads/aqua/finetuning/__init__.py +7 -0
- ads/aqua/finetuning/constants.py +23 -0
- ads/aqua/finetuning/entities.py +181 -0
- ads/aqua/finetuning/finetuning.py +749 -0
- ads/aqua/model/__init__.py +8 -0
- ads/aqua/model/constants.py +60 -0
- ads/aqua/model/entities.py +385 -0
- ads/aqua/model/enums.py +32 -0
- ads/aqua/model/model.py +2134 -0
- ads/aqua/model/utils.py +52 -0
- ads/aqua/modeldeployment/__init__.py +6 -0
- ads/aqua/modeldeployment/constants.py +10 -0
- ads/aqua/modeldeployment/deployment.py +1315 -0
- ads/aqua/modeldeployment/entities.py +653 -0
- ads/aqua/modeldeployment/utils.py +543 -0
- ads/aqua/resources/gpu_shapes_index.json +94 -0
- ads/aqua/server/__init__.py +4 -0
- ads/aqua/server/__main__.py +24 -0
- ads/aqua/server/app.py +47 -0
- ads/aqua/server/aqua_spec.yml +1291 -0
- ads/aqua/training/__init__.py +4 -0
- ads/aqua/training/exceptions.py +476 -0
- ads/aqua/ui.py +519 -0
- ads/automl/__init__.py +9 -0
- ads/automl/driver.py +330 -0
- ads/automl/provider.py +975 -0
- ads/bds/__init__.py +5 -0
- ads/bds/auth.py +127 -0
- ads/bds/big_data_service.py +255 -0
- ads/catalog/__init__.py +19 -0
- ads/catalog/model.py +1576 -0
- ads/catalog/notebook.py +461 -0
- ads/catalog/project.py +468 -0
- ads/catalog/summary.py +178 -0
- ads/common/__init__.py +11 -0
- ads/common/analyzer.py +65 -0
- ads/common/artifact/.model-ignore +63 -0
- ads/common/artifact/__init__.py +10 -0
- ads/common/auth.py +1122 -0
- ads/common/card_identifier.py +83 -0
- ads/common/config.py +647 -0
- ads/common/data.py +165 -0
- ads/common/decorator/__init__.py +9 -0
- ads/common/decorator/argument_to_case.py +88 -0
- ads/common/decorator/deprecate.py +69 -0
- ads/common/decorator/require_nonempty_arg.py +65 -0
- ads/common/decorator/runtime_dependency.py +178 -0
- ads/common/decorator/threaded.py +97 -0
- ads/common/decorator/utils.py +35 -0
- ads/common/dsc_file_system.py +303 -0
- ads/common/error.py +14 -0
- ads/common/extended_enum.py +81 -0
- ads/common/function/__init__.py +5 -0
- ads/common/function/fn_util.py +142 -0
- ads/common/function/func_conf.yaml +25 -0
- ads/common/ipython.py +76 -0
- ads/common/model.py +679 -0
- ads/common/model_artifact.py +1759 -0
- ads/common/model_artifact_schema.json +107 -0
- ads/common/model_export_util.py +664 -0
- ads/common/model_metadata.py +24 -0
- ads/common/object_storage_details.py +296 -0
- ads/common/oci_client.py +179 -0
- ads/common/oci_datascience.py +46 -0
- ads/common/oci_logging.py +1144 -0
- ads/common/oci_mixin.py +957 -0
- ads/common/oci_resource.py +136 -0
- ads/common/serializer.py +559 -0
- ads/common/utils.py +1852 -0
- ads/common/word_lists.py +1491 -0
- ads/common/work_request.py +189 -0
- ads/config.py +1 -0
- ads/data_labeling/__init__.py +13 -0
- ads/data_labeling/boundingbox.py +253 -0
- ads/data_labeling/constants.py +47 -0
- ads/data_labeling/data_labeling_service.py +244 -0
- ads/data_labeling/interface/__init__.py +5 -0
- ads/data_labeling/interface/loader.py +16 -0
- ads/data_labeling/interface/parser.py +16 -0
- ads/data_labeling/interface/reader.py +23 -0
- ads/data_labeling/loader/__init__.py +5 -0
- ads/data_labeling/loader/file_loader.py +241 -0
- ads/data_labeling/metadata.py +110 -0
- ads/data_labeling/mixin/__init__.py +5 -0
- ads/data_labeling/mixin/data_labeling.py +232 -0
- ads/data_labeling/ner.py +129 -0
- ads/data_labeling/parser/__init__.py +5 -0
- ads/data_labeling/parser/dls_record_parser.py +388 -0
- ads/data_labeling/parser/export_metadata_parser.py +94 -0
- ads/data_labeling/parser/export_record_parser.py +473 -0
- ads/data_labeling/reader/__init__.py +5 -0
- ads/data_labeling/reader/dataset_reader.py +574 -0
- ads/data_labeling/reader/dls_record_reader.py +121 -0
- ads/data_labeling/reader/export_record_reader.py +62 -0
- ads/data_labeling/reader/jsonl_reader.py +75 -0
- ads/data_labeling/reader/metadata_reader.py +203 -0
- ads/data_labeling/reader/record_reader.py +263 -0
- ads/data_labeling/record.py +52 -0
- ads/data_labeling/visualizer/__init__.py +5 -0
- ads/data_labeling/visualizer/image_visualizer.py +525 -0
- ads/data_labeling/visualizer/text_visualizer.py +357 -0
- ads/database/__init__.py +5 -0
- ads/database/connection.py +338 -0
- ads/dataset/__init__.py +10 -0
- ads/dataset/capabilities.md +51 -0
- ads/dataset/classification_dataset.py +339 -0
- ads/dataset/correlation.py +226 -0
- ads/dataset/correlation_plot.py +563 -0
- ads/dataset/dask_series.py +173 -0
- ads/dataset/dataframe_transformer.py +110 -0
- ads/dataset/dataset.py +1979 -0
- ads/dataset/dataset_browser.py +360 -0
- ads/dataset/dataset_with_target.py +995 -0
- ads/dataset/exception.py +25 -0
- ads/dataset/factory.py +987 -0
- ads/dataset/feature_engineering_transformer.py +35 -0
- ads/dataset/feature_selection.py +107 -0
- ads/dataset/forecasting_dataset.py +26 -0
- ads/dataset/helper.py +1450 -0
- ads/dataset/label_encoder.py +99 -0
- ads/dataset/mixin/__init__.py +5 -0
- ads/dataset/mixin/dataset_accessor.py +134 -0
- ads/dataset/pipeline.py +58 -0
- ads/dataset/plot.py +710 -0
- ads/dataset/progress.py +86 -0
- ads/dataset/recommendation.py +297 -0
- ads/dataset/recommendation_transformer.py +502 -0
- ads/dataset/regression_dataset.py +14 -0
- ads/dataset/sampled_dataset.py +1050 -0
- ads/dataset/target.py +98 -0
- ads/dataset/timeseries.py +18 -0
- ads/dbmixin/__init__.py +5 -0
- ads/dbmixin/db_pandas_accessor.py +153 -0
- ads/environment/__init__.py +9 -0
- ads/environment/ml_runtime.py +66 -0
- ads/evaluations/README.md +14 -0
- ads/evaluations/__init__.py +109 -0
- ads/evaluations/evaluation_plot.py +983 -0
- ads/evaluations/evaluator.py +1334 -0
- ads/evaluations/statistical_metrics.py +543 -0
- ads/experiments/__init__.py +9 -0
- ads/experiments/capabilities.md +0 -0
- ads/explanations/__init__.py +21 -0
- ads/explanations/base_explainer.py +142 -0
- ads/explanations/capabilities.md +83 -0
- ads/explanations/explainer.py +190 -0
- ads/explanations/mlx_global_explainer.py +1050 -0
- ads/explanations/mlx_interface.py +386 -0
- ads/explanations/mlx_local_explainer.py +287 -0
- ads/explanations/mlx_whatif_explainer.py +201 -0
- ads/feature_engineering/__init__.py +20 -0
- ads/feature_engineering/accessor/__init__.py +5 -0
- ads/feature_engineering/accessor/dataframe_accessor.py +535 -0
- ads/feature_engineering/accessor/mixin/__init__.py +5 -0
- ads/feature_engineering/accessor/mixin/correlation.py +166 -0
- ads/feature_engineering/accessor/mixin/eda_mixin.py +266 -0
- ads/feature_engineering/accessor/mixin/eda_mixin_series.py +85 -0
- ads/feature_engineering/accessor/mixin/feature_types_mixin.py +211 -0
- ads/feature_engineering/accessor/mixin/utils.py +65 -0
- ads/feature_engineering/accessor/series_accessor.py +431 -0
- ads/feature_engineering/adsimage/__init__.py +5 -0
- ads/feature_engineering/adsimage/image.py +192 -0
- ads/feature_engineering/adsimage/image_reader.py +170 -0
- ads/feature_engineering/adsimage/interface/__init__.py +5 -0
- ads/feature_engineering/adsimage/interface/reader.py +19 -0
- ads/feature_engineering/adsstring/__init__.py +7 -0
- ads/feature_engineering/adsstring/oci_language/__init__.py +8 -0
- ads/feature_engineering/adsstring/string/__init__.py +8 -0
- ads/feature_engineering/data_schema.json +57 -0
- ads/feature_engineering/dataset/__init__.py +5 -0
- ads/feature_engineering/dataset/zip_code_data.py +42062 -0
- ads/feature_engineering/exceptions.py +40 -0
- ads/feature_engineering/feature_type/__init__.py +133 -0
- ads/feature_engineering/feature_type/address.py +184 -0
- ads/feature_engineering/feature_type/adsstring/__init__.py +5 -0
- ads/feature_engineering/feature_type/adsstring/common_regex_mixin.py +164 -0
- ads/feature_engineering/feature_type/adsstring/oci_language.py +93 -0
- ads/feature_engineering/feature_type/adsstring/parsers/__init__.py +5 -0
- ads/feature_engineering/feature_type/adsstring/parsers/base.py +47 -0
- ads/feature_engineering/feature_type/adsstring/parsers/nltk_parser.py +96 -0
- ads/feature_engineering/feature_type/adsstring/parsers/spacy_parser.py +221 -0
- ads/feature_engineering/feature_type/adsstring/string.py +258 -0
- ads/feature_engineering/feature_type/base.py +58 -0
- ads/feature_engineering/feature_type/boolean.py +183 -0
- ads/feature_engineering/feature_type/category.py +146 -0
- ads/feature_engineering/feature_type/constant.py +137 -0
- ads/feature_engineering/feature_type/continuous.py +151 -0
- ads/feature_engineering/feature_type/creditcard.py +314 -0
- ads/feature_engineering/feature_type/datetime.py +190 -0
- ads/feature_engineering/feature_type/discrete.py +134 -0
- ads/feature_engineering/feature_type/document.py +43 -0
- ads/feature_engineering/feature_type/gis.py +251 -0
- ads/feature_engineering/feature_type/handler/__init__.py +5 -0
- ads/feature_engineering/feature_type/handler/feature_validator.py +524 -0
- ads/feature_engineering/feature_type/handler/feature_warning.py +319 -0
- ads/feature_engineering/feature_type/handler/warnings.py +128 -0
- ads/feature_engineering/feature_type/integer.py +142 -0
- ads/feature_engineering/feature_type/ip_address.py +144 -0
- ads/feature_engineering/feature_type/ip_address_v4.py +138 -0
- ads/feature_engineering/feature_type/ip_address_v6.py +138 -0
- ads/feature_engineering/feature_type/lat_long.py +256 -0
- ads/feature_engineering/feature_type/object.py +43 -0
- ads/feature_engineering/feature_type/ordinal.py +132 -0
- ads/feature_engineering/feature_type/phone_number.py +135 -0
- ads/feature_engineering/feature_type/string.py +171 -0
- ads/feature_engineering/feature_type/text.py +93 -0
- ads/feature_engineering/feature_type/unknown.py +43 -0
- ads/feature_engineering/feature_type/zip_code.py +164 -0
- ads/feature_engineering/feature_type_manager.py +406 -0
- ads/feature_engineering/schema.py +795 -0
- ads/feature_engineering/utils.py +245 -0
- ads/feature_store/.readthedocs.yaml +19 -0
- ads/feature_store/README.md +65 -0
- ads/feature_store/__init__.py +9 -0
- ads/feature_store/common/__init__.py +0 -0
- ads/feature_store/common/enums.py +339 -0
- ads/feature_store/common/exceptions.py +18 -0
- ads/feature_store/common/spark_session_singleton.py +125 -0
- ads/feature_store/common/utils/__init__.py +0 -0
- ads/feature_store/common/utils/base64_encoder_decoder.py +72 -0
- ads/feature_store/common/utils/feature_schema_mapper.py +283 -0
- ads/feature_store/common/utils/transformation_utils.py +82 -0
- ads/feature_store/common/utils/utility.py +403 -0
- ads/feature_store/data_validation/__init__.py +0 -0
- ads/feature_store/data_validation/great_expectation.py +129 -0
- ads/feature_store/dataset.py +1230 -0
- ads/feature_store/dataset_job.py +530 -0
- ads/feature_store/docs/Dockerfile +7 -0
- ads/feature_store/docs/Makefile +44 -0
- ads/feature_store/docs/conf.py +28 -0
- ads/feature_store/docs/requirements.txt +14 -0
- ads/feature_store/docs/source/ads.feature_store.query.rst +20 -0
- ads/feature_store/docs/source/cicd.rst +137 -0
- ads/feature_store/docs/source/conf.py +86 -0
- ads/feature_store/docs/source/data_versioning.rst +33 -0
- ads/feature_store/docs/source/dataset.rst +388 -0
- ads/feature_store/docs/source/dataset_job.rst +27 -0
- ads/feature_store/docs/source/demo.rst +70 -0
- ads/feature_store/docs/source/entity.rst +78 -0
- ads/feature_store/docs/source/feature_group.rst +624 -0
- ads/feature_store/docs/source/feature_group_job.rst +29 -0
- ads/feature_store/docs/source/feature_store.rst +122 -0
- ads/feature_store/docs/source/feature_store_class.rst +123 -0
- ads/feature_store/docs/source/feature_validation.rst +66 -0
- ads/feature_store/docs/source/figures/cicd.png +0 -0
- ads/feature_store/docs/source/figures/data_validation.png +0 -0
- ads/feature_store/docs/source/figures/data_versioning.png +0 -0
- ads/feature_store/docs/source/figures/dataset.gif +0 -0
- ads/feature_store/docs/source/figures/dataset.png +0 -0
- ads/feature_store/docs/source/figures/dataset_lineage.png +0 -0
- ads/feature_store/docs/source/figures/dataset_statistics.png +0 -0
- ads/feature_store/docs/source/figures/dataset_statistics_viz.png +0 -0
- ads/feature_store/docs/source/figures/dataset_validation_results.png +0 -0
- ads/feature_store/docs/source/figures/dataset_validation_summary.png +0 -0
- ads/feature_store/docs/source/figures/drift_monitoring.png +0 -0
- ads/feature_store/docs/source/figures/entity.png +0 -0
- ads/feature_store/docs/source/figures/feature_group.png +0 -0
- ads/feature_store/docs/source/figures/feature_group_lineage.png +0 -0
- ads/feature_store/docs/source/figures/feature_group_statistics_viz.png +0 -0
- ads/feature_store/docs/source/figures/feature_store_deployment.png +0 -0
- ads/feature_store/docs/source/figures/feature_store_overview.png +0 -0
- ads/feature_store/docs/source/figures/featuregroup.gif +0 -0
- ads/feature_store/docs/source/figures/lineage_d1.png +0 -0
- ads/feature_store/docs/source/figures/lineage_d2.png +0 -0
- ads/feature_store/docs/source/figures/lineage_fg.png +0 -0
- ads/feature_store/docs/source/figures/logo-dark-mode.png +0 -0
- ads/feature_store/docs/source/figures/logo-light-mode.png +0 -0
- ads/feature_store/docs/source/figures/overview.png +0 -0
- ads/feature_store/docs/source/figures/resource_manager.png +0 -0
- ads/feature_store/docs/source/figures/resource_manager_feature_store_stack.png +0 -0
- ads/feature_store/docs/source/figures/resource_manager_home.png +0 -0
- ads/feature_store/docs/source/figures/stats_1.png +0 -0
- ads/feature_store/docs/source/figures/stats_2.png +0 -0
- ads/feature_store/docs/source/figures/stats_d.png +0 -0
- ads/feature_store/docs/source/figures/stats_fg.png +0 -0
- ads/feature_store/docs/source/figures/transformation.png +0 -0
- ads/feature_store/docs/source/figures/transformations.gif +0 -0
- ads/feature_store/docs/source/figures/validation.png +0 -0
- ads/feature_store/docs/source/figures/validation_fg.png +0 -0
- ads/feature_store/docs/source/figures/validation_results.png +0 -0
- ads/feature_store/docs/source/figures/validation_summary.png +0 -0
- ads/feature_store/docs/source/index.rst +81 -0
- ads/feature_store/docs/source/module.rst +8 -0
- ads/feature_store/docs/source/notebook.rst +94 -0
- ads/feature_store/docs/source/overview.rst +47 -0
- ads/feature_store/docs/source/quickstart.rst +176 -0
- ads/feature_store/docs/source/release_notes.rst +194 -0
- ads/feature_store/docs/source/setup_feature_store.rst +81 -0
- ads/feature_store/docs/source/statistics.rst +58 -0
- ads/feature_store/docs/source/transformation.rst +199 -0
- ads/feature_store/docs/source/ui.rst +65 -0
- ads/feature_store/docs/source/user_guides.setup.feature_store_operator.rst +66 -0
- ads/feature_store/docs/source/user_guides.setup.helm_chart.rst +192 -0
- ads/feature_store/docs/source/user_guides.setup.terraform.rst +338 -0
- ads/feature_store/entity.py +718 -0
- ads/feature_store/execution_strategy/__init__.py +0 -0
- ads/feature_store/execution_strategy/delta_lake/__init__.py +0 -0
- ads/feature_store/execution_strategy/delta_lake/delta_lake_service.py +375 -0
- ads/feature_store/execution_strategy/engine/__init__.py +0 -0
- ads/feature_store/execution_strategy/engine/spark_engine.py +316 -0
- ads/feature_store/execution_strategy/execution_strategy.py +113 -0
- ads/feature_store/execution_strategy/execution_strategy_provider.py +47 -0
- ads/feature_store/execution_strategy/spark/__init__.py +0 -0
- ads/feature_store/execution_strategy/spark/spark_execution.py +618 -0
- ads/feature_store/feature.py +192 -0
- ads/feature_store/feature_group.py +1494 -0
- ads/feature_store/feature_group_expectation.py +346 -0
- ads/feature_store/feature_group_job.py +602 -0
- ads/feature_store/feature_lineage/__init__.py +0 -0
- ads/feature_store/feature_lineage/graphviz_service.py +180 -0
- ads/feature_store/feature_option_details.py +50 -0
- ads/feature_store/feature_statistics/__init__.py +0 -0
- ads/feature_store/feature_statistics/statistics_service.py +99 -0
- ads/feature_store/feature_store.py +699 -0
- ads/feature_store/feature_store_registrar.py +518 -0
- ads/feature_store/input_feature_detail.py +149 -0
- ads/feature_store/mixin/__init__.py +4 -0
- ads/feature_store/mixin/oci_feature_store.py +145 -0
- ads/feature_store/model_details.py +73 -0
- ads/feature_store/query/__init__.py +0 -0
- ads/feature_store/query/filter.py +266 -0
- ads/feature_store/query/generator/__init__.py +0 -0
- ads/feature_store/query/generator/query_generator.py +298 -0
- ads/feature_store/query/join.py +161 -0
- ads/feature_store/query/query.py +403 -0
- ads/feature_store/query/validator/__init__.py +0 -0
- ads/feature_store/query/validator/query_validator.py +57 -0
- ads/feature_store/response/__init__.py +0 -0
- ads/feature_store/response/response_builder.py +68 -0
- ads/feature_store/service/__init__.py +0 -0
- ads/feature_store/service/oci_dataset.py +139 -0
- ads/feature_store/service/oci_dataset_job.py +199 -0
- ads/feature_store/service/oci_entity.py +125 -0
- ads/feature_store/service/oci_feature_group.py +164 -0
- ads/feature_store/service/oci_feature_group_job.py +214 -0
- ads/feature_store/service/oci_feature_store.py +182 -0
- ads/feature_store/service/oci_lineage.py +87 -0
- ads/feature_store/service/oci_transformation.py +104 -0
- ads/feature_store/statistics/__init__.py +0 -0
- ads/feature_store/statistics/abs_feature_value.py +49 -0
- ads/feature_store/statistics/charts/__init__.py +0 -0
- ads/feature_store/statistics/charts/abstract_feature_plot.py +37 -0
- ads/feature_store/statistics/charts/box_plot.py +148 -0
- ads/feature_store/statistics/charts/frequency_distribution.py +65 -0
- ads/feature_store/statistics/charts/probability_distribution.py +68 -0
- ads/feature_store/statistics/charts/top_k_frequent_elements.py +98 -0
- ads/feature_store/statistics/feature_stat.py +126 -0
- ads/feature_store/statistics/generic_feature_value.py +33 -0
- ads/feature_store/statistics/statistics.py +41 -0
- ads/feature_store/statistics_config.py +101 -0
- ads/feature_store/templates/feature_store_template.yaml +45 -0
- ads/feature_store/transformation.py +499 -0
- ads/feature_store/validation_output.py +57 -0
- ads/hpo/__init__.py +9 -0
- ads/hpo/_imports.py +91 -0
- ads/hpo/ads_search_space.py +439 -0
- ads/hpo/distributions.py +325 -0
- ads/hpo/objective.py +280 -0
- ads/hpo/search_cv.py +1657 -0
- ads/hpo/stopping_criterion.py +75 -0
- ads/hpo/tuner_artifact.py +413 -0
- ads/hpo/utils.py +91 -0
- ads/hpo/validation.py +140 -0
- ads/hpo/visualization/__init__.py +5 -0
- ads/hpo/visualization/_contour.py +23 -0
- ads/hpo/visualization/_edf.py +20 -0
- ads/hpo/visualization/_intermediate_values.py +21 -0
- ads/hpo/visualization/_optimization_history.py +25 -0
- ads/hpo/visualization/_parallel_coordinate.py +169 -0
- ads/hpo/visualization/_param_importances.py +26 -0
- ads/jobs/__init__.py +53 -0
- ads/jobs/ads_job.py +663 -0
- ads/jobs/builders/__init__.py +5 -0
- ads/jobs/builders/base.py +156 -0
- ads/jobs/builders/infrastructure/__init__.py +6 -0
- ads/jobs/builders/infrastructure/base.py +165 -0
- ads/jobs/builders/infrastructure/dataflow.py +1252 -0
- ads/jobs/builders/infrastructure/dsc_job.py +1894 -0
- ads/jobs/builders/infrastructure/dsc_job_runtime.py +1233 -0
- ads/jobs/builders/infrastructure/utils.py +65 -0
- ads/jobs/builders/runtimes/__init__.py +5 -0
- ads/jobs/builders/runtimes/artifact.py +338 -0
- ads/jobs/builders/runtimes/base.py +325 -0
- ads/jobs/builders/runtimes/container_runtime.py +242 -0
- ads/jobs/builders/runtimes/python_runtime.py +1016 -0
- ads/jobs/builders/runtimes/pytorch_runtime.py +204 -0
- ads/jobs/cli.py +104 -0
- ads/jobs/env_var_parser.py +131 -0
- ads/jobs/extension.py +160 -0
- ads/jobs/schema/__init__.py +5 -0
- ads/jobs/schema/infrastructure_schema.json +116 -0
- ads/jobs/schema/job_schema.json +42 -0
- ads/jobs/schema/runtime_schema.json +183 -0
- ads/jobs/schema/validator.py +141 -0
- ads/jobs/serializer.py +296 -0
- ads/jobs/templates/__init__.py +5 -0
- ads/jobs/templates/container.py +6 -0
- ads/jobs/templates/driver_notebook.py +177 -0
- ads/jobs/templates/driver_oci.py +500 -0
- ads/jobs/templates/driver_python.py +48 -0
- ads/jobs/templates/driver_pytorch.py +852 -0
- ads/jobs/templates/driver_utils.py +615 -0
- ads/jobs/templates/hostname_from_env.c +55 -0
- ads/jobs/templates/oci_metrics.py +181 -0
- ads/jobs/utils.py +104 -0
- ads/llm/__init__.py +28 -0
- ads/llm/autogen/__init__.py +2 -0
- ads/llm/autogen/constants.py +15 -0
- ads/llm/autogen/reports/__init__.py +2 -0
- ads/llm/autogen/reports/base.py +67 -0
- ads/llm/autogen/reports/data.py +103 -0
- ads/llm/autogen/reports/session.py +526 -0
- ads/llm/autogen/reports/templates/chat_box.html +13 -0
- ads/llm/autogen/reports/templates/chat_box_lt.html +5 -0
- ads/llm/autogen/reports/templates/chat_box_rt.html +6 -0
- ads/llm/autogen/reports/utils.py +56 -0
- ads/llm/autogen/v02/__init__.py +4 -0
- ads/llm/autogen/v02/client.py +295 -0
- ads/llm/autogen/v02/log_handlers/__init__.py +2 -0
- ads/llm/autogen/v02/log_handlers/oci_file_handler.py +83 -0
- ads/llm/autogen/v02/loggers/__init__.py +6 -0
- ads/llm/autogen/v02/loggers/metric_logger.py +320 -0
- ads/llm/autogen/v02/loggers/session_logger.py +580 -0
- ads/llm/autogen/v02/loggers/utils.py +86 -0
- ads/llm/autogen/v02/runtime_logging.py +163 -0
- ads/llm/chain.py +268 -0
- ads/llm/chat_template.py +31 -0
- ads/llm/deploy.py +63 -0
- ads/llm/guardrails/__init__.py +5 -0
- ads/llm/guardrails/base.py +442 -0
- ads/llm/guardrails/huggingface.py +44 -0
- ads/llm/langchain/__init__.py +5 -0
- ads/llm/langchain/plugins/__init__.py +5 -0
- ads/llm/langchain/plugins/chat_models/__init__.py +5 -0
- ads/llm/langchain/plugins/chat_models/oci_data_science.py +1027 -0
- ads/llm/langchain/plugins/embeddings/__init__.py +4 -0
- ads/llm/langchain/plugins/embeddings/oci_data_science_model_deployment_endpoint.py +184 -0
- ads/llm/langchain/plugins/llms/__init__.py +5 -0
- ads/llm/langchain/plugins/llms/oci_data_science_model_deployment_endpoint.py +979 -0
- ads/llm/requirements.txt +3 -0
- ads/llm/serialize.py +219 -0
- ads/llm/serializers/__init__.py +0 -0
- ads/llm/serializers/retrieval_qa.py +153 -0
- ads/llm/serializers/runnable_parallel.py +27 -0
- ads/llm/templates/score_chain.jinja2 +155 -0
- ads/llm/templates/tool_chat_template_hermes.jinja +130 -0
- ads/llm/templates/tool_chat_template_mistral_parallel.jinja +94 -0
- ads/model/__init__.py +52 -0
- ads/model/artifact.py +573 -0
- ads/model/artifact_downloader.py +254 -0
- ads/model/artifact_uploader.py +267 -0
- ads/model/base_properties.py +238 -0
- ads/model/common/.model-ignore +66 -0
- ads/model/common/__init__.py +5 -0
- ads/model/common/utils.py +142 -0
- ads/model/datascience_model.py +2635 -0
- ads/model/deployment/__init__.py +20 -0
- ads/model/deployment/common/__init__.py +5 -0
- ads/model/deployment/common/utils.py +308 -0
- ads/model/deployment/model_deployer.py +466 -0
- ads/model/deployment/model_deployment.py +1846 -0
- ads/model/deployment/model_deployment_infrastructure.py +671 -0
- ads/model/deployment/model_deployment_properties.py +493 -0
- ads/model/deployment/model_deployment_runtime.py +838 -0
- ads/model/extractor/__init__.py +5 -0
- ads/model/extractor/automl_extractor.py +74 -0
- ads/model/extractor/embedding_onnx_extractor.py +80 -0
- ads/model/extractor/huggingface_extractor.py +88 -0
- ads/model/extractor/keras_extractor.py +84 -0
- ads/model/extractor/lightgbm_extractor.py +93 -0
- ads/model/extractor/model_info_extractor.py +114 -0
- ads/model/extractor/model_info_extractor_factory.py +105 -0
- ads/model/extractor/pytorch_extractor.py +87 -0
- ads/model/extractor/sklearn_extractor.py +112 -0
- ads/model/extractor/spark_extractor.py +89 -0
- ads/model/extractor/tensorflow_extractor.py +85 -0
- ads/model/extractor/xgboost_extractor.py +94 -0
- ads/model/framework/__init__.py +5 -0
- ads/model/framework/automl_model.py +178 -0
- ads/model/framework/embedding_onnx_model.py +438 -0
- ads/model/framework/huggingface_model.py +399 -0
- ads/model/framework/lightgbm_model.py +266 -0
- ads/model/framework/pytorch_model.py +266 -0
- ads/model/framework/sklearn_model.py +250 -0
- ads/model/framework/spark_model.py +326 -0
- ads/model/framework/tensorflow_model.py +254 -0
- ads/model/framework/xgboost_model.py +258 -0
- ads/model/generic_model.py +3518 -0
- ads/model/model_artifact_boilerplate/README.md +381 -0
- ads/model/model_artifact_boilerplate/__init__.py +5 -0
- ads/model/model_artifact_boilerplate/artifact_introspection_test/__init__.py +5 -0
- ads/model/model_artifact_boilerplate/artifact_introspection_test/model_artifact_validate.py +427 -0
- ads/model/model_artifact_boilerplate/artifact_introspection_test/requirements.txt +2 -0
- ads/model/model_artifact_boilerplate/runtime.yaml +7 -0
- ads/model/model_artifact_boilerplate/score.py +61 -0
- ads/model/model_file_description_schema.json +68 -0
- ads/model/model_introspect.py +331 -0
- ads/model/model_metadata.py +1810 -0
- ads/model/model_metadata_mixin.py +460 -0
- ads/model/model_properties.py +63 -0
- ads/model/model_version_set.py +739 -0
- ads/model/runtime/__init__.py +5 -0
- ads/model/runtime/env_info.py +306 -0
- ads/model/runtime/model_deployment_details.py +37 -0
- ads/model/runtime/model_provenance_details.py +58 -0
- ads/model/runtime/runtime_info.py +81 -0
- ads/model/runtime/schemas/inference_env_info_schema.yaml +16 -0
- ads/model/runtime/schemas/model_provenance_schema.yaml +36 -0
- ads/model/runtime/schemas/training_env_info_schema.yaml +16 -0
- ads/model/runtime/utils.py +201 -0
- ads/model/serde/__init__.py +5 -0
- ads/model/serde/common.py +40 -0
- ads/model/serde/model_input.py +547 -0
- ads/model/serde/model_serializer.py +1184 -0
- ads/model/service/__init__.py +5 -0
- ads/model/service/oci_datascience_model.py +1076 -0
- ads/model/service/oci_datascience_model_deployment.py +500 -0
- ads/model/service/oci_datascience_model_version_set.py +176 -0
- ads/model/transformer/__init__.py +5 -0
- ads/model/transformer/onnx_transformer.py +324 -0
- ads/mysqldb/__init__.py +5 -0
- ads/mysqldb/mysql_db.py +227 -0
- ads/opctl/__init__.py +18 -0
- ads/opctl/anomaly_detection.py +11 -0
- ads/opctl/backend/__init__.py +5 -0
- ads/opctl/backend/ads_dataflow.py +353 -0
- ads/opctl/backend/ads_ml_job.py +710 -0
- ads/opctl/backend/ads_ml_pipeline.py +164 -0
- ads/opctl/backend/ads_model_deployment.py +209 -0
- ads/opctl/backend/base.py +146 -0
- ads/opctl/backend/local.py +1053 -0
- ads/opctl/backend/marketplace/__init__.py +9 -0
- ads/opctl/backend/marketplace/helm_helper.py +173 -0
- ads/opctl/backend/marketplace/local_marketplace.py +271 -0
- ads/opctl/backend/marketplace/marketplace_backend_runner.py +71 -0
- ads/opctl/backend/marketplace/marketplace_operator_interface.py +44 -0
- ads/opctl/backend/marketplace/marketplace_operator_runner.py +24 -0
- ads/opctl/backend/marketplace/marketplace_utils.py +212 -0
- ads/opctl/backend/marketplace/models/__init__.py +5 -0
- ads/opctl/backend/marketplace/models/bearer_token.py +94 -0
- ads/opctl/backend/marketplace/models/marketplace_type.py +70 -0
- ads/opctl/backend/marketplace/models/ocir_details.py +56 -0
- ads/opctl/backend/marketplace/prerequisite_checker.py +238 -0
- ads/opctl/cli.py +707 -0
- ads/opctl/cmds.py +869 -0
- ads/opctl/conda/__init__.py +5 -0
- ads/opctl/conda/cli.py +193 -0
- ads/opctl/conda/cmds.py +749 -0
- ads/opctl/conda/config.yaml +34 -0
- ads/opctl/conda/manifest_template.yaml +13 -0
- ads/opctl/conda/multipart_uploader.py +188 -0
- ads/opctl/conda/pack.py +89 -0
- ads/opctl/config/__init__.py +5 -0
- ads/opctl/config/base.py +57 -0
- ads/opctl/config/diagnostics/__init__.py +5 -0
- ads/opctl/config/diagnostics/distributed/default_requirements_config.yaml +62 -0
- ads/opctl/config/merger.py +255 -0
- ads/opctl/config/resolver.py +297 -0
- ads/opctl/config/utils.py +79 -0
- ads/opctl/config/validator.py +17 -0
- ads/opctl/config/versioner.py +68 -0
- ads/opctl/config/yaml_parsers/__init__.py +7 -0
- ads/opctl/config/yaml_parsers/base.py +58 -0
- ads/opctl/config/yaml_parsers/distributed/__init__.py +7 -0
- ads/opctl/config/yaml_parsers/distributed/yaml_parser.py +201 -0
- ads/opctl/constants.py +66 -0
- ads/opctl/decorator/__init__.py +5 -0
- ads/opctl/decorator/common.py +129 -0
- ads/opctl/diagnostics/__init__.py +5 -0
- ads/opctl/diagnostics/__main__.py +25 -0
- ads/opctl/diagnostics/check_distributed_job_requirements.py +212 -0
- ads/opctl/diagnostics/check_requirements.py +144 -0
- ads/opctl/diagnostics/requirement_exception.py +9 -0
- ads/opctl/distributed/README.md +109 -0
- ads/opctl/distributed/__init__.py +5 -0
- ads/opctl/distributed/certificates.py +32 -0
- ads/opctl/distributed/cli.py +207 -0
- ads/opctl/distributed/cmds.py +731 -0
- ads/opctl/distributed/common/__init__.py +5 -0
- ads/opctl/distributed/common/abstract_cluster_provider.py +449 -0
- ads/opctl/distributed/common/abstract_framework_spec_builder.py +88 -0
- ads/opctl/distributed/common/cluster_config_helper.py +103 -0
- ads/opctl/distributed/common/cluster_provider_factory.py +21 -0
- ads/opctl/distributed/common/cluster_runner.py +54 -0
- ads/opctl/distributed/common/framework_factory.py +29 -0
- ads/opctl/docker/Dockerfile.job +103 -0
- ads/opctl/docker/Dockerfile.job.arm +107 -0
- ads/opctl/docker/Dockerfile.job.gpu +175 -0
- ads/opctl/docker/base-env.yaml +13 -0
- ads/opctl/docker/cuda.repo +6 -0
- ads/opctl/docker/operator/.dockerignore +0 -0
- ads/opctl/docker/operator/Dockerfile +41 -0
- ads/opctl/docker/operator/Dockerfile.gpu +85 -0
- ads/opctl/docker/operator/cuda.repo +6 -0
- ads/opctl/docker/operator/environment.yaml +8 -0
- ads/opctl/forecast.py +11 -0
- ads/opctl/index.yaml +3 -0
- ads/opctl/model/__init__.py +5 -0
- ads/opctl/model/cli.py +65 -0
- ads/opctl/model/cmds.py +73 -0
- ads/opctl/operator/README.md +4 -0
- ads/opctl/operator/__init__.py +31 -0
- ads/opctl/operator/cli.py +344 -0
- ads/opctl/operator/cmd.py +596 -0
- ads/opctl/operator/common/__init__.py +5 -0
- ads/opctl/operator/common/backend_factory.py +460 -0
- ads/opctl/operator/common/const.py +27 -0
- ads/opctl/operator/common/data/synthetic.csv +16001 -0
- ads/opctl/operator/common/dictionary_merger.py +148 -0
- ads/opctl/operator/common/errors.py +42 -0
- ads/opctl/operator/common/operator_config.py +99 -0
- ads/opctl/operator/common/operator_loader.py +811 -0
- ads/opctl/operator/common/operator_schema.yaml +130 -0
- ads/opctl/operator/common/operator_yaml_generator.py +152 -0
- ads/opctl/operator/common/utils.py +208 -0
- ads/opctl/operator/lowcode/__init__.py +5 -0
- ads/opctl/operator/lowcode/anomaly/MLoperator +16 -0
- ads/opctl/operator/lowcode/anomaly/README.md +207 -0
- ads/opctl/operator/lowcode/anomaly/__init__.py +5 -0
- ads/opctl/operator/lowcode/anomaly/__main__.py +103 -0
- ads/opctl/operator/lowcode/anomaly/cmd.py +35 -0
- ads/opctl/operator/lowcode/anomaly/const.py +167 -0
- ads/opctl/operator/lowcode/anomaly/environment.yaml +10 -0
- ads/opctl/operator/lowcode/anomaly/model/__init__.py +5 -0
- ads/opctl/operator/lowcode/anomaly/model/anomaly_dataset.py +146 -0
- ads/opctl/operator/lowcode/anomaly/model/anomaly_merlion.py +162 -0
- ads/opctl/operator/lowcode/anomaly/model/automlx.py +99 -0
- ads/opctl/operator/lowcode/anomaly/model/autots.py +115 -0
- ads/opctl/operator/lowcode/anomaly/model/base_model.py +404 -0
- ads/opctl/operator/lowcode/anomaly/model/factory.py +110 -0
- ads/opctl/operator/lowcode/anomaly/model/isolationforest.py +78 -0
- ads/opctl/operator/lowcode/anomaly/model/oneclasssvm.py +78 -0
- ads/opctl/operator/lowcode/anomaly/model/randomcutforest.py +120 -0
- ads/opctl/operator/lowcode/anomaly/model/tods.py +119 -0
- ads/opctl/operator/lowcode/anomaly/operator_config.py +127 -0
- ads/opctl/operator/lowcode/anomaly/schema.yaml +401 -0
- ads/opctl/operator/lowcode/anomaly/utils.py +88 -0
- ads/opctl/operator/lowcode/common/__init__.py +5 -0
- ads/opctl/operator/lowcode/common/const.py +10 -0
- ads/opctl/operator/lowcode/common/data.py +116 -0
- ads/opctl/operator/lowcode/common/errors.py +47 -0
- ads/opctl/operator/lowcode/common/transformations.py +296 -0
- ads/opctl/operator/lowcode/common/utils.py +384 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/MLoperator +13 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/README.md +30 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/__init__.py +5 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/__main__.py +116 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/cmd.py +85 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/const.py +15 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/environment.yaml +0 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/models/__init__.py +4 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/models/apigw_config.py +32 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/models/db_config.py +43 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/models/mysql_config.py +120 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/models/serializable_yaml_model.py +34 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/operator_utils.py +386 -0
- ads/opctl/operator/lowcode/feature_store_marketplace/schema.yaml +160 -0
- ads/opctl/operator/lowcode/forecast/MLoperator +25 -0
- ads/opctl/operator/lowcode/forecast/README.md +209 -0
- ads/opctl/operator/lowcode/forecast/__init__.py +5 -0
- ads/opctl/operator/lowcode/forecast/__main__.py +89 -0
- ads/opctl/operator/lowcode/forecast/cmd.py +40 -0
- ads/opctl/operator/lowcode/forecast/const.py +92 -0
- ads/opctl/operator/lowcode/forecast/environment.yaml +20 -0
- ads/opctl/operator/lowcode/forecast/errors.py +26 -0
- ads/opctl/operator/lowcode/forecast/model/__init__.py +5 -0
- ads/opctl/operator/lowcode/forecast/model/arima.py +279 -0
- ads/opctl/operator/lowcode/forecast/model/automlx.py +553 -0
- ads/opctl/operator/lowcode/forecast/model/autots.py +312 -0
- ads/opctl/operator/lowcode/forecast/model/base_model.py +875 -0
- ads/opctl/operator/lowcode/forecast/model/factory.py +106 -0
- ads/opctl/operator/lowcode/forecast/model/forecast_datasets.py +492 -0
- ads/opctl/operator/lowcode/forecast/model/ml_forecast.py +243 -0
- ads/opctl/operator/lowcode/forecast/model/neuralprophet.py +482 -0
- ads/opctl/operator/lowcode/forecast/model/prophet.py +450 -0
- ads/opctl/operator/lowcode/forecast/model_evaluator.py +244 -0
- ads/opctl/operator/lowcode/forecast/operator_config.py +234 -0
- ads/opctl/operator/lowcode/forecast/schema.yaml +506 -0
- ads/opctl/operator/lowcode/forecast/utils.py +397 -0
- ads/opctl/operator/lowcode/forecast/whatifserve/__init__.py +7 -0
- ads/opctl/operator/lowcode/forecast/whatifserve/deployment_manager.py +285 -0
- ads/opctl/operator/lowcode/forecast/whatifserve/score.py +246 -0
- ads/opctl/operator/lowcode/pii/MLoperator +17 -0
- ads/opctl/operator/lowcode/pii/README.md +208 -0
- ads/opctl/operator/lowcode/pii/__init__.py +5 -0
- ads/opctl/operator/lowcode/pii/__main__.py +78 -0
- ads/opctl/operator/lowcode/pii/cmd.py +39 -0
- ads/opctl/operator/lowcode/pii/constant.py +84 -0
- ads/opctl/operator/lowcode/pii/environment.yaml +17 -0
- ads/opctl/operator/lowcode/pii/errors.py +27 -0
- ads/opctl/operator/lowcode/pii/model/__init__.py +5 -0
- ads/opctl/operator/lowcode/pii/model/factory.py +82 -0
- ads/opctl/operator/lowcode/pii/model/guardrails.py +167 -0
- ads/opctl/operator/lowcode/pii/model/pii.py +145 -0
- ads/opctl/operator/lowcode/pii/model/processor/__init__.py +34 -0
- ads/opctl/operator/lowcode/pii/model/processor/email_replacer.py +34 -0
- ads/opctl/operator/lowcode/pii/model/processor/mbi_replacer.py +35 -0
- ads/opctl/operator/lowcode/pii/model/processor/name_replacer.py +225 -0
- ads/opctl/operator/lowcode/pii/model/processor/number_replacer.py +73 -0
- ads/opctl/operator/lowcode/pii/model/processor/remover.py +26 -0
- ads/opctl/operator/lowcode/pii/model/report.py +487 -0
- ads/opctl/operator/lowcode/pii/operator_config.py +95 -0
- ads/opctl/operator/lowcode/pii/schema.yaml +108 -0
- ads/opctl/operator/lowcode/pii/utils.py +43 -0
- ads/opctl/operator/lowcode/recommender/MLoperator +16 -0
- ads/opctl/operator/lowcode/recommender/README.md +206 -0
- ads/opctl/operator/lowcode/recommender/__init__.py +5 -0
- ads/opctl/operator/lowcode/recommender/__main__.py +82 -0
- ads/opctl/operator/lowcode/recommender/cmd.py +33 -0
- ads/opctl/operator/lowcode/recommender/constant.py +30 -0
- ads/opctl/operator/lowcode/recommender/environment.yaml +11 -0
- ads/opctl/operator/lowcode/recommender/model/base_model.py +212 -0
- ads/opctl/operator/lowcode/recommender/model/factory.py +56 -0
- ads/opctl/operator/lowcode/recommender/model/recommender_dataset.py +25 -0
- ads/opctl/operator/lowcode/recommender/model/svd.py +106 -0
- ads/opctl/operator/lowcode/recommender/operator_config.py +81 -0
- ads/opctl/operator/lowcode/recommender/schema.yaml +265 -0
- ads/opctl/operator/lowcode/recommender/utils.py +13 -0
- ads/opctl/operator/runtime/__init__.py +5 -0
- ads/opctl/operator/runtime/const.py +17 -0
- ads/opctl/operator/runtime/container_runtime_schema.yaml +50 -0
- ads/opctl/operator/runtime/marketplace_runtime.py +50 -0
- ads/opctl/operator/runtime/python_marketplace_runtime_schema.yaml +21 -0
- ads/opctl/operator/runtime/python_runtime_schema.yaml +21 -0
- ads/opctl/operator/runtime/runtime.py +115 -0
- ads/opctl/schema.yaml.yml +36 -0
- ads/opctl/script.py +40 -0
- ads/opctl/spark/__init__.py +5 -0
- ads/opctl/spark/cli.py +43 -0
- ads/opctl/spark/cmds.py +147 -0
- ads/opctl/templates/diagnostic_report_template.jinja2 +102 -0
- ads/opctl/utils.py +344 -0
- ads/oracledb/__init__.py +5 -0
- ads/oracledb/oracle_db.py +346 -0
- ads/pipeline/__init__.py +39 -0
- ads/pipeline/ads_pipeline.py +2279 -0
- ads/pipeline/ads_pipeline_run.py +772 -0
- ads/pipeline/ads_pipeline_step.py +605 -0
- ads/pipeline/builders/__init__.py +5 -0
- ads/pipeline/builders/infrastructure/__init__.py +5 -0
- ads/pipeline/builders/infrastructure/custom_script.py +32 -0
- ads/pipeline/cli.py +119 -0
- ads/pipeline/extension.py +291 -0
- ads/pipeline/schema/__init__.py +5 -0
- ads/pipeline/schema/cs_step_schema.json +35 -0
- ads/pipeline/schema/ml_step_schema.json +31 -0
- ads/pipeline/schema/pipeline_schema.json +71 -0
- ads/pipeline/visualizer/__init__.py +5 -0
- ads/pipeline/visualizer/base.py +570 -0
- ads/pipeline/visualizer/graph_renderer.py +272 -0
- ads/pipeline/visualizer/text_renderer.py +84 -0
- ads/secrets/__init__.py +11 -0
- ads/secrets/adb.py +386 -0
- ads/secrets/auth_token.py +86 -0
- ads/secrets/big_data_service.py +365 -0
- ads/secrets/mysqldb.py +149 -0
- ads/secrets/oracledb.py +160 -0
- ads/secrets/secrets.py +407 -0
- ads/telemetry/__init__.py +7 -0
- ads/telemetry/base.py +69 -0
- ads/telemetry/client.py +122 -0
- ads/telemetry/telemetry.py +257 -0
- ads/templates/dataflow_pyspark.jinja2 +13 -0
- ads/templates/dataflow_sparksql.jinja2 +22 -0
- ads/templates/func.jinja2 +20 -0
- ads/templates/schemas/openapi.json +1740 -0
- ads/templates/score-pkl.jinja2 +173 -0
- ads/templates/score.jinja2 +322 -0
- ads/templates/score_embedding_onnx.jinja2 +202 -0
- ads/templates/score_generic.jinja2 +165 -0
- ads/templates/score_huggingface_pipeline.jinja2 +217 -0
- ads/templates/score_lightgbm.jinja2 +185 -0
- ads/templates/score_onnx.jinja2 +407 -0
- ads/templates/score_onnx_new.jinja2 +473 -0
- ads/templates/score_oracle_automl.jinja2 +185 -0
- ads/templates/score_pyspark.jinja2 +154 -0
- ads/templates/score_pytorch.jinja2 +219 -0
- ads/templates/score_scikit-learn.jinja2 +184 -0
- ads/templates/score_tensorflow.jinja2 +184 -0
- ads/templates/score_xgboost.jinja2 +178 -0
- ads/text_dataset/__init__.py +5 -0
- ads/text_dataset/backends.py +211 -0
- ads/text_dataset/dataset.py +445 -0
- ads/text_dataset/extractor.py +207 -0
- ads/text_dataset/options.py +53 -0
- ads/text_dataset/udfs.py +22 -0
- ads/text_dataset/utils.py +49 -0
- ads/type_discovery/__init__.py +9 -0
- ads/type_discovery/abstract_detector.py +21 -0
- ads/type_discovery/constant_detector.py +41 -0
- ads/type_discovery/continuous_detector.py +54 -0
- ads/type_discovery/credit_card_detector.py +99 -0
- ads/type_discovery/datetime_detector.py +92 -0
- ads/type_discovery/discrete_detector.py +118 -0
- ads/type_discovery/document_detector.py +146 -0
- ads/type_discovery/ip_detector.py +68 -0
- ads/type_discovery/latlon_detector.py +90 -0
- ads/type_discovery/phone_number_detector.py +63 -0
- ads/type_discovery/type_discovery_driver.py +87 -0
- ads/type_discovery/typed_feature.py +594 -0
- ads/type_discovery/unknown_detector.py +41 -0
- ads/type_discovery/zipcode_detector.py +48 -0
- ads/vault/__init__.py +7 -0
- ads/vault/vault.py +237 -0
- {oracle_ads-2.13.9rc0.dist-info → oracle_ads-2.13.10rc0.dist-info}/METADATA +150 -149
- oracle_ads-2.13.10rc0.dist-info/RECORD +858 -0
- {oracle_ads-2.13.9rc0.dist-info → oracle_ads-2.13.10rc0.dist-info}/WHEEL +1 -2
- {oracle_ads-2.13.9rc0.dist-info → oracle_ads-2.13.10rc0.dist-info}/entry_points.txt +2 -1
- oracle_ads-2.13.9rc0.dist-info/RECORD +0 -9
- oracle_ads-2.13.9rc0.dist-info/top_level.txt +0 -1
- {oracle_ads-2.13.9rc0.dist-info → oracle_ads-2.13.10rc0.dist-info}/licenses/LICENSE.txt +0 -0
@@ -0,0 +1,1846 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8; -*-
|
3
|
+
|
4
|
+
# Copyright (c) 2021, 2023 Oracle and/or its affiliates.
|
5
|
+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
6
|
+
|
7
|
+
|
8
|
+
import collections
|
9
|
+
import copy
|
10
|
+
import datetime
|
11
|
+
import oci
|
12
|
+
import warnings
|
13
|
+
import time
|
14
|
+
from typing import Dict, List, Union, Any
|
15
|
+
|
16
|
+
import oci.loggingsearch
|
17
|
+
from ads.common import auth as authutil
|
18
|
+
import pandas as pd
|
19
|
+
from ads.model.serde.model_input import JsonModelInputSERDE
|
20
|
+
from ads.common.oci_logging import (
|
21
|
+
LOG_INTERVAL,
|
22
|
+
LOG_RECORDS_LIMIT,
|
23
|
+
ConsolidatedLog,
|
24
|
+
OCILog,
|
25
|
+
)
|
26
|
+
from ads.config import COMPARTMENT_OCID, PROJECT_OCID
|
27
|
+
from ads.jobs.builders.base import Builder
|
28
|
+
from ads.jobs.builders.infrastructure.utils import get_value
|
29
|
+
from ads.model.common.utils import _is_json_serializable
|
30
|
+
from ads.model.deployment.common.utils import send_request
|
31
|
+
from ads.model.deployment.model_deployment_infrastructure import (
|
32
|
+
DEFAULT_BANDWIDTH_MBPS,
|
33
|
+
DEFAULT_REPLICA,
|
34
|
+
DEFAULT_SHAPE_NAME,
|
35
|
+
DEFAULT_OCPUS,
|
36
|
+
DEFAULT_MEMORY_IN_GBS,
|
37
|
+
MODEL_DEPLOYMENT_INFRASTRUCTURE_TYPE,
|
38
|
+
ModelDeploymentInfrastructure,
|
39
|
+
)
|
40
|
+
from ads.model.deployment.model_deployment_runtime import (
|
41
|
+
ModelDeploymentCondaRuntime,
|
42
|
+
ModelDeploymentContainerRuntime,
|
43
|
+
ModelDeploymentMode,
|
44
|
+
ModelDeploymentRuntime,
|
45
|
+
ModelDeploymentRuntimeType,
|
46
|
+
OCIModelDeploymentRuntimeType,
|
47
|
+
)
|
48
|
+
from ads.model.service.oci_datascience_model_deployment import (
|
49
|
+
OCIDataScienceModelDeployment,
|
50
|
+
)
|
51
|
+
from ads.common import utils as ads_utils
|
52
|
+
from .common import utils
|
53
|
+
from .common.utils import State
|
54
|
+
from .model_deployment_properties import ModelDeploymentProperties
|
55
|
+
from oci.data_science.models import (
|
56
|
+
LogDetails,
|
57
|
+
CreateModelDeploymentDetails,
|
58
|
+
UpdateModelDeploymentDetails,
|
59
|
+
)
|
60
|
+
|
61
|
+
DEFAULT_WAIT_TIME = 1200
|
62
|
+
DEFAULT_POLL_INTERVAL = 10
|
63
|
+
DEFAULT_WORKFLOW_STEPS = 6
|
64
|
+
DELETE_WORKFLOW_STEPS = 2
|
65
|
+
DEACTIVATE_WORKFLOW_STEPS = 2
|
66
|
+
DEFAULT_RETRYING_REQUEST_ATTEMPTS = 3
|
67
|
+
|
68
|
+
MODEL_DEPLOYMENT_KIND = "deployment"
|
69
|
+
MODEL_DEPLOYMENT_TYPE = "modelDeployment"
|
70
|
+
MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON = "TRITON"
|
71
|
+
|
72
|
+
MODEL_DEPLOYMENT_RUNTIMES = {
|
73
|
+
ModelDeploymentRuntimeType.CONDA: ModelDeploymentCondaRuntime,
|
74
|
+
ModelDeploymentRuntimeType.CONTAINER: ModelDeploymentContainerRuntime,
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
class ModelDeploymentLogType:
|
79
|
+
PREDICT = "predict"
|
80
|
+
ACCESS = "access"
|
81
|
+
|
82
|
+
|
83
|
+
class LogNotConfiguredError(Exception): # pragma: no cover
|
84
|
+
pass
|
85
|
+
|
86
|
+
|
87
|
+
class ModelDeploymentPredictError(Exception): # pragma: no cover
|
88
|
+
pass
|
89
|
+
|
90
|
+
|
91
|
+
class ModelDeployment(Builder):
|
92
|
+
"""
|
93
|
+
A class used to represent a Model Deployment.
|
94
|
+
|
95
|
+
Attributes
|
96
|
+
----------
|
97
|
+
config: (dict)
|
98
|
+
Deployment configuration parameters
|
99
|
+
properties: (ModelDeploymentProperties)
|
100
|
+
ModelDeploymentProperties object
|
101
|
+
workflow_state_progress: (str)
|
102
|
+
Workflow request id
|
103
|
+
workflow_steps: (int)
|
104
|
+
The number of steps in the workflow
|
105
|
+
dsc_model_deployment: (OCIDataScienceModelDeployment)
|
106
|
+
The OCIDataScienceModelDeployment instance.
|
107
|
+
state: (State)
|
108
|
+
Returns the deployment state of the current Model Deployment object
|
109
|
+
created_by: (str)
|
110
|
+
The user that creates the model deployment
|
111
|
+
lifecycle_state: (str)
|
112
|
+
Model deployment lifecycle state
|
113
|
+
lifecycle_details: (str)
|
114
|
+
Model deployment lifecycle details
|
115
|
+
time_created: (datetime)
|
116
|
+
The time when the model deployment is created
|
117
|
+
display_name: (str)
|
118
|
+
Model deployment display name
|
119
|
+
description: (str)
|
120
|
+
Model deployment description
|
121
|
+
freeform_tags: (dict)
|
122
|
+
Model deployment freeform tags
|
123
|
+
defined_tags: (dict)
|
124
|
+
Model deployment defined tags
|
125
|
+
runtime: (ModelDeploymentRuntime)
|
126
|
+
Model deployment runtime
|
127
|
+
infrastructure: (ModelDeploymentInfrastructure)
|
128
|
+
Model deployment infrastructure
|
129
|
+
|
130
|
+
|
131
|
+
Methods
|
132
|
+
-------
|
133
|
+
deploy(wait_for_completion, **kwargs)
|
134
|
+
Deploy the current Model Deployment object
|
135
|
+
delete(wait_for_completion, **kwargs)
|
136
|
+
Deletes the current Model Deployment object
|
137
|
+
update(wait_for_completion, **kwargs)
|
138
|
+
Updates a model deployment
|
139
|
+
activate(wait_for_completion, max_wait_time, poll_interval)
|
140
|
+
Activates a model deployment
|
141
|
+
deactivate(wait_for_completion, max_wait_time, poll_interval)
|
142
|
+
Deactivates a model deployment
|
143
|
+
list(status, compartment_id, project_id, **kwargs)
|
144
|
+
List model deployment within given compartment and project.
|
145
|
+
with_display_name(display_name)
|
146
|
+
Sets model deployment display name
|
147
|
+
with_description(description)
|
148
|
+
Sets model deployment description
|
149
|
+
with_freeform_tags(freeform_tags)
|
150
|
+
Sets model deployment freeform tags
|
151
|
+
with_defined_tags(defined_tags)
|
152
|
+
Sets model deployment defined tags
|
153
|
+
with_runtime(self, runtime)
|
154
|
+
Sets model deployment runtime
|
155
|
+
with_infrastructure(self, infrastructure)
|
156
|
+
Sets model deployment infrastructure
|
157
|
+
from_dict(obj_dict)
|
158
|
+
Deserializes model deployment instance from dict
|
159
|
+
from_id(id)
|
160
|
+
Loads model deployment instance from ocid
|
161
|
+
sync()
|
162
|
+
Updates the model deployment instance from backend
|
163
|
+
|
164
|
+
|
165
|
+
Examples
|
166
|
+
--------
|
167
|
+
>>> # Build model deployment from builder apis:
|
168
|
+
>>> ds_model_deployment = (ModelDeployment()
|
169
|
+
... .with_display_name("TestModelDeployment")
|
170
|
+
... .with_description("Testing the test model deployment")
|
171
|
+
... .with_freeform_tags(tag1="val1", tag2="val2")
|
172
|
+
... .with_infrastructure(
|
173
|
+
... (ModelDeploymentInfrastructure()
|
174
|
+
... .with_project_id(<project_id>)
|
175
|
+
... .with_compartment_id(<compartment_id>)
|
176
|
+
... .with_shape_name("VM.Standard.E4.Flex")
|
177
|
+
... .with_shape_config_details(
|
178
|
+
... ocpus=1,
|
179
|
+
... memory_in_gbs=16
|
180
|
+
... )
|
181
|
+
... .with_replica(1)
|
182
|
+
... .with_bandwidth_mbps(10)
|
183
|
+
... .with_web_concurrency(10)
|
184
|
+
... .with_access_log(
|
185
|
+
... log_group_id=<log_group_id>,
|
186
|
+
... log_id=<log_id>
|
187
|
+
... )
|
188
|
+
... .with_predict_log(
|
189
|
+
... log_group_id=<log_group_id>,
|
190
|
+
... log_id=<log_id>
|
191
|
+
... ))
|
192
|
+
... )
|
193
|
+
... .with_runtime(
|
194
|
+
... (ModelDeploymentContainerRuntime()
|
195
|
+
... .with_image(<image>)
|
196
|
+
... .with_image_digest(<image_digest>)
|
197
|
+
... .with_entrypoint(<entrypoint>)
|
198
|
+
... .with_server_port(<server_port>)
|
199
|
+
... .with_health_check_port(<health_check_port>)
|
200
|
+
... .with_env({"key":"value"})
|
201
|
+
... .with_deployment_mode("HTTPS_ONLY")
|
202
|
+
... .with_model_uri(<model_uri>)
|
203
|
+
... .with_bucket_uri(<bucket_uri>)
|
204
|
+
... .with_auth(<auth>)
|
205
|
+
... .with_timeout(<time_out>))
|
206
|
+
... )
|
207
|
+
... )
|
208
|
+
>>> ds_model_deployment.deploy()
|
209
|
+
>>> ds_model_deployment.status
|
210
|
+
>>> ds_model_deployment.with_display_name("new name").update()
|
211
|
+
>>> ds_model_deployment.deactivate()
|
212
|
+
>>> ds_model_deployment.sync()
|
213
|
+
>>> ds_model_deployment.list(status="ACTIVE")
|
214
|
+
>>> ds_model_deployment.delete()
|
215
|
+
|
216
|
+
>>> # Build model deployment from yaml
|
217
|
+
>>> ds_model_deployment = ModelDeployment.from_yaml(uri=<path_to_yaml>)
|
218
|
+
"""
|
219
|
+
|
220
|
+
_PREFIX = "datascience_model_deployment"
|
221
|
+
|
222
|
+
CONST_ID = "id"
|
223
|
+
CONST_CREATED_BY = "createdBy"
|
224
|
+
CONST_DISPLAY_NAME = "displayName"
|
225
|
+
CONST_DESCRIPTION = "description"
|
226
|
+
CONST_FREEFORM_TAG = "freeformTags"
|
227
|
+
CONST_DEFINED_TAG = "definedTags"
|
228
|
+
CONST_MODEL_DEPLOYMENT_URL = "modelDeploymentUrl"
|
229
|
+
CONST_INFRASTRUCTURE = "infrastructure"
|
230
|
+
CONST_RUNTIME = "runtime"
|
231
|
+
CONST_LIFECYCLE_STATE = "lifecycleState"
|
232
|
+
CONST_LIFECYCLE_DETAILS = "lifecycleDetails"
|
233
|
+
CONST_TIME_CREATED = "timeCreated"
|
234
|
+
|
235
|
+
attribute_map = {
|
236
|
+
CONST_ID: "id",
|
237
|
+
CONST_CREATED_BY: "created_by",
|
238
|
+
CONST_DISPLAY_NAME: "display_name",
|
239
|
+
CONST_DESCRIPTION: "description",
|
240
|
+
CONST_FREEFORM_TAG: "freeform_tags",
|
241
|
+
CONST_DEFINED_TAG: "defined_tags",
|
242
|
+
CONST_MODEL_DEPLOYMENT_URL: "model_deployment_url",
|
243
|
+
CONST_INFRASTRUCTURE: "infrastructure",
|
244
|
+
CONST_RUNTIME: "runtime",
|
245
|
+
CONST_LIFECYCLE_STATE: "lifecycle_state",
|
246
|
+
CONST_LIFECYCLE_DETAILS: "lifecycle_details",
|
247
|
+
CONST_TIME_CREATED: "time_created",
|
248
|
+
}
|
249
|
+
|
250
|
+
initialize_spec_attributes = [
|
251
|
+
"display_name",
|
252
|
+
"description",
|
253
|
+
"freeform_tags",
|
254
|
+
"defined_tags",
|
255
|
+
"infrastructure",
|
256
|
+
"runtime",
|
257
|
+
]
|
258
|
+
model_input_serializer = JsonModelInputSERDE()
|
259
|
+
|
260
|
+
def __init__(
|
261
|
+
self,
|
262
|
+
properties: Union[ModelDeploymentProperties, Dict] = None,
|
263
|
+
config: Dict = None,
|
264
|
+
model_deployment_id: str = None,
|
265
|
+
model_deployment_url: str = "",
|
266
|
+
spec: Dict = None,
|
267
|
+
**kwargs,
|
268
|
+
):
|
269
|
+
"""Initializes a ModelDeployment object.
|
270
|
+
|
271
|
+
Parameters
|
272
|
+
----------
|
273
|
+
properties: (Union[ModelDeploymentProperties, Dict], optional). Defaults to None.
|
274
|
+
Object containing deployment properties.
|
275
|
+
The properties can be `None` when `kwargs` are used for specifying properties.
|
276
|
+
config: (Dict, optional). Defaults to None.
|
277
|
+
ADS auth dictionary for OCI authentication.
|
278
|
+
This can be generated by calling `ads.common.auth.api_keys()` or `ads.common.auth.resource_principal()`.
|
279
|
+
If this is `None` then the `ads.common.default_signer(client_kwargs)` will be used.
|
280
|
+
model_deployment_id: (str, optional). Defaults to None.
|
281
|
+
Model deployment OCID.
|
282
|
+
model_deployment_url: (str, optional). Defaults to empty string.
|
283
|
+
Model deployment url.
|
284
|
+
spec: (dict, optional). Defaults to None.
|
285
|
+
Model deployment spec.
|
286
|
+
kwargs:
|
287
|
+
Keyword arguments for initializing `ModelDeploymentProperties` or `ModelDeployment`.
|
288
|
+
"""
|
289
|
+
|
290
|
+
if spec and properties:
|
291
|
+
raise ValueError(
|
292
|
+
"You can only pass in either `spec` or `properties` to initialize model deployment instance."
|
293
|
+
)
|
294
|
+
|
295
|
+
if config:
|
296
|
+
warnings.warn(
|
297
|
+
"Parameter `config` was deprecated in 2.8.2 from ModelDeployment constructor and will be removed in 3.0.0. Please use `ads.set_auth()` to config the auth information. "
|
298
|
+
"Check: https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/authentication.html"
|
299
|
+
)
|
300
|
+
|
301
|
+
if properties:
|
302
|
+
warnings.warn(
|
303
|
+
"Parameter `properties` was deprecated in 2.8.2 from ModelDeployment constructor and will be removed in 3.0.0. Please use `spec` or the builder pattern to initialize model deployment instance. "
|
304
|
+
"Check: https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_registration/quick_start.html"
|
305
|
+
)
|
306
|
+
|
307
|
+
if model_deployment_url or model_deployment_id:
|
308
|
+
warnings.warn(
|
309
|
+
"Parameter `model_deployment_url` and `model_deployment_id` were deprecated in 2.8.2 from ModelDeployment constructor and will be removed in 3.0.0. These two fields will be auto-populated from the service side. "
|
310
|
+
"Check: https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_registration/quick_start.html"
|
311
|
+
)
|
312
|
+
|
313
|
+
initialize_spec = {}
|
314
|
+
initialize_spec_kwargs = {}
|
315
|
+
if spec:
|
316
|
+
initialize_spec = spec
|
317
|
+
initialize_spec_kwargs = self._extract_spec_kwargs(**kwargs)
|
318
|
+
elif not properties and not spec:
|
319
|
+
if self.CONST_INFRASTRUCTURE in kwargs or self.CONST_RUNTIME in kwargs:
|
320
|
+
initialize_spec_kwargs = self._extract_spec_kwargs(**kwargs)
|
321
|
+
|
322
|
+
super().__init__(spec=initialize_spec, **initialize_spec_kwargs)
|
323
|
+
|
324
|
+
self.properties = (
|
325
|
+
properties
|
326
|
+
if isinstance(properties, ModelDeploymentProperties)
|
327
|
+
else ModelDeploymentProperties(oci_model_deployment=properties, **kwargs)
|
328
|
+
)
|
329
|
+
|
330
|
+
self.current_state = (
|
331
|
+
State._from_str(self.properties.lifecycle_state)
|
332
|
+
if self.properties.lifecycle_state
|
333
|
+
else State.UNKNOWN
|
334
|
+
)
|
335
|
+
|
336
|
+
self._access_log = None
|
337
|
+
self._predict_log = None
|
338
|
+
self.dsc_model_deployment = OCIDataScienceModelDeployment()
|
339
|
+
|
340
|
+
@property
|
341
|
+
def kind(self) -> str:
|
342
|
+
"""The kind of the object as showing in YAML.
|
343
|
+
|
344
|
+
Returns
|
345
|
+
-------
|
346
|
+
str
|
347
|
+
deployment
|
348
|
+
"""
|
349
|
+
return MODEL_DEPLOYMENT_KIND
|
350
|
+
|
351
|
+
@property
|
352
|
+
def type(self) -> str:
|
353
|
+
"""The type of the object as showing in YAML.
|
354
|
+
|
355
|
+
Returns
|
356
|
+
-------
|
357
|
+
str
|
358
|
+
deployment
|
359
|
+
"""
|
360
|
+
return MODEL_DEPLOYMENT_TYPE
|
361
|
+
|
362
|
+
@property
|
363
|
+
def model_deployment_id(self) -> str:
|
364
|
+
"""The model deployment ocid.
|
365
|
+
|
366
|
+
Returns
|
367
|
+
-------
|
368
|
+
str
|
369
|
+
The model deployment ocid.
|
370
|
+
"""
|
371
|
+
return self.get_spec(self.CONST_ID, None)
|
372
|
+
|
373
|
+
@property
|
374
|
+
def id(self) -> str:
|
375
|
+
"""The model deployment ocid.
|
376
|
+
|
377
|
+
Returns
|
378
|
+
-------
|
379
|
+
str
|
380
|
+
The model deployment ocid.
|
381
|
+
"""
|
382
|
+
return self.get_spec(self.CONST_ID, None)
|
383
|
+
|
384
|
+
@property
|
385
|
+
def created_by(self) -> str:
|
386
|
+
"""The user that creates the model deployment.
|
387
|
+
|
388
|
+
Returns
|
389
|
+
-------
|
390
|
+
str
|
391
|
+
The user that creates the model deployment.
|
392
|
+
"""
|
393
|
+
return self.get_spec(self.CONST_CREATED_BY, None)
|
394
|
+
|
395
|
+
@property
|
396
|
+
def url(self) -> str:
|
397
|
+
"""Model deployment url.
|
398
|
+
|
399
|
+
Returns
|
400
|
+
-------
|
401
|
+
str
|
402
|
+
Model deployment url.
|
403
|
+
"""
|
404
|
+
return self.get_spec(self.CONST_MODEL_DEPLOYMENT_URL, None)
|
405
|
+
|
406
|
+
@property
|
407
|
+
def lifecycle_state(self) -> str:
|
408
|
+
"""Model deployment lifecycle state.
|
409
|
+
|
410
|
+
Returns
|
411
|
+
-------
|
412
|
+
str
|
413
|
+
Model deployment lifecycle state.
|
414
|
+
"""
|
415
|
+
return self.get_spec(self.CONST_LIFECYCLE_STATE, None)
|
416
|
+
|
417
|
+
@property
|
418
|
+
def lifecycle_details(self) -> str:
|
419
|
+
"""Model deployment lifecycle details.
|
420
|
+
|
421
|
+
Returns
|
422
|
+
-------
|
423
|
+
str
|
424
|
+
Model deployment lifecycle details.
|
425
|
+
"""
|
426
|
+
return self.get_spec(self.CONST_LIFECYCLE_DETAILS, None)
|
427
|
+
|
428
|
+
@property
|
429
|
+
def time_created(self) -> datetime:
|
430
|
+
"""The time when the model deployment is created.
|
431
|
+
|
432
|
+
Returns
|
433
|
+
-------
|
434
|
+
datetime
|
435
|
+
The time when the model deployment is created.
|
436
|
+
"""
|
437
|
+
return self.get_spec(self.CONST_TIME_CREATED, None)
|
438
|
+
|
439
|
+
@property
|
440
|
+
def display_name(self) -> str:
|
441
|
+
"""Model deployment display name.
|
442
|
+
|
443
|
+
Returns
|
444
|
+
-------
|
445
|
+
str
|
446
|
+
Model deployment display name.
|
447
|
+
"""
|
448
|
+
return self.get_spec(self.CONST_DISPLAY_NAME, None)
|
449
|
+
|
450
|
+
def with_display_name(self, display_name: str) -> "ModelDeployment":
|
451
|
+
"""Sets the name of model deployment.
|
452
|
+
|
453
|
+
Parameters
|
454
|
+
----------
|
455
|
+
display_name: str
|
456
|
+
The name of model deployment.
|
457
|
+
|
458
|
+
Returns
|
459
|
+
-------
|
460
|
+
ModelDeployment
|
461
|
+
The ModelDeployment instance (self).
|
462
|
+
"""
|
463
|
+
return self.set_spec(self.CONST_DISPLAY_NAME, display_name)
|
464
|
+
|
465
|
+
@property
|
466
|
+
def description(self) -> str:
|
467
|
+
"""Model deployment description.
|
468
|
+
|
469
|
+
Returns
|
470
|
+
-------
|
471
|
+
str
|
472
|
+
Model deployment description.
|
473
|
+
"""
|
474
|
+
return self.get_spec(self.CONST_DESCRIPTION, None)
|
475
|
+
|
476
|
+
def with_description(self, description: str) -> "ModelDeployment":
|
477
|
+
"""Sets the description of model deployment.
|
478
|
+
|
479
|
+
Parameters
|
480
|
+
----------
|
481
|
+
description: str
|
482
|
+
The description of model deployment.
|
483
|
+
|
484
|
+
Returns
|
485
|
+
-------
|
486
|
+
ModelDeployment
|
487
|
+
The ModelDeployment instance (self).
|
488
|
+
"""
|
489
|
+
return self.set_spec(self.CONST_DESCRIPTION, description)
|
490
|
+
|
491
|
+
@property
|
492
|
+
def freeform_tags(self) -> Dict:
|
493
|
+
"""Model deployment freeform tags.
|
494
|
+
|
495
|
+
Returns
|
496
|
+
-------
|
497
|
+
Dict
|
498
|
+
Model deployment freeform tags.
|
499
|
+
"""
|
500
|
+
return self.get_spec(self.CONST_FREEFORM_TAG, {})
|
501
|
+
|
502
|
+
def with_freeform_tags(self, **kwargs) -> "ModelDeployment":
|
503
|
+
"""Sets the freeform tags of model deployment.
|
504
|
+
|
505
|
+
Parameters
|
506
|
+
----------
|
507
|
+
kwargs
|
508
|
+
The freeform tags of model deployment.
|
509
|
+
|
510
|
+
Returns
|
511
|
+
-------
|
512
|
+
ModelDeployment
|
513
|
+
The ModelDeployment instance (self).
|
514
|
+
"""
|
515
|
+
return self.set_spec(self.CONST_FREEFORM_TAG, kwargs)
|
516
|
+
|
517
|
+
@property
|
518
|
+
def defined_tags(self) -> Dict:
|
519
|
+
"""Model deployment defined tags.
|
520
|
+
|
521
|
+
Returns
|
522
|
+
-------
|
523
|
+
Dict
|
524
|
+
Model deployment defined tags.
|
525
|
+
"""
|
526
|
+
return self.get_spec(self.CONST_DEFINED_TAG, {})
|
527
|
+
|
528
|
+
def with_defined_tags(self, **kwargs) -> "ModelDeployment":
|
529
|
+
"""Sets the defined tags of model deployment.
|
530
|
+
|
531
|
+
Parameters
|
532
|
+
----------
|
533
|
+
kwargs
|
534
|
+
The defined tags of model deployment.
|
535
|
+
|
536
|
+
Returns
|
537
|
+
-------
|
538
|
+
ModelDeployment
|
539
|
+
The ModelDeployment instance (self).
|
540
|
+
"""
|
541
|
+
return self.set_spec(self.CONST_DEFINED_TAG, kwargs)
|
542
|
+
|
543
|
+
@property
|
544
|
+
def runtime(self) -> "ModelDeploymentRuntime":
|
545
|
+
"""Model deployment runtime.
|
546
|
+
|
547
|
+
Returns
|
548
|
+
-------
|
549
|
+
ModelDeploymentRuntime
|
550
|
+
Model deployment runtime.
|
551
|
+
"""
|
552
|
+
return self.get_spec(self.CONST_RUNTIME, None)
|
553
|
+
|
554
|
+
def with_runtime(self, runtime: ModelDeploymentRuntime) -> "ModelDeployment":
|
555
|
+
"""Sets the runtime of model deployment.
|
556
|
+
|
557
|
+
Parameters
|
558
|
+
----------
|
559
|
+
runtime: ModelDeploymentRuntime
|
560
|
+
The runtime of model deployment.
|
561
|
+
|
562
|
+
Returns
|
563
|
+
-------
|
564
|
+
ModelDeployment
|
565
|
+
The ModelDeployment instance (self).
|
566
|
+
"""
|
567
|
+
return self.set_spec(self.CONST_RUNTIME, runtime)
|
568
|
+
|
569
|
+
@property
|
570
|
+
def infrastructure(self) -> "ModelDeploymentInfrastructure":
|
571
|
+
"""Model deployment infrastructure.
|
572
|
+
|
573
|
+
Returns
|
574
|
+
-------
|
575
|
+
ModelDeploymentInfrastructure
|
576
|
+
Model deployment infrastructure.
|
577
|
+
"""
|
578
|
+
return self.get_spec(self.CONST_INFRASTRUCTURE, None)
|
579
|
+
|
580
|
+
def with_infrastructure(
|
581
|
+
self, infrastructure: ModelDeploymentInfrastructure
|
582
|
+
) -> "ModelDeployment":
|
583
|
+
"""Sets the infrastructure of model deployment.
|
584
|
+
|
585
|
+
Parameters
|
586
|
+
----------
|
587
|
+
infrastructure: ModelDeploymentInfrastructure
|
588
|
+
The infrastructure of model deployment.
|
589
|
+
|
590
|
+
Returns
|
591
|
+
-------
|
592
|
+
ModelDeployment
|
593
|
+
The ModelDeployment instance (self).
|
594
|
+
"""
|
595
|
+
return self.set_spec(self.CONST_INFRASTRUCTURE, infrastructure)
|
596
|
+
|
597
|
+
def deploy(
|
598
|
+
self,
|
599
|
+
wait_for_completion: bool = True,
|
600
|
+
max_wait_time: int = DEFAULT_WAIT_TIME,
|
601
|
+
poll_interval: int = DEFAULT_POLL_INTERVAL,
|
602
|
+
):
|
603
|
+
"""Deploys the current ModelDeployment object
|
604
|
+
|
605
|
+
Parameters
|
606
|
+
----------
|
607
|
+
wait_for_completion: bool
|
608
|
+
Flag set for whether to wait for deployment to be deployed before proceeding.
|
609
|
+
Defaults to True.
|
610
|
+
max_wait_time: int
|
611
|
+
Maximum amount of time to wait in seconds (Defaults to 1200).
|
612
|
+
Negative implies infinite wait time.
|
613
|
+
poll_interval: int
|
614
|
+
Poll interval in seconds (Defaults to 10).
|
615
|
+
|
616
|
+
Returns
|
617
|
+
-------
|
618
|
+
ModelDeployment
|
619
|
+
The instance of ModelDeployment.
|
620
|
+
"""
|
621
|
+
create_model_deployment_details = (
|
622
|
+
self._build_model_deployment_details()
|
623
|
+
if self._spec
|
624
|
+
else self.properties.build()
|
625
|
+
)
|
626
|
+
|
627
|
+
response = self.dsc_model_deployment.create(
|
628
|
+
create_model_deployment_details=create_model_deployment_details,
|
629
|
+
wait_for_completion=wait_for_completion,
|
630
|
+
max_wait_time=max_wait_time,
|
631
|
+
poll_interval=poll_interval,
|
632
|
+
)
|
633
|
+
|
634
|
+
return self._update_from_oci_model(response)
|
635
|
+
|
636
|
+
def delete(
|
637
|
+
self,
|
638
|
+
wait_for_completion: bool = True,
|
639
|
+
max_wait_time: int = DEFAULT_WAIT_TIME,
|
640
|
+
poll_interval: int = DEFAULT_POLL_INTERVAL,
|
641
|
+
):
|
642
|
+
"""Deletes the ModelDeployment
|
643
|
+
|
644
|
+
Parameters
|
645
|
+
----------
|
646
|
+
wait_for_completion: bool
|
647
|
+
Flag set for whether to wait for deployment to be deleted before proceeding.
|
648
|
+
Defaults to True.
|
649
|
+
max_wait_time: int
|
650
|
+
Maximum amount of time to wait in seconds (Defaults to 1200).
|
651
|
+
Negative implies infinite wait time.
|
652
|
+
poll_interval: int
|
653
|
+
Poll interval in seconds (Defaults to 10).
|
654
|
+
|
655
|
+
Returns
|
656
|
+
-------
|
657
|
+
ModelDeployment
|
658
|
+
The instance of ModelDeployment.
|
659
|
+
"""
|
660
|
+
response = self.dsc_model_deployment.delete(
|
661
|
+
wait_for_completion=wait_for_completion,
|
662
|
+
max_wait_time=max_wait_time,
|
663
|
+
poll_interval=poll_interval,
|
664
|
+
)
|
665
|
+
|
666
|
+
return self._update_from_oci_model(response)
|
667
|
+
|
668
|
+
def update(
|
669
|
+
self,
|
670
|
+
properties: Union[ModelDeploymentProperties, dict, None] = None,
|
671
|
+
wait_for_completion: bool = True,
|
672
|
+
max_wait_time: int = DEFAULT_WAIT_TIME,
|
673
|
+
poll_interval: int = DEFAULT_POLL_INTERVAL,
|
674
|
+
**kwargs,
|
675
|
+
):
|
676
|
+
"""Updates a model deployment
|
677
|
+
|
678
|
+
You can update `model_deployment_configuration_details` and change `instance_shape` and `model_id`
|
679
|
+
when the model deployment is in the ACTIVE lifecycle state.
|
680
|
+
The `bandwidth_mbps` or `instance_count` can only be updated while the model deployment is in the `INACTIVE` state.
|
681
|
+
Changes to the `bandwidth_mbps` or `instance_count` will take effect the next time
|
682
|
+
the `ActivateModelDeployment` action is invoked on the model deployment resource.
|
683
|
+
|
684
|
+
Parameters
|
685
|
+
----------
|
686
|
+
properties: ModelDeploymentProperties or dict
|
687
|
+
The properties for updating the deployment.
|
688
|
+
wait_for_completion: bool
|
689
|
+
Flag set for whether to wait for deployment to be updated before proceeding.
|
690
|
+
Defaults to True.
|
691
|
+
max_wait_time: int
|
692
|
+
Maximum amount of time to wait in seconds (Defaults to 1200).
|
693
|
+
Negative implies infinite wait time.
|
694
|
+
poll_interval: int
|
695
|
+
Poll interval in seconds (Defaults to 10).
|
696
|
+
kwargs:
|
697
|
+
dict
|
698
|
+
|
699
|
+
Returns
|
700
|
+
-------
|
701
|
+
ModelDeployment
|
702
|
+
The instance of ModelDeployment.
|
703
|
+
"""
|
704
|
+
if properties:
|
705
|
+
warnings.warn(
|
706
|
+
"Parameter `properties` is deprecated from ModelDeployment `update()` in 2.8.6 and will be removed in 3.0.0. Please use the builder pattern or kwargs to update model deployment instance. "
|
707
|
+
"Check: https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_registration/quick_start.html"
|
708
|
+
)
|
709
|
+
|
710
|
+
updated_properties = properties
|
711
|
+
if not isinstance(properties, ModelDeploymentProperties):
|
712
|
+
updated_properties = ModelDeploymentProperties(
|
713
|
+
oci_model_deployment=properties, **kwargs
|
714
|
+
)
|
715
|
+
|
716
|
+
update_model_deployment_details = (
|
717
|
+
updated_properties.to_update_deployment()
|
718
|
+
if properties or updated_properties.oci_model_deployment or kwargs
|
719
|
+
else self._update_model_deployment_details(**kwargs)
|
720
|
+
)
|
721
|
+
|
722
|
+
response = self.dsc_model_deployment.update(
|
723
|
+
update_model_deployment_details=update_model_deployment_details,
|
724
|
+
wait_for_completion=wait_for_completion,
|
725
|
+
max_wait_time=max_wait_time,
|
726
|
+
poll_interval=poll_interval,
|
727
|
+
)
|
728
|
+
|
729
|
+
return self._update_from_oci_model(response)
|
730
|
+
|
731
|
+
def watch(
|
732
|
+
self,
|
733
|
+
log_type: str = None,
|
734
|
+
time_start: datetime = None,
|
735
|
+
interval: int = LOG_INTERVAL,
|
736
|
+
log_filter: str = None,
|
737
|
+
) -> "ModelDeployment":
|
738
|
+
"""Streams the access and/or predict logs of model deployment.
|
739
|
+
|
740
|
+
Parameters
|
741
|
+
----------
|
742
|
+
log_type: str, optional
|
743
|
+
The log type. Can be `access`, `predict` or None.
|
744
|
+
Defaults to None.
|
745
|
+
time_start : datetime.datetime, optional
|
746
|
+
Starting time for the log query.
|
747
|
+
Defaults to None.
|
748
|
+
interval : int, optional
|
749
|
+
The time interval between sending each request to pull logs from OCI logging service.
|
750
|
+
Defaults to 3.
|
751
|
+
log_filter : str, optional
|
752
|
+
Expression for filtering the logs. This will be the WHERE clause of the query.
|
753
|
+
Defaults to None.
|
754
|
+
|
755
|
+
Returns
|
756
|
+
-------
|
757
|
+
ModelDeployment
|
758
|
+
The instance of ModelDeployment.
|
759
|
+
"""
|
760
|
+
status = ""
|
761
|
+
while not self._stop_condition():
|
762
|
+
status = self._check_and_print_status(status)
|
763
|
+
time.sleep(interval)
|
764
|
+
|
765
|
+
time_start = time_start or self.time_created
|
766
|
+
try:
|
767
|
+
count = self.logs(log_type).stream(
|
768
|
+
source=self.model_deployment_id,
|
769
|
+
interval=interval,
|
770
|
+
stop_condition=self._stream_stop_condition,
|
771
|
+
time_start=time_start,
|
772
|
+
log_filter=log_filter,
|
773
|
+
)
|
774
|
+
|
775
|
+
if not count:
|
776
|
+
print(
|
777
|
+
"No logs in the last 14 days. Please reset time_start to see older logs."
|
778
|
+
)
|
779
|
+
return self.sync()
|
780
|
+
except KeyboardInterrupt:
|
781
|
+
print("Stop watching logs.")
|
782
|
+
pass
|
783
|
+
|
784
|
+
def _stop_condition(self):
|
785
|
+
"""Stops the sync once the model deployment is in a terminal state."""
|
786
|
+
return self.state in [State.ACTIVE, State.FAILED, State.DELETED, State.INACTIVE]
|
787
|
+
|
788
|
+
def _stream_stop_condition(self):
|
789
|
+
"""Stops the stream sync once the model deployment is in a terminal state."""
|
790
|
+
return self.state in [State.FAILED, State.DELETED, State.INACTIVE]
|
791
|
+
|
792
|
+
def _check_and_print_status(self, prev_status) -> str:
|
793
|
+
"""Check and print the next status.
|
794
|
+
|
795
|
+
Parameters
|
796
|
+
----------
|
797
|
+
prev_status: str
|
798
|
+
The previous model deployment status.
|
799
|
+
|
800
|
+
Returns
|
801
|
+
-------
|
802
|
+
str:
|
803
|
+
The next model deployment status.
|
804
|
+
"""
|
805
|
+
status = self._model_deployment_status_text()
|
806
|
+
if status != prev_status:
|
807
|
+
timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
808
|
+
print(f"{timestamp} - {status}")
|
809
|
+
return status
|
810
|
+
|
811
|
+
def _model_deployment_status_text(self) -> str:
|
812
|
+
"""Formats the status message.
|
813
|
+
|
814
|
+
Returns
|
815
|
+
-------
|
816
|
+
str:
|
817
|
+
The model deployment life status and life cycle details.
|
818
|
+
"""
|
819
|
+
details = f", {self.lifecycle_details}" if self.lifecycle_details else ""
|
820
|
+
return f"Model Deployment {self.lifecycle_state}" + details
|
821
|
+
|
822
|
+
@property
|
823
|
+
def state(self) -> State:
|
824
|
+
"""Returns the deployment state of the current Model Deployment object"""
|
825
|
+
request_attempts = 0
|
826
|
+
while request_attempts < DEFAULT_RETRYING_REQUEST_ATTEMPTS:
|
827
|
+
request_attempts += 1
|
828
|
+
try:
|
829
|
+
self.current_state = State._from_str(self.sync().lifecycle_state)
|
830
|
+
break
|
831
|
+
except:
|
832
|
+
pass
|
833
|
+
time.sleep(1)
|
834
|
+
|
835
|
+
return self.current_state
|
836
|
+
|
837
|
+
@property
|
838
|
+
def status(self) -> State:
|
839
|
+
"""Returns the deployment state of the current Model Deployment object"""
|
840
|
+
return self.state
|
841
|
+
|
842
|
+
def predict(
|
843
|
+
self,
|
844
|
+
json_input=None,
|
845
|
+
data: Any = None,
|
846
|
+
serializer: "ads.model.ModelInputSerializer" = model_input_serializer,
|
847
|
+
auto_serialize_data: bool = False,
|
848
|
+
model_name: str = None,
|
849
|
+
model_version: str = None,
|
850
|
+
**kwargs,
|
851
|
+
) -> dict:
|
852
|
+
"""Returns prediction of input data run against the model deployment endpoint.
|
853
|
+
|
854
|
+
Examples
|
855
|
+
--------
|
856
|
+
>>> import numpy as np
|
857
|
+
>>> from ads.model import ModelInputSerializer
|
858
|
+
>>> class MySerializer(ModelInputSerializer):
|
859
|
+
... def serialize(self, data):
|
860
|
+
... serialized_data = 1
|
861
|
+
... return serialized_data
|
862
|
+
>>> model_deployment = ModelDeployment.from_id(<model_deployment_id>)
|
863
|
+
>>> prediction = model_deployment.predict(
|
864
|
+
... data=np.array([1, 2, 3]),
|
865
|
+
... serializer=MySerializer(),
|
866
|
+
... auto_serialize_data=True,
|
867
|
+
... )['prediction']
|
868
|
+
|
869
|
+
Parameters
|
870
|
+
----------
|
871
|
+
json_input: Json serializable
|
872
|
+
JSON payload for the prediction.
|
873
|
+
data: Any
|
874
|
+
Data for the prediction.
|
875
|
+
serializer: ads.model.ModelInputSerializer
|
876
|
+
Defaults to ads.model.JsonModelInputSerializer.
|
877
|
+
auto_serialize_data: bool
|
878
|
+
Defaults to False. Indicate whether to auto serialize input data using `serializer`.
|
879
|
+
If `auto_serialize_data=False`, `data` required to be bytes or json serializable
|
880
|
+
and `json_input` required to be json serializable. If `auto_serialize_data` set
|
881
|
+
to True, data will be serialized before sending to model deployment endpoint.
|
882
|
+
model_name: str
|
883
|
+
Defaults to None. When the `inference_server="triton"`, the name of the model to invoke.
|
884
|
+
model_version: str
|
885
|
+
Defaults to None. When the `inference_server="triton"`, the version of the model to invoke.
|
886
|
+
kwargs:
|
887
|
+
content_type: str
|
888
|
+
Used to indicate the media type of the resource.
|
889
|
+
By default, it will be `application/octet-stream` for bytes input and `application/json` otherwise.
|
890
|
+
The content-type header will be set to this value when calling the model deployment endpoint.
|
891
|
+
|
892
|
+
Returns
|
893
|
+
-------
|
894
|
+
dict:
|
895
|
+
Prediction results.
|
896
|
+
|
897
|
+
"""
|
898
|
+
current_state = self.sync().lifecycle_state
|
899
|
+
if current_state != State.ACTIVE.name:
|
900
|
+
raise ModelDeploymentPredictError(
|
901
|
+
"This model deployment is not in active state, you will not be able to use predict end point. "
|
902
|
+
f"Current model deployment state: {current_state} "
|
903
|
+
)
|
904
|
+
endpoint = f"{self.url}/predict"
|
905
|
+
signer = authutil.default_signer()["signer"]
|
906
|
+
header = {
|
907
|
+
"signer": signer,
|
908
|
+
"content_type": kwargs.get("content_type", None),
|
909
|
+
}
|
910
|
+
header.update(kwargs.pop("headers", {}))
|
911
|
+
|
912
|
+
if data is None and json_input is None:
|
913
|
+
raise AttributeError(
|
914
|
+
"Neither `data` nor `json_input` are provided. You need to provide one of them."
|
915
|
+
)
|
916
|
+
if data is not None and json_input is not None:
|
917
|
+
raise AttributeError(
|
918
|
+
"`data` and `json_input` are both provided. You can only use one of them."
|
919
|
+
)
|
920
|
+
|
921
|
+
try:
|
922
|
+
if auto_serialize_data:
|
923
|
+
data = data or json_input
|
924
|
+
serialized_data = serializer.serialize(data=data)
|
925
|
+
return send_request(
|
926
|
+
data=serialized_data,
|
927
|
+
endpoint=endpoint,
|
928
|
+
is_json_payload=_is_json_serializable(serialized_data),
|
929
|
+
header=header,
|
930
|
+
)
|
931
|
+
|
932
|
+
if json_input is not None:
|
933
|
+
if not _is_json_serializable(json_input):
|
934
|
+
raise ValueError(
|
935
|
+
"`json_input` must be json serializable. "
|
936
|
+
"Set `auto_serialize_data` to True, or serialize the provided input data first,"
|
937
|
+
"or using `data` to pass binary data."
|
938
|
+
)
|
939
|
+
utils.get_logger().warning(
|
940
|
+
"The `json_input` argument of `predict()` will be deprecated soon. "
|
941
|
+
"Please use `data` argument. "
|
942
|
+
)
|
943
|
+
data = json_input
|
944
|
+
|
945
|
+
is_json_payload = _is_json_serializable(data)
|
946
|
+
if not isinstance(data, bytes) and not is_json_payload:
|
947
|
+
raise TypeError(
|
948
|
+
"`data` is not bytes or json serializable. Set `auto_serialize_data` to `True` to serialize the input data."
|
949
|
+
)
|
950
|
+
if model_name and model_version:
|
951
|
+
header["model-name"] = model_name
|
952
|
+
header["model-version"] = model_version
|
953
|
+
elif bool(model_version) ^ bool(model_name):
|
954
|
+
raise ValueError(
|
955
|
+
"`model_name` and `model_version` have to be provided together."
|
956
|
+
)
|
957
|
+
prediction = send_request(
|
958
|
+
data=data,
|
959
|
+
endpoint=endpoint,
|
960
|
+
is_json_payload=is_json_payload,
|
961
|
+
header=header,
|
962
|
+
)
|
963
|
+
return prediction
|
964
|
+
except oci.exceptions.ServiceError as ex:
|
965
|
+
# When bandwidth exceeds the allocated value, TooManyRequests error (429) will be raised by oci backend.
|
966
|
+
if ex.status == 429:
|
967
|
+
bandwidth_mbps = self.infrastructure.bandwidth_mbps or DEFAULT_BANDWIDTH_MBPS
|
968
|
+
utils.get_logger().warning(
|
969
|
+
f"Load balancer bandwidth exceeds the allocated {bandwidth_mbps} Mbps."
|
970
|
+
"To estimate the actual bandwidth, use formula: (payload size in KB) * (estimated requests per second) * 8 / 1024."
|
971
|
+
"To resolve the issue, try sizing down the payload, slowing down the request rate or increasing the allocated bandwidth."
|
972
|
+
)
|
973
|
+
raise
|
974
|
+
|
975
|
+
def activate(
|
976
|
+
self,
|
977
|
+
wait_for_completion: bool = True,
|
978
|
+
max_wait_time: int = DEFAULT_WAIT_TIME,
|
979
|
+
poll_interval: int = DEFAULT_POLL_INTERVAL,
|
980
|
+
) -> "ModelDeployment":
|
981
|
+
"""Activates a model deployment
|
982
|
+
|
983
|
+
Parameters
|
984
|
+
----------
|
985
|
+
wait_for_completion: bool
|
986
|
+
Flag set for whether to wait for deployment to be activated before proceeding.
|
987
|
+
Defaults to True.
|
988
|
+
max_wait_time: int
|
989
|
+
Maximum amount of time to wait in seconds (Defaults to 1200).
|
990
|
+
Negative implies infinite wait time.
|
991
|
+
poll_interval: int
|
992
|
+
Poll interval in seconds (Defaults to 10).
|
993
|
+
|
994
|
+
Returns
|
995
|
+
-------
|
996
|
+
ModelDeployment
|
997
|
+
The instance of ModelDeployment.
|
998
|
+
"""
|
999
|
+
response = self.dsc_model_deployment.activate(
|
1000
|
+
wait_for_completion=wait_for_completion,
|
1001
|
+
max_wait_time=max_wait_time,
|
1002
|
+
poll_interval=poll_interval,
|
1003
|
+
)
|
1004
|
+
|
1005
|
+
return self._update_from_oci_model(response)
|
1006
|
+
|
1007
|
+
def deactivate(
|
1008
|
+
self,
|
1009
|
+
wait_for_completion: bool = True,
|
1010
|
+
max_wait_time: int = DEFAULT_WAIT_TIME,
|
1011
|
+
poll_interval: int = DEFAULT_POLL_INTERVAL,
|
1012
|
+
) -> "ModelDeployment":
|
1013
|
+
"""Deactivates a model deployment
|
1014
|
+
|
1015
|
+
Parameters
|
1016
|
+
----------
|
1017
|
+
wait_for_completion: bool
|
1018
|
+
Flag set for whether to wait for deployment to be deactivated before proceeding.
|
1019
|
+
Defaults to True.
|
1020
|
+
max_wait_time: int
|
1021
|
+
Maximum amount of time to wait in seconds (Defaults to 1200).
|
1022
|
+
Negative implies infinite wait time.
|
1023
|
+
poll_interval: int
|
1024
|
+
Poll interval in seconds (Defaults to 10).
|
1025
|
+
|
1026
|
+
Returns
|
1027
|
+
-------
|
1028
|
+
ModelDeployment
|
1029
|
+
The instance of ModelDeployment.
|
1030
|
+
"""
|
1031
|
+
response = self.dsc_model_deployment.deactivate(
|
1032
|
+
wait_for_completion=wait_for_completion,
|
1033
|
+
max_wait_time=max_wait_time,
|
1034
|
+
poll_interval=poll_interval,
|
1035
|
+
)
|
1036
|
+
|
1037
|
+
return self._update_from_oci_model(response)
|
1038
|
+
|
1039
|
+
def _log_details(self, log_type: str = ModelDeploymentLogType.ACCESS):
|
1040
|
+
"""Gets log details for the provided `log_type`.
|
1041
|
+
|
1042
|
+
Properties
|
1043
|
+
----------
|
1044
|
+
log_type: (str, optional). Defaults to "access".
|
1045
|
+
The log type. Can be "access" or "predict".
|
1046
|
+
|
1047
|
+
Returns
|
1048
|
+
-------
|
1049
|
+
oci.datascience_model.CategoryLogDetails
|
1050
|
+
Category log details of the ModelDeployment.
|
1051
|
+
|
1052
|
+
Raises
|
1053
|
+
------
|
1054
|
+
AttributeError
|
1055
|
+
Deployment doesn't have requested log configuration.
|
1056
|
+
|
1057
|
+
"""
|
1058
|
+
if self.properties.category_log_details and getattr(
|
1059
|
+
self.properties.category_log_details, log_type
|
1060
|
+
):
|
1061
|
+
return getattr(self.properties.category_log_details, log_type)
|
1062
|
+
elif self.infrastructure:
|
1063
|
+
category_log_details = self._build_category_log_details()
|
1064
|
+
log = category_log_details.get(log_type, None)
|
1065
|
+
if log and log.get("logId", None) and log.get("logGroupId", None):
|
1066
|
+
return LogDetails(
|
1067
|
+
log_id=log.get("logId"), log_group_id=log.get("logGroupId")
|
1068
|
+
)
|
1069
|
+
|
1070
|
+
raise LogNotConfiguredError(
|
1071
|
+
f"Deployment `{self.model_deployment_id}` "
|
1072
|
+
f"has no `{log_type}` log configuration."
|
1073
|
+
)
|
1074
|
+
|
1075
|
+
@property
|
1076
|
+
def predict_log(self) -> OCILog:
|
1077
|
+
"""Gets the model deployment predict logs object.
|
1078
|
+
|
1079
|
+
Returns
|
1080
|
+
-------
|
1081
|
+
OCILog
|
1082
|
+
The OCILog object containing the predict logs.
|
1083
|
+
"""
|
1084
|
+
if not self._predict_log:
|
1085
|
+
log_details = self._log_details(log_type=ModelDeploymentLogType.PREDICT)
|
1086
|
+
compartment_id = (
|
1087
|
+
self.infrastructure.compartment_id
|
1088
|
+
if self.infrastructure
|
1089
|
+
else self.properties.compartment_id
|
1090
|
+
)
|
1091
|
+
self._predict_log = OCILog(
|
1092
|
+
compartment_id=compartment_id or COMPARTMENT_OCID,
|
1093
|
+
id=log_details.log_id,
|
1094
|
+
log_group_id=log_details.log_group_id,
|
1095
|
+
source=self.model_deployment_id,
|
1096
|
+
annotation=ModelDeploymentLogType.PREDICT,
|
1097
|
+
)
|
1098
|
+
return self._predict_log
|
1099
|
+
|
1100
|
+
@property
|
1101
|
+
def access_log(self) -> OCILog:
|
1102
|
+
"""Gets the model deployment access logs object.
|
1103
|
+
|
1104
|
+
Returns
|
1105
|
+
-------
|
1106
|
+
OCILog
|
1107
|
+
The OCILog object containing the access logs.
|
1108
|
+
"""
|
1109
|
+
if not self._access_log:
|
1110
|
+
log_details = self._log_details(log_type=ModelDeploymentLogType.ACCESS)
|
1111
|
+
compartment_id = (
|
1112
|
+
self.infrastructure.compartment_id
|
1113
|
+
if self.infrastructure
|
1114
|
+
else self.properties.compartment_id
|
1115
|
+
)
|
1116
|
+
self._access_log = OCILog(
|
1117
|
+
compartment_id=compartment_id or COMPARTMENT_OCID,
|
1118
|
+
id=log_details.log_id,
|
1119
|
+
log_group_id=log_details.log_group_id,
|
1120
|
+
source=self.model_deployment_id,
|
1121
|
+
annotation=ModelDeploymentLogType.ACCESS,
|
1122
|
+
)
|
1123
|
+
return self._access_log
|
1124
|
+
|
1125
|
+
def logs(self, log_type: str = None) -> ConsolidatedLog:
|
1126
|
+
"""Gets the access or predict logs.
|
1127
|
+
|
1128
|
+
Parameters
|
1129
|
+
----------
|
1130
|
+
log_type: (str, optional). Defaults to None.
|
1131
|
+
The log type. Can be "access", "predict" or None.
|
1132
|
+
|
1133
|
+
Returns
|
1134
|
+
-------
|
1135
|
+
ConsolidatedLog
|
1136
|
+
The ConsolidatedLog object containing the logs.
|
1137
|
+
"""
|
1138
|
+
loggers = []
|
1139
|
+
if not log_type:
|
1140
|
+
try:
|
1141
|
+
loggers.append(self.access_log)
|
1142
|
+
except LogNotConfiguredError:
|
1143
|
+
pass
|
1144
|
+
|
1145
|
+
try:
|
1146
|
+
loggers.append(self.predict_log)
|
1147
|
+
except LogNotConfiguredError:
|
1148
|
+
pass
|
1149
|
+
|
1150
|
+
if not loggers:
|
1151
|
+
raise LogNotConfiguredError(
|
1152
|
+
"Neither `predict` nor `access` log was configured for the model deployment."
|
1153
|
+
)
|
1154
|
+
elif log_type == ModelDeploymentLogType.ACCESS:
|
1155
|
+
loggers = [self.access_log]
|
1156
|
+
elif log_type == ModelDeploymentLogType.PREDICT:
|
1157
|
+
loggers = [self.predict_log]
|
1158
|
+
else:
|
1159
|
+
raise ValueError(
|
1160
|
+
"Parameter log_type should be either access, predict or None."
|
1161
|
+
)
|
1162
|
+
|
1163
|
+
return ConsolidatedLog(*loggers)
|
1164
|
+
|
1165
|
+
def show_logs(
|
1166
|
+
self,
|
1167
|
+
time_start: datetime.datetime = None,
|
1168
|
+
time_end: datetime.datetime = None,
|
1169
|
+
limit: int = LOG_RECORDS_LIMIT,
|
1170
|
+
log_type: str = None,
|
1171
|
+
):
|
1172
|
+
"""Shows deployment logs as a pandas dataframe.
|
1173
|
+
|
1174
|
+
Parameters
|
1175
|
+
----------
|
1176
|
+
time_start: (datetime.datetime, optional). Defaults to None.
|
1177
|
+
Starting date and time in RFC3339 format for retrieving logs.
|
1178
|
+
Defaults to None. Logs will be retrieved 14 days from now.
|
1179
|
+
time_end: (datetime.datetime, optional). Defaults to None.
|
1180
|
+
Ending date and time in RFC3339 format for retrieving logs.
|
1181
|
+
Defaults to None. Logs will be retrieved until now.
|
1182
|
+
limit: (int, optional). Defaults to 100.
|
1183
|
+
The maximum number of items to return.
|
1184
|
+
log_type: (str, optional). Defaults to None.
|
1185
|
+
The log type. Can be "access", "predict" or None.
|
1186
|
+
|
1187
|
+
Returns
|
1188
|
+
-------
|
1189
|
+
A pandas DataFrame containing logs.
|
1190
|
+
"""
|
1191
|
+
logging = self.logs(log_type=log_type)
|
1192
|
+
|
1193
|
+
def prepare_log_record(log):
|
1194
|
+
"""Converts a log record to ordered dict"""
|
1195
|
+
log_content = log.get("logContent", {})
|
1196
|
+
return collections.OrderedDict(
|
1197
|
+
[
|
1198
|
+
("type", log_content.get("type").split(".")[-1]),
|
1199
|
+
("id", log_content.get("id")),
|
1200
|
+
("message", log_content.get("data", {}).get("message")),
|
1201
|
+
("time", log_content.get("time")),
|
1202
|
+
]
|
1203
|
+
)
|
1204
|
+
|
1205
|
+
logs = logging.search(
|
1206
|
+
source=self.model_deployment_id,
|
1207
|
+
time_start=time_start,
|
1208
|
+
time_end=time_end,
|
1209
|
+
limit=limit,
|
1210
|
+
)
|
1211
|
+
return pd.DataFrame([prepare_log_record(log.data) for log in logs])
|
1212
|
+
|
1213
|
+
def sync(self) -> "ModelDeployment":
|
1214
|
+
"""Updates the model deployment instance from backend.
|
1215
|
+
|
1216
|
+
Returns
|
1217
|
+
-------
|
1218
|
+
ModelDeployment
|
1219
|
+
The ModelDeployment instance (self).
|
1220
|
+
"""
|
1221
|
+
return self._update_from_oci_model(
|
1222
|
+
OCIDataScienceModelDeployment.from_id(self.model_deployment_id)
|
1223
|
+
)
|
1224
|
+
|
1225
|
+
@classmethod
|
1226
|
+
def list(
|
1227
|
+
cls,
|
1228
|
+
status: str = None,
|
1229
|
+
compartment_id: str = None,
|
1230
|
+
project_id: str = None,
|
1231
|
+
**kwargs,
|
1232
|
+
) -> List["ModelDeployment"]:
|
1233
|
+
"""Lists the model deployments associated with current compartment id and status
|
1234
|
+
|
1235
|
+
Parameters
|
1236
|
+
----------
|
1237
|
+
status : str
|
1238
|
+
Status of deployment. Defaults to None.
|
1239
|
+
Allowed values: `ACTIVE`, `CREATING`, `DELETED`, `DELETING`, `FAILED`, `INACTIVE` and `UPDATING`.
|
1240
|
+
compartment_id : str
|
1241
|
+
Target compartment to list deployments from.
|
1242
|
+
Defaults to the compartment set in the environment variable "NB_SESSION_COMPARTMENT_OCID".
|
1243
|
+
If "NB_SESSION_COMPARTMENT_OCID" is not set, the root compartment ID will be used.
|
1244
|
+
An ValueError will be raised if root compartment ID cannot be determined.
|
1245
|
+
project_id : str
|
1246
|
+
Target project to list deployments from.
|
1247
|
+
Defaults to the project id in the environment variable "PROJECT_OCID".
|
1248
|
+
kwargs :
|
1249
|
+
The values are passed to oci.data_science.DataScienceClient.list_model_deployments.
|
1250
|
+
|
1251
|
+
Returns
|
1252
|
+
-------
|
1253
|
+
list
|
1254
|
+
A list of ModelDeployment objects.
|
1255
|
+
"""
|
1256
|
+
deployments = OCIDataScienceModelDeployment.list(
|
1257
|
+
status=status,
|
1258
|
+
compartment_id=compartment_id,
|
1259
|
+
project_id=project_id,
|
1260
|
+
**kwargs,
|
1261
|
+
)
|
1262
|
+
return [cls()._update_from_oci_model(deployment) for deployment in deployments]
|
1263
|
+
|
1264
|
+
@classmethod
|
1265
|
+
def list_df(
|
1266
|
+
cls,
|
1267
|
+
status: str = None,
|
1268
|
+
compartment_id: str = None,
|
1269
|
+
project_id: str = None,
|
1270
|
+
) -> pd.DataFrame:
|
1271
|
+
"""Returns the model deployments associated with current compartment and status
|
1272
|
+
as a Dataframe that can be easily visualized
|
1273
|
+
|
1274
|
+
Parameters
|
1275
|
+
----------
|
1276
|
+
status : str
|
1277
|
+
Status of deployment. Defaults to None.
|
1278
|
+
Allowed values: `ACTIVE`, `CREATING`, `DELETED`, `DELETING`, `FAILED`, `INACTIVE` and `UPDATING`.
|
1279
|
+
compartment_id : str
|
1280
|
+
Target compartment to list deployments from.
|
1281
|
+
Defaults to the compartment set in the environment variable "NB_SESSION_COMPARTMENT_OCID".
|
1282
|
+
If "NB_SESSION_COMPARTMENT_OCID" is not set, the root compartment ID will be used.
|
1283
|
+
An ValueError will be raised if root compartment ID cannot be determined.
|
1284
|
+
project_id : str
|
1285
|
+
Target project to list deployments from.
|
1286
|
+
Defaults to the project id in the environment variable "PROJECT_OCID".
|
1287
|
+
|
1288
|
+
Returns
|
1289
|
+
-------
|
1290
|
+
DataFrame
|
1291
|
+
pandas Dataframe containing information about the ModelDeployments
|
1292
|
+
"""
|
1293
|
+
model_deployments = cls.list(
|
1294
|
+
status=status, compartment_id=compartment_id, project_id=project_id
|
1295
|
+
)
|
1296
|
+
if isinstance(status, str) or status == None:
|
1297
|
+
status = State._from_str(status)
|
1298
|
+
display = pd.DataFrame()
|
1299
|
+
ids, urls, status_list = [], [], []
|
1300
|
+
for model_deployment in model_deployments:
|
1301
|
+
state_of_model = State._from_str(model_deployment.lifecycle_state)
|
1302
|
+
if status == State.UNKNOWN or status.name == state_of_model.name:
|
1303
|
+
ids.append(model_deployment.model_deployment_id)
|
1304
|
+
urls.append(model_deployment.url)
|
1305
|
+
status_list.append(model_deployment.lifecycle_state)
|
1306
|
+
display["deployment_id"] = ids
|
1307
|
+
display["deployment_url"] = urls
|
1308
|
+
display["current_state"] = status_list
|
1309
|
+
return display
|
1310
|
+
|
1311
|
+
@classmethod
|
1312
|
+
def from_id(cls, id: str) -> "ModelDeployment":
|
1313
|
+
"""Loads the model deployment instance from ocid.
|
1314
|
+
|
1315
|
+
Parameters
|
1316
|
+
----------
|
1317
|
+
id: str
|
1318
|
+
The ocid of model deployment.
|
1319
|
+
|
1320
|
+
Returns
|
1321
|
+
-------
|
1322
|
+
ModelDeployment
|
1323
|
+
The ModelDeployment instance (self).
|
1324
|
+
"""
|
1325
|
+
oci_model = OCIDataScienceModelDeployment.from_id(id)
|
1326
|
+
return cls(properties=oci_model)._update_from_oci_model(oci_model)
|
1327
|
+
|
1328
|
+
@classmethod
|
1329
|
+
def from_dict(cls, obj_dict: Dict) -> "ModelDeployment":
|
1330
|
+
"""Loads model deployment instance from a dictionary of configurations.
|
1331
|
+
|
1332
|
+
Parameters
|
1333
|
+
----------
|
1334
|
+
obj_dict: Dict
|
1335
|
+
A dictionary of configurations.
|
1336
|
+
|
1337
|
+
Returns
|
1338
|
+
-------
|
1339
|
+
ModelDeployment
|
1340
|
+
The model deployment instance.
|
1341
|
+
"""
|
1342
|
+
if not isinstance(obj_dict, dict):
|
1343
|
+
raise ValueError(
|
1344
|
+
"The config data for initializing the model deployment is invalid."
|
1345
|
+
)
|
1346
|
+
spec = ads_utils.batch_convert_case(
|
1347
|
+
copy.deepcopy(obj_dict.get("spec")), "camel"
|
1348
|
+
)
|
1349
|
+
|
1350
|
+
mappings = {
|
1351
|
+
cls.CONST_INFRASTRUCTURE: {
|
1352
|
+
MODEL_DEPLOYMENT_INFRASTRUCTURE_TYPE: ModelDeploymentInfrastructure,
|
1353
|
+
},
|
1354
|
+
cls.CONST_RUNTIME: {
|
1355
|
+
ModelDeploymentRuntimeType.CONDA: ModelDeploymentCondaRuntime,
|
1356
|
+
ModelDeploymentRuntimeType.CONTAINER: ModelDeploymentContainerRuntime,
|
1357
|
+
},
|
1358
|
+
}
|
1359
|
+
model_deployment = cls()
|
1360
|
+
|
1361
|
+
for key, value in spec.items():
|
1362
|
+
if key in mappings:
|
1363
|
+
mapping = mappings[key]
|
1364
|
+
child_config = value
|
1365
|
+
if child_config.get("type") not in mapping:
|
1366
|
+
raise NotImplementedError(
|
1367
|
+
f"{key.title()} type: {child_config.get('type')} is not supported."
|
1368
|
+
)
|
1369
|
+
model_deployment.set_spec(
|
1370
|
+
key, mapping[child_config.get("type")].from_dict(child_config)
|
1371
|
+
)
|
1372
|
+
else:
|
1373
|
+
model_deployment.set_spec(key, value)
|
1374
|
+
|
1375
|
+
return model_deployment
|
1376
|
+
|
1377
|
+
def to_dict(self, **kwargs) -> Dict:
|
1378
|
+
"""Serializes model deployment to a dictionary.
|
1379
|
+
|
1380
|
+
Returns
|
1381
|
+
-------
|
1382
|
+
dict
|
1383
|
+
The model deployment serialized as a dictionary.
|
1384
|
+
"""
|
1385
|
+
spec = copy.deepcopy(self._spec)
|
1386
|
+
for key, value in spec.items():
|
1387
|
+
if hasattr(value, "to_dict"):
|
1388
|
+
value = value.to_dict()
|
1389
|
+
spec[key] = value
|
1390
|
+
|
1391
|
+
return {
|
1392
|
+
"kind": self.kind,
|
1393
|
+
"type": self.type,
|
1394
|
+
"spec": ads_utils.batch_convert_case(spec, "camel"),
|
1395
|
+
}
|
1396
|
+
|
1397
|
+
def _update_from_oci_model(self, oci_model_instance) -> "ModelDeployment":
|
1398
|
+
"""Updates model deployment instance from OCIDataScienceModelDeployment.
|
1399
|
+
|
1400
|
+
Parameters
|
1401
|
+
----------
|
1402
|
+
oci_model_instance: OCIDataScienceModelDeployment
|
1403
|
+
The OCIDataScienceModelDeployment instance.
|
1404
|
+
|
1405
|
+
Returns
|
1406
|
+
-------
|
1407
|
+
ModelDeployment
|
1408
|
+
The model deployment instance.
|
1409
|
+
"""
|
1410
|
+
self.dsc_model_deployment = oci_model_instance
|
1411
|
+
for key, value in self.attribute_map.items():
|
1412
|
+
if hasattr(oci_model_instance, value):
|
1413
|
+
self.set_spec(key, getattr(oci_model_instance, value))
|
1414
|
+
|
1415
|
+
infrastructure = ModelDeploymentInfrastructure()
|
1416
|
+
self._extract_from_oci_model(
|
1417
|
+
infrastructure, oci_model_instance, infrastructure.sub_level_attribute_maps
|
1418
|
+
)
|
1419
|
+
|
1420
|
+
model_deployment_configuration_details = getattr(
|
1421
|
+
oci_model_instance, "model_deployment_configuration_details", None
|
1422
|
+
)
|
1423
|
+
environment_configuration_details = getattr(
|
1424
|
+
model_deployment_configuration_details,
|
1425
|
+
"environment_configuration_details",
|
1426
|
+
None,
|
1427
|
+
)
|
1428
|
+
runtime = (
|
1429
|
+
ModelDeploymentContainerRuntime()
|
1430
|
+
if getattr(
|
1431
|
+
environment_configuration_details,
|
1432
|
+
"environment_configuration_type",
|
1433
|
+
None,
|
1434
|
+
)
|
1435
|
+
== OCIModelDeploymentRuntimeType.CONTAINER
|
1436
|
+
else ModelDeploymentCondaRuntime()
|
1437
|
+
)
|
1438
|
+
|
1439
|
+
self._extract_from_oci_model(runtime, oci_model_instance)
|
1440
|
+
infrastructure.set_spec(
|
1441
|
+
infrastructure.CONST_WEB_CONCURRENCY,
|
1442
|
+
runtime.env.get("WEB_CONCURRENCY", None),
|
1443
|
+
)
|
1444
|
+
if (
|
1445
|
+
runtime.env.get("CONTAINER_TYPE", None)
|
1446
|
+
== MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON
|
1447
|
+
):
|
1448
|
+
runtime.set_spec(
|
1449
|
+
runtime.CONST_INFERENCE_SERVER,
|
1450
|
+
MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON.lower(),
|
1451
|
+
)
|
1452
|
+
|
1453
|
+
self.set_spec(self.CONST_INFRASTRUCTURE, infrastructure)
|
1454
|
+
self.set_spec(self.CONST_RUNTIME, runtime)
|
1455
|
+
|
1456
|
+
return self
|
1457
|
+
|
1458
|
+
@staticmethod
|
1459
|
+
def _extract_from_oci_model(
|
1460
|
+
dsc_instance: Union[ModelDeploymentInfrastructure, ModelDeploymentRuntime],
|
1461
|
+
oci_model_instance: OCIDataScienceModelDeployment,
|
1462
|
+
sub_level: Dict = {},
|
1463
|
+
) -> Union[ModelDeploymentInfrastructure, ModelDeploymentRuntime]:
|
1464
|
+
"""Extract attributes from OCIDataScienceModelDeployment.
|
1465
|
+
|
1466
|
+
Parameters
|
1467
|
+
----------
|
1468
|
+
dsc_instance: Union[ModelDeploymentInfrastructure, ModelDeploymentRuntime]
|
1469
|
+
The ModelDeploymentInfrastructure or ModelDeploymentRuntime instance.
|
1470
|
+
oci_model_instance: OCIDataScienceModelDeployment
|
1471
|
+
The OCIDataScienceModelDeployment instance.
|
1472
|
+
sub_level: Dict
|
1473
|
+
The sub level attribute maps of ModelDeploymentInfrastructure or ModelDeploymentRuntime
|
1474
|
+
|
1475
|
+
Returns
|
1476
|
+
-------
|
1477
|
+
Union[ModelDeploymentInfrastructure, ModelDeploymentRuntime]
|
1478
|
+
The ModelDeploymentInfrastructure or ModelDeploymentRuntime instance.
|
1479
|
+
"""
|
1480
|
+
for infra_attr, dsc_attr in dsc_instance.payload_attribute_map.items():
|
1481
|
+
value = get_value(oci_model_instance, dsc_attr)
|
1482
|
+
if value:
|
1483
|
+
if infra_attr not in sub_level:
|
1484
|
+
dsc_instance._spec[infra_attr] = value
|
1485
|
+
else:
|
1486
|
+
dsc_instance._spec[infra_attr] = {}
|
1487
|
+
for sub_infra_attr, sub_dsc_attr in sub_level[infra_attr].items():
|
1488
|
+
sub_value = get_value(value, sub_dsc_attr)
|
1489
|
+
if sub_value:
|
1490
|
+
dsc_instance._spec[infra_attr][sub_infra_attr] = sub_value
|
1491
|
+
return dsc_instance
|
1492
|
+
|
1493
|
+
def _build_model_deployment_details(self) -> CreateModelDeploymentDetails:
|
1494
|
+
"""Builds CreateModelDeploymentDetails from model deployment instance.
|
1495
|
+
|
1496
|
+
Returns
|
1497
|
+
-------
|
1498
|
+
CreateModelDeploymentDetails
|
1499
|
+
The CreateModelDeploymentDetails instance.
|
1500
|
+
"""
|
1501
|
+
if not (self.infrastructure and self.runtime):
|
1502
|
+
raise ValueError(
|
1503
|
+
"Missing parameter runtime or infrastructure. Try reruning it after parameters are fully configured."
|
1504
|
+
)
|
1505
|
+
|
1506
|
+
create_model_deployment_details = {
|
1507
|
+
self.CONST_DISPLAY_NAME: self.display_name or self._random_display_name(),
|
1508
|
+
self.CONST_DESCRIPTION: self.description,
|
1509
|
+
self.CONST_DEFINED_TAG: self.defined_tags,
|
1510
|
+
self.CONST_FREEFORM_TAG: self.freeform_tags,
|
1511
|
+
self.runtime.CONST_DEPLOYMENT_MODE: self.runtime.deployment_mode
|
1512
|
+
or ModelDeploymentMode.HTTPS,
|
1513
|
+
self.infrastructure.CONST_COMPARTMENT_ID: self.infrastructure.compartment_id
|
1514
|
+
or COMPARTMENT_OCID,
|
1515
|
+
self.infrastructure.CONST_PROJECT_ID: self.infrastructure.project_id
|
1516
|
+
or PROJECT_OCID,
|
1517
|
+
self.infrastructure.CONST_MODEL_DEPLOYMENT_CONFIG_DETAILS: self._build_model_deployment_configuration_details(),
|
1518
|
+
self.infrastructure.CONST_CATEGORY_LOG_DETAILS: self._build_category_log_details(),
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
return OCIDataScienceModelDeployment(
|
1522
|
+
**create_model_deployment_details
|
1523
|
+
).to_oci_model(CreateModelDeploymentDetails)
|
1524
|
+
|
1525
|
+
def _update_model_deployment_details(
|
1526
|
+
self, **kwargs
|
1527
|
+
) -> UpdateModelDeploymentDetails:
|
1528
|
+
"""Builds UpdateModelDeploymentDetails from model deployment instance.
|
1529
|
+
|
1530
|
+
Returns
|
1531
|
+
-------
|
1532
|
+
UpdateModelDeploymentDetails
|
1533
|
+
The UpdateModelDeploymentDetails instance.
|
1534
|
+
"""
|
1535
|
+
if not (self.infrastructure and self.runtime):
|
1536
|
+
raise ValueError(
|
1537
|
+
"Missing parameter runtime or infrastructure. Try reruning it after parameters are fully configured."
|
1538
|
+
)
|
1539
|
+
self._update_spec(**kwargs)
|
1540
|
+
update_model_deployment_details = {
|
1541
|
+
self.CONST_DISPLAY_NAME: self.display_name,
|
1542
|
+
self.CONST_DESCRIPTION: self.description,
|
1543
|
+
self.CONST_DEFINED_TAG: self.defined_tags,
|
1544
|
+
self.CONST_FREEFORM_TAG: self.freeform_tags,
|
1545
|
+
self.infrastructure.CONST_MODEL_DEPLOYMENT_CONFIG_DETAILS: self._build_model_deployment_configuration_details(),
|
1546
|
+
self.infrastructure.CONST_CATEGORY_LOG_DETAILS: self._build_category_log_details(),
|
1547
|
+
}
|
1548
|
+
return OCIDataScienceModelDeployment(
|
1549
|
+
**update_model_deployment_details
|
1550
|
+
).to_oci_model(UpdateModelDeploymentDetails)
|
1551
|
+
|
1552
|
+
def _update_spec(self, **kwargs) -> "ModelDeployment":
|
1553
|
+
"""Updates model deployment specs from kwargs.
|
1554
|
+
|
1555
|
+
Parameters
|
1556
|
+
----------
|
1557
|
+
kwargs:
|
1558
|
+
display_name: (str)
|
1559
|
+
Model deployment display name
|
1560
|
+
description: (str)
|
1561
|
+
Model deployment description
|
1562
|
+
freeform_tags: (dict)
|
1563
|
+
Model deployment freeform tags
|
1564
|
+
defined_tags: (dict)
|
1565
|
+
Model deployment defined tags
|
1566
|
+
|
1567
|
+
Additional kwargs arguments.
|
1568
|
+
Can be any attribute that `ads.model.deployment.ModelDeploymentCondaRuntime`, `ads.model.deployment.ModelDeploymentContainerRuntime`
|
1569
|
+
and `ads.model.deployment.ModelDeploymentInfrastructure` accepts.
|
1570
|
+
|
1571
|
+
Returns
|
1572
|
+
-------
|
1573
|
+
ModelDeployment
|
1574
|
+
The instance of ModelDeployment.
|
1575
|
+
"""
|
1576
|
+
if not kwargs:
|
1577
|
+
return self
|
1578
|
+
|
1579
|
+
converted_specs = ads_utils.batch_convert_case(kwargs, "camel")
|
1580
|
+
specs = {
|
1581
|
+
"self": self._spec,
|
1582
|
+
"runtime": self.runtime._spec,
|
1583
|
+
"infrastructure": self.infrastructure._spec,
|
1584
|
+
}
|
1585
|
+
sub_set = {
|
1586
|
+
self.infrastructure.CONST_ACCESS_LOG,
|
1587
|
+
self.infrastructure.CONST_PREDICT_LOG,
|
1588
|
+
self.infrastructure.CONST_SHAPE_CONFIG_DETAILS,
|
1589
|
+
}
|
1590
|
+
for spec_value in specs.values():
|
1591
|
+
for key in spec_value:
|
1592
|
+
if key in converted_specs:
|
1593
|
+
if key in sub_set:
|
1594
|
+
for sub_key in converted_specs[key]:
|
1595
|
+
converted_sub_key = ads_utils.snake_to_camel(sub_key)
|
1596
|
+
spec_value[key][converted_sub_key] = converted_specs[key][
|
1597
|
+
sub_key
|
1598
|
+
]
|
1599
|
+
else:
|
1600
|
+
spec_value[key] = copy.deepcopy(converted_specs[key])
|
1601
|
+
self = (
|
1602
|
+
ModelDeployment(spec=specs["self"])
|
1603
|
+
.with_runtime(
|
1604
|
+
MODEL_DEPLOYMENT_RUNTIMES[self.runtime.type](spec=specs["runtime"])
|
1605
|
+
)
|
1606
|
+
.with_infrastructure(
|
1607
|
+
ModelDeploymentInfrastructure(spec=specs["infrastructure"])
|
1608
|
+
)
|
1609
|
+
)
|
1610
|
+
|
1611
|
+
return self
|
1612
|
+
|
1613
|
+
def _build_model_deployment_configuration_details(self) -> Dict:
|
1614
|
+
"""Builds model deployment configuration details from model deployment instance.
|
1615
|
+
|
1616
|
+
Returns
|
1617
|
+
-------
|
1618
|
+
Dict:
|
1619
|
+
Dict contains model deployment configuration details.
|
1620
|
+
"""
|
1621
|
+
infrastructure = self.infrastructure
|
1622
|
+
runtime = self.runtime
|
1623
|
+
|
1624
|
+
instance_configuration = {
|
1625
|
+
infrastructure.CONST_INSTANCE_SHAPE_NAME: infrastructure.shape_name
|
1626
|
+
or DEFAULT_SHAPE_NAME,
|
1627
|
+
}
|
1628
|
+
|
1629
|
+
if instance_configuration[infrastructure.CONST_INSTANCE_SHAPE_NAME].endswith(
|
1630
|
+
"Flex"
|
1631
|
+
):
|
1632
|
+
instance_configuration[
|
1633
|
+
infrastructure.CONST_MODEL_DEPLOYMENT_INSTANCE_SHAPE_CONFIG_DETAILS
|
1634
|
+
] = {
|
1635
|
+
infrastructure.CONST_OCPUS: infrastructure.shape_config_details.get(
|
1636
|
+
"ocpus", None
|
1637
|
+
)
|
1638
|
+
or DEFAULT_OCPUS,
|
1639
|
+
infrastructure.CONST_MEMORY_IN_GBS: infrastructure.shape_config_details.get(
|
1640
|
+
"memory_in_gbs", None
|
1641
|
+
)
|
1642
|
+
or infrastructure.shape_config_details.get("memoryInGBs", None)
|
1643
|
+
or DEFAULT_MEMORY_IN_GBS,
|
1644
|
+
}
|
1645
|
+
|
1646
|
+
if infrastructure.subnet_id:
|
1647
|
+
instance_configuration[
|
1648
|
+
infrastructure.CONST_SUBNET_ID
|
1649
|
+
] = infrastructure.subnet_id
|
1650
|
+
|
1651
|
+
if infrastructure.private_endpoint_id:
|
1652
|
+
if not hasattr(
|
1653
|
+
oci.data_science.models.InstanceConfiguration, "private_endpoint_id"
|
1654
|
+
):
|
1655
|
+
# TODO: add oci version with private endpoint support.
|
1656
|
+
raise EnvironmentError(
|
1657
|
+
"Private endpoint is not supported in the current OCI SDK installed."
|
1658
|
+
)
|
1659
|
+
|
1660
|
+
instance_configuration[
|
1661
|
+
infrastructure.CONST_PRIVATE_ENDPOINT_ID
|
1662
|
+
] = infrastructure.private_endpoint_id
|
1663
|
+
|
1664
|
+
scaling_policy = {
|
1665
|
+
infrastructure.CONST_POLICY_TYPE: "FIXED_SIZE",
|
1666
|
+
infrastructure.CONST_INSTANCE_COUNT: infrastructure.replica
|
1667
|
+
or DEFAULT_REPLICA,
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
if not runtime.model_uri:
|
1671
|
+
raise ValueError(
|
1672
|
+
"Missing parameter model uri. Try reruning it after model uri is configured."
|
1673
|
+
)
|
1674
|
+
|
1675
|
+
model_id = runtime.model_uri
|
1676
|
+
if not model_id.startswith("ocid"):
|
1677
|
+
from ads.model.datascience_model import DataScienceModel
|
1678
|
+
|
1679
|
+
dsc_model = DataScienceModel(
|
1680
|
+
name=self.display_name,
|
1681
|
+
compartment_id=self.infrastructure.compartment_id or COMPARTMENT_OCID,
|
1682
|
+
project_id=self.infrastructure.project_id or PROJECT_OCID,
|
1683
|
+
artifact=runtime.model_uri,
|
1684
|
+
).create(
|
1685
|
+
bucket_uri=runtime.bucket_uri,
|
1686
|
+
auth=runtime.auth,
|
1687
|
+
region=runtime.region,
|
1688
|
+
overwrite_existing_artifact=runtime.overwrite_existing_artifact,
|
1689
|
+
remove_existing_artifact=runtime.remove_existing_artifact,
|
1690
|
+
timeout=runtime.timeout,
|
1691
|
+
)
|
1692
|
+
model_id = dsc_model.id
|
1693
|
+
|
1694
|
+
model_configuration_details = {
|
1695
|
+
infrastructure.CONST_BANDWIDTH_MBPS: infrastructure.bandwidth_mbps
|
1696
|
+
or DEFAULT_BANDWIDTH_MBPS,
|
1697
|
+
infrastructure.CONST_INSTANCE_CONFIG: instance_configuration,
|
1698
|
+
runtime.CONST_MODEL_ID: model_id,
|
1699
|
+
infrastructure.CONST_SCALING_POLICY: scaling_policy,
|
1700
|
+
}
|
1701
|
+
|
1702
|
+
if runtime.env:
|
1703
|
+
if not hasattr(
|
1704
|
+
oci.data_science.models,
|
1705
|
+
"ModelDeploymentEnvironmentConfigurationDetails",
|
1706
|
+
):
|
1707
|
+
raise EnvironmentError(
|
1708
|
+
"Environment variable hasn't been supported in the current OCI SDK installed."
|
1709
|
+
)
|
1710
|
+
|
1711
|
+
environment_variables = runtime.env
|
1712
|
+
if infrastructure.web_concurrency:
|
1713
|
+
environment_variables["WEB_CONCURRENCY"] = str(
|
1714
|
+
infrastructure.web_concurrency
|
1715
|
+
)
|
1716
|
+
runtime.set_spec(runtime.CONST_ENV, environment_variables)
|
1717
|
+
if (
|
1718
|
+
hasattr(runtime, "inference_server")
|
1719
|
+
and runtime.inference_server
|
1720
|
+
and runtime.inference_server.upper()
|
1721
|
+
== MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON
|
1722
|
+
):
|
1723
|
+
environment_variables[
|
1724
|
+
"CONTAINER_TYPE"
|
1725
|
+
] = MODEL_DEPLOYMENT_INFERENCE_SERVER_TRITON
|
1726
|
+
runtime.set_spec(runtime.CONST_ENV, environment_variables)
|
1727
|
+
environment_configuration_details = {
|
1728
|
+
runtime.CONST_ENVIRONMENT_CONFIG_TYPE: runtime.environment_config_type,
|
1729
|
+
runtime.CONST_ENVIRONMENT_VARIABLES: runtime.env,
|
1730
|
+
}
|
1731
|
+
|
1732
|
+
if runtime.environment_config_type == OCIModelDeploymentRuntimeType.CONTAINER:
|
1733
|
+
if not hasattr(
|
1734
|
+
oci.data_science.models,
|
1735
|
+
"OcirModelDeploymentEnvironmentConfigurationDetails",
|
1736
|
+
):
|
1737
|
+
raise EnvironmentError(
|
1738
|
+
"Container runtime hasn't been supported in the current OCI SDK installed."
|
1739
|
+
)
|
1740
|
+
environment_configuration_details["image"] = runtime.image
|
1741
|
+
environment_configuration_details["imageDigest"] = runtime.image_digest
|
1742
|
+
environment_configuration_details["cmd"] = runtime.cmd
|
1743
|
+
environment_configuration_details["entrypoint"] = runtime.entrypoint
|
1744
|
+
environment_configuration_details["serverPort"] = runtime.server_port
|
1745
|
+
environment_configuration_details[
|
1746
|
+
"healthCheckPort"
|
1747
|
+
] = runtime.health_check_port
|
1748
|
+
|
1749
|
+
model_deployment_configuration_details = {
|
1750
|
+
infrastructure.CONST_DEPLOYMENT_TYPE: "SINGLE_MODEL",
|
1751
|
+
infrastructure.CONST_MODEL_CONFIG_DETAILS: model_configuration_details,
|
1752
|
+
runtime.CONST_ENVIRONMENT_CONFIG_DETAILS: environment_configuration_details,
|
1753
|
+
}
|
1754
|
+
|
1755
|
+
if runtime.deployment_mode == ModelDeploymentMode.STREAM:
|
1756
|
+
if not hasattr(oci.data_science.models, "StreamConfigurationDetails"):
|
1757
|
+
raise EnvironmentError(
|
1758
|
+
"Model deployment mode hasn't been supported in the current OCI SDK installed."
|
1759
|
+
)
|
1760
|
+
model_deployment_configuration_details[
|
1761
|
+
infrastructure.CONST_STREAM_CONFIG_DETAILS
|
1762
|
+
] = {
|
1763
|
+
runtime.CONST_INPUT_STREAM_IDS: runtime.input_stream_ids,
|
1764
|
+
runtime.CONST_OUTPUT_STREAM_IDS: runtime.output_stream_ids,
|
1765
|
+
}
|
1766
|
+
|
1767
|
+
return model_deployment_configuration_details
|
1768
|
+
|
1769
|
+
def _build_category_log_details(self) -> Dict:
|
1770
|
+
"""Builds category log details from model deployment instance.
|
1771
|
+
|
1772
|
+
Returns
|
1773
|
+
-------
|
1774
|
+
Dict:
|
1775
|
+
Dict contains category log details.
|
1776
|
+
"""
|
1777
|
+
if self.infrastructure.log_group_id and self.infrastructure.log_id:
|
1778
|
+
log_group_details = {
|
1779
|
+
self.infrastructure.CONST_LOG_GROUP_ID: self.infrastructure.log_group_id,
|
1780
|
+
self.infrastructure.CONST_LOG_ID: self.infrastructure.log_id,
|
1781
|
+
}
|
1782
|
+
return {
|
1783
|
+
self.infrastructure.CONST_ACCESS: log_group_details,
|
1784
|
+
self.infrastructure.CONST_PREDICT: log_group_details,
|
1785
|
+
}
|
1786
|
+
|
1787
|
+
logs = {}
|
1788
|
+
if (
|
1789
|
+
self.infrastructure.access_log and
|
1790
|
+
self.infrastructure.access_log.get(self.infrastructure.CONST_LOG_GROUP_ID, None)
|
1791
|
+
and self.infrastructure.access_log.get(self.infrastructure.CONST_LOG_ID, None)
|
1792
|
+
):
|
1793
|
+
logs[self.infrastructure.CONST_ACCESS] = {
|
1794
|
+
self.infrastructure.CONST_LOG_GROUP_ID: self.infrastructure.access_log.get(
|
1795
|
+
"logGroupId", None
|
1796
|
+
),
|
1797
|
+
self.infrastructure.CONST_LOG_ID: self.infrastructure.access_log.get(
|
1798
|
+
"logId", None
|
1799
|
+
),
|
1800
|
+
}
|
1801
|
+
if (
|
1802
|
+
self.infrastructure.predict_log and
|
1803
|
+
self.infrastructure.predict_log.get(self.infrastructure.CONST_LOG_GROUP_ID, None)
|
1804
|
+
and self.infrastructure.predict_log.get(self.infrastructure.CONST_LOG_ID, None)
|
1805
|
+
):
|
1806
|
+
logs[self.infrastructure.CONST_PREDICT] = {
|
1807
|
+
self.infrastructure.CONST_LOG_GROUP_ID: self.infrastructure.predict_log.get(
|
1808
|
+
"logGroupId", None
|
1809
|
+
),
|
1810
|
+
self.infrastructure.CONST_LOG_ID: self.infrastructure.predict_log.get(
|
1811
|
+
"logId", None
|
1812
|
+
),
|
1813
|
+
}
|
1814
|
+
|
1815
|
+
return logs
|
1816
|
+
|
1817
|
+
def _random_display_name(self):
|
1818
|
+
"""Generates a random display name."""
|
1819
|
+
return f"{self._PREFIX}-{ads_utils.get_random_name_for_resource()}"
|
1820
|
+
|
1821
|
+
def _extract_spec_kwargs(self, **kwargs) -> Dict:
|
1822
|
+
"""Extract spec related keyword arguments from kwargs.
|
1823
|
+
|
1824
|
+
Parameters
|
1825
|
+
----------
|
1826
|
+
kwargs
|
1827
|
+
|
1828
|
+
Returns
|
1829
|
+
-------
|
1830
|
+
Dict:
|
1831
|
+
Dict contains model deployment spec related keyword arguments.
|
1832
|
+
"""
|
1833
|
+
spec_kwargs = {}
|
1834
|
+
for attribute in self.initialize_spec_attributes:
|
1835
|
+
if attribute in kwargs:
|
1836
|
+
spec_kwargs[attribute] = kwargs[attribute]
|
1837
|
+
return spec_kwargs
|
1838
|
+
|
1839
|
+
def build(self) -> "ModelDeployment":
|
1840
|
+
"""Load default values from the environment for the job infrastructure."""
|
1841
|
+
build_method = getattr(self.infrastructure, "build", None)
|
1842
|
+
if build_method and callable(build_method):
|
1843
|
+
build_method()
|
1844
|
+
else:
|
1845
|
+
raise NotImplementedError
|
1846
|
+
return self
|