[DRAFT] adding generated and custom code for custom training#45951
Open
jayesh-tanna wants to merge 1 commit intofeature/azure-ai-projects/2.0.2from
Open
[DRAFT] adding generated and custom code for custom training#45951jayesh-tanna wants to merge 1 commit intofeature/azure-ai-projects/2.0.2from
jayesh-tanna wants to merge 1 commit intofeature/azure-ai-projects/2.0.2from
Conversation
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.
Description
Typespec PullRequest: Azure/azure-rest-api-specs#41619
Add Training Jobs support to
azure-ai-projectsSDKOverview
This PR introduces
CommandJobsupport underclient.beta.training.jobs(sync) andasync_client.beta.training.jobs(async), enabling users to create, get, list, update,cancel, and delete training jobs from the Azure AI Projects SDK without wrapping boilerplate.
A lot of our customers are currently using
azure-ai-mlfeels familiar to them — same patterns, same mental model. That way, when they are ready to move to Azure AI Foundry, the migration is a small step rather than a full rewrite.Design Choices
1. Flat
CommandJobsurface — no envelope requiredCallers pass
CommandJobdirectly tocreate_or_updateand receiveCommandJobback fromget/list. The SDK wraps/unwraps theJob(properties=...)wire envelope transparently.2. Custom
CommandJobsubclass (model patch)CommandJobextends the auto-generated_RestCommandJoband exposes read-onlynameandidproperties promoted from the outer
Jobenvelope returned by the service.3.
_from_rest_objectfactory methodA classmethod on
CommandJobconstructs the flat model from any service response object,with explicit
ValueError/TypeErroron unexpected shapes rather than silentNonefields.4.
CommandJobLimits.timeoutacceptsint,float, ortimedeltaThe patched
CommandJobLimits.__init__converts plain numeric seconds totimedeltabeforeforwarding to the generated model, eliminating a common serialization foot-gun.
5. Auto-injection of
Foundry-Featurespreview headerEvery operation (list, get, create_or_update, begin_delete, begin_cancel) automatically injects
Foundry-Features: Jobs=V1Previewso callers never need to pass it manually as a custom header.6. Automatic local-path resolution for
codeandinputsIf
codeor an inputpathis a local file or folder, the SDK transparently uploads it as adataset asset and swaps in the returned datastore URI before the request is sent.
7. Input validation before every create/update
create_or_updatevalidatesname,command,environment_image_reference, andcomputeare non-empty upfront, surfacing clear
ValueErrors instead of opaque HTTP 400 responses.8. Full async mirror (
_patch_jobs_async.py)All sync customizations are mirrored in the async operations class using
async/awaitanddistributed_trace_async, including async dataset upload resolution forcodeandinputs.Customizations Summary
CommandJobmodel withnameandidpropertiesJobenvelope. We subclass the generated model to surfacenameandiddirectly on the object so callers never need to unwrapjob.properties.name.CommandJob._from_rest_objectfactoryJobresponse into a flatCommandJobin one place, with typed error messages if the response shape is unexpected (missing properties, wrong job type).Jobenvelope wrapping increate_or_updateJob(properties=CommandJob(...)). The patch wraps the caller's flatCommandJobinto the envelope automatically before the HTTP call, keeping the public API clean.CommandJobLimitstimeout coercion__init__to accept plainint/floatseconds in addition totimedelta, converting them automatically. Removes a class of runtime serialization errors when callers pass numeric timeouts.Foundry-Featurespreview header injectionFoundry-Features: Jobs=V1Previewinto every request from_inject_preview_header, so the preview feature flag is always active without callers needing to know about it.codeandinputscodeor inputpathis uploaded to a new dataset viaDatasetsOperationsand the field is replaced with the returned datastore URI transparently.name:versionorazureai:name:versionform is resolved to a full datastore URI by fetching the existing dataset, removing the need for callers to look up URIs manually._validateguardname,command,environment_image_reference, andcomputeare non-empty before any network call, giving callers an immediateValueErrorwith a clear message instead of a cryptic HTTP 400.async/awaitin_patch_jobs_async.pyso the async client has identical behaviour.Pending / Future Work
command()factory function — Following the same pattern asazure-ai-ml's top-levelcommand()function (seeazure.ai.ml.entities._builders.command_func), a standalonecommand(*, command, environment, compute, inputs, outputs, ...)helper will be added so userscan write
job = command(...); client.beta.training.jobs.create_or_update(name, job)withoutconstructing
CommandJobdirectly.header injection,
_from_rest_objecterror paths, async equivalents) will be added in this PRin the next commit.
Sample code
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines