Package org.tribuo.interop.oci
Class OCIUtil
java.lang.Object
org.tribuo.interop.oci.OCIUtil
Utils for uploading and deploying models to OCI Data Science.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Configuration for OCI DS.static final class
Configuration for an OCI DS Model artifact.static final class
Configuration for an OCI DS Model Deployment.static enum
Enum for OCI model types. -
Method Summary
Modifier and TypeMethodDescriptionprotected static String
buildRuntimeYaml
(String condaName, String condaPath) Builds the runtime.yaml String from the supplied arguments, throwingIllegalArgumentException
if they are invalid.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) Creates an OCI DS model and uploads the model artifact.static <T extends Output<T>,
U extends Model<T> & ONNXExportable>
StringcreateModel
(U model, com.oracle.bmc.datascience.DataScienceClient client, com.fasterxml.jackson.databind.ObjectMapper mapper, OCIUtil.OCIModelArtifactConfig config) Creates an OCI DS model and uploads the model artifact.protected static Path
createModelArtifact
(Path onnxFile, OCIUtil.OCIModelArtifactConfig config) Creates the OCI DS model artifact zip file.static com.fasterxml.jackson.databind.ObjectMapper
Creates an ObjectMapper capable of parsing the OCI DS json.static String
deploy
(OCIUtil.OCIModelDeploymentConfig config, com.oracle.bmc.datascience.DataScienceClient client, com.fasterxml.jackson.databind.ObjectMapper mapper) Creates a Model deployment from an uploaded model.protected static boolean
validateCondaName
(String input) Validates that the name is a valid conda environment.protected static boolean
validateCondaPath
(String input) Validates that the path is a valid OCI object storage path.
-
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
andruntime.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 beONNXExportable
.- 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
andruntime.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 configurationclient
- 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
Builds the runtime.yaml String from the supplied arguments, throwingIllegalArgumentException
if they are invalid.- Parameters:
condaName
- The conda environment name.condaPath
- The conda environment path.- Returns:
- The runtime.yaml String.
-
validateCondaName
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
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.
-