bentoml / aws-sagemaker-deploy

Fast model deployment on AWS Sagemaker
Apache License 2.0
14 stars 15 forks source link

Erro when try to create instace on aws-sagemaker "No module named 'sagemaker_service'" #53

Open kascesar opened 4 months ago

kascesar commented 4 months ago

Hi, hope some one may help pls: Im getting this error when try to implement my bento on sagemaker:

2024-02-07T14:58:58+0000 [INFO] [cli] Service loaded from Bento directory: bentoml.Service(tag="tensorflow_fatiguelog:noxtfiwfzcm4fmg4", path="/home/bentoml/bento/")
2024-02-07T14:58:58+0000 [INFO] [cli] Environ for worker 0: set CPU thread count to 4
2024-02-07T14:58:58+0000 [INFO] [cli] Prometheus metrics for HTTP BentoServer from "sagemaker_service:svc" can be accessed at http://localhost:8080/metrics.
2024-02-07T14:58:58+0000 [INFO] [cli] Starting production HTTP BentoServer from "sagemaker_service:svc" listening on http://0.0.0.0:8080 (Press CTRL+C to quit)
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bentoml/_internal/service/loader.py", line 151, in import_service
    module = importlib.import_module(module_name, package=working_dir)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked

ModuleNotFoundError: No module named 'sagemaker_service'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bentoml/_internal/service/loader.py", line 409, in load
    svc = import_service(
  File "/usr/local/lib/python3.10/site-packages/simple_di/__init__.py", line 139, in _
    return func(*_inject_args(bind.args), **_inject_kwargs(bind.kwargs))
  File "/usr/local/lib/python3.10/site-packages/bentoml/_internal/service/loader.py", line 153, in import_service
    raise ImportServiceError(f'Failed to import module "{module_name}": {e}')
bentoml.exceptions.ImportServiceError: Failed to import module "sagemaker_service": No module named 'sagemaker_service'

my bentofile.yaml:

service: "service:svc"
# description: "file: ./README.md"
labels:
  type: anomaly-detector
  owner: ow-ds
  stage: demo
include:
  - "service.py"
python:
  packages:
    - tensorflow

models:
  - tensorflow_fatiguelog:latest

service.py

import numpy as np

import bentoml
from bentoml.io import NumpyNdarray

runner = bentoml.keras.get("tensorflow_fatiguelog:latest").to_runner()

svc = bentoml.Service(
    name="tensorflow_fatiguelog",
    runners=[runner],
)

@svc.api(
    input=NumpyNdarray(dtype="float32", shape=(1, 1, 5, 4, 4)),
    output=NumpyNdarray(dtype="float32", shape=(1, 1, 5, 4, 4)),
)
async def predict(f) -> "np.ndarray":
    return await runner.async_run(f)

deplyment file

api_version: v1
name: fatiguelog-anomaly-det
operator:
  name: aws-sagemaker
template: terraform
spec:
  region: us-east-1
  instance_type: ml.t2.xlarge
  initial_instance_count: 1
  timeout: 60
  initial_sampling_percentage: 1
env: {}

Getting same erro when follow this steps by steps tutorial :

https://www.youtube.com/watch?v=Zci_D4az9FU

code of this tutorial

https://github.com/jankrepl/mildlyoverfitted/tree/master/mini_tutorials/bentoml

I dont know if this error is generated by specific permision or another thing, hope this information help your to solve my problem. Thanks a lot!

youcandanch commented 4 months ago

Make sure you're using bentoml 1.1.9 -- it seems like this crops up if you're using > 1.2. Ran into it myself this morning.

kascesar commented 4 months ago

1.1.11 solve the issue for me. 1.1.9 generate errors on "bento build" comand. Hope solve this error for version 2.x. Thanks!