mlflow_util.py 852 B

123456789101112131415161718192021222324252627
  1. import mlflow
  2. import os
  3. import numpy as np
  4. import urllib.parse
  5. def get_prev_run(function, params, tags=None, git_commit=None):
  6. query = 'attributes.status = "FINISHED"'
  7. query += ' and tags."function" = "{}"'.format(function)
  8. for key, val in params.items():
  9. query += ' and '
  10. query += 'params.{} = "{}"'.format(key, val)
  11. if tags:
  12. for key, val in tags.items():
  13. query += ' and '
  14. query += 'tags."{}" = "{}"'.format(key, val)
  15. runs = mlflow.search_runs(filter_string=query)
  16. if runs.empty:
  17. return None
  18. else:
  19. # TODO should check git_commit
  20. return mlflow.tracking.MlflowClient().get_run(
  21. runs.iloc[0].loc['run_id'])
  22. def load_uri(uri):
  23. url_data = urllib.parse.urlparse(uri)
  24. path = urllib.parse.unquote(url_data.path)
  25. return np.load(path)