Skip to content

Hyperparameters not provided when using a .sh script as Estimator entrypoint  #3101

@Guillem96

Description

@Guillem96

Describe the bug
When setting a .sh script as an Estimator entrypoint I do not get the hyperparameters as CLI options.

To reproduce

# train.sh
echo "python train.py $@"  # For some reason $@ is empty
# run_train_job.py
from sagemaker.pytorch.estimator import PyTorch

input_path = ...
instance_type = "ml.m5.large"

estimator = PyTorch(
        entry_point="train.sh",
        source_dir=".",
        instance_type=instance_type,
        instance_count=1,
        framework_version="1.10",
        py_version="py38",
        hyperparameters={"test": "test-value"},
)
estimator.fit({"train": input_path}, job_name=f"jk-training-job-{job_suffix}")

Expected behavior
The train.sh files echos: python tain.py --test test-value. But actually the $@ is empty.

Additional context

Checking the cloudwatch logs, I see that sagemaker tries to run my script like so:

$ /bin/sh -c train.sh  --test test-value

If I replicate this command locally, I can easily reproduce the error.
I've realized that's the -c option that "empties" the $@ (and other special variables). Is there any particular reason to use that -c flag?

System information
A description of your system. Please provide:

  • SageMaker Python SDK version: 2.88.3
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): PyTorch
  • Framework version: 1.10
  • Python version: py38
  • CPU or GPU: CPU
  • Custom Docker image (Y/N): N

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions