Skip to content

Commit 5991cf8

Browse files
committed
feat: Support placeholders for TuningStep parameters
1 parent 23878de commit 5991cf8

File tree

11 files changed

+977
-93
lines changed

11 files changed

+977
-93
lines changed

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: "\U0001F41B Bug Report"
3+
about: Report a bug
4+
title: "short issue description"
5+
labels: bug, needs-triage
6+
---
7+
8+
<!--
9+
description of the bug:
10+
-->
11+
12+
13+
14+
15+
### Reproduction Steps
16+
17+
<!--
18+
minimal amount of code that causes the bug (if possible) or a reference.
19+
20+
The code sample should be an SSCCE. See http://sscce.org/ for details.
21+
In short, provide a code sample that we can copy/paste, run and reproduce.
22+
-->
23+
24+
### What did you expect to happen?
25+
26+
<!--
27+
What were you trying to achieve by performing the steps above?
28+
-->
29+
30+
### What actually happened?
31+
32+
<!--
33+
What is the unexpected behavior you were seeing? If you got an error, paste it here.
34+
-->
35+
36+
37+
### Environment
38+
39+
- **AWS Step Functions Data Science Python SDK version :**
40+
- **Python Version:** <!-- Version of Python (run the command `python3 --version`) -->
41+
42+
### Other
43+
44+
<!-- e.g. detailed explanation, stack-traces, related issues, suggestions on how to fix, links for us to have context, eg. associated pull-request, stackoverflow, slack, etc -->
45+
46+
47+
48+
49+
---
50+
51+
This is :bug: Bug Report

.github/ISSUE_TEMPLATE/doc.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: "📕 Documentation Issue"
3+
about: Issue in the reference documentation
4+
title: "short issue description"
5+
labels: feature-request, documentation, needs-triage
6+
---
7+
8+
<!--
9+
- want to help? submit a pull request! docs can be found here: https://github.com/aws/aws-step-functions-data-science-sdk-python/tree/main/doc
10+
-->
11+
12+
<!--
13+
link to reference doc page:
14+
-->
15+
16+
17+
18+
<!--
19+
describe your issue:
20+
-->
21+
22+
23+
24+
25+
26+
---
27+
28+
This is a 📕 documentation issue
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: "\U0001F680 Feature Request"
3+
about: Request a new feature
4+
title: "short issue description"
5+
labels: feature-request, needs-triage
6+
---
7+
8+
<!-- short description of the feature you are proposing: -->
9+
10+
11+
12+
13+
14+
### Use Case
15+
16+
<!-- why do you need this feature? -->
17+
18+
19+
20+
21+
22+
### Proposed Solution
23+
24+
<!-- Please include prototype/workaround/sketch/reference implementation: -->
25+
26+
27+
28+
29+
30+
### Other
31+
32+
<!--
33+
e.g. detailed explanation, stacktraces, related issues, suggestions on how to fix,
34+
links for us to have context, eg. associated pull-request, stackoverflow, slack, etc
35+
-->
36+
37+
38+
39+
40+
41+
* [ ] :wave: I may be able to implement this feature request
42+
* [ ] :warning: This feature might incur a breaking change
43+
44+
---
45+
46+
This is a :rocket: Feature Request

