gpt4 book ai didi

python - Azure ML Pipeline禁止文件上传

转载 作者:行者123 更新时间:2023-12-03 02:05:05 25 4
gpt4 key购买 nike

使用适用于 Azure ML 的 Python SDK V2 创建管道时,我当前工作目录的所有内容都会上传。我可以将某些正在上传的文件列入黑名单吗?例如。我使用 load_env(".env") 来读取一些凭据,但我不希望它被上传。

目录内容:

./src
utilities.py # contains helper function to get Azure credentials
.env # contains credentials
conda.yaml
script.py

最小管道示例:

import mldesigner
import mlflow
from azure.ai.ml import MLClient
from azure.ai.ml.dsl import pipeline

from src.utilities import get_credential

credential = get_credential() # calls `load_env(".env") locally
ml_client = MLClient(
credential=credential,
subscription_id="foo",
resource_group_name="bar",
workspace_name="foofoo",
)


@mldesigner.command_component(
name="testcomponent",
display_name="Test Component",
description="Test Component description.",
environment=dict(
conda_file="./conda.yaml",
image="mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04",
),
)
def test_component():
mlflow.log_metric("metric", 0)


cluster_name = "foobar"


@pipeline(default_compute=cluster_name)
def pipe():
test_component()


pipeline_job = pipe()

pipeline_job = ml_client.jobs.create_or_update(
pipeline_job, experiment_name="pipeline_samples"
)

运行 python script.py 后,将创建管道作业并在 Azure ML 中运行。如果我查看 Azure ML UI 中的管道并检查测试组件和选项卡代码,我会找到包括.env在内的所有源文件。

如何在创建管道作业时阻止使用 SDK 上传此文件?

最佳答案

您可以在工作目录中使用 .gitignore.amlignore 文件来指定要忽略的文件和目录。默认情况下运行管道时,不会包含这些文件。

这是document以防止不必要的文件。

# Get all files in the current working directory
all_files = os.listdir()
# Remove ".env" file from the list of files
all_files.remove(".env")

@pipeline(default_compute=cluster_name, files=all_files)
def pipe():
test_component()


pipeline_job = pipe()

pipeline_job = ml_client.jobs.create_or_update(
pipeline_job, experiment_name="pipeline_samples"
)

关于python - Azure ML Pipeline禁止文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75106061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com