如何在 Sagemaker 的处理步骤中将包上传到实例?
How to upload packages to an instance in a Processing step in Sagemaker?
我必须对某些数据进行大规模特征工程。我目前的方法是使用 SKLearnProcessor
启动一个实例,然后通过选择更大的实例大小或增加实例数量来扩展作业。我需要使用一些默认情况下未安装在 Sagemaker 实例上的软件包,因此我想使用 .whl 文件安装这些软件包。
另一个障碍是 Sagemaker 角色无法访问互联网。
import boto3
import sagemaker
from sagemaker import get_execution_role
from sagemaker.sklearn.processing import SKLearnProcessor
sess = sagemaker.Session()
sess.default_bucket()
region = boto3.session.Session().region_name
role = get_execution_role()
sklearn_processor = SKLearnProcessor(framework_version='0.20.0',
role=role,
sagemaker_session = sess,
instance_type="ml.t3.medium",
instance_count=1)
sklearn_processor.run(code='script.py')
尝试的解决方案:
- 将包上传到 CodeCommit 存储库并将存储库克隆到 SKLearnProcessor 实例中。失败,错误
fatal: could not read Username for 'https://git-codecommit.eu-west-1.amazonaws.com': No such device or address
。我尝试将 repo 克隆到 sagemaker notebook 实例中并且它有效,所以它不是我的脚本的问题。
- 使用 bash 脚本通过 CLI 从 s3 复制包。我使用的 bash 脚本基于 this post。但是包永远不会被复制,也不会抛出错误消息。
- 也研究了使用软件包
s3fs
,但它似乎不适合复制 wheel 文件。
备选方案
我的客户对从自定义 docker 图像启动容器犹豫不决。还有其他选择吗?
2. Use a bash script to copy the packages from s3 using the CLI. The bash script I used is based off this post. But the packages never get copied, and an error message is not thrown.
这种方法似乎很合理。
您最好将 SKLearnProcessor
上的 command
字段覆盖为 /bin/bash
,运行 一个 bash 脚本,例如 install_and_run_my_python_code.sh
安装包含您的 python 依赖项的轮子,然后 运行 是您的主要 python 入口点脚本。
此外,您可以使用 ProcessingInput 下载代码,而不是使用 bash 脚本中的 AWS CLI 调用,而不是使用 AWS S3 调用在脚本中下载代码,这就是 SKLearnProcessor
在所有实例中下载入口点 script.py
代码的作用。
我必须对某些数据进行大规模特征工程。我目前的方法是使用 SKLearnProcessor
启动一个实例,然后通过选择更大的实例大小或增加实例数量来扩展作业。我需要使用一些默认情况下未安装在 Sagemaker 实例上的软件包,因此我想使用 .whl 文件安装这些软件包。
另一个障碍是 Sagemaker 角色无法访问互联网。
import boto3
import sagemaker
from sagemaker import get_execution_role
from sagemaker.sklearn.processing import SKLearnProcessor
sess = sagemaker.Session()
sess.default_bucket()
region = boto3.session.Session().region_name
role = get_execution_role()
sklearn_processor = SKLearnProcessor(framework_version='0.20.0',
role=role,
sagemaker_session = sess,
instance_type="ml.t3.medium",
instance_count=1)
sklearn_processor.run(code='script.py')
尝试的解决方案:
- 将包上传到 CodeCommit 存储库并将存储库克隆到 SKLearnProcessor 实例中。失败,错误
fatal: could not read Username for 'https://git-codecommit.eu-west-1.amazonaws.com': No such device or address
。我尝试将 repo 克隆到 sagemaker notebook 实例中并且它有效,所以它不是我的脚本的问题。 - 使用 bash 脚本通过 CLI 从 s3 复制包。我使用的 bash 脚本基于 this post。但是包永远不会被复制,也不会抛出错误消息。
- 也研究了使用软件包
s3fs
,但它似乎不适合复制 wheel 文件。
备选方案
我的客户对从自定义 docker 图像启动容器犹豫不决。还有其他选择吗?
2. Use a bash script to copy the packages from s3 using the CLI. The bash script I used is based off this post. But the packages never get copied, and an error message is not thrown.
这种方法似乎很合理。
您最好将 SKLearnProcessor
上的 command
字段覆盖为 /bin/bash
,运行 一个 bash 脚本,例如 install_and_run_my_python_code.sh
安装包含您的 python 依赖项的轮子,然后 运行 是您的主要 python 入口点脚本。
此外,您可以使用 ProcessingInput 下载代码,而不是使用 bash 脚本中的 AWS CLI 调用,而不是使用 AWS S3 调用在脚本中下载代码,这就是 SKLearnProcessor
在所有实例中下载入口点 script.py
代码的作用。