AWS Sagemaker SKlearn 入口点允许多个脚本

AWS Sagemaker SKlearn entry point allow multiple script

我正在尝试按照教程 here 来实现用于特征预处理的自定义推理管道。它使用 python sklearn sdk 从脚本中引入自定义预处理管道。例如:

from sagemaker.sklearn.estimator import SKLearn

script_path = 'preprocessing.py'

sklearn_preprocessor = SKLearn(
    entry_point=script_path,
    role=role,
    train_instance_type="ml.c4.xlarge",
    sagemaker_session=sagemaker_session)

但是我找不到发送多个文件的方法。我需要多个文件的原因是因为我有一个在 sklearn 管道中使用的自定义 class 需要从自定义模块导入。如果不导入,由于 pickle 的工作方式(至少我认为它与 pickle 有关),在同一 preprocessing.py 文件中包含自定义 class 时会引发错误 AttributeError: module '__main__' has no attribute 'CustomClassName'

有人知道是否可以发送多个文件吗?

Sagemaker 新手,谢谢!!

有一个 source_dir 参数,它将 "lift" 一个文件目录到容器并将其放在您的导入路径中。

你的入口点脚本应该放在那里并从那个位置引用。

您也可以在 SKLearn 中使用 dependencies 参数。例如

sklearn_preprocessor = SKLearn(
    entry_point=script_path,
    role=role,
    train_instance_type="ml.c4.xlarge",
    sagemaker_session=sagemaker_session,
    dependencies=['script1.py', 'script2.py']
    )