Skip to content

Failed to import code copied into the /opt/ml/model/code/lib directory #1065

@anotinelg

Description

@anotinelg

System Information

Python Version: 3.6
sagemaker-python-sdk Version: master (1.42.1.dev0)
sagemaker-mxnet-serving-container: 1.1.4.dev0) (using sagemkaer-infernece 1.0.1)
Are you using a custom image: no

Describe the problem

I am trying to deploy a model with a script depending on a library. The dependency to the library is configured with the dependenciesparameter of the MXNetmodel.
The model is successfully created, but When the model is started, the lib is not found by the code. It seems that that the sagemaker-mxnet-serving-container does not include in sys.path the /opt/ml/code/lib directory.
I am not sure if the integration bug must be solved into that repository or the sagemaker-mxnet-serving-container. As far as I understand, there is a fundamental changes in that repository which breaks the integration between both.

My source directory is:

- src
---- mypackage
--------__init__.py
--------myscript.py
--------utils.py

I create the model as:

MXNetModel( entry_point='../src/mypackage/myscript.py',
                         dependencies= ['../src/mypackage']
                         ...       
                         py_version='py3')

The output.tar.gz is the following:

- model/
---- my model.params
---- ...
---- code /
----------myscript.py (the script is copied at root)
----------lib/ 
--------------mypackage (the dependent lib is copied into the lib/ directory)
-------------------__init__.py
-------------------myscript.py
-------------------utils.py

The code in question is

lib_dir = os.path.join(code_dir, "lib")

Nota: I have found a solution adding the following into the myscript.py:

sys.path.append('/opt/ml/model/code/lib')

But I guess this should not be the place to do it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions