Skip to content

[azure-ai-projects] Add @dynamic pipeline nodes compiled at job runtime - #16

Open
zzn2 wants to merge 4 commits into
feature/azure-ai-projects/training-prpr-2.2.0-pipelinesfrom
zhizhu-microsoft-sdk-dynamic-pipelines
Open

zzn2 wants to merge 4 commits into
feature/azure-ai-projects/training-prpr-2.2.0-pipelinesfrom
zhizhu-microsoft-sdk-dynamic-pipelines

Conversation

@zzn2

@zzn2 zzn2 commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Background

The azure.ai.projects.dsl module can author Foundry pipelines with @component and @pipeline, including nested pipelines, but every graph must be fully known at submission time. Many training workflows only know their shape once the job runs: the number of shards comes from a data scan, the set of evaluations depends on an earlier step, and so on. The Foundry pipeline service already supports this through dynamic Command nodes, which compile a subgraph at runtime that the service then expands in place. Until now, authoring such nodes required mldesigner and therefore azure-ai-ml inside the job image.

This PR adds azure.ai.projects.dsl.dynamic, a decorator that defines a dynamic node directly in the project SDK, together with a small runtime executor that compiles and registers the subgraph without mldesigner or azure-ai-ml.

@dynamic
def fan_out(shards: int) -> None:
    for shard in range(shards.result()):
        train(shard=shard)

@pipeline(compute_id=..., environment_image_reference=..., user_assigned_identity_id=...)
def workflow(shards: int):
    fan_out(shards=shards)

How it works

sequenceDiagram
    participant SDK as Client SDK<br/>(@pipeline / @dynamic)
    participant Svc as Foundry pipeline service
    participant Node as Dynamic node<br/>(azure.ai.projects._dynamic_executor)
    participant Proj as Foundry project APIs
    participant RH as Run history (via MLflow)
    SDK->>Proj: register Command component<br/>properties azureml.pipelines.dynamic=true
    SDK->>Svc: submit PipelineJob
    Svc->>Node: run node with resolved inputs
    Node->>Node: call user function, collect created nodes
    Node->>Proj: upload code, register Pipeline component mldyn-hash/1
    Node->>RH: PATCH run property<br/>azureml.pipelines.dynamicSubPipelineComponentId
    Svc->>Svc: expand registered subgraph in place of the node
Loading

Authoring. @dynamic is always source-backed, like a source @component: the function's code root is snapshotted and uploaded. The node's command is python -m azure.ai.projects._dynamic_executor <settings> <module> <function> <inputs...>, where <settings> is a URL-safe base64 JSON of the enclosing pipeline's compute, image, identity and instance type, so nodes created at runtime inherit them. The component carries the property azureml.pipelines.dynamic: "true"; registration of top-level Command components (from #14) now forwards component properties into the registered resource's properties as well, since that is where the service reads the marker.

Runtime. The executor imports the user function, passes each input as an input reference whose .result() returns the resolved value (so Python control flow can depend on it), and records every @component call as a node of a new Pipeline component whose inputs mirror the dynamic node's inputs (${{parent.inputs.x}} bindings are preserved). It uploads code through the same client.beta.jobs code-resolution path used at submission, registers the Pipeline component under a run- and content-derived name (mldyn-<hash>, version 1, anonymous, client_component_hash property, Foundry-Features: Jobs=V1Preview), and writes the component ID to the node's run as azureml.pipelines.dynamicSubPipelineComponentId. The service reads that property after the node completes and expands the subgraph.

Design note

Ported from mldesigner: the decorator contract (marker property, input references with .result()), runtime invocation of the user function to collect nodes, content-hashed anonymous Pipeline component registration against the Foundry project endpoint derived from AZUREML_ARM_WORKSPACE_NAME (<account>@<project>@AML), and the RunHistory write. Left in mldesigner: mldesigner's own component model and mldesigner execute CLI, AML workspace (non-Foundry) registration, environment objects other than an image, dynamic outputs and output validation, and any azure-ai-ml interop. The executor reuses the existing DSL (_PipelineContext, _component_ports, _CONVERSIONS) rather than adding a second component model.

Backend contract. The marker property, the RunHistory key, the mldyn- naming and the generated interface shape (inputs matching the dynamic node, no outputs) follow the contract the Foundry pipeline service consumes today, as exercised by a completed Foundry project dynamic job whose compiler registered mldyn-<hash>/1 and whose two expanded child runs completed.

Identity and registration. The executor authenticates to the project with the job's user-assigned managed identity (DEFAULT_IDENTITY_CLIENT_ID) via ManagedIdentityCredential, so that identity needs permission to upload data and register components in the project.

RunHistory write and the dynamic extra. The project SDK has no RunHistory client, and the job platform already hands each run MLflow tracking credentials (MLFLOW_TRACKING_URI / token). The executor therefore uses MLflow's host credentials, rewrites the tracking host from mlflow/v2.0 to history/v1.0, and PATCHes /experimentids/{exp}/runs/{run} with the property, the same route mldesigner uses. Tokens are never read into the SDK or logged. Because only the job image needs this, mlflow-skinny and azureml-mlflow are declared as a new optional extra, azure-ai-projects[dynamic], rather than hard dependencies; a missing install raises an ImportError naming the extra.

Scope and limitations

  • Dynamic functions may only create @component (Command) nodes; they cannot declare outputs, return values, or create nested pipelines.
  • Dynamic nodes are supported as top-level nodes of the submitted pipeline. A dynamic node inside a nested @pipeline is not registered with the marker by the current registration flow and has not been validated end to end with the service.
  • Nodes created at runtime use the image-only environment, compute, identity and instance type of the enclosing @pipeline.
  • The job image must contain this version of azure-ai-projects with the dynamic extra.
  • Without AZUREML_RUN_ID (for example, when run locally), the executor prints the compiled spec instead of registering it.

Dependencies

This builds on pipeline work already merged into the integration branch:

Customer samples using @pipeline and @dynamic follow in a separate PR.

zzn2 and others added 2 commits December 4, 2026 01:32
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@zzn2
zzn2 force-pushed the zhizhu-microsoft-sdk-dynamic-pipelines branch from 75742c9 to 8a5ad0e Compare December 4, 2026 09:33
…ode delegate

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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