コード例 #1
0
def _train_model(args):
    UCAIPService.get().create_training_pipeline(
        training_pipeline_name=args["pipelineName"],
        dataset_id=args["datasetId"],
        model_name=args["modelName"],
        target_column=args["targetColumn"],
        prediction_type=args["predictionType"],
        objective=args["objective"],
        budget_hours=args["budgetHours"],
        transformations=args["transformations"])
    return {"success": True}
コード例 #2
0
def _create_tables_dataset(args):
    file_source = args.get("fileSource")
    if file_source:
        decoded = base64.decodebytes(file_source["data"])
        UCAIPService.get().create_dataset_from_file(
            display_name=args["displayName"],
            file_name=file_source["name"],
            file_data=decoded)
    else:
        UCAIPService.get().create_dataset(
            display_name=args["displayName"],
            gcs_uri=args.get("gcsSource"),
            bigquery_uri=args.get("bigquerySource"))
    return {"success": True}
コード例 #3
0
def create_training_pipeline(
    display_name: str, dataset_id: str, model_name: str, target_column: str,
    prediction_type: str, objective: str, budget_hours: int,
    transformations: Dict[str, Dict[str, str]]
) -> aiplatform_v1alpha1.TrainingPipeline:
    """Create a simple training pipeline and train a model from a tables dataset on uCAIP

  Args:
      display_name (str): The user-defined name of the training pipeline
      dataset_id (str): ID of the dataset to train from
      model_name (str): The user-defined name of the model to create
      target_column (str): Name of the target column
      prediction_type (str): Type of prediction on the target column, can be "regression" or "classification"
      objective (str): Optimization objective.
        Supported binary classification optimisation objectives: maximize-au-roc, minimize-log-loss, maximize-au-prc.
        Supported multi-class classification optimisation objective: minimize-log-loss.
        Supported regression optimization objectives: minimize-rmse, minimize-mae, minimize-rmsle.
      budget_hours (int): Budget of node-hours to allocate to train the model
      transformations (Dict[str, Dict[str, str]]): Transformations to apply to each column

  Returns:
      aiplatform_v1alpha1.TrainingPipeline: The newly created training pipeline
  """
    return UCAIPService.get().create_training_pipeline(
        display_name, dataset_id, model_name, target_column, prediction_type,
        objective, budget_hours, transformations)
コード例 #4
0
def import_dataset(dataset_id: str) -> pandas.DataFrame:
    """Import an existing tables dataset to a Pandas DataFrame

  Args:
      dataset_id (str): ID of the dataset to import

  Returns:
      pandas.DataFrame
  """
    return UCAIPService.get().import_dataset(dataset_id)
コード例 #5
0
def predict(endpoint_id: str, instance: object) -> object:
    """Send a prediction request to a uCAIP model endpoint

  Args:
      endpoint_id (str): ID of the uCAIP endpoint
      instance (object): The prediction instance, should match the input format that the endpoint expects

  Returns:
      object: Prediction results from the model
  """
    return UCAIPService.get().predict_tables(endpoint_id, instance)
コード例 #6
0
def create_dataset(display_name: str,
                   dataframe: pandas.DataFrame = None,
                   file_path: str = None,
                   gcs_uri: str = None,
                   bigquery_uri: str = None) -> aiplatform_v1alpha1.Dataset:
    """Create a tabular dataset in uCAIP from a given source.
  One of dataframe, file_path, gcs_uri or bigquery_uri must be provided.

  Args:
      display_name (str): The user-defined name of the dataset
      dataframe (pandas.DataFrame, optional): Pandas DataFrame to import data from. Defaults to None.
      file_path (str, optional): Local file path to import data from. Defaults to None.
      gcs_uri (str, optional): URI of csv in GCS to import data from. Defaults to None.
      bigquery_uri (str, optional): URI of bigquery table to import data from. Defaults to None.

  Raises:
      APIError: Raised if no valid source is provided

  Returns:
      aiplatform_v1alpha1.Dataset: The newly created dataset
  """
    if dataframe is not None:
        return UCAIPService.get().create_dataset_from_dataframe(
            display_name, dataframe)
    elif file_path is not None:
        file_name = os.path.basename(file_path)
        if not os.path.exists(file_path):
            raise APIError("File path " + file_path + " not found.")
        with open(file_path, "rb") as f:
            return UCAIPService.get().create_dataset_from_file(
                display_name, file_name, f.read())
    elif gcs_uri is not None:
        return UCAIPService.get().create_dataset(display_name=display_name,
                                                 gcs_uri=gcs_uri)
    elif bigquery_uri is not None:
        return UCAIPService.get().create_dataset(display_name=display_name,
                                                 bigquery_uri=bigquery_uri)
    else:
        raise APIError(
            "One of { dataframe, file_path, gcs_uri, bigquery_uri } must be provided."
        )
