使用mlflow的一组工具(参见https://mlflow.org)

mlflowhelper的Python项目详细描述


mlflowhelper

使用mlflow的一组工具(请参见https://mlflow.org

功能

  • 托管项目日志记录和加载
    • 自动项目日志记录和清理
    • 并行运行脚本时不覆盖文件
    • 正在加载项目
    • 日志和加载行为的中心配置
  • 通过对mlflowhelper.log_vars()
  • 的简单调用,记录all函数参数和局部变量

文档

管理工件记录和加载

一般功能
frommatplotlibimportpyplotaspltimportmlflowhelperwithmlflowhelper.start_run():withmlflowhelper.managed_artifact("plot.png")asartifact:fig=plt.figure()plt.plot([1,2,3],[1,2,3])fig.savefig(artifact.get_path())

此代码段自动记录创建的工件(plot.png)。 同时,if将在临时文件夹中创建工件,这样您就不必担心 并行运行脚本时覆盖它。 默认情况下,这也会在日志记录之后清理工件和临时文件夹。

您还可以在目录级别管理工件:

frommatplotlibimportpyplotaspltimportmlflowhelperwithmlflowhelper.start_run():withmlflowhelper.managed_artifact_dir("plots")asartifact_dir:# plot 1fig=plt.figure()plt.plot([1,2,3],[1,2,3])fig.savefig(artifact_dir.get_path("plot1.png"))# plot 2fig=plt.figure()plt.plot([1,2,3],[1,2,3])fig.savefig(artifact_dir.get_path("plot2.png"))

工件加载

您可能希望运行实验,但要重用来自不同运行的一些预计算工件(例如 作为预处理数据、训练模型等)。具体操作如下:

importmlflowhelperimportpandasaspdwithmlflowhelper.start_run():mlflowhelper.set_load(run_id="e1363f760b1e4ab3a9e93f856f2e9341",stages=["load_data"])# activate loading from previous runwithmlflowhelper.managed_artifact_dir("data.csv",stage="load_data")asartifact:ifartifact.loaded:# load artifactdata=pd.read_csv(artifact.get_path())else:# create and save artifactdata=pd.read_csv("/shared/dir/data.csv").sample(frac=1)data.to_csv(artifact.get_path())

同样,这也适用于目录:

importmlflowhelperimportpandasaspdmlflowhelper.set_load(run_id="e1363f760b1e4ab3a9e93f856f2e9341",stages=["load_data"])# activate loading from previous runwithmlflowhelper.start_run():withmlflowhelper.managed_artifact_dir("data",stage="load_data")asartifact_dir:train_path=artifact_dir.get_path("test.csv")test_path=artifact_dir.get_path("train.csv")ifartifact_dir.loaded:# load artifactstrain=pd.read_csv(train_path)test=pd.read_csv(test_path)else:data=pd.read_csv("/shared/dir/data.csv").sample(frac=1)train=data.iloc[:100,:]test=data.iloc[100:,:]# save artifactstrain.to_csv(train_path)test.to_csv(test_path)

注意:必须在mlflowhelper.managed_artifact(_dir)中设置stage参数才能启用加载。

中央日志和加载行为管理

日志记录和加载行为可以通过一种中心方式进行管理:

importmlflowhelperimportpandasaspdwithmlflowhelper.start_run():# activate loading the stage `load_data` from previous run `e1363f760b1e4ab3a9e93f856f2e9341`mlflowhelper.set_load(run_id="e1363f760b1e4ab3a9e93f856f2e9341",stages=["load_data"])# deactivate logging the stage `load_data`, in this case for example because it was loaded from a previous runmlflowhelper.set_skip_log(stages=["load_data"])withmlflowhelper.managed_artifact_dir("data",stage="load_data")asartifact_dir:train_path=artifact_dir.get_path("test.csv")test_path=artifact_dir.get_path("train.csv")ifartifact_dir.loaded:# load artifactstrain=pd.read_csv(train_path)test=pd.read_csv(test_path)else:data=pd.read_csv("/shared/dir/data.csv").sample(frac=1)train=data.iloc[:100,:]test=data.iloc[100:,:]# save artifactstrain.to_csv(train_path)test.to_csv(test_path)

注意:要集中管理stage参数,必须在mlflowhelper.managed_artifact(_dir)中设置。

简单的参数记录

^ EM1}$$MyFuelHelp>EEM>帮助您永远不要忘记日志参数,因为它很容易记录所有现有变量 使用mlflowhelper.log_vars

importmlflowhelperdefmain(param1,param2,param3="defaultvalue",verbose=0,*args,**kwargs):some_variable="x"withmlflowhelper.start_run():# mlflow.start_run() is also OK heremlflowhelper.log_vars(exclude=["verbose"])if__name__=='__main__':main("a","b",something_else=6)

这将记录:

{"param1":"a","param2":"b","param3":"defaultvalue","something_else":6}

其他

mlflowhelper

待办事项/想法

  • []检查加载是否可以跨实验工作
  • []清除本地工件(通过运行标记为已删除的API进行检查并删除其工件)
  • []通过基于实验和运行创建子目录来支持嵌套运行
  • []支持从中央缓存加载而不是从运行加载
  • []从加载的位置和内容自动登录
  • []为记录的阶段设置标记(在加载之前检查工件)
  • []考虑加载扩展:
    • []嵌套加载有意义吗(特定嵌套运行的不同加载)?
    • []混合加载有意义吗(从不同阶段的不同运行加载工件)?

此项目是使用PyScaffold 3.2.1建立的。详细信息和用法 有关pyscaffold的信息,请参见https://pyscaffold.org/

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
将PHP生成的公钥转换为Java公钥   java在服务中启动可取消的后台任务   java我能做这个通用的事情吗?   java Axis 1.4.1版在IBM上的部署为8.5版   java如何进行同步web服务调用   java从Spring控制器中的多个select获取值   java如何在JFrame中声明类(包含sapache Poi)的对象   jaxb反序列化XML以在Java中动态创建类   java如何为部署在Google云上的应用程序实现Google OAuth?   java我想了解libgdx的资产管理器   Java整数溢出   Windows任务管理器javaw。exe内存与Java任务控制   java如何让Android等待?