Class OCIUtil

java.lang.Object
org.tribuo.interop.oci.OCIUtil

public abstract class OCIUtil extends Object
Utils for uploading and deploying models to OCI Data Science.
  • Method Details

    • createObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper createObjectMapper()
      Creates an ObjectMapper capable of parsing the OCI DS json.
      Returns:
      A configured ObjectMapper.
    • createModel

      public static <T extends Output<T>, U extends Model<T> & ONNXExportable> String createModel(U model, com.oracle.bmc.datascience.DataScienceClient client, com.fasterxml.jackson.databind.ObjectMapper mapper, OCIUtil.OCIModelArtifactConfig config) throws IOException
      Creates an OCI DS model and uploads the model artifact.

      Uses ORT as the deployment environment, and inserts a suitable score.py and runtime.yaml which assume the input is a plain multi-dimensional json array of floats, and the output is a json object with a single field called "predictions".

      Type Parameters:
      T - The model output type.
      U - The model class, must be ONNXExportable.
      Parameters:
      model - The model to deploy.
      client - The DS Client to handle authentication.
      mapper - The object mapper for writing out the JSON results.
      config - The upload configuration.
      Returns:
      The model ID.
      Throws:
      IOException - If the zip file could not be created, or it would not upload to OCI DS.
    • createModelArtifact

      protected static Path createModelArtifact(Path onnxFile, OCIUtil.OCIModelArtifactConfig config) throws IOException
      Creates the OCI DS model artifact zip file.
      Parameters:
      onnxFile - The ONNX file to create.
      config - The model artifact configuration.
      Returns:
      The path referring to the zip file.
      Throws:
      IOException - If the file could not be created or the ONNX file could not be read.
    • createModel

      public static String createModel(Path onnxFile, ModelProvenance provenance, OCIUtil.OCIModelType modelType, com.oracle.bmc.datascience.DataScienceClient client, com.fasterxml.jackson.databind.ObjectMapper mapper, OCIUtil.OCIModelArtifactConfig config) throws IOException
      Creates an OCI DS model and uploads the model artifact.

      Uses ORT as the deployment environment, and inserts a suitable score.py and runtime.yaml which assume the input is a plain multi-dimensional json array of floats, and the output is a json object with a single field called "predictions".

      Parameters:
      onnxFile - The ONNX file to deploy.
      provenance - The model provenance for storing in the model catalog.
      modelType - The model type.
      client - The DS Client to handle authentication.
      mapper - The object mapper for writing out the JSON results.
      config - The upload configuration.
      Returns:
      The model ID.
      Throws:
      IOException - If the zip file could not be created, or it would not upload to OCI DS.
    • deploy

      public static String deploy(OCIUtil.OCIModelDeploymentConfig config, com.oracle.bmc.datascience.DataScienceClient client, com.fasterxml.jackson.databind.ObjectMapper mapper) throws IOException
      Creates a Model deployment from an uploaded model.
      Parameters:
      config - The model deployment configuration
      client - The DS Client.
      mapper - The object mapper for converting between JSON and objects. Must be configured with the appropriate filters.
      Returns:
      The model deployment URL.
      Throws:
      IOException - If the deployment failed.
    • buildRuntimeYaml

      protected static String buildRuntimeYaml(String condaName, String condaPath)
      Builds the runtime.yaml String from the supplied arguments, throwing IllegalArgumentException if they are invalid.
      Parameters:
      condaName - The conda environment name.
      condaPath - The conda environment path.
      Returns:
      The runtime.yaml String.
    • validateCondaName

      protected static boolean validateCondaName(String input)
      Validates that the name is a valid conda environment.
      Parameters:
      input - The input to check.
      Returns:
      True if it's a valid environment name.
    • validateCondaPath

      protected static boolean validateCondaPath(String input)
      Validates that the path is a valid OCI object storage path.

      This check is intentionally more restrictive than necessary.

      Parameters:
      input - The input to check.
      Returns:
      True if it's a valid environment name.