Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Accept user-defined env variables for the entry-point #4175

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/sagemaker/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ def _upload_code(self, key_prefix: str, repack: bool = False) -> None:

def _script_mode_env_vars(self):
"""Returns a mapping of environment variables for script mode execution"""
script_name = None
dir_name = None
script_name = self.env.get(SCRIPT_PARAM_NAME.upper(), "")
dir_name = self.env.get(DIR_PARAM_NAME.upper(), "")
if self.uploaded_code:
script_name = self.uploaded_code.script_name
if self.repacked_model_data or self.enable_network_isolation():
Expand All @@ -783,8 +783,8 @@ def _script_mode_env_vars(self):
else "file://" + self.source_dir
)
return {
SCRIPT_PARAM_NAME.upper(): script_name or str(),
DIR_PARAM_NAME.upper(): dir_name or str(),
SCRIPT_PARAM_NAME.upper(): script_name,
DIR_PARAM_NAME.upper(): dir_name,
CONTAINER_LOG_LEVEL_PARAM_NAME.upper(): to_string(self.container_log_level),
SAGEMAKER_REGION_PARAM_NAME.upper(): self.sagemaker_session.boto_region_name,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,32 @@ def test_register_hf_pytorch_model_auto_infer_framework(
sagemaker_session.create_model_package_from_containers.assert_called_with(
**expected_create_model_package_request
)


def test_accept_user_defined_environment_variables(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to update these tests with the another version :
FAILED tests/unit/sagemaker/training_compiler/test_huggingface_pytorch_compiler.py::test_accept_user_defined_environment_variables[4.21.1]
FAILED tests/unit/sagemaker/training_compiler/test_huggingface_pytorch_compiler.py::test_accept_user_defined_environment_variables[4.21]

arg = '4.21.1'
available_options = ['4.6.1', '4.10.2', '4.11.0', '4.12.3', '4.17.0', '4.26.0', ...]
arg_name = 'huggingface version'

    def _validate_arg(arg, available_options, arg_name):
        """Checks if the arg is in the available options, and raises a ``ValueError`` if not."""
        if arg not in available_options:
>           raise ValueError(
                "Unsupported {arg_name}: {arg}. You may need to upgrade your SDK version "
                "(pip install -U sagemaker) for newer {arg_name}s. Supported {arg_name}(s): "
                "{options}.".format(arg_name=arg_name, arg=arg, options=", ".join(available_options))
            )
E           ValueError: Unsupported huggingface version: 4.21.1. You may need to upgrade your SDK version (pip install -U sagemaker) for newer huggingface versions. Supported huggingface version(s): 4.6.1, 4.10.2, 4.11.0, 4.12.3, 4.17.0, 4.26.0, 4.28.1, 4.6, 4.10, 4.11, 4.12, 4.17, 4.26, 4.28.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand. Where is the version picked by the test defined?

I just rebased the pull request.

sagemaker_session,
huggingface_training_compiler_version,
huggingface_training_compiler_pytorch_version,
huggingface_training_compiler_pytorch_py_version,
):
program = "inference.py"
directory = "/opt/ml/model/code"

hf_model = HuggingFaceModel(
model_data="s3://some/data.tar.gz",
role=ROLE,
transformers_version=huggingface_training_compiler_version,
pytorch_version=huggingface_training_compiler_pytorch_version,
py_version=huggingface_training_compiler_pytorch_py_version,
sagemaker_session=sagemaker_session,
env={
"SAGEMAKER_PROGRAM": program,
"SAGEMAKER_SUBMIT_DIRECTORY": directory,
},
image_uri="fakeimage",
)

container_env = hf_model.prepare_container_def("ml.m4.xlarge")["Environment"]

assert container_env["SAGEMAKER_PROGRAM"] == program
assert container_env["SAGEMAKER_SUBMIT_DIRECTORY"] == directory