Search in sources :

Example 6 with Provenance

use of com.oracle.labs.mlrg.olcut.provenance.Provenance in project tribuo by oracle.

the class OCIModel method createOCIModel.

/**
 * Creates an {@code OCIModel} by wrapping an OCI DS Model Deployment endpoint.
 * <p>
 * Uses the endpointURL as the value to hash for the trainer provenance.
 *
 * @param factory         The output factory to use.
 * @param featureMapping  The feature mapping between Tribuo names and model integer ids.
 * @param outputMapping   The output mapping between Tribuo outputs and model integer ids.
 * @param configFile      The OCI configuration file, if null use the default file.
 * @param profileName     The profile name in the OCI configuration file, if null uses the default profile.
 * @param endpointURL     The endpoint URL.
 * @param outputConverter The converter for the specified output type.
 * @param <T> The output type.
 * @return An OCIModel ready to score new inputs.
 */
public static <T extends Output<T>> OCIModel<T> createOCIModel(OutputFactory<T> factory, Map<String, Integer> featureMapping, Map<T, Integer> outputMapping, Path configFile, String profileName, String endpointURL, OCIOutputConverter<T> outputConverter) {
    try {
        ImmutableFeatureMap featureMap = ExternalModel.createFeatureMap(featureMapping.keySet());
        ImmutableOutputInfo<T> outputInfo = ExternalModel.createOutputInfo(factory, outputMapping);
        OffsetDateTime now = OffsetDateTime.now();
        ExternalTrainerProvenance trainerProvenance = new ExternalTrainerProvenance((endpointURL).getBytes(StandardCharsets.UTF_8));
        DatasetProvenance datasetProvenance = new ExternalDatasetProvenance("unknown-external-data", factory, false, featureMapping.size(), outputMapping.size());
        String[] endpoint = endpointURL.split("/");
        String domain = "https://" + endpoint[2] + "/";
        String modelDeploymentId = endpoint[3];
        HashMap<String, Provenance> runProvenance = new HashMap<>();
        runProvenance.put("configFile", new FileProvenance("configFile", configFile));
        runProvenance.put("endpointURL", new StringProvenance("endpointURL", endpointURL));
        runProvenance.put("modelDeploymentId", new StringProvenance("modelDeploymentId", modelDeploymentId));
        ModelProvenance provenance = new ModelProvenance(OCIModel.class.getName(), now, datasetProvenance, trainerProvenance, runProvenance);
        return new OCIModel<T>("oci-ds-model", provenance, featureMap, outputInfo, featureMapping, configFile, profileName, domain, modelDeploymentId, outputConverter);
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to load configuration from path " + configFile, e);
    }
}
Also used : ExternalDatasetProvenance(org.tribuo.interop.ExternalDatasetProvenance) ModelProvenance(org.tribuo.provenance.ModelProvenance) DatasetProvenance(org.tribuo.provenance.DatasetProvenance) ExternalTrainerProvenance(org.tribuo.interop.ExternalTrainerProvenance) FileProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.FileProvenance) Provenance(com.oracle.labs.mlrg.olcut.provenance.Provenance) StringProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance) ExternalDatasetProvenance(org.tribuo.interop.ExternalDatasetProvenance) ExternalTrainerProvenance(org.tribuo.interop.ExternalTrainerProvenance) HashMap(java.util.HashMap) StringProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance) ModelProvenance(org.tribuo.provenance.ModelProvenance) DatasetProvenance(org.tribuo.provenance.DatasetProvenance) ExternalDatasetProvenance(org.tribuo.interop.ExternalDatasetProvenance) IOException(java.io.IOException) FileProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.FileProvenance) OffsetDateTime(java.time.OffsetDateTime) ImmutableFeatureMap(org.tribuo.ImmutableFeatureMap)

Example 7 with Provenance

use of com.oracle.labs.mlrg.olcut.provenance.Provenance in project tribuo by oracle.

the class StripProvenance method cleanProvenance.

/**
 * Creates a new model provenance with the requested provenances stripped out.
 * @param old The old model provenance.
 * @param provenanceHash The hash of the provenance (if requested it can be written into the new provenance for tracking).
 * @param opt The program options.
 * @return A new model provenance.
 */
