使用 Kedro 挂钩将 git_sha 作为参数记录在 Mlflow 上

Logging the git_sha as a parameter on Mlflow using Kedro hooks

我想在 Mlflow 上记录 git_sha 参数,如 documentation 中所示。在我看来,仅 运行 下面的代码部分就足以让 git_sha 登录到 Mlflow UI 中。我说得对吗?

@hook_impl
    def before_pipeline_run(self, run_params: Dict[str, Any]) -> None:
        """Hook implementation to start an MLflow run
        with the same run_id as the Kedro pipeline run.
        """
        mlflow.start_run(run_name=run_params["run_id"])
        mlflow.log_params(run_params)

但这不起作用,因为我只得到了 git_sha 参数。当我查看 hooks specs 时,似乎此参数不属于 run_params(不再是?)

有没有办法获取 git sha(也许来自上下文日志?)并将其添加到记录的参数中?

提前致谢!

虽然强烈建议将 git 与 Kedro 一起使用,但这不是必需的,因此 Kedro 的任何部分(除了 kedro-starters 如果我们是迂腐的)都不是 'aware' git.

在您的 before_pipeline_hook 中,您可以很容易地检索信息 via the techniques documented here。对于整个代码库来说这似乎微不足道,如果您想说提供特定于管道的哈希值,则涉及更多。