amazon web services - tar.gz file in s3 bucket is not loaded in sagemaker notebook - Stack Overflow

I'm just testing AWS tools to serve using sagemaker. My current progress is that I've already

I'm just testing AWS tools to serve using sagemaker. My current progress is that I've already created a trained model, and compressed pth, inference.py, requirement.txt, and other necessary files into tar.gz and deployed them to an s3 bucket.

$ tar -tzf birefnet.tar.gz
./
./ckpt/
./ckpt/BiRefNet-general-epoch_244.pth
./config.py
./dataset.py
./evaluation/
./inference.py
./requirements.txt
.
.

Here are the contents of the compressed file. After uploading to the bucket, I tried to load the tar.gz file in the bucket using pytorchmodel in the sagemaker notebook. However, I keep getting an error that inference.py is missing. I tried asking for help from chatgpt and many others, but was unsuccessful. Here is the code I wrote:

import sagemaker
from sagemaker.pytorch import PyTorchModel


sagemaker_session = sagemaker.Session()
role = sagemaker.get_execution_role()  

model_data = 's3://sagemaker-birefnet-up/path/to/birefnet.tar.gz'

pytorch_model = PyTorchModel(
    model_data=model_data,
    role=role,
    entry_point='inference.py',
    framework_version='2.5.1',
    py_version='py311',
    sagemaker_session=sagemaker_session
)

predictor = pytorch_model.deploy(
    initial_instance_count=1,
    instance_type='ml.t2.medium',
)

FileNotFoundError: [Errno 2] No such file or directory: 'inference.py'

What did I do wrong?

I thought what I wanted to do was simple. I tried recompressing and changing the model path, but nothing worked.

I'm just testing AWS tools to serve using sagemaker. My current progress is that I've already created a trained model, and compressed pth, inference.py, requirement.txt, and other necessary files into tar.gz and deployed them to an s3 bucket.

$ tar -tzf birefnet.tar.gz
./
./ckpt/
./ckpt/BiRefNet-general-epoch_244.pth
./config.py
./dataset.py
./evaluation/
./inference.py
./requirements.txt
.
.

Here are the contents of the compressed file. After uploading to the bucket, I tried to load the tar.gz file in the bucket using pytorchmodel in the sagemaker notebook. However, I keep getting an error that inference.py is missing. I tried asking for help from chatgpt and many others, but was unsuccessful. Here is the code I wrote:

import sagemaker
from sagemaker.pytorch import PyTorchModel


sagemaker_session = sagemaker.Session()
role = sagemaker.get_execution_role()  

model_data = 's3://sagemaker-birefnet-up/path/to/birefnet.tar.gz'

pytorch_model = PyTorchModel(
    model_data=model_data,
    role=role,
    entry_point='inference.py',
    framework_version='2.5.1',
    py_version='py311',
    sagemaker_session=sagemaker_session
)

predictor = pytorch_model.deploy(
    initial_instance_count=1,
    instance_type='ml.t2.medium',
)

FileNotFoundError: [Errno 2] No such file or directory: 'inference.py'

What did I do wrong?

I thought what I wanted to do was simple. I tried recompressing and changing the model path, but nothing worked.

Share Improve this question asked Mar 25 at 8:48 dev_seodev_seo 1
Add a comment  | 

1 Answer 1

Reset to default 0

I think both inference.py and requirements.txt should be located in a subfolder named code, unless you specify a different folder using the parameter source_dir argument when creating PyTorch estimator.

See here for details.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744208863a4563236.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信