Code Monkey home page Code Monkey logo

Comments (9)

josephjohansson avatar josephjohansson commented on August 16, 2024 24

I seem to have figured out the issue here. It seems that when the image is being spun up as an endpoint, there is some code that removes all files inside /opt/ml/model BEFORE copying and unzipping model.tar.gz from S3. If you package your custom inference code in model.tar.gz then it will work. I have spent many hours figuring this out. Also, your saved model should be called model_0.pth as that is what MMS will pass to your custom inference code as the parameter model_dir.

model.tar.gz
|- model_0.pth
|- code
| |- inference.py

This sort of behavior from the code is in fact really concerning because it means that in order to change your custom inference code, you need to repackage your model data. This really makes working with this container setup in a CICD way clunky and hacky at best.

At the very least, we should be adding what I mentioned above to the README or documentation for this project since its incredibly unclear how you would add your own custom inference code.

from sagemaker-pytorch-inference-toolkit.

dsprahul avatar dsprahul commented on August 16, 2024 1

Expanding on @josephjohansson's answer, to extend pre-built images with custom inference code for TensorFlow serving, you need to package your inference code so that the model.tar.gz extracts like this:
image

To pack it that way, you should run
tar -czf model.tar.gz <model_dir> <code_dir>

I found this out by using SageMaker's TensorFlowModel API to package a model with an entry_point and inspecting its contents.

They should really expand details here so an unsuspecting dev would know what's happening in the background.

from sagemaker-pytorch-inference-toolkit.

davidthomas426 avatar davidthomas426 commented on August 16, 2024 1

Documentation on using this package with custom inference code, including model artifact structure, as well as how SageMaker runs the container, can be found here:

I'll summarize certain relevant details that should clear up confusion in this thread.

When deploying your model to a SageMaker Endpoint, you first create a SageMaker Model from your model artifact, either using SageMaker's CreateModel API (https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateModel.html) or with the SageMaker Python SDK (https://sagemaker.readthedocs.io/en/stable/frameworks/pytorch/using_pytorch.html#create-a-pytorchmodel-object). You then create a SageMaker endpoint. When SageMaker deploys the model, SageMaker downloads and unpacks the model artifact and mounts the unpacked directory at /opt/ml/model in the container as a readonly Docker volume.

from sagemaker-pytorch-inference-toolkit.

artmatsak avatar artmatsak commented on August 16, 2024

Anyone please?

from sagemaker-pytorch-inference-toolkit.

nadiaya avatar nadiaya commented on August 16, 2024

Yes, the example you are using was for a different container.

Since we switched to use MMS as our model server inside the container the code now needs to be copied under /opt/ml/model/code/ .

from sagemaker-pytorch-inference-toolkit.

shamazharikh avatar shamazharikh commented on August 16, 2024

Hi,
I was facing the same issue, below is the Dockerfile I am using. It seems the model_fn is still not being read. @artmatsak Were you able to solve this issue?
@nadiaya Any help here would be appreciated!

ARG REGION=us-east-1

FROM 763104351884.dkr.ecr.$REGION.amazonaws.com/pytorch-inference-eia:1.3.1-cpu-py36-ubuntu16.04

ENV PATH="/opt/ml/code:${PATH}"

COPY /src /opt/ml/model/code

RUN pip3 install -r /opt/ml/code/requirements.txt

ENV SAGEMAKER_SUBMIT_DIRECTORY /opt/ml/model/code

ENV SAGEMAKER_PROGRAM serve.py

from sagemaker-pytorch-inference-toolkit.

velenciucsergiu avatar velenciucsergiu commented on August 16, 2024

hello. Just out of the curiosity : in current release, do we have the possibility to have multi/model capabilities for pytorch containers?

from sagemaker-pytorch-inference-toolkit.

ajaykarpur avatar ajaykarpur commented on August 16, 2024

hello. Just out of the curiosity : in current release, do we have the possibility to have multi/model capabilities for pytorch containers?

@velenciucsergiu Multi-model support is available for PyTorch 1.4.0 and 1.5.0:

LABEL com.amazonaws.sagemaker.capabilities.multi-models=true

LABEL com.amazonaws.sagemaker.capabilities.multi-models=true

LABEL com.amazonaws.sagemaker.capabilities.multi-models=true

from sagemaker-pytorch-inference-toolkit.

sephiartlist avatar sephiartlist commented on August 16, 2024

Hi @josephjohansson
Does your solution also relate to deploy Inference model within Docker containers? and if so how?

from sagemaker-pytorch-inference-toolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.