Skip to content

Feat/foreach step - #6473

Open
nayan3107 wants to merge 5 commits into
aws:masterfrom
nayan3107:feat/foreach-step
Open

nayan3107 wants to merge 5 commits into
aws:masterfrom
nayan3107:feat/foreach-step

Conversation

@nayan3107

Copy link
Copy Markdown
Contributor

What: Add ForEachStep to sagemaker.mlops.workflow. A ForEach step runs its body step(s) once per item of a list resolved at execution time, with a concurrency cap of 1–50.

iterable_items: a property reference that resolves to a JSON list, or a literal list of up to 100 scalars/property references.
for_each_body: one or more steps (Condition, Fail and nested ForEach are not allowed). Body steps read the current item via CurrentItem(), including deep paths and bracket indexing (CurrentItem().a.b, CurrentItem()["score"]).
ForEachSelector(pick="MaxBy"|"MinBy", field=IterationOutput(body_step).) picks one iteration.
Downstream references: properties.IterationOutputs[i].., properties.Selected., and the aggregates Status, InputItemCount, TotalStepCount, SucceededStepCount, FailedStepCount, StoppedStepCount.
StepsCompiler and PipelineGraph compile ForEach bodies and enforce unique step names across bodies.
Why: SageMaker Pipelines adds a ForEach step type; this exposes it in the PySDK.

Test: Unit tests for the new step, compiler paths and pipeline wire format, including full Pipeline.definition() checks; all 413 tests in sagemaker-mlops/tests/unit/workflow pass.

Original implementation by Daniel Castro; rebased onto master and aligned with the current service contract.

Daniel Castro and others added 5 commits October 14, 2026 10:39
Adds a new ForEachStep to sagemaker.mlops.workflow that iterates a
body of steps over a collection at pipeline execution time. Supports
CurrentItem / ChildOutput references, a Selector for picking values
from prior child outputs, and a configurable max_concurrency in the
range [1, 50].

- New for_each_step.py exposing ForEachStep, ForEachSelector,
  ForEachSelectorPickType, CurrentItem, and ChildOutput.
- Add FOR_EACH to StepTypeEnum.
- Extend StepsCompiler to compile ForEachStep bodies and share
  duplicate-name detection with ConditionStep by generalizing
  _flatten_condition_step into _flatten_compound_step.
- Track for_each_body dependencies in PipelineGraph and enforce
  unique step names across ForEachStep bodies.
- Re-export the new symbols from sagemaker.mlops.workflow.
- Unit tests covering the new step type, compiler paths, and
  pipeline wire format.
Remove Status, InputItemCount, TotalStepCount, SucceededStepCount,
FailedStepCount, and StoppedStepCount from ForEachStep.properties.
Only ChildOutputs[i] and Selected remain as downstream-referenceable
properties.

This aligns with the backend policy change: any child failure now
causes the entire ForEach step to fail (no partial success). The
PartiallySucceeded status is removed, making aggregate counters
no longer meaningful to downstream steps.
Remove _TerminalPropertyReference class and CurrentItem overrides.
CurrentItem now inherits full drilling from _ForEachPropertyReference:
- Deep dot paths: CurrentItem().a.b.c
- Bracket indexing: CurrentItem()['score'], CurrentItem()[0]

All forms produce valid {"Get": "ForEach.CurrentItem..."} expressions.
The service resolves these at expansion time for each child lane.
Remove the "exactly one body step" restriction so ForEach bodies can
contain any number of steps. Each iteration spawns one child instance
of every body step. Rename ChildOutput / ChildOutputs to
IterationOutput / IterationOutputs across the public API.

Property reference changes:
- properties.IterationOutputs[i].<bodyStepName>.<member> now requires
  a body step name qualifier, since an iteration may span multiple
  body steps.
- properties.Selected.<member> resolves directly to the selector-
  picked iteration's output — no body step name qualifier, because
  the selector's field already identifies the target body step.
The service still resolves the ForEach aggregate members (Status,
InputItemCount and the step counts) as downstream references, and
accepts a literal IterableItems list of up to 100 scalars or property
references. Expose both and add ForEach to the step-type guard test.
---
X-AI-Prompt: Fix the ForEachStep gaps against the Tioga backend
X-AI-Tool: kiro-cli

This branch is waiting to be deployed

1 waiting deployment
manual-approval — 839b04b2 Waiting Oct 14, 2026 by nayan3107 via wait-for-approval #667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant