无法将拥抱脸部模型部署到 sagemaker 端点 - C:\.sagemaker-code-config 未找到

问题描述 投票:0回答:1

我正在尝试使用 sagemaker 和拥抱面部库创建 sagemaker 端点。

import sagemaker
sess = sagemaker.Session()
sagemaker_session_bucket=None
if sagemaker_session_bucket is None and sess is not None:
    # set to default bucket if a bucket name is not given
    sagemaker_session_bucket = sess.default_bucket()

role = "my-IAM-role"

sess = sagemaker.Session(default_bucket=sagemaker_session_bucket)

repository = "FremyCompany/BioLORD-2023-M"
model_id=repository.split("/")[-1]
s3_location=f"s3://{sess.default_bucket()}/custom_inference/{model_id}/model.tar.gz"

from sagemaker.huggingface.model import HuggingFaceModel


# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
   model_data=s3_location,       # path to your model and script
   role = role,
   transformers_version="4.37.0",  # transformers version used
   pytorch_version="2.1.0",        # pytorch version used
   py_version="py310",            # python version used
)

# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
   initial_instance_count=1,
   instance_type="ml.m4.xlarge",
   endpoint_name="bioLORD-test"
)

但是当我执行代码时它会永远运行。 当我中断执行并检查

KeyboardInterrupt
错误上方的日志时,出现以下内容:

FileNotFoundError                         Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python312\Lib\pathlib.py:860, in Path.exists(self, follow_symlinks)
    859 try:
--> 860     self.stat(follow_symlinks=follow_symlinks)
    861 except OSError as e:

File ~\AppData\Local\Programs\Python\Python312\Lib\pathlib.py:840, in Path.stat(self, follow_symlinks)
    836 """
    837 Return the result of the stat() system call on this path, like
    838 os.stat() does.
    839 """
--> 840 return os.stat(self, follow_symlinks=follow_symlinks)

FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\.sagemaker-code-config'

During handling of the above exception, another exception occurred:

KeyboardInterrupt                         Traceback (most recent call last)

我不久前已从 MacOS 转移到 Windows,并且此代码可以在 Mac 上正常运行。 我尝试搜索“sagemaker-code-config”,但找不到任何有用的东西。 我也不明白为什么代码会永远运行而不是抛出

FileNotFoundError
。 感谢您的帮助!

附注我尝试在 WSL 中的 Ubuntu 中执行相同的代码,但得到了相同的结果。

python deployment amazon-sagemaker huggingface mlops
1个回答
0
投票

SageMaker Python SDK 使用函数来识别本地

.sagemaker-code-config
配置文件,该文件用于在 Studio 上添加相关项目标签。

代码递归遍历文件系统,直到找到该文件。您可以在此处查看实施情况。这是相关部分:

STUDIO_PROJECT_CONFIG = ".sagemaker-code-config"

[...]

try:
    wd = Path(working_dir) if working_dir else Path.cwd()

    path = None
    while path is None and not wd.match("/"):
        candidate = wd / STUDIO_PROJECT_CONFIG
        if Path.exists(candidate):
            path = candidate
        wd = wd.parent

    return path
except Exception as e:
    [...]

通常,如果找不到文件,代码应该继续执行,但与 Windows 上的文件系统交互可能会导致死锁,这可能是由于防病毒程序或类似问题造成的。

使用

_append_project_tags
的代码路径将被多次调用,例如当您部署模型时

我无法在 Windows 上测试它,但我建议在代码所在的同一工作目录中创建一个空的

.sagemaker-code-config
文件。这应该可以防止递归路径遍历。

© www.soinside.com 2019 - 2024. All rights reserved.