Commit 83bcc00
authored
fix(sagemaker-templates): Fix batch inference parameter resolution (#425)
* 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.
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.
* 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.
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.
* 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.
* fix(sagemaker-templates): Convert sparse matrix to dense in batch inference 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.
* style(sagemaker-templates): Fix linting issues in batch inference preprocessing
- Remove unused boto3 import
- Move glob import to top
- Fix line length violations (E501)
- Remove trailing whitespace (W293)
* style(sagemaker-templates): Apply ruff formatting to preprocessing.py
---------
Co-authored-by: Nuri Boardman <nurboard@amazon.com>1 parent 6140600 commit 83bcc00
2 files changed
Lines changed: 20 additions & 14 deletions
File tree
- modules/sagemaker/sagemaker-templates/templates/batch_inference/seed_code/build_app
- ml_pipelines/transformer
- source_scripts
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
144 | 150 | | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
148 | 154 | | |
149 | | - | |
150 | | - | |
151 | 155 | | |
152 | 156 | | |
153 | 157 | | |
| |||
Lines changed: 13 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | 64 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
73 | 73 | | |
74 | | - | |
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
| |||
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
0 commit comments