private static ModelProvenance cleanProvenance(ModelProvenance old, String provenanceHash, StripProvenanceOptions opt) {
    // Dataset provenance
    DatasetProvenance datasetProvenance;
    if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(DATASET)) {
        datasetProvenance = new EmptyDatasetProvenance();
    } else {
        datasetProvenance = old.getDatasetProvenance();
    }
    // Trainer provenance
    TrainerProvenance trainerProvenance;
    if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(TRAINER)) {
        trainerProvenance = new EmptyTrainerProvenance();
    } else {
        trainerProvenance = old.getTrainerProvenance();
    }
    // Instance provenance
    OffsetDateTime time;
    Map<String, Provenance> instanceProvenance;
    if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(INSTANCE)) {
        instanceProvenance = new HashMap<>();
        time = OffsetDateTime.MIN;
    } else {
        instanceProvenance = new HashMap<>(old.getInstanceProvenance().getMap());
        time = old.getTrainingTime();
    }
    if (opt.storeHash) {
        logger.info("Writing provenance hash into instance map.");
        instanceProvenance.put("original-provenance-hash", new HashProvenance(opt.hashType, "original-provenance-hash", provenanceHash));
    }
    boolean stripSystem;
    if (opt.removeProvenances.contains(ALL) || opt.removeProvenances.contains(SYSTEM)) {
        stripSystem = true;
    } else {
        stripSystem = false;
    }
    return new ModelProvenance(old.getClassName(), time, datasetProvenance, trainerProvenance, instanceProvenance, !stripSystem);
}
Also used : HashProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.HashProvenance) ObjectProvenance(com.oracle.labs.mlrg.olcut.provenance.ObjectProvenance) ModelProvenance(org.tribuo.provenance.ModelProvenance) HashProvenance(com.oracle.labs.mlrg.olcut.provenance.primitives.HashProvenance) DatasetProvenance(org.tribuo.provenance.DatasetProvenance) EmptyTrainerProvenance(org.tribuo.provenance.impl.EmptyTrainerProvenance) EmptyDatasetProvenance(org.tribuo.provenance.impl.EmptyDatasetProvenance) Provenance(com.oracle.labs.mlrg.olcut.provenance.Provenance) TrainerProvenance(org.tribuo.provenance.TrainerProvenance) EnsembleModelProvenance(org.tribuo.provenance.EnsembleModelProvenance) ListProvenance(com.oracle.labs.mlrg.olcut.provenance.ListProvenance) EmptyTrainerProvenance(org.tribuo.provenance.impl.EmptyTrainerProvenance) OffsetDateTime(java.time.OffsetDateTime) ModelProvenance(org.tribuo.provenance.ModelProvenance) EnsembleModelProvenance(org.tribuo.provenance.EnsembleModelProvenance) DatasetProvenance(org.tribuo.provenance.DatasetProvenance) EmptyDatasetProvenance(org.tribuo.provenance.impl.EmptyDatasetProvenance) EmptyTrainerProvenance(org.tribuo.provenance.impl.EmptyTrainerProvenance) TrainerProvenance(org.tribuo.provenance.TrainerProvenance) EmptyDatasetProvenance(org.tribuo.provenance.impl.EmptyDatasetProvenance)

Aggregations

Provenance (com.oracle.labs.mlrg.olcut.provenance.Provenance)7 StringProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.StringProvenance)5 DatasetProvenance (org.tribuo.provenance.DatasetProvenance)5 ModelProvenance (org.tribuo.provenance.ModelProvenance)5 OffsetDateTime (java.time.OffsetDateTime)4 ListProvenance (com.oracle.labs.mlrg.olcut.provenance.ListProvenance)3 ObjectProvenance (com.oracle.labs.mlrg.olcut.provenance.ObjectProvenance)3 HashMap (java.util.HashMap)3 ExternalDatasetProvenance (org.tribuo.interop.ExternalDatasetProvenance)3 ExternalTrainerProvenance (org.tribuo.interop.ExternalTrainerProvenance)3 OnnxModelMetadata (ai.onnxruntime.OnnxModelMetadata)2 OrtException (ai.onnxruntime.OrtException)2 HashProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.HashProvenance)2 LongProvenance (com.oracle.labs.mlrg.olcut.provenance.primitives.LongProvenance)2 IOException (java.io.IOException)2 URL (java.net.URL)2 ImmutableFeatureMap (org.tribuo.ImmutableFeatureMap)2 EnsembleModelProvenance (org.tribuo.provenance.EnsembleModelProvenance)2 TrainerProvenance (org.tribuo.provenance.TrainerProvenance)2 EmptyDatasetProvenance (org.tribuo.provenance.impl.EmptyDatasetProvenance)2