fix(sagemaker-templates): Fix batch inference parameter resolution - #425
Merged
Conversation
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.
Changes:
- Use ProcessingInput with parameter as source for dynamic S3 paths
- Specify explicit destination filename to avoid path ambiguity
- Follows the same pattern as xgboost_abalone template
This fixes the issue where InputDataUrl parameter was passed as
'{"Get": "Parameters.InputDataUrl"}' instead of the actual S3 path,
causing preprocessing jobs to fail with IndexError.
Resolves parameter resolution for batch inference pipelines.
newman911
force-pushed
the
fix/batch-inference-parameter-resolution
branch
from
February 27, 2026 19:05
9756f47 to
d098ee1
Compare
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.
Changes:
- Use ProcessingInput with parameter as source for dynamic S3 paths
- Pass S3 URL parameter to script so it can extract filename
- Script constructs local path from filename
- Remove S3 download logic (ProcessingInput handles it)
This fixes the issue where InputDataUrl parameter was passed as
'{"Get": "Parameters.InputDataUrl"}' instead of the actual S3 path,
causing preprocessing jobs to fail with IndexError.
Resolves parameter resolution for batch inference pipelines.
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.
…erence preprocessing The preprocessing script was outputting sparse matrix format instead of CSV, causing the Transformer step to fail with 'could not convert string to float'. Fix: Convert sparse matrix to dense array before writing to CSV.
…processing - Remove unused boto3 import - Move glob import to top - Fix line length violations (E501) - Remove trailing whitespace (W293)
newman911
marked this pull request as draft
March 3, 2026 18:26
newman911
marked this pull request as ready for review
March 3, 2026 18:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Changes:
This fixes the issue where InputDataUrl parameter was passed as '{"Get": "Parameters.InputDataUrl"}' instead of the actual S3 path, causing preprocessing jobs to fail with IndexError.
Resolves parameter resolution for batch inference pipelines.
Describe your changes
Issue ticket number and link
Checklist before requesting a review
CHANGELOG.MDwith a description of my changesscripts/validate.sh)seedfarmer applyBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Test case executed:
Results:
What we verified:
What we didn't test:
The parameter resolution bug is fixed. The remaining Transformer failure is a separate pre-existing issue where the template's preprocessing doesn't match what the model expects.[1:57 PM][amzn-builder] 42% > what was the deploy command we tested?
Where the artifact was modified to point to the fix/batch-inference-parameter-resolution branch instead of release/3.2.2.
Then executed the pipeline with:
bash
aws sagemaker start-pipeline-execution
--pipeline-name workshop-batch-inference
--pipeline-parameters
Name=InputDataUrl,Value=s3://mlops-workshop-model-training-757126856234/batch-inference-input/test.csv
Name=OutputsBucketName,Value=mlops-workshop-model-training-757126856234
Name=TransformInstanceCount,Value=1
Name=TransformInstanceType,Value=ml.m5.large
Name=ProcessingInstanceCount,Value=1
Name=ProcessingInstanceType,Value=ml.m5.large
--pipeline-execution-display-name "Sparse-Matrix-Fix"[1:57 PM][amzn-builder] 42% > cat the config file
I will run the following command: cat ~/Downloads/test-batch-inference/batch-inference-config-fixed.json 2>/dev/null || cat ./batch-inference-config-fixed.json 2>/dev/null || echo "File not found" (using tool: shell)
Purpose: Find and cat config file
{
"SAGEMAKER_PROJECT_ID": "workshop-batch-inference",
"SAGEMAKER_PROJECT_NAME": "workshop-batch-inference",
"SAGEMAKER_DOMAIN_ID": "d-egtvvpzmveem",
"SAGEMAKER_DOMAIN_ARN": "arn:aws:sagemaker:us-east-1:757126856234:domain/d-egtvvpzmveem",
"REPOSITORY_TYPE": "CodeCommit",
"BASE_JOB_PREFIX": "batch",
"MODEL_PACKAGE_GROUP_NAME": "workshop-model-training-workshop-model-training",
"MODEL_BUCKET_NAME": "mlops-workshop-model-training-757126856234"
}