Skip to content

Commit e3620dc

Browse files
committed
fix(sagemaker-templates): Fix batch inference parameter resolution
The batch inference template was passing ParameterString objects directly to job_arguments, which caused them to be serialized as literal JSON strings instead of being resolved at runtime. Root cause: ParameterString objects cannot be passed to job_arguments in SageMaker SDK - they get serialized as '{"Get": "Parameters.Name"}' instead of being resolved. This is unique to batch_inference template; all other templates use hardcoded strings. Solution: - Use ProcessingInput to download file from S3 URL parameter - Script finds CSV file in /opt/ml/processing/input/ directory - Remove --input-data from job_arguments (can't pass parameters there) This allows users to specify different input data via InputDataUrl parameter while working around the SDK limitation.
1 parent b5f4e37 commit e3620dc

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

  • modules/sagemaker/sagemaker-templates/templates/batch_inference/seed_code/build_app

modules/sagemaker/sagemaker-templates/templates/batch_inference/seed_code/build_app/ml_pipelines/transformer/pipeline.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ def get_pipeline(
152152
],
153153
code="source_scripts/preprocessing.py",
154154
job_arguments=[
155-
"--input-data",
156-
input_data,
157155
"--do-train-test-split",
158156
"False",
159157
],

modules/sagemaker/sagemaker-templates/templates/batch_inference/seed_code/build_app/source_scripts/preprocessing.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,22 @@ def merge_two_dicts(x: Dict[str, Any], y: Dict[str, Any]) -> Dict[str, Any]:
5555
if __name__ == "__main__":
5656
logger.debug("Starting preprocessing.")
5757
parser = argparse.ArgumentParser()
58-
parser.add_argument("--input-data", type=str, required=True)
58+
parser.add_argument("--input-data", type=str, required=False)
5959
parser.add_argument("--do-train-test-split", type=str, default="True")
6060
args = parser.parse_args()
6161

6262
base_dir = "/opt/ml/processing"
6363
pathlib.Path(f"{base_dir}/data").mkdir(parents=True, exist_ok=True)
64-
input_data = args.input_data
65-
logger.info("Input data S3 URL: %s", input_data)
6664

67-
# Extract filename from S3 URL - file is already downloaded by ProcessingInput
68-
filename = input_data.split('/')[-1]
69-
fn = f"/opt/ml/processing/input/{filename}"
70-
logger.info("Reading file: %s", fn)
65+
# ProcessingInput downloads file to /opt/ml/processing/input/
66+
# Find the CSV file (parameter can't be passed to job_arguments)
67+
import glob
68+
csv_files = glob.glob("/opt/ml/processing/input/*.csv")
69+
if csv_files:
70+
fn = csv_files[0]
71+
logger.info("Found CSV file: %s", fn)
72+
else:
73+
raise ValueError("No CSV files found in /opt/ml/processing/input/")
7174

7275
df = pd.read_csv(
7376
fn,

0 commit comments

Comments
 (0)