.github/pull_request_template.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
### Description
2+
3+
Please include a summary of the change being made.
4+
5+
Fixes #(issue)
6+
7+
### Why is the change necessary?
8+
9+
What capability does it enable? What problem does it solve?
10+
11+
### Solution
12+
13+
Please include an overview of the solution. Discuss trade-offs made, caveats, alternatives, etc.
14+
15+
### Testing
16+
17+
How was this change tested?
18+
19+
----
20+
21+
### Pull Request Checklist
22+
23+
Please check all boxes (including N/A items)
24+
25+
#### Testing
26+
27+
- [ ] Unit tests added
28+
- [ ] Integration test added
29+
- [ ] Manual testing - why was it necessary? could it be automated?
30+
31+
#### Documentation
32+
33+
- [ ] __docs__: All relevant [docs](https://github.com/aws/aws-step-functions-data-science-sdk-python/tree/main/doc) updated
34+
- [ ] __docstrings__: All public APIs documented
35+
36+
### Title and description
37+
38+
- [ ] __Change type__: Title is prefixed with change type: and follows [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
39+
- [ ] __References__: Indicate issues fixed via: `Fixes #xxx`
40+
41+
----
42+
43+
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

src/stepfunctions/steps/sagemaker.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -185,36 +185,42 @@ def __merge_hyperparameters(self, training_step_hyperparameters, estimator_hyper
185185
merged_hyperparameters[key] = value
186186
return merged_hyperparameters
187187

188+
188189
class TransformStep(Task):
189190

190191
"""
191192
Creates a Task State to execute a `SageMaker Transform Job <https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTransformJob.html>`_.
192193
"""
193194

194-
def __init__(self, state_id, transformer, job_name, model_name, data, data_type='S3Prefix', content_type=None, compression_type=None, split_type=None, experiment_config=None, wait_for_completion=True, tags=None, input_filter=None, output_filter=None, join_source=None, **kwargs):
195+
def __init__(self, state_id, transformer, job_name, model_name, data, data_type='S3Prefix', content_type=None,
196+
compression_type=None, split_type=None, experiment_config=None, wait_for_completion=True, tags=None,
197+
input_filter=None, output_filter=None, join_source=None, **kwargs):
195198
"""
196199
Args:
197200
state_id (str): State name whose length **must be** less than or equal to 128 unicode characters. State names **must be** unique within the scope of the whole state machine.
198201
transformer (sagemaker.transformer.Transformer): The SageMaker transformer to use in the TransformStep.
199202
job_name (str or Placeholder): Specify a transform job name. We recommend to use :py:class:`~stepfunctions.inputs.ExecutionInput` placeholder collection to pass the value dynamically in each execution.
200203
model_name (str or Placeholder): Specify a model name for the transform job to use. We recommend to use :py:class:`~stepfunctions.inputs.ExecutionInput` placeholder collection to pass the value dynamically in each execution.
201-
data (str): Input data location in S3.
202-
data_type (str): What the S3 location defines (default: 'S3Prefix').
204+
data (str or Placeholder): Input data location in S3.
205+
data_type (str or Placeholder): What the S3 location defines (default: 'S3Prefix').
203206
Valid values:
204207
205208
* 'S3Prefix' - the S3 URI defines a key name prefix. All objects with this prefix will
206209
be used as inputs for the transform job.
207210
* 'ManifestFile' - the S3 URI points to a single manifest file listing each S3 object
208211
to use as an input for the transform job.
209-
content_type (str): MIME type of the input data (default: None).
210-
compression_type (str): Compression type of the input data, if compressed (default: None). Valid values: 'Gzip', None.
211-
split_type (str): The record delimiter for the input object (default: 'None'). Valid values: 'None', 'Line', 'RecordIO', and 'TFRecord'.
212-
experiment_config (dict, optional): Specify the experiment config for the transform. (Default: None)
212+
content_type (str or Placeholder): MIME type of the input data (default: None).
213+
compression_type (str or Placeholder): Compression type of the input data, if compressed (default: None). Valid values: 'Gzip', None.
214+
split_type (str or Placeholder): The record delimiter for the input object (default: 'None'). Valid values: 'None', 'Line', 'RecordIO', and 'TFRecord'.
215+
experiment_config (dict or Placeholder, optional): Specify the experiment config for the transform. (Default: None)
213216
wait_for_completion(bool, optional): Boolean value set to `True` if the Task state should wait for the transform job to complete before proceeding to the next step in the workflow. Set to `False` if the Task state should submit the transform job and proceed to the next step. (default: True)
214-
tags (list[dict], optional): `List to tags <https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html>`_ to associate with the resource.
215-
input_filter (str): A JSONPath to select a portion of the input to pass to the algorithm container for inference. If you omit the field, it gets the value ‘$’, representing the entire input. For CSV data, each row is taken as a JSON array, so only index-based JSONPaths can be applied, e.g. $[0], $[1:]. CSV data should follow the RFC format. See Supported JSONPath Operators for a table of supported JSONPath operators. For more information, see the SageMaker API documentation for CreateTransformJob. Some examples: “$[1:]”, “$.features” (default: None).
216-
output_filter (str): A JSONPath to select a portion of the joined/original output to return as the output. For more information, see the SageMaker API documentation for CreateTransformJob. Some examples: “$[1:]”, “$.prediction” (default: None).
217-
join_source (str): The source of data to be joined to the transform output. It can be set to ‘Input’ meaning the entire input record will be joined to the inference result. You can use OutputFilter to select the useful portion before uploading to S3. (default: None). Valid values: Input, None.
217+
tags (list[dict] or Placeholder, optional): `List to tags <https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html>`_ to associate with the resource.
218+
input_filter (str or Placeholder): A JSONPath to select a portion of the input to pass to the algorithm container for inference. If you omit the field, it gets the value ‘$’, representing the entire input. For CSV data, each row is taken as a JSON array, so only index-based JSONPaths can be applied, e.g. $[0], $[1:]. CSV data should follow the RFC format. See Supported JSONPath Operators for a table of supported JSONPath operators. For more information, see the SageMaker API documentation for CreateTransformJob. Some examples: “$[1:]”, “$.features” (default: None).
219+
output_filter (str or Placeholder): A JSONPath to select a portion of the joined/original output to return as the output. For more information, see the SageMaker API documentation for CreateTransformJob. Some examples: “$[1:]”, “$.prediction” (default: None).
220+
join_source (str or Placeholder): The source of data to be joined to the transform output. It can be set to ‘Input’ meaning the entire input record will be joined to the inference result. You can use OutputFilter to select the useful portion before uploading to S3. (default: None). Valid values: Input, None.
221+
parameters(dict, optional): The value of this field is merged with other arguments to become the request payload for SageMaker `CreateTransformJob<https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateTransformJob.html>`_.
222+
You can use `parameters` to override the value provided by other arguments and specify any field's value dynamically using `Placeholders<https://aws-step-functions-data-science-sdk.readthedocs.io/en/stable/placeholders.html?highlight=placeholder#stepfunctions.inputs.Placeholder>`_.
223+
218224
"""
219225
if wait_for_completion:
220226
"""
@@ -233,7 +239,7 @@ def __init__(self, state_id, transformer, job_name, model_name, data, data_type=
233239
SageMakerApi.CreateTransformJob)
234240

235241
if isinstance(job_name, str):
236-
parameters = transform_config(
242+
transform_parameters = transform_config(
237243
transformer=transformer,
238244
data=data,
239245
data_type=data_type,
@@ -246,7 +252,7 @@ def __init__(self, state_id, transformer, job_name, model_name, data, data_type=
246252
join_source=join_source
247253
)
248254
else:
249-
parameters = transform_config(
255+
transform_parameters = transform_config(
250256
transformer=transformer,
251257
data=data,
252258
data_type=data_type,
@@ -259,17 +265,21 @@ def __init__(self, state_id, transformer, job_name, model_name, data, data_type=
259265
)
260266

261267
if isinstance(job_name, Placeholder):
262-
parameters['TransformJobName'] = job_name
268+
transform_parameters['TransformJobName'] = job_name
263269

264-
parameters['ModelName'] = model_name
270+
transform_parameters['ModelName'] = model_name
265271

266272
if experiment_config is not None:
267-
parameters['ExperimentConfig'] = experiment_config
273+
transform_parameters['ExperimentConfig'] = experiment_config
268274

269275
if tags:
270-
parameters['Tags'] = tags_dict_to_kv_list(tags)
276+
transform_parameters['Tags'] = tags if isinstance(tags, Placeholder) else tags_dict_to_kv_list(tags)
271277

272-
kwargs[Field.Parameters.value] = parameters
278+
if Field.Parameters.value in kwargs and isinstance(kwargs[Field.Parameters.value], dict):
279+
# Update transform_parameters with input parameters
280+
merge_dicts(transform_parameters, kwargs[Field.Parameters.value])
281+
282+
kwargs[Field.Parameters.value] = transform_parameters
273283
super(TransformStep, self).__init__(state_id, **kwargs)
274284

275285

@@ -444,7 +454,10 @@ def __init__(self, state_id, tuner, job_name, data, wait_for_completion=True, ta
444454
:class:`sagemaker.amazon.amazon_estimator.RecordSet` objects,
445455
where each instance is a different channel of training data.
446456
wait_for_completion(bool, optional): Boolean value set to `True` if the Task state should wait for the tuning job to complete before proceeding to the next step in the workflow. Set to `False` if the Task state should submit the tuning job and proceed to the next step. (default: True)
447-
tags (list[dict], optional): `List to tags <https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html>`_ to associate with the resource.
457+
tags (list[dict] or Placeholder, optional): `List to tags <https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html>`_ to associate with the resource.
458+
parameters(dict, optional): The value of this field is merged with other arguments to become the request payload for SageMaker `CreateHyperParameterTuningJob<https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHyperParameterTuningJob.html>`_.
459+
You can use `parameters` to override the value provided by other arguments and specify any field's value dynamically using `Placeholders<https://aws-step-functions-data-science-sdk.readthedocs.io/en/stable/placeholders.html?highlight=placeholder#stepfunctions.inputs.Placeholder>`_.
460+
448461
"""
449462
if wait_for_completion:
450463
"""
@@ -462,19 +475,22 @@ def __init__(self, state_id, tuner, job_name, data, wait_for_completion=True, ta
462475
kwargs[Field.Resource.value] = get_service_integration_arn(SAGEMAKER_SERVICE_NAME,
463476
SageMakerApi.CreateHyperParameterTuningJob)
464477

465-
parameters = tuning_config(tuner=tuner, inputs=data, job_name=job_name).copy()
478+
tuning_parameters = tuning_config(tuner=tuner, inputs=data, job_name=job_name).copy()
466479

467480
if job_name is not None:
468-
parameters['HyperParameterTuningJobName'] = job_name
481+
tuning_parameters['HyperParameterTuningJobName'] = job_name
469482

470-
if 'S3Operations' in parameters:
471-
del parameters['S3Operations']
483+
if 'S3Operations' in tuning_parameters:
484+
del tuning_parameters['S3Operations']
472485

473486
if tags:
474-
parameters['Tags'] = tags_dict_to_kv_list(tags)
487+
tuning_parameters['Tags'] = tags if isinstance(tags, Placeholder) else tags_dict_to_kv_list(tags)
475488

476-
kwargs[Field.Parameters.value] = parameters
489+
if Field.Parameters.value in kwargs and isinstance(kwargs[Field.Parameters.value], dict):
490+
# Update tuning parameters with input parameters
491+
merge_dicts(tuning_parameters, kwargs[Field.Parameters.value])
477492

493+
kwargs[Field.Parameters.value] = tuning_parameters
478494
super(TuningStep, self).__init__(state_id, **kwargs)
479495

480496

0 commit comments

Comments
 (0)