コード例 #7
0
def export_saved_model(display_name: str, model_path: str,
                       framework: ModelFramework) -> aiplatform_v1alpha1.Model:
    """Export a custom pretrained model to uCAIP from a folder containing the saved model

  Args:
      display_name (str): The user-defined name of the model
      model_path (str): Local path to the folder containing saved model artifacts (e.g saved_model.pb)
      framework (jupyterlab_ucaip.types.ModelFramework): The framework used to train the model

  Returns:
      aiplatform_v1alpha1.Model: The newly created model
  """
    return UCAIPService.get().export_saved_model(display_name, model_path,
                                                 framework)
コード例 #8
0
def _get_all_endpoints(args):
    return UCAIPService.get().get_all_endpoints()
コード例 #9
0
def _check_deploying(args):
    return UCAIPService.get().get_deploying_endpoints(
        model_name=args["modelName"], endpoint_id=args["endpointId"])
コード例 #10
0
def _get_endpoints(args):
    return UCAIPService.get().get_endpoints(model_id=args["modelId"])
コード例 #11
0
def _get_pipelines(_):
    return UCAIPService.get().get_training_pipelines()
コード例 #12
0
def _get_pipeline(args):
    return UCAIPService.get().get_training_pipeline(args["pipelineId"])
コード例 #13
0
def _predict_tables(args):
    return UCAIPService.get().predict_tables(endpoint_id=args["endpointId"],
                                             instance=args["inputs"])
コード例 #14
0
def _deploy_model(args):
    UCAIPService.get().deploy_model(model_id=args["modelId"],
                                    machine_type=args["machineType"],
                                    endpoint_id=args["endpointId"])
    return {"success": True}
コード例 #15
0
def _list_datasets(_):
    return UCAIPService.get().get_datasets()
コード例 #16
0
def _delete_endpoint(args):
    UCAIPService.get().delete_endpoint(endpoint_id=args["endpointId"])
    return {"success": True}
コード例 #17
0
def _delete_model(args):
    UCAIPService.get().model_client.delete_model(name=args["modelId"])
    return {"success": True}
コード例 #18
0
def _delete_dataset(args):
    UCAIPService.get().dataset_client.delete_dataset(name=args["datasetId"])
    return {"success": True}
コード例 #19
0
def deploy_model(model_id: str,
                 machine_type: str,
                 min_replicas: int = 1,
                 endpoint_id: str = None):
  return UCAIPService.get().deploy_model(model_id, machine_type, min_replicas,
                                         endpoint_id)
コード例 #20
0
ファイル: handlers.py プロジェクト: mkalil/jupyter-extensions
def _check_deploying(args):
    return UCAIPService.get().check_deploying(model_name=args["modelName"])
コード例 #21
0
ファイル: handlers.py プロジェクト: mkalil/jupyter-extensions
def _deploy_model(args):
    UCAIPService.get().deploy_model(model_id=args["modelId"])
    return {"success": True}
コード例 #22
0
def _list_model_evaluations(args):
    return UCAIPService.get().get_model_evaluation(args["modelId"])
コード例 #23
0
def _get_dataset_details(args):
    return UCAIPService.get().get_dataset_details(args["datasetId"])
コード例 #24
0
def _undeploy_model(args):
    UCAIPService.get().undeploy_model(
        deployed_model_id=args["deployedModelId"],
        endpoint_id=args["endpointId"])
    return {"success": True}
コード例 #25
0
def _list_models(_):
    return UCAIPService.get().get_models()
コード例 #26
0
ファイル: handlers.py プロジェクト: mkalil/jupyter-extensions
def _table_info(args):
    return UCAIPService.get().get_table_specs(args["datasetId"])