Skip to content

perf(optimizers): wire amsgrad to the fused compiled training path (#653) - #1653

Merged
ooples merged 1 commit into
masterfrom
perf/653-fused-optimizer-coverage
Jun 22, 2026
Merged

ooples merged 1 commit into
masterfrom
perf/653-fused-optimizer-coverage

Conversation

@ooples

@ooples ooples commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

#653 core-saturation, training-perf lever: widen fused-optimizer coverage so AMSGrad no longer falls off the fused compiled training path into the eager tape fallback.

AMSGradOptimizer<T> now implements IFusedOptimizerSpec and maps to the Tensors OptimizerType.AMSGrad fused kernel via TryMapToFusedOptimizerConfig, so TrainWithTape keeps AMSGrad on the fused fast path (which eliminates the bulk of the tape-walk backward cost) instead of dropping to the eager fallback cliff. The map is guarded: it declines (returns false) when UseAdaptiveLearningRate is set or the LR schedule isn't fused-representable, so those paths still run eager — correctness preserved.

Tests

FusedOptimizerParityTests.AMSGrad_FusedMatchesEager_NoWorseThanAdam — runs the fused (compiled) vs eager training step for 40 steps and asserts:

  • the fused path actually engages (fusedSteps > 0),
  • training makes progress (trainDelta > 1e-6),
  • fused-vs-eager parameter divergence stays within the Adam-parity bound.

Green locally.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • AMSGrad optimizer now supports fused-training compilation mode for optimized performance.
  • Tests

    • Added integration test to verify training parity between fused and eager execution modes for AMSGrad.

AMSGradOptimizer did not implement IFusedOptimizerSpec, so every Train()
step fell back to the eager autograd tape — a multi-x perf cliff — even
though the Tensors fused kernel already implements the AMSGrad variant
(the same OptimizerType.AMSGrad that AdamOptimizer.UseAMSGrad selects).

Implement IFusedOptimizerSpec on AMSGradOptimizer (Adam-shaped params:
beta1/beta2/epsilon, no decoupled weight decay), mirroring the Adam/AdaMax
specs and falling back when an adaptive LR or unsupported scheduler is set.

Adds an AMSGrad case to FusedOptimizerParityTests proving the fused path
engages (fusedSteps>0) and produces parameter-identical results to the
eager tape over 40 steps (within the Adam control tolerance). Full parity
suite green: 9/9.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aidotnet_website Ready Ready Preview, Comment Jun 21, 2026 4:41pm
aidotnet-playground-api Ready Ready Preview, Comment Jun 21, 2026 4:41pm

@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 14479147-565f-4cbf-9e41-222098d426e0

📥 Commits

Reviewing files that changed from the base of the PR and between 7a46620 and 16ee571.

📒 Files selected for processing (2)
  • src/Optimizers/AMSGradOptimizer.cs
  • tests/AiDotNet.Tests/IntegrationTests/Optimizers/FusedOptimizerParityTests.cs

Walkthrough

AMSGradOptimizer adds Fused.IFusedOptimizerSpec to its class declaration and implements TryGetFusedOptimizerConfig, which returns a FusedOptimizerConfig for OptimizerType.AMSGrad unless adaptive LR mode is active or no fused scheduler can be resolved. A new integration test verifies fused/eager parity against an Adam control.

Changes

AMSGrad Fused Optimizer Integration

Layer / File(s) Summary
IFusedOptimizerSpec implementation on AMSGradOptimizer
src/Optimizers/AMSGradOptimizer.cs
Class declaration updated to implement Fused.IFusedOptimizerSpec; TryGetFusedOptimizerConfig added with guard clauses for adaptive LR mode and unresolvable fused LR schedules, returning a populated FusedOptimizerConfig with Beta1, Beta2, Epsilon, and derived schedule otherwise.
Fused/eager parity integration test
tests/AiDotNet.Tests/IntegrationTests/Optimizers/FusedOptimizerParityTests.cs
New [Fact] test trains Adam for a control divergence value, then runs AMSGradOptimizer on both fused and eager code paths, asserting parity via AssertOptimizerParity and a not-worse-than-Adam bound.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🧮 AMSGrad steps in, fused and keen,
No adaptive mode to intervene.
Beta1, Beta2, Epsilon align,
A config returned when the schedule is fine.
Parity tested, Adam's the bar—
The gradient flows, near and far. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf(optimizers): wire amsgrad to the fused compiled training path' clearly and specifically describes the main change—enabling AMSGradOptimizer to use the fused compiled training path for performance improvement.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/653-fused-optimizer-coverage

Comment @coderabbitai help to get the list of available commands and usage tips.

@ooples
ooples merged commit 062aa37 into master Jun 22, 2026
60 of 80 checks passed
@ooples
ooples deleted the perf/653-fused-optimizer-coverage branch June 22, 2026 02:53

This branch was successfully deployed

2 active deployments
Preview – aidotnet_website — 16ee5713 Deployed Jun 21, 2026 by vercel[bot]
Preview – aidotnet-playground-api — 16ee5713 Deployed Jun 21, 2026 by vercel[bot]
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