How do I load python modules which are not available in Sagemaker?

后端 未结 2 1649
日久生厌
日久生厌 2020-12-07 05:43

I want to install spacy which is not available as part of the Sagemaker platform. How should can I pip install it?

2条回答
  •  情书的邮戳
    2020-12-07 05:55

    When creating you model, you can specify the requirements.txt as an environment variable.

    For Eg.

    env = {
        'SAGEMAKER_REQUIREMENTS': 'requirements.txt', # path relative to `source_dir` below.
    }
    sagemaker_model = TensorFlowModel(model_data = 's3://mybucket/modelTarFile,
                                      role = role,
                                      entry_point = 'entry.py',
                                      code_location = 's3://mybucket/runtime-code/',
                                      source_dir = 'src',
                                      env = env,
                                      name = 'model_name',
                                      sagemaker_session = sagemaker_session,
                                     )
    

    This would ensure that the requirements file is run after the docker container is created, before running any code on it.

提交回复
热议问题