Own the intelligence your enterprise runs on. Programmed Training in Microsoft Foundry, now in public preview, lets you write the training loop while Foundry runs the GPUs. It gives developers a Python API for authoring custom training recipes: your code decides what to sample, how to score responses, and when to update model weights. The preview includes the Fine-Tuning Sessions Python SDK, a public cookbook of training recipes, and LoRA training for four open-weight models: Qwen3.8-27B, Qwen3.6-35B-A3B, gpt-oss-120b, and Muse-Glimmer-30B. Nemotron Ultra is available on request, including a 256K-context variant, and long-context variants of Muse-Glimmer-30B and Qwen3.8-27B are coming soon.
Programmed Training joins recent Foundry fine-tuning updates: Open-source models and MAI-Code-1.1-Flash in Managed Fine-Tuning, and Multi-LoRA deployment on Managed Compute. Together, they give teams a flexible path from training data to a deployed adapter, at the level of control each workload needs. Configure a Managed Training job when a supported recipe fits. Program the loop when your application needs something more.
For teams training agents, Programmed Training also pairs with RL Environments (RLE), now in private preview. RLE runs your agent in sandboxes that resemble production, grades each attempt, and returns the result to your loop. The last section of this post covers how the two fit together.
Why a programmable training loop
We work with customers across a wide range of model training use cases. For many, the goal is a small, cost-effective model that excels at a well-defined task. Managed Training gives these teams the shortest time to value: they focus on collecting the right training and evaluation data, without becoming experts in the underlying algorithms.
As agentic applications grow in prominence, the tasks customers train for are getting more complex. Take an enterprise building a bespoke coding agent. Training a model to inspect a repository, call tools, respond to test failures, and revise a change is hard. The model has to act in an environment over multiple turns, and your training program has to coordinate that environment, score the outcomes, and decide which experience becomes training data.
Teams building workloads like this tend to arrive from one of two directions, and each runs into a different wall.
Coming from Managed Training: you need more control. A managed job takes your data and settings and runs a supported method end to end. That works well until the training logic itself becomes the differentiator:
- Custom rewards. Scoring with your own code, such as running a test suite or combining several graders into one signal.
- Training environments. Executing real tool calls and multi-turn interactions in a sandbox that resembles production, between each rollout and update.
- Curricula. Sequencing stages, such as SFT followed by RL, or adjusting the data mix and difficulty as the model improves.
Each of these needs your code running inside the loop, which takes a lower-level API than a configured job provides.
Coming from a self-managed stack: you need GPUs, and you need them to run well. Teams running their own post-training with open-source frameworks such as TRL, verl, or prime-rl already have that control. Their challenge is the infrastructure underneath it:
- Access. Securing enough accelerator capacity, especially for larger models, is difficult, and capacity often isn’t available when an experiment is ready to run.
- Efficiency. An RL run alternates between sampling and training. Keeping both busy, tuning distributed configurations, and recovering from failures is ongoing engineering work.
- Cost. Reserved GPUs bill by the hour, whether they are busy or waiting on an environment or a reward calculation.
Programmed Training is built for both groups. You keep loop-level control in your own Python, and Foundry provisions and runs the GPUs behind each operation, with usage billed by the tokens your loop processes. See when to use Programmed Training for more scenarios.
Five composable GPU operations
Most modern post-training methods are built from the same few steps: generate responses, turn them into a learning signal, compute gradients, and update the weights. Supervised fine-tuning, preference learning, distillation, and reinforcement learning differ mainly in where the training data comes from and how the loss is calculated. Programmed Training exposes those shared steps as five operations that run on GPUs managed by Foundry. Your Python driver composes them into the algorithm you need, from a single supervised update to a multi-turn RL loop.
The Fine-Tuning Sessions Python SDK keeps each operation separate, so your program decides what happens between them:
| Operation | What Foundry executes | What your driver decides |
|---|---|---|
sample | Generates responses from a selected sampler checkpoint | Which prompts, how many responses each, and whether they are rollouts or evaluation |
forward_backward | Computes a supported objective and accumulates gradients | Which batch, which loss, and which tokens contribute to learning |
optim_step | Applies accumulated gradients to the LoRA adapter | When to update, and with which optimizer settings |
save_weights_for_sampler | Refreshes sampler weights from the current adapter | When the next round of sampling should use the update |
save_weights | Saves adapter and optimizer state | How often to checkpoint, so training can resume in a compatible session |
One set of operations, many post-training methods
| Method | How your driver composes the operations |
|---|---|
| Supervised fine-tuning | Run forward_backward with cross_entropy on demonstrations, then optim_step. No sampling required. |
| Reinforcement learning | sample rollouts, score them and compute advantages in your driver, run forward_backward with a policy loss, then optim_step. Refresh with save_weights_for_sampler before the next round. |
| Multi-turn and tool-use RL | Run the same loop, with your driver coordinating tool calls and environment observations between turns and excluding observations from the learning signal. |
| Preference learning | Compose a preference loss in Python. The cookbook's custom-loss helper combines the service's forward outputs with the loss your driver computes. |
| Distillation | Train a student model toward a teacher model's responses, starting from the cookbook's distillation recipes. |
The SDK provides the loss primitives: loss_fn accepts cross_entropy, importance_sampling, ppo, cispo, and sapo. Your driver supplies the rest of the algorithm, including grouping, grading, and advantage computation. When you need an objective outside that list, the cookbook's custom-loss helper composes the service's forward outputs with a differentiable loss you compute in Python; the service does not accept uploaded arbitrary training code. Each method has a starting point in the cookbook, and key concepts covers loss inputs and token weights.
The shortest composition is a supervised update:
from azure.ai.finetuningsessions.models import AdamParams, LossFn
session.forward_backward(batch, loss_fn=LossFn.CROSS_ENTROPY)
session.optim_step(
AdamParams(
learning_rate=2e-5,
beta1=0.9,
beta2=0.95,
eps=1e-8,
weight_decay=0.0,
)
)
saved = session.save_weights("first-update")
checkpoint = f"{session.session_id}/{saved.checkpoint_id}"
The fragment assumes an authenticated, open session and a nonempty tokenized batch prepared as shown in the SDK cheatsheet; the optimizer values are illustrative.
RL example, step by step
Here is how the five operations compose into one iteration of the quickstart's math RL recipe, which samples four answers to each of eight problems, then learns from how each answer compares with the others in its group. Your Python program is the training driver: it prepares inputs, scores results, and decides what happens next. Foundry holds the model and adapter state and executes each operation your driver requests.
The teal steps are yours to change. You own the data, rewards, token masks, update schedule, and evaluation logic. Your driver can run on a CPU, including your laptop. Any reward models or environments you add have their own compute requirements. For the full sequence, see how an RL loop works.
Programmed Training in action
To see what a custom loop can do for a real agent task, read how Whitney AI used Programmed Training to train a code review agent. Their driver scored each review against the fixes that pull request authors actually made, then ran supervised fine-tuning followed by RL on Qwen3.8-27B. With about 250 training examples, the tuned model nearly doubled its review quality and edged out a leading frontier model at high reasoning while using 4.5x fewer tokens.
| ~2x review quality over the base model | 4.5x fewer tokens than a leading frontier model | ~250 training examples |
Managed Training or Programmed Training?
Managed Training already supports reinforcement fine-tuning (RFT) with graders, so the deciding question is who runs the loop. Choose Programmed Training when you need to control rollout collection, environment interaction, batch construction, or the timing of updates and evaluations.
| Choose by | Managed Training | Programmed Training |
|---|---|---|
| Workflow | Submit data and settings; Foundry runs the training job. | Write the Python driver; Foundry executes the model operations. |
| Control | Supported hyperparameters, datasets, and RFT graders. | Rollouts, rewards, losses, gradient accumulation, updates, and checkpoints. |
| Best fit | Teams using supported SFT, DPO, or RFT workflows, depending on the model. | ML practitioners building custom learning workflows or multi-turn environment interactions. |
Both approaches use Foundry-managed training infrastructure. Model eligibility differs between them. Compare them side by side in choose your training approach.
Models and deployment
Models
Programmed Training is launching with Global support for 4 OSS models with more coming soon:
- Qwen3.8-27B
- Qwen3.6-35B-A3B
- gpt-oss-120b
- Muse-Glimmer-30B
Also available on request or coming soon:
- Nemotron Ultra (available on request)
- Nemotron Ultra, 256K context (available on request)
- Muse-Glimmer-30B, 128K context (coming soon)
- Qwen3.8-27B, 256K context (coming soon)
For on-request models, work with your Microsoft account team when you request preview access.
Support for MAI-Code-2-Flash is coming soon through Managed Training for RFT and is not part of this Programmed Training preview.
Deployment
When an adapter is ready to serve, deploy it with Managed Compute. Managed Compute runs a matching base model with one or more compatible LoRA adapters on dedicated GPU capacity. With Multi-LoRA adapter deployment, several adapters can share one base-model deployment.
Deployment is a separate step from sampling inside a training session. Review the model compatibility matrix before choosing your training and deployment configuration.
Pricing: pay for the tokens your loop uses
Programmed Training meters the work your loop performs in four categories:
- Prefill: uncached sampling inputs
- Cached prefill: inputs served from the prompt cache
- Sampling: generated outputs
- Training: tokens processed by training operations
List prices in USD per 1 million tokens:
| Model | Prefill | Cached prefill | Sampling | Training |
|---|---|---|---|---|
| Qwen3.6-35B-A3B | $0.54 | $0.108 | $1.335 | $1.177 |
| Qwen3.8-27B | $1.86 | $0.372 | $5.595 | $4.103 |
| gpt-oss-120b | $0.33 | $0.066 | $0.84 | $0.737 |
| Muse-Glimmer-30B | $1.96 | $0.392 | $4.88 | $5.86 |
Note: Prices reflect rates at the time of publishing. For up-to-date pricing, please refer to the Fine-Tuning Pricing Page.
Programmed Training and RL Environments: your loop, grounded in a real production setup
RL Environments (RLE) is in private preview. Access is by request and is separate from the Programmed Training public preview. Capabilities may change before broader availability.
Post-training used to start with a labeled dataset. Now it can start with a success criteria: you define what a good outcome looks like, and the agent practices in a production-like setup until it gets there.
In the math example above, scoring is one line of Python: the answer is right or it isn't. For an agent, that step is most of the work. Go back to the coding agent from the start of this post. To score one attempt, you need a repository in a known state, the tools the agent will really use, somewhere isolated to run them, and a grader that can tell a correct change from one that only looks correct. Then you need all of that again, in parallel, for every rollout in the batch.
Programmed Training leaves that work to your driver by design. RL Environments is the Foundry capability that takes it on: managed sandboxes, where agents complete tasks as they would in production, get graded, and improve.
How RLE works
- An environment is a versioned set of tasks plus a grader that scores each attempt.
- A harness is how the agent acts on a task: the system prompt, tools, and control loop around the model that decide each next step.
- A rollout puts them together: one model, in one harness, attempting one task from the environment in a fresh, isolated sandbox. The environment then grades the result.
- Each rollout returns two things: a trajectory (the model calls, tool calls, retries, and final state) and a reward from the grader.
Run rollouts with any harness. Use the harness you already run in production, with its own tools. That can be a pre-built harness, such as OpenCode for Harbor-style coding tasks, or your existing agent, hosted in Foundry or any other cloud: just point RLE at it.
No harness yet? Build an OpenEnv-style environment with the tools and rules built in, and RLE runs rollouts with that environment and your chosen model.
How the two fit together
Your Programmed Training loop calls execute_rollout using the RLE SDK. RLE runs the rollouts in parallel, grades them, and returns rewards and trajectories as ready-to-use learning samples. From there the loop is the one you already know: your driver turns rewards into advantages and builds the batch, and Foundry runs forward_backward and optim_step on serverless GPUs.
| Programmed Training | RL Environments | |
|---|---|---|
| Status | Public preview | Private preview |
| What it gives you | Control of the learning loop: rewards, losses, sampling, and update timing | Reusable tasks, tools, and verifiable scoring in the harness you choose |
| What Foundry runs | Model operations and LoRA updates on serverless GPUs | Concurrent rollouts in isolated, managed sandboxes |
| What comes back | Samples, log probabilities, and updated adapter weights | A reward and a full trajectory for each rollout |
Why use them together
- Training that carries over to production. Bring an existing agent, a pre-built harness, or your own loop. The agent practices inside the harness it actually ships in, not a simplified copy with mock tools.
- Rewards for the whole job, not only the answer. The grader scores outcome and process: the tool calls, the retries and recoveries, and the state the agent leaves behind.
- One environment for evaluation and training. The same versioned environment serves both, so results before and after training are directly comparable.
- Scale without building it. Rollouts run in parallel, and RLE manages the sandboxes for built-in and pre-built harnesses.
- Fully traceable rollouts. Open any rollout's trace to see each tool call, sub-agent invoked, tokens consumed, and the reward it earned. Compare traces side by side and follow the reward graph across a run. Built-in skills help you analyze rollouts at scale and spot reward hacking before it reaches your model.
Neither depends on the other. Programmed Training works with any environment and reward code your driver can run, and RLE also works with Managed Training, where Foundry runs the RL loop for you. Together they cover both halves of agent training: you program how the model learns, and RLE grounds what it learns in real tasks, tools and your definition of success.
To try RL Environments, request private preview access and tell us about your team and scenario.
Get started
Three steps take you from access to your first custom training loop:
- Request access. Complete the access request form. Once approved, use a Foundry project in a supported region and assign yourself the Foundry User role.
- Run the quickstart. The quickstart walks you through installing the cookbook, signing in with the Azure CLI, and running a small math RL recipe end to end.
- Make it yours. Swap in your own data or reward function using the cookbook recipes, and compare against a held-out baseline before you scale up.
For the full picture, read the Programmed Training overview and key concepts.
Ready to write your own loop? Request Programmed Training preview access.