Skip to content

Commit

Permalink
Add model_uuid to Java Model (#5165)
Browse files Browse the repository at this point in the history
* add model_uuid

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* rename

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* test

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* uncomment

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* add test

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* update tests

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* set model uuid

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>

* address comments

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
  • Loading branch information
harupy committed Dec 15, 2021
1 parent f9b5745 commit 2668809
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import org.mlflow.Flavor;
import org.mlflow.utils.FileUtils;
import org.mlflow.utils.SerializationUtils;
Expand Down Expand Up @@ -41,6 +42,9 @@ public static class Signature {
@JsonProperty("input_example")
private Map<String, Object> input_example;

@JsonProperty("model_uuid")
private String modelUuid;

private String rootPath;

/**
Expand Down Expand Up @@ -82,6 +86,11 @@ public Optional<String> getRunId() {
return Optional.ofNullable(this.runId);
}

/** @return The MLflow model's uuid */
public Optional<String> getModelUuid() {
return Optional.ofNullable(this.modelUuid);
}

/** @return The path to the root directory of the MLflow model */
public Optional<String> getRootPath() {
return Optional.ofNullable(this.rootPath);
Expand Down
13 changes: 13 additions & 0 deletions mlflow/java/scoring/src/test/java/org/mlflow/ModelTest.java
Expand Up @@ -17,6 +17,19 @@ public void testModelIsLoadedFromYamlUsingConfigPathCorrectly() {
Model model = Model.fromConfigPath(configPath);
Assert.assertTrue(model.getFlavor(MLeapFlavor.FLAVOR_NAME, MLeapFlavor.class).isPresent());
Assert.assertTrue(model.getUtcTimeCreated().isPresent());
Assert.assertTrue(model.getModelUuid().isPresent());
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Encountered an exception while reading the model from a configuration path!");
}
}

@Test
public void testModelIsLoadedCorrectlyWhenModelUuidDoesNotExist() {
String configPath = getClass().getResource("sample_model_root/MLmodel.no.model_uuid").getFile();
try {
Model model = Model.fromConfigPath(configPath);
Assert.assertFalse(model.getModelUuid().isPresent());
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Encountered an exception while reading the model from a configuration path!");
Expand Down
Expand Up @@ -5,7 +5,7 @@ flavors:
utc_time_created: '2018-08-10 18:34:28.720095'
run_id: c228016dea284522882b657d91eeffa6
artifact_path: model

model_uuid: 4ab08bf9d91e4535bc2719f9210840c3
signature:
inputs: '[{"name": "fixed acidity", "type": "double"}, {"name": "volatile acidity",
"type": "double"}, {"name": "citric acid", "type": "double"}, {"name": "residual
Expand Down
@@ -0,0 +1,7 @@
flavors:
mleap:
mleap_version: 0.8.1
model_data: mleap/model
utc_time_created: "2018-08-10 18:34:28.720095"
run_id: c228016dea284522882b657d91eeffa6
artifact_path: model
2 changes: 0 additions & 2 deletions mlflow/mleap.py
Expand Up @@ -182,8 +182,6 @@ def save_model(
model. The given example will be converted to a Pandas DataFrame and then
serialized to json using the Pandas split-oriented format. Bytes are
base64-encoded.
"""
if mlflow_model is None:
mlflow_model = Model()
Expand Down

0 comments on commit 2668809

Please sign in to comment.