ads.model.deployment.common package

Submodules

ads.model.deployment.common.progress_bar module

class ads.model.deployment.common.progress_bar.DummyProgressBar(*args, **kwargs)

Bases: ProgressBar

DummyProgressBar is represents a progress bar for non-notebook environments. It inherits from the abstract class ProgressBar. It allows use of the same contextlib enter and exit methods

update(*args, **kwargs)
class ads.model.deployment.common.progress_bar.ProgressBar

Bases: object

ProgressBar is an abstract class for creating progress bars.

__enter__()

runtime context entry method

update(description)

abstract method for update

__exit__(exc_type, exc_val, exc_tb)

runtime context exit method

abstract update(description)
class ads.model.deployment.common.progress_bar.TqdmProgressBar(max_progress=100, description='Running', verbose=False)

Bases: ProgressBar

TqdmProgressBar represents a progress bar for notebooks. It inherits from the abstract class ProgressBar

max_progress(int)

The maximum value for the progress bar

decription(str)

The progres bar’s description

progress_bar(tqdm_notebook)

Notebook widget

verbose(bool)

verbosity flag

__enter__()

runtime context entry method

__init__(max_progress, description, verbose)

init method for class

update(description=None)

updates progress bar

__exit__(exc_type, exc_val, exc_tb)

runtime context exit method

Class initialization function

Parameters:
  • max_progress (int, optional) – the maximum progress bar value (defaults to 100)

  • description (str, optional) – the progress bar description (defaults to “Running”)

  • verbose (bool, optional) – verbosity flag (defaults to False)

update(description=None)

update updates the progress bar

Parameters:

description (str, optional) – progress bar description

Returns:

Nothing

ads.model.deployment.common.utils module

Utilities used by the model deployment package

class ads.model.deployment.common.utils.OCIClientManager(config=None)

Bases: object

OCIClientManager is a helper class used for accessing DataScienceClient and DataScienceCompositeClient objects

ds_client - class attribute for data science client
ds_composite_client - class attribute for data science composite client
default_compartment_id()

Determines the default compartment OCID This method finds the compartment OCID from (in priority order): an environment variable, an API key config or a resource principal signer.

Parameters:

config (dict, optional) –

The model deployment config, which contains the following keys: auth: Authentication method, must be either “resource_principal” or “api_key”. If auth is not specified:

  1. api_key will be used if available.

  2. If api_key is not available, resource_principal will be used.

oci_config_file: OCI API key config file location. Defaults to “~/.oci/config” oci_config_profile: OCI API key config profile name. Defaults to “DEFAULT”

Returns:

The compartment OCID if found. Otherwise None.

Return type:

str or None

prepare_artifact(model_uri: str, properties: Dict) str

Prepare model artifact. Returns model ocid.

Parameters:
  • model_uri (str) – uri to model files, can be local or in cloud storage

  • properties (dict) – dictionary of properties that are needed for creating a model.

  • ds_client (DataScienceClient) – OCI DataScienceClient

Returns:

model ocid

Return type:

str

class ads.model.deployment.common.utils.State(value)

Bases: Enum

An enumeration.

ACTIVE = 1
CREATING = 2
DELETED = 3
DELETING = 4
FAILED = 5
INACTIVE = 6
UNKNOWN = 8
UPDATING = 7
ads.model.deployment.common.utils.get_logger()
ads.model.deployment.common.utils.get_progress_bar(max_progress, description='Initializing')

get_progress_bar return an instance of ProgressBar, sensitive to the runtime environment

Parameters:
  • max_progress (int) – Progress bar max

  • description (str, optional) – Progress bar description (defaults to “Initializing”)

Returns:

An instance of ProgressBar. Either a DummyProgressBar (non-notebook) or TqdmProgressBar (notebook environement)

ads.model.deployment.common.utils.is_notebook()

is_notebook returns True if the environment is a Jupyter notebook and False otherwise

Parameters:

None

Returns:

True if Jupyter notebook; False otherwise

Return type:

bool

Raises:

NameError – If retrieving the shell name from get_ipython() throws an error

ads.model.deployment.common.utils.seconds_since(t)

seconds_since returns the seconds since t. t is assumed to be a time in epoch seconds since time.time() returns the current time in epoch seconds.

Parameters:

t (int) –

Returns

int: the number of seconds since t

ads.model.deployment.common.utils.send_request(data, endpoint: str, dry_run: bool = False, is_json_payload: bool = False, header: dict = {})

Sends the data to the predict endpoint.

Parameters:
  • data (bytes or Json serializable) – data need to be sent to the endpoint.

  • endpoint (str) – The model HTTP endpoint.

  • dry_run (bool, optional) – Defaults to False.

  • is_json_payload (bool, optional) – Indicate whether to send data with a application/json MIME TYPE. Defaults to False.

  • header (dict, optional) – A dictionary of HTTP headers to send to the specified url. Defaults to {}.

Returns:

A JSON representive of a requests.Response object.

ads.model.deployment.common.utils.set_log_level(level='INFO')

set_log_level sets the logger level

Parameters:

level (str, optional) – The logger level. Defaults to “INFO”

Returns:

Nothing

Module contents