【问题标题】:MLflow proxied artifact access: Unable to locate credentialsMLflow 代理工件访问:无法找到凭据
【发布时间】:2022-11-10 09:45:21
【问题描述】:

我正在使用 MLflow 来跟踪我的实验。我正在使用 S3 存储桶作为工件存储。为了访问它,我想使用代理工件访问,如docs 中所述,但这对我不起作用,因为它在本地查找凭据(但服务器应该处理这个)。

预期行为

如文档中所述,我希望在本地,我不需要指定我的 AWS 凭证,因为服务器会为我处理这个。来自docs

这消除了允许最终用户对远程对象存储(例如,s3、adls、gcs、hdfs)进行直接路径访问以进行工件处理的需要,并消除了最终用户提供访问凭据以与底层交互的需要对象存储。

实际行为/错误

每当我在我的机器上运行实验时,我都会遇到以下错误:

botocore.exceptions.NoCredentialsError: Unable to locate credentials

所以错误是本地的。但是,这不应该发生,因为服务器应该处理身份验证,而不是我需要在本地存储我的凭据。另外,我希望我什至不需要库 boto3 在本地。

尝试过的解决方案

我知道我需要创建一个新实验,因为现有实验可能仍使用 this SO answer 以及 docs 中的注释中提出的不同工件位置。创建一个新实验并没有解决我的错误。每当我运行实验时,我都会在控制台中得到一个明确的日志来验证这一点:

INFO mlflow.tracking.fluent: Experiment with name 'test' does not exist. Creating a new experiment.

