public class MlflowClient extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_EXPERIMENT_ID |
Constructor and Description |
---|
MlflowClient()
Return a default client based on the MLFLOW_TRACKING_URI environment variable.
|
MlflowClient(MlflowHostCredsProvider hostCredsProvider)
Create a new MlflowClient; users should prefer constructing ApiClients via
MlflowClient() or MlflowClient(String) if possible. |
MlflowClient(String trackingUri)
Instantiate a new client using the provided tracking uri.
|
Modifier and Type | Method and Description |
---|---|
String |
createExperiment(String experimentName)
Create a new experiment using the default artifact location provided by the server.
|
Service.RunInfo |
createRun()
Create a new run under the default experiment with no application name.
|
Service.RunInfo |
createRun(Service.CreateRun request)
Create a new run.
|
Service.RunInfo |
createRun(String experimentId)
Create a new run under the given experiment.
|
void |
deleteExperiment(String experimentId)
Mark an experiment and associated runs, params, metrics, etc.
|
void |
deleteRun(String runId)
Delete a run with the given ID.
|
void |
deleteTag(String runId,
String key)
Delete a tag on the run ID with a specific key.
|
File |
downloadArtifacts(String runId)
Return a local directory containing *all* artifacts within the run's artifact directory.
|
File |
downloadArtifacts(String runId,
String artifactPath)
Return a local file or directory containing all artifacts within the given artifactPath
within the run's root artifactDirectory.
|
File |
downloadLatestModelVersion(String modelName,
String stage)
:: experimental ::
this api may change or be removed in a future release without warning.
|
File |
downloadModelVersion(String modelName,
String version)
:: Experimental ::
This API may change or be removed in a future release without warning.
|
Service.GetExperiment.Response |
getExperiment(String experimentId) |
Optional<Service.Experiment> |
getExperimentByName(String experimentName) |
List<ModelRegistry.ModelVersion> |
getLatestVersions(String modelName)
:: Experimental ::
This API may change or be removed in a future release without warning.
|
List<ModelRegistry.ModelVersion> |
getLatestVersions(String modelName,
Iterable<String> stages)
:: Experimental ::
This API may change or be removed in a future release without warning.
|
List<Service.Metric> |
getMetricHistory(String runId,
String key) |
String |
getModelVersionDownloadUri(String modelName,
String version)
:: Experimental ::
This API may change or be removed in a future release without warning.
|
Service.Run |
getRun(String runId)
Get metadata, params, tags, and metrics for a run.
|
List<Service.FileInfo> |
listArtifacts(String runId)
List the artifacts immediately under the run's root artifact directory.
|
List<Service.FileInfo> |
listArtifacts(String runId,
String artifactPath)
List the artifacts immediately under the given artifactPath within the run's root artifact
directory.
|
List<Service.Experiment> |
listExperiments() |
List<Service.RunInfo> |
listRunInfos(String experimentId) |
void |
logArtifact(String runId,
File localFile)
Upload the given local file or directory to the run's root artifact directory.
|
void |
logArtifact(String runId,
File localFile,
String artifactPath)
Upload the given local file or directory to an artifactPath
within the run's root directory.
|
void |
logArtifacts(String runId,
File localDir)
Upload all files within the given local directory the run's root artifact directory.
|
void |
logArtifacts(String runId,
File localDir,
String artifactPath)
Upload all files within the given local director an artifactPath within the run's root
artifact directory.
|
void |
logBatch(String runId,
Iterable<Service.Metric> metrics,
Iterable<Service.Param> params,
Iterable<Service.RunTag> tags)
Log multiple metrics, params, and/or tags against a given run (argument runId).
|
void |
logMetric(String runId,
String key,
double value)
Log a new metric against the given run, as a key-value pair.
|
void |
logMetric(String runId,
String key,
double value,
long timestamp,
long step)
Log a new metric against the given run, as a key-value pair.
|
void |
logParam(String runId,
String key,
String value)
Log a parameter against the given run, as a key-value pair.
|
void |
renameExperiment(String experimentId,
String newName)
Update an experiment's name.
|
void |
restoreExperiment(String experimentId)
Restore an experiment marked for deletion.
|
void |
restoreRun(String runId)
Restore a deleted run with the given ID.
|
List<Service.RunInfo> |
searchRuns(List<String> experimentIds,
String searchFilter)
Deprecated.
As of 1.1.0 - please use
#searchRuns(List, String, ViewType, int) or
similar that returns a page of Run results. |
List<Service.RunInfo> |
searchRuns(List<String> experimentIds,
String searchFilter,
Service.ViewType runViewType)
Deprecated.
As of 1.1.0 - please use
#searchRuns(List, String, ViewType, int) or
similar that returns a page of Run results. |
RunsPage |
searchRuns(List<String> experimentIds,
String searchFilter,
Service.ViewType runViewType,
int maxResults)
Return runs from provided list of experiments that satisfy the search query.
|
RunsPage |
searchRuns(List<String> experimentIds,
String searchFilter,
Service.ViewType runViewType,
int maxResults,
List<String> orderBy)
Return runs from provided list of experiments that satisfy the search query.
|
RunsPage |
searchRuns(List<String> experimentIds,
String searchFilter,
Service.ViewType runViewType,
int maxResults,
List<String> orderBy,
String pageToken)
Return runs from provided list of experiments that satisfy the search query.
|
String |
sendGet(String path)
:: Experimental ::
This API may change or be removed in a future release without warning.
|
String |
sendPatch(String path,
String json) |
String |
sendPost(String path,
String json)
:: Experimental ::
This API may change or be removed in a future release without warning.
|
void |
setExperimentTag(String experimentId,
String key,
String value)
Log a new tag against the given experiment as a key-value pair.
|
void |
setTag(String runId,
String key,
String value)
Log a new tag against the given run, as a key-value pair.
|
void |
setTerminated(String runId)
Set the status of a run to be FINISHED at the current time.
|
void |
setTerminated(String runId,
Service.RunStatus status)
Set the status of a run to be completed at the current time.
|
void |
setTerminated(String runId,
Service.RunStatus status,
long endTime)
Set the status of a run to be completed at the given endTime.
|
protected static final String DEFAULT_EXPERIMENT_ID
public MlflowClient()
public MlflowClient(String trackingUri)
public MlflowClient(MlflowHostCredsProvider hostCredsProvider)
MlflowClient()
or MlflowClient(String)
if possible.public Service.Run getRun(String runId)
public List<Service.Metric> getMetricHistory(String runId, String key)
public Service.RunInfo createRun()
public Service.RunInfo createRun(String experimentId)
public Service.RunInfo createRun(Service.CreateRun request)
import org.mlflow.api.proto.Service.CreateRun; CreateRun.Builder request = CreateRun.newBuilder(); request.setExperimentId(experimentId); request.setSourceVersion("my-version"); createRun(request.build());
public List<Service.RunInfo> listRunInfos(String experimentId)
public List<Service.RunInfo> searchRuns(List<String> experimentIds, String searchFilter)
#searchRuns(List, String, ViewType, int)
or
similar that returns a page of Run results.experimentIds
- List of experiment IDs.searchFilter
- SQL compatible search query string. Format of this query string is
similar to that specified on MLflow UI.
Example : "params.model = 'LogisticRegression' and metrics.acc = 0.9"
If null, the result will be equivalent to having an empty search filter.public List<Service.RunInfo> searchRuns(List<String> experimentIds, String searchFilter, Service.ViewType runViewType)
#searchRuns(List, String, ViewType, int)
or
similar that returns a page of Run results.experimentIds
- List of experiment IDs.searchFilter
- SQL compatible search query string. Format of this query string is
similar to that specified on MLflow UI.
Example : "params.model = 'LogisticRegression' and metrics.acc != 0.9"
If null, the result will be equivalent to having an empty search filter.runViewType
- ViewType for expected runs. One of (ACTIVE_ONLY, DELETED_ONLY, ALL)
If null, only runs with viewtype ACTIVE_ONLY will be searched.public RunsPage searchRuns(List<String> experimentIds, String searchFilter, Service.ViewType runViewType, int maxResults)
experimentIds
- List of experiment IDs.searchFilter
- SQL compatible search query string. Format of this query string is
similar to that specified on MLflow UI.
Example : "params.model = 'LogisticRegression' and metrics.acc != 0.9"
If null, the result will be equivalent to having an empty search filter.runViewType
- ViewType for expected runs. One of (ACTIVE_ONLY, DELETED_ONLY, ALL)
If null, only runs with viewtype ACTIVE_ONLY will be searched.maxResults
- Maximum number of runs desired in one page.public RunsPage searchRuns(List<String> experimentIds, String searchFilter, Service.ViewType runViewType, int maxResults, List<String> orderBy)
experimentIds
- List of experiment IDs.searchFilter
- SQL compatible search query string. Format of this query string is
similar to that specified on MLflow UI.
Example : "params.model = 'LogisticRegression' and metrics.acc != 0.9"
If null, the result will be equivalent to having an empty search filter.runViewType
- ViewType for expected runs. One of (ACTIVE_ONLY, DELETED_ONLY, ALL)
If null, only runs with viewtype ACTIVE_ONLY will be searched.maxResults
- Maximum number of runs desired in one page.orderBy
- List of properties to order by. Example: "metrics.acc DESC".public RunsPage searchRuns(List<String> experimentIds, String searchFilter, Service.ViewType runViewType, int maxResults, List<String> orderBy, String pageToken)
experimentIds
- List of experiment IDs.searchFilter
- SQL compatible search query string. Format of this query string is
similar to that specified on MLflow UI.
Example : "params.model = 'LogisticRegression' and metrics.acc != 0.9"
If null, the result will be equivalent to having an empty search filter.runViewType
- ViewType for expected runs. One of (ACTIVE_ONLY, DELETED_ONLY, ALL)
If null, only runs with viewtype ACTIVE_ONLY will be searched.maxResults
- Maximum number of runs desired in one page.orderBy
- List of properties to order by. Example: "metrics.acc DESC".pageToken
- String token specifying the next page of results. It should be obtained from
a call to searchRuns(List, String)
.public List<Service.Experiment> listExperiments()
public Service.GetExperiment.Response getExperiment(String experimentId)
public Optional<Service.Experiment> getExperimentByName(String experimentName)
public String createExperiment(String experimentName)
experimentName
- Name of the experiment. This must be unique across all experiments.public void deleteExperiment(String experimentId)
public void restoreExperiment(String experimentId)
public void renameExperiment(String experimentId, String newName)
public void deleteRun(String runId)
public void restoreRun(String runId)
public void logParam(String runId, String key, String value)
public void logMetric(String runId, String key, double value)
runId
- The ID of the run in which to record the metric.key
- The key identifying the metric for which to record the specified value.value
- The value of the metric.public void logMetric(String runId, String key, double value, long timestamp, long step)
runId
- The ID of the run in which to record the metric.key
- The key identifying the metric for which to record the specified value.value
- The value of the metric.timestamp
- The timestamp at which to record the metric value.step
- The step at which to record the metric value.public void setExperimentTag(String experimentId, String key, String value)
experimentId
- The ID of the experiment on which to set the tagkey
- The key used to identify the tag.value
- The value of the tag.public void setTag(String runId, String key, String value)
runId
- The ID of the run on which to set the tagkey
- The key used to identify the tag.value
- The value of the tag.public void deleteTag(String runId, String key)
runId
- String ID of the runkey
- Name of the tagpublic void logBatch(String runId, Iterable<Service.Metric> metrics, Iterable<Service.Param> params, Iterable<Service.RunTag> tags)
public void setTerminated(String runId)
public void setTerminated(String runId, Service.RunStatus status)
public void setTerminated(String runId, Service.RunStatus status, long endTime)
public String sendGet(String path)
public String sendPost(String path, String json)
public void logArtifact(String runId, File localFile)
logArtifact(runId, "/my/localModel") listArtifacts(runId) // returns "localModel"
runId
- Run ID of an existing MLflow run.localFile
- File or directory to upload. Must exist.public void logArtifact(String runId, File localFile, String artifactPath)
logArtifact(runId, "/my/localModel", "model") listArtifacts(runId, "model") // returns "model/localModel"(i.e., the localModel file is now available in model/localModel). If logging a directory, the directory is renamed to artifactPath.
runId
- Run ID of an existing MLflow run.localFile
- File or directory to upload. Must exist.artifactPath
- Artifact path relative to the run's root directory. Should NOT
start with a /.public void logArtifacts(String runId, File localDir)
logArtifacts(runId, "/my/local/dir") listArtifacts(runId) // returns "file1" and "file2"
runId
- Run ID of an existing MLflow run.localDir
- Directory to upload. Must exist, and must be a directory (not a simple file).public void logArtifacts(String runId, File localDir, String artifactPath)
logArtifacts(runId, "/my/local/dir", "model") listArtifacts(runId, "model") // returns "model/file1" and "model/file2"(i.e., the contents of the local directory are now available in model/).
runId
- Run ID of an existing MLflow run.localDir
- Directory to upload. Must exist, and must be a directory (not a simple file).artifactPath
- Artifact path relative to the run's root directory. Should NOT
start with a /.public List<Service.FileInfo> listArtifacts(String runId)
runId
- Run ID of an existing MLflow run.public List<Service.FileInfo> listArtifacts(String runId, String artifactPath)
runId
- Run ID of an existing MLflow run.artifactPath
- Artifact path relative to the run's root directory. Should NOT
start with a /.public File downloadArtifacts(String runId)
runId
- Run ID of an existing MLflow run.public File downloadArtifacts(String runId, String artifactPath)
downloadArtifacts(runId, "model") // returns a local directory containing "file1" and "file2" downloadArtifacts(runId, "model/file1") // returns a local *file* with the contents of file1.Note that this will download the entire subdirectory path, and so may be expensive if the subdirectory has a lot of data.
runId
- Run ID of an existing MLflow run.artifactPath
- Artifact path relative to the run's root directory. Should NOT
start with a /.public List<ModelRegistry.ModelVersion> getLatestVersions(String modelName)
import org.mlflow.api.proto.ModelRegistry.ModelVersion;
List <ModelVersion>
detailsList = getLatestVersions("model");
for (ModelVersion details : detailsList) {
System.out.println("Model Name: " + details.getModelVersion()
.getRegisteredModel()
.getName());
System.out.println("Model Version: " + details.getModelVersion().getVersion());
System.out.println("Current Stage: " + details.getCurrentStage());
}
modelName
- The name of the modelModelRegistry.ModelVersion
public List<ModelRegistry.ModelVersion> getLatestVersions(String modelName, Iterable<String> stages)
import org.mlflow.api.proto.ModelRegistry.ModelVersion; List<ModelVersion>
detailsList = getLatestVersions("model", Lists.newArrayList<String>
("Staging")); for (ModelVersion details : detailsList) { System.out.println("Model Name: " + details.getModelVersion() .getRegisteredModel() .getName()); System.out.println("Model Version: " + details.getModelVersion().getVersion()); System.out.println("Current Stage: " + details.getCurrentStage()); }
modelName
- The name of the modelstages
- A list of stagesModelRegistry.ModelVersion
public String getModelVersionDownloadUri(String modelName, String version)
String modelUri = getModelVersionDownloadUri("model", 0);
modelName
- The name of the modelversion
- The version number of the modelpublic File downloadModelVersion(String modelName, String version)
File modelVersionFile = downloadModelVersion("model", 0);
modelName
- The name of the modelversion
- The version number of the modelFile
) containing model artifactspublic File downloadLatestModelVersion(String modelName, String stage)
File modelVersionFile = downloadLatestModelVersion("model", "Staging");(i.e., the contents of the local directory are now available).
modelName
- The name of the modelstage
- The name of the stageFile
) containing model artifactsCopyright © 2020. All rights reserved.