相关问题(#1#2)指的是不同的场景,也是described in the docs

服务器配置

服务器在具有以下配置的 kubernetes pod 上运行:

mlflow server \
    --host 0.0.0.0 \
    --port 5000 \
    --backend-store-uri postgresql://user:pw@endpoint \
    --artifacts-destination s3://my_bucket/artifacts \
    --serve-artifacts \
    --default-artifact-root s3://my_bucket/artifacts \

我希望我的配置是正确的,查看文档 page 1page 2

如果我将端口转发到本地机器,我可以看到 mlflow UI。由于我在上面发送的错误,我还看到实验运行失败。

我的代码

我的代码中失败的相关部分是模型的日志记录:

mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("test2)

...

# this works
mlflow.log_params(hyperparameters)
                        
model = self._train(model_name, hyperparameters, X_train, y_train)
y_pred = model.predict(X_test)
self._evaluate(y_test, y_pred)

# this fails with the error from above
mlflow.sklearn.log_model(model, "artifacts")

问题

我可能忽略了一些东西。是否需要在本地表明我想使用代理的人工访问?如果是,我该怎么做?有什么我错过的吗?

完整回溯

  File /dir/venv/lib/python3.9/site-packages/mlflow/models/model.py", line 295, in log
    mlflow.tracking.fluent.log_artifacts(local_path, artifact_path)
  File /dir/venv/lib/python3.9/site-packages/mlflow/tracking/fluent.py", line 726, in log_artifacts
    MlflowClient().log_artifacts(run_id, local_dir, artifact_path)
  File /dir/venv/lib/python3.9/site-packages/mlflow/tracking/client.py", line 1001, in log_artifacts
    self._tracking_client.log_artifacts(run_id, local_dir, artifact_path)
  File /dir/venv/lib/python3.9/site-packages/mlflow/tracking/_tracking_service/client.py", line 346, in log_artifacts
    self._get_artifact_repo(run_id).log_artifacts(local_dir, artifact_path)
  File /dir/venv/lib/python3.9/site-packages/mlflow/store/artifact/s3_artifact_repo.py", line 141, in log_artifacts
    self._upload_file(
  File /dir/venv/lib/python3.9/site-packages/mlflow/store/artifact/s3_artifact_repo.py", line 117, in _upload_file
    s3_client.upload_file(Filename=local_file, Bucket=bucket, Key=key, ExtraArgs=extra_args)
  File /dir/venv/lib/python3.9/site-packages/boto3/s3/inject.py", line 143, in upload_file
    return transfer.upload_file(
  File /dir/venv/lib/python3.9/site-packages/boto3/s3/transfer.py", line 288, in upload_file
    future.result()
  File /dir/venv/lib/python3.9/site-packages/s3transfer/futures.py", line 103, in result
    return self._coordinator.result()
  File /dir/venv/lib/python3.9/site-packages/s3transfer/futures.py", line 266, in result
    raise self._exception
  File /dir/venv/lib/python3.9/site-packages/s3transfer/tasks.py", line 139, in __call__
    return self._execute_main(kwargs)
  File /dir/venv/lib/python3.9/site-packages/s3transfer/tasks.py", line 162, in _execute_main
    return_value = self._main(**kwargs)
  File /dir/venv/lib/python3.9/site-packages/s3transfer/upload.py", line 758, in _main
    client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
  File /dir/venv/lib/python3.9/site-packages/botocore/client.py", line 508, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File /dir/venv/lib/python3.9/site-packages/botocore/client.py", line 898, in _make_api_call
    http, parsed_response = self._make_request(
  File /dir/venv/lib/python3.9/site-packages/botocore/client.py", line 921, in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
  File /dir/venv/lib/python3.9/site-packages/botocore/endpoint.py", line 119, in make_request
    return self._send_request(request_dict, operation_model)
  File /dir/venv/lib/python3.9/site-packages/botocore/endpoint.py", line 198, in _send_request
    request = self.create_request(request_dict, operation_model)
  File /dir/venv/lib/python3.9/site-packages/botocore/endpoint.py", line 134, in create_request
    self._event_emitter.emit(
  File /dir/venv/lib/python3.9/site-packages/botocore/hooks.py", line 412, in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
  File /dir/venv/lib/python3.9/site-packages/botocore/hooks.py", line 256, in emit
    return self._emit(event_name, kwargs)
  File /dir/venv/lib/python3.9/site-packages/botocore/hooks.py", line 239, in _emit
    response = handler(**kwargs)
  File /dir/venv/lib/python3.9/site-packages/botocore/signers.py", line 103, in handler
    return self.sign(operation_name, request)
  File /dir/venv/lib/python3.9/site-packages/botocore/signers.py", line 187, in sign
    auth.add_auth(request)
  File /dir/venv/lib/python3.9/site-packages/botocore/auth.py", line 407, in add_auth
    raise NoCredentialsError()
botocore.exceptions.NoCredentialsError: Unable to locate credentials

【问题讨论】:

标签: amazon-web-services machine-learning amazon-s3 boto3 mlflow


【解决方案1】:

问题是服务器在错误的运行参数上运行,--default-artifact-root 需要删除或设置为mlflow-artifacts:/

来自mlflow server --help

  --default-artifact-root URI  Directory in which to store artifacts for any
                               new experiments created. For tracking server
                               backends that rely on SQL, this option is
                               required in order to store artifacts. Note that
                               this flag does not impact already-created
                               experiments with any previous configuration of
                               an MLflow server instance. By default, data
                               will be logged to the mlflow-artifacts:/ uri
                               proxy if the --serve-artifacts option is
                               enabled. Otherwise, the default location will
                               be ./mlruns.

【讨论】:

    【解决方案2】:

    有同样的问题和接受的答案似乎并不能解决我的问题。
    删除或设置 mlflow-artifacts 而不是 s3 都不适合我。此外,它给了我一个错误,因为我有一个远程backend-store-uri,我需要在运行 mlflow 服务器时设置default-artifact-root

    我是如何解决的,我发现错误是不言自明的,它指出它无法找到凭证的原因是下面的 mlflow 使用 boto3 来完成所有事务。由于我已经在.env 中设置了我的环境变量,因此只需加载文件对我来说就足够了并且解决了这个问题。如果您有类似的情况,那么只需在启动 mlflow 服务器之前运行以下命令,

    set -a
    source .env
    set +a
    

    这将加载环境变量,你会很高兴。

    笔记:

    • 我将远程服务器用于后端和工件存储,主要是 postgres 和 minio。
    • 对于远程后端 backend-store-uri 是必须的,否则您将无法启动您的 mlflow 服务器

    【讨论】:

      猜你喜欢
      • 2018-12-07
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-12
      • 2021-04-25
      • 1970-01-01
      相关资源
      最近更新 更多