Skip to content

chore: remove dead AiDotNet JIT scaffolding; bump Tensors to 0.42.3 (Closes #1015)#1155

Merged
ooples merged 16 commits intomasterfrom
chore/remove-dead-jit-scaffolding
Apr 20, 2026
Merged

chore: remove dead AiDotNet JIT scaffolding; bump Tensors to 0.42.3 (Closes #1015)#1155
ooples merged 16 commits intomasterfrom
chore/remove-dead-jit-scaffolding

Conversation

@ooples
Copy link
Copy Markdown
Owner

@ooples ooples commented Apr 18, 2026

Summary

Closes #1015.

AiDotNet's in-tree JitCompiler was deleted some time ago (commit b7ed739) and replaced by the fully-automatic compilation pipeline in `AiDotNet.Tensors` — `AutoTracer` + `CompiledInferencePlan` + `CompiledTrainingPlan`, all auto-enabled, hooked into every `CpuEngine` op. But the AiDotNet side kept ~30 files of stubs, a dead `src/InferenceOptimization/` IR/passes/kernels tree (36 .cs files), a dead `TapeLayerBridge`, a chain of JIT-only helper methods inside layer base classes, and six stale `docs/JIT_*.md` files. This PR clears that debt and pins the latest Tensors with the automatic compilation work.

Per the facade pattern, compilation is transparent — nothing changes at the user-facing API level. `model.Predict(x)` auto-compiles on the 2nd call with the same shape; `TrainWithTape` auto-uses `CompiledTrainingPlan`. Opt out via `TensorCodecOptions.Current.EnableCompilation = false` or the still-supported `AiModelBuilder.ConfigureJitCompilation()` builder API (which projects its config onto the live `TensorCodecOptions` under the hood).

Done

Phase 0 — `AiDotNet.Tensors` 0.38.0 → 0.42.3 (and `AiDotNet.Native.OneDNN` in lockstep). No source changes needed; API is backward-compatible across the bump.

Phase 1 — Deleted dead directories & files:

  • `src/InferenceOptimization/` entire tree (36 .cs + README + ARCHITECTURE).
  • `tests/AiDotNet.Tests/InferenceOptimization/`, `IntegrationTests/InferenceOptimization/`, `AiDotNetBenchmarkTests/InferenceOptimization/`.
  • `src/NeuralNetworks/SyntheticData/TapeLayerBridge.cs` (zero callers — its xmldoc falsely claimed WGAN-GP use; WGANGP.cs actually uses `GradientTape` directly).
  • `src/Helpers/UsingsHelper.cs` + test `GlobalUsings.cs` aliases for the deleted types.
  • 1 dead test region in `MergedPRBugFixTests.cs`.
  • 6 `docs/JIT_*.md` files + `tests/.../Benchmarks/JIT_BENCHMARKS_README.md` + `examples/JitCompiler/`.

Phase 2 — Removed `ExportComputationGraph` / `SupportsJitCompilation` / JIT-only graph builders from 22 base/model/layer files including LayerBase, NeuralNetworkBase, every model base (Classifier, Regression, Diffusion, VAE, NoisePredictor, TimeSeries, Survival, Online, Causal, AutoML, Sharded, RL), plus layer-internal dead helpers (ApplyActivationToGraph / CanActivationBeJitted / BuildComputationGraph / kernel-graph helpers / tree-graph helpers). Scrubbed stale "JIT compilation support via ExportComputationGraph()" bullets from 4 Graph* layer xmldoc comments. Removed obsolete `JitRemoved_SupportsJitIsFalse` / `LocallyWeightedRegression_SoftMode_EnablesJitCompilation` / etc. test assertions.

Preserved (live, facade-required):

  • `src/Configuration/JitCompilationConfig.cs` + `AiModelBuilder.ConfigureJitCompilation()` — the user-facing opt-out surface. Its `ApplyToTensorCodec()` projects settings onto the live `TensorCodecOptions`.
  • `src/Inference/InferenceOptimizer.cs`, `src/Configuration/InferenceOptimizationConfig.cs` — live KV-cache / speculative-decoding / weight-only-quantization config (unrelated to the deleted `InferenceOptimization` tree despite the naming collision).
  • `src/Autodiff/` — legacy autodiff with `ComputationNode`, `TensorOperations`, `GradientCheckpointing`. Live.
  • `src/Training/CompiledTapeTrainingStep.cs` + `src/Inference/CompiledModelHost.cs` — the live auto-compile paths that `Predict` / `TrainWithTape` route through.

Test plan

  • `dotnet build src/AiDotNet.csproj` green on net10.0 and net471, 0 errors.
  • `dotnet build tests/AiDotNet.Tests` green on both TFMs, 0 errors.
  • `dotnet build AiDotNetBenchmarkTests` green, 0 errors.
  • Existing auto-compile regression tests pass: 14/14 on both `CompileForwardTests` (CompileForward pre-warm contract) and `CompiledModelHostTests` (host dispose, concurrent predict, structure-version invalidation).
  • `grep ExportComputationGraph src/` → zero production references (33 remaining refs are harmless mock stubs in test fixtures).
  • Downstream CI: will confirm model-family shards still run green (the Tensors bump also brings the recent backward-op perf + net471 SIMD work which should help the perf: fix 5 cancelled CI jobs — Diffusion models OOM/timeout from eager weight allocation #1136 timeout situation).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Updated AiDotNet.Tensors and AiDotNet.Native.OneDNN package versions to 0.46.0.
  • Documentation

    • Removed multiple JIT and inference-optimization guides, roadmaps, examples, and module READMEs.
  • Tests

    • Removed numerous benchmarks and inference-optimization/IR validation test suites and related example tests.
  • Refactor

    • Removed JIT compilation surface and the inference-optimization subsystem, including related public APIs and example usage points.

franklinic and others added 3 commits April 17, 2026 09:17
Also bumps AiDotNet.Native.OneDNN in lockstep. Picks up the recent
perf work (backward-op primitive fast paths, net471 SIMD gap fix,
memory planning / tile scheduling / operator reordering, plan
serialization + stitching audit fixes) and is the baseline for the
dead-JIT-scaffolding cleanup in issue #1015.

Both net10.0 and net471 build with 0 errors. No source changes needed
— the Tensors API is backward-compatible across 0.38 → 0.42.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The src/InferenceOptimization/ directory (16 .cs files + Core/IR/Kernels/Passes
subdirs + README + ARCHITECTURE) was orphaned JIT IR/optimization-pass
scaffolding from a compilation model that no longer exists. Zero production
code in src/ referenced it — only tests and benchmarks did. The AiDotNet.Tensors
compilation system (AutoTracer + CompiledInferencePlan + CompiledTrainingPlan,
auto-enabled) is the replacement.

Removed:
- src/InferenceOptimization/ (full tree, 36 .cs files)
- tests/AiDotNet.Tests/InferenceOptimization/ + IntegrationTests/InferenceOptimization/
- AiDotNetBenchmarkTests/InferenceOptimization/
- The InferenceOptimization PR #768 regression-tests region in MergedPRBugFixTests.cs
- global using MemoryLayout / QuantizationParams aliases in src/Helpers/UsingsHelper.cs
  and tests/AiDotNet.Tests/GlobalUsings.cs (nothing else in either project uses
  either of those short names)
- src/NeuralNetworks/SyntheticData/TapeLayerBridge.cs — public method
  ExportMLPGeneratorGraph had zero callers; xmldoc falsely claimed WGAN-GP use
  but WGANGP.cs:450-456 already uses GradientTape<T> directly
- SyntheticTabularGeneratorBase.ExportMLPGeneratorGraph wrapper (dead)
- SyntheticTabularGeneratorBase.SupportsJitCompilation + ExportComputationGraph
  stubs (both threw NotSupportedException)

Scrubbed TapeLayerBridge mentions from MedSynthGenerator, MisGANGenerator,
TimeGANGenerator private helper xmldoc (the helpers themselves remain —
they're still used by in-progress gradient-penalty code or kept for
analysis).

Cosmetic: the "// InferenceOptimization Operations" and
"// Fused Operations for InferenceOptimization" comment labels in
src/Enums/OperationType.cs are replaced with generic labels. The enum
values themselves are public API and left in place.

LIVE and untouched (different systems that share a prefix):
- src/Inference/InferenceOptimizer.cs (KV-cache, speculative decoding)
- src/Configuration/InferenceOptimizationConfig.cs (quantization config)

Build: net10.0 + net471 both green, 0 errors. Tests build green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The removed AiDotNet JitCompiler left behind a graveyard of stub
methods and now-unreachable graph-building helpers. All of them either
threw NotSupportedException or built ComputationNode<T> trees for a
compiler that no longer exists.

Deleted:
- ExportComputationGraph method on: LayerBase, NeuralNetworkBase,
  ClassifierBase, MultiLabelClassifierBase, RegressionBase,
  NonLinearRegressionBase, DecisionTreeRegressionBase,
  DecisionTreeAsyncRegressionBase, DiffusionModelBase, VAEModelBase,
  NoisePredictorBase, AutoMLModelBase, ShardedModelBase, CausalModelBase,
  OnlineLearningModelBase, TimeSeriesModelBase,
  ReinforcementLearningAgentBase, SurvivalModelBase, NBEATSBlock,
  AiModelResult, MCDropoutLayer, BayesianDenseLayer.
- ConvertLayerToGraph helper on NeuralNetworkBase.
- SupportsJitCompilation property on LayerBase + same accompanying
  bases (kept on IActivationFunction / IVectorActivationFunction
  interfaces and their implementations since those are still consumed
  by LoRA / SE / Hyperbolic layer fallback paths).
- Layer-internal graph helpers: LayerBase.ApplyActivationToGraph,
  CanActivationBeJitted, SparseLinearLayer.ApplyActivationToComputationNode,
  SqueezeAndExcitationLayer.ApplyActivationToGraphNode,
  SpyNetLayer.{BuildComputationGraph,BuildPyramidGraph,CreateGridFromFlowGraph,
  CreateIdentityGrid,CreateScaleTensor},
  DeformableConvolutionalLayer.BuildComputationGraph.
- NonLinearRegressionBase kernel-graph helpers:
  ComputeLinearKernel, ComputeRBFKernel, ComputeSigmoidKernel,
  ComputePolynomialKernel, ComputeLaplacianKernel, CreateFilledTensorLike.
- DecisionTreeRegressionBase / DecisionTreeAsyncRegressionBase
  ExportNodeAsComputationGraph + GetMaxFeatureIndexFromTree helpers.
- NBEATSBlock.ApplyBasisExpansionGraph helper.
- TestScaffoldGenerator emitting the SupportsJitCompilation /
  ExportComputationGraph stubs into generated test fixtures.

Stale xmldoc bullets "JIT compilation support via ExportComputationGraph()"
removed from GraphAttentionLayer, GraphIsomorphismLayer, GraphSAGELayer,
PrincipalNeighbourhoodAggregationLayer.

Tests: removed obsolete *_JitRemoved_SupportsJitIsFalse* assertions from
BaseClassesIntegrationTests and the LoRA/KNN/LWR/RotaryPE/QuantizedAttention
SupportsJitCompilation checks. Removed MixedPrecisionIntegrationTests'
TestLayer override of SupportsJitCompilation / ExportComputationGraph.

Compilation is transparent via AiDotNet.Tensors' AutoTracer (auto-enabled,
hot paths compile to CompiledInferencePlan after the 2nd call). Opt out
via TensorCodecOptions.Current.EnableCompilation or the still-supported
AiModelBuilder.ConfigureJitCompilation() builder API (which projects
config onto the live TensorCodecOptions under the hood).

Build: net10.0 + net471 + tests all green, 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 18, 2026

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

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
aidotnet_website Ignored Ignored Apr 19, 2026 3:31pm
aidotnet-playground-api Ignored Ignored Preview Apr 19, 2026 3:31pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 18, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Removes the AiDotNet JIT / inference-optimization subsystem and all related artifacts: IR (HLIR/LLIR), optimizer/passes, custom operators and kernels (GEMM, Conv, Attention), HLIR→LLIR lowering, OptimizationInitializer/registry, ExportComputationGraph/IJitCompilable surfaces, tests, docs, examples, and bumps AiDotNet.Tensors / OneDNN versions.

Changes

Cohort / File(s) Summary
InferenceOptimization core & IR
src/InferenceOptimization/..., src/InferenceOptimization/Core/*, src/InferenceOptimization/IR/*
Entire inference-optimization subsystem deleted: IR types (IRTypes), HLIR/LLIR graphs/nodes/ops, compiler contracts, lowering pipeline, optimization graph/node/level/options, memory plan and device config types.
Optimization passes
src/InferenceOptimization/Passes/*
Deleted pass framework and all concrete passes (IOptimizationPass, OptimizationPassBase and passes: constant folding, CSE, algebraic simplification, fusion passes, DCE, layout, memory reuse, in-place, strength reduction, etc.).
Kernels & registry/initializer
src/InferenceOptimization/Kernels/*, src/InferenceOptimization/CustomOperatorRegistry.cs, src/InferenceOptimization/OptimizationInitializer.cs, src/InferenceOptimization/ICustomOperator.cs
Removed custom operator interfaces, registry, initializer and kernel implementations (GemmKernel, ConvolutionKernel, AttentionKernel) plus operator metadata APIs.
HLIR→LLIR lowering & low-level ops
src/InferenceOptimization/IR/Lowering/*, src/InferenceOptimization/IR/LowLevel/*
Removed HLIR→LLIR lowering pipeline and LLIR op model, memory-planning, scheduling/auto-schedule, and related metrics/validation utilities.
Benchmarks, examples & docs
AiDotNetBenchmarkTests/InferenceOptimization/*, examples/JitCompiler/*, docs/JIT_*.md, src/InferenceOptimization/README.md, src/InferenceOptimization/ARCHITECTURE.md
Deleted BenchmarkDotNet benchmarks, JIT compiler examples, JIT docs/guides/roadmap/workspace design and module README/architecture files.
Tests: IR, lowering, optimizer & kernels
tests/AiDotNet.Tests/InferenceOptimization/...
Removed extensive test suites covering HLIR/LLIR, lowering, optimization graph/passes, kernel validation tests and benchmark README.
Model & layer JIT API surface
src/*/*ModelBase.cs, src/NeuralNetworks/.../LayerBase.cs, src/NeuralNetworks/.../*Layer.cs, src/Models/Results/AiModelResult.cs, AiDotNetBenchmarkTests/Helpers/MockNeuralNetwork.cs
Removed ExportComputationGraph / SupportsJitCompilation members and many layer-specific graph-export helpers/overrides across models and layers (Regression, Diffusion, NeuralNetworks, RL, TimeSeries, SyntheticData, Uncertainty, DistributedTraining, etc.).
Supporting items & misc
Directory.Packages.props, src/Helpers/UsingsHelper.cs, tests/AiDotNet.Tests/GlobalUsings.cs, src/AiDotNet.Generators/TestScaffoldGenerator.cs, various XML docs
Bumped AiDotNet.Tensors and AiDotNet.Native.OneDNN to 0.46.0; removed global using aliases (MemoryLayout, QuantizationParams); generator no longer emits two JIT-related members; multiple XML doc edits removing JIT references.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related issues

  • #1059 — Directly related: both remove ExportComputationGraph/SupportsJitCompilation surfaces from layers and models.
  • #1015 — Highly relevant: this PR removes the JIT/optimization infra that #1015 expects for zero-allocation diffusion forward passes.
  • #1149 — Related: touches HLIR→LLIR lowering, fusion passes and CompileForward features that are deleted here.
  • #435 — Inverse relationship: this PR removes much of the subsystem originally introduced in that issue/PR.
  • #768 — Overlaps: both modify optimization passes and kernel integration; deletions here negate that work.

Possibly related PRs

Poem

Kernels folded and passes cut clean,
Graphs and docs now off the screen.
Benchmarks quiet, tests laid to rest,
A leaner tree begins its quest.
✂️📚🔧

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/remove-dead-jit-scaffolding

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
src/Enums/OperationType.cs (1)

3-18: 🧹 Nitpick | 🔵 Trivial

Consider clarifying JIT compilation references in file-level documentation.

The file-level documentation mentions "JIT compilation" and "the JIT compiler" (lines 4, 12), but the PR removes the InferenceOptimization subsystem. While JIT compilation is preserved via the AiDotNet.Tensors package (AutoTracer + CompiledInferencePlan), users reading this enum might be confused about what compilation model is now in effect.

Consider updating the remarks to clarify that JIT compilation now refers to the Tensors package's automatic compilation pipeline rather than the removed InferenceOptimization subsystem.

📝 Suggested documentation clarification
 /// <remarks>
 /// <para>
 /// <b>For Beginners:</b> Operation types identify mathematical operations performed on tensors in neural networks.
 ///
 /// When building a computation graph, each operation (like adding two tensors or applying an activation function)
 /// needs to be identified so that:
-/// 1. The JIT compiler can optimize the code
+/// 1. The automatic compilation pipeline (via AiDotNet.Tensors) can optimize the code
 /// 2. The automatic differentiation system can compute gradients correctly
 /// 3. The system can analyze and transform the computation graph
 ///
 /// This enum provides type-safe identification of operations, preventing typos and enabling better tooling support.
 /// </para>
 /// </remarks>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Enums/OperationType.cs` around lines 3 - 18, Update the file-level
remarks in the OperationType enum to clarify that references to "JIT
compilation" and "the JIT compiler" now refer to the AiDotNet.Tensors package
automatic compilation pipeline (e.g., AutoTracer + CompiledInferencePlan) rather
than the removed InferenceOptimization subsystem; explicitly mention
OperationType and that these operation types are used by the Tensors package's
AutoTracer/CompiledInferencePlan pipeline for automatic compilation and
differentiation so readers aren’t confused about the current compilation model.
src/NeuralNetworks/SyntheticData/MisGANGenerator.cs (2)

643-645: ⚠️ Potential issue | 🔴 Critical

BLOCKING: Stub method with empty implementation.

BackwardMaskGenerator(Tensor<T> gradOutput) is an empty stub with no implementation. This violates production readiness requirements.

Required action:

  • Implement the backward pass for the mask generator, or
  • Remove this method entirely if it's not needed for MisGAN training

As per coding guidelines: "Every PR must contain production-ready code. Flag ALL stubs, placeholders, TODO comments, simplified implementations, and non-production-ready code as blocking issues."

🔧 Proposed fix if unused
-#region Backward Passes
-
-    private void BackwardMaskGenerator(Tensor<T> gradOutput)
-    {
-    }
-
     private void UpdateDataGeneratorParameters(T learningRate)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NeuralNetworks/SyntheticData/MisGANGenerator.cs` around lines 643 - 645,
The BackwardMaskGenerator(Tensor<T> gradOutput) method is a blocking empty
stub—either implement the mask-generator backward pass or remove the method; to
implement it, compute and propagate gradients from gradOutput through the mask
generator component (e.g., call the mask generator's backward routine such as
MaskGenerator.Backward(gradOutput) or equivalent), accumulate/merge resulting
parameter gradients into the MisGANGenerator's gradient buffers and ensure
gradients flow to any shared inputs (latent vectors or shared layers) and
optimizer state; update any related methods that expect returned gradients and
add unit tests that confirm gradients are non-null and parameters update during
training (or delete usages and references if you choose to remove the method).

596-604: ⚠️ Potential issue | 🔴 Critical

BLOCKING: Gradient penalty methods are incomplete stubs.

Both ApplyDataGradientPenalty and ApplyMaskGradientPenalty are called during training (lines 556, 588) but only build layer lists without implementing the actual gradient penalty computation. The class documentation explicitly states MisGAN uses "WGAN-GP training" with gradient penalty, making this a critical missing feature.

This is a BLOCKING issue. Either:

  1. Implement the gradient penalty computation (recommended for WGAN-GP), or
  2. Remove the calls and update documentation to clarify MisGAN does not use gradient penalty

Shipping methods that are called but do nothing silently breaks the training algorithm.

As per coding guidelines: "Incomplete features: Half-implemented patterns where some code paths work but others silently do nothing."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NeuralNetworks/SyntheticData/MisGANGenerator.cs` around lines 596 - 604,
Both ApplyDataGradientPenalty and ApplyMaskGradientPenalty are empty stubs
called during training; implement proper WGAN-GP gradient penalty computation
inside these methods using the discriminator layer lists from
BuildDataDiscLayerList and BuildMaskDiscLayerList respectively: for each, create
interpolated samples between real and fake, run them through the corresponding
discriminator to get scores, compute gradients of scores w.r.t. interpolated
inputs, calculate the L2 norm per-sample, form penalty = lambda * (norm - 1)^2
(use the existing penalty weight from class config), and backpropagate/add this
penalty to the discriminator loss as done elsewhere in the training loop;
alternatively, if you choose not to support GP, remove the calls to
ApplyDataGradientPenalty and ApplyMaskGradientPenalty from the training code and
update class docs to state MisGAN does not use gradient penalty.
src/NeuralNetworks/SyntheticData/TimeGANGenerator.cs (1)

481-483: ⚠️ Potential issue | 🔴 Critical

BLOCKING: Empty backward passes region in production code.

The empty #region Backward Passes section violates production readiness requirements. While TimeGAN uses manual gradient updates in the training steps rather than standard backpropagation, this empty region suggests incomplete refactoring or dead code structure.

Required action:

  • If backward passes are not needed (GAN-style manual training), remove this empty region entirely
  • If backward passes should be implemented for the base class contract, implement them
  • Do not ship empty region markers in production code

As per coding guidelines: "Every PR must contain production-ready code. Flag ALL stubs, placeholders, TODO comments, simplified implementations, and non-production-ready code as blocking issues."

🔧 Proposed fix: Remove empty region
-#region Backward Passes
-
-#endregion
-
 `#region` Parameter Updates
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/NeuralNetworks/SyntheticData/TimeGANGenerator.cs` around lines 481 - 483,
The empty "#region Backward Passes" in the TimeGANGenerator class is a blocking
leftover; remove the entire empty region marker from TimeGANGenerator (delete
the "#region Backward Passes" ... "#endregion" block) so no empty regions remain
in production code, and if the generator must satisfy a base-class contract
implement the required backward methods/overrides (matching the base class
method signatures) inside TimeGANGenerator instead of leaving an empty region;
do not leave stub or placeholder region markers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/TimeSeries/NBEATSBlock.cs`:
- Around line 77-92: ParameterCount, GetParameters and SetParameters omit the
generic-mode trainable basis tensors (_basisBackcast and _basisForecast), so
include those tensors alongside the existing fully-connected params: update
ParameterCount to add _basisBackcast.Length and _basisForecast.Length when those
fields are non-null, extend GetParameters to append the flattened values of
_basisBackcast and _basisForecast after iterating _fcWeights/_fcBiases, and
update SetParameters to consume values back into _basisBackcast and
_basisForecast (respecting their shapes) when reconstructing parameters; use the
existing parameter ordering (fc weights, fc biases, then bases) so import/export
remains consistent and handle null checks for non-generic mode.
- Line 367: The override UpdateParameters(T learningRate) in NBEATSBlock
currently has an empty body and must be made explicit; replace the silent no-op
with a fail-fast behavior by throwing a NotImplementedException (or another
appropriate exception) so callers on the training boundary are immediately
notified, or alternatively delegate to the concrete parameter-update
implementation used by this block (e.g., call a concrete
UpdateParametersImplementation or forward to the optimizer path); update the
method body of UpdateParameters to either throw NotImplementedException with a
clear message referencing NBEATSBlock and learningRate or to call the concrete
update method so the behavior is explicit and production-safe.
- Around line 125-150: The constructor for NBEATSBlock is missing validation for
thetaSizeBackcast, thetaSizeForecast, and polynomialDegree; add checks in the
constructor (same area where lookbackWindow, forecastHorizon, hiddenLayerSize,
and numHiddenLayers are validated) to throw ArgumentException or
ArgumentOutOfRangeException using
nameof(thetaSizeBackcast)/nameof(thetaSizeForecast)/nameof(polynomialDegree)
when theta sizes are not > 0 and when polynomialDegree is negative (or out of an
expected range), then proceed to assign _thetaSizeBackcast, _thetaSizeForecast,
and _polynomialDegree only after validation.

---

Outside diff comments:
In `@src/Enums/OperationType.cs`:
- Around line 3-18: Update the file-level remarks in the OperationType enum to
clarify that references to "JIT compilation" and "the JIT compiler" now refer to
the AiDotNet.Tensors package automatic compilation pipeline (e.g., AutoTracer +
CompiledInferencePlan) rather than the removed InferenceOptimization subsystem;
explicitly mention OperationType and that these operation types are used by the
Tensors package's AutoTracer/CompiledInferencePlan pipeline for automatic
compilation and differentiation so readers aren’t confused about the current
compilation model.

In `@src/NeuralNetworks/SyntheticData/MisGANGenerator.cs`:
- Around line 643-645: The BackwardMaskGenerator(Tensor<T> gradOutput) method is
a blocking empty stub—either implement the mask-generator backward pass or
remove the method; to implement it, compute and propagate gradients from
gradOutput through the mask generator component (e.g., call the mask generator's
backward routine such as MaskGenerator.Backward(gradOutput) or equivalent),
accumulate/merge resulting parameter gradients into the MisGANGenerator's
gradient buffers and ensure gradients flow to any shared inputs (latent vectors
or shared layers) and optimizer state; update any related methods that expect
returned gradients and add unit tests that confirm gradients are non-null and
parameters update during training (or delete usages and references if you choose
to remove the method).
- Around line 596-604: Both ApplyDataGradientPenalty and
ApplyMaskGradientPenalty are empty stubs called during training; implement
proper WGAN-GP gradient penalty computation inside these methods using the
discriminator layer lists from BuildDataDiscLayerList and BuildMaskDiscLayerList
respectively: for each, create interpolated samples between real and fake, run
them through the corresponding discriminator to get scores, compute gradients of
scores w.r.t. interpolated inputs, calculate the L2 norm per-sample, form
penalty = lambda * (norm - 1)^2 (use the existing penalty weight from class
config), and backpropagate/add this penalty to the discriminator loss as done
elsewhere in the training loop; alternatively, if you choose not to support GP,
remove the calls to ApplyDataGradientPenalty and ApplyMaskGradientPenalty from
the training code and update class docs to state MisGAN does not use gradient
penalty.

In `@src/NeuralNetworks/SyntheticData/TimeGANGenerator.cs`:
- Around line 481-483: The empty "#region Backward Passes" in the
TimeGANGenerator class is a blocking leftover; remove the entire empty region
marker from TimeGANGenerator (delete the "#region Backward Passes" ...
"#endregion" block) so no empty regions remain in production code, and if the
generator must satisfy a base-class contract implement the required backward
methods/overrides (matching the base class method signatures) inside
TimeGANGenerator instead of leaving an empty region; do not leave stub or
placeholder region markers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e540961b-c8e5-4acb-ae85-389196fe0272

📥 Commits

Reviewing files that changed from the base of the PR and between 825519c and fdd4e0e.

📒 Files selected for processing (109)
  • AiDotNetBenchmarkTests/InferenceOptimization/AttentionBenchmark.cs
  • AiDotNetBenchmarkTests/InferenceOptimization/GemmBenchmark.cs
  • AiDotNetBenchmarkTests/InferenceOptimization/SimdBenchmark.cs
  • Directory.Packages.props
  • docs/JIT-Compiler-Usage-Guide.md
  • docs/JIT_ACTIVATION_MAPPING.md
  • docs/JIT_COMPILATION_PATTERN_GUIDE.md
  • docs/JIT_ROADMAP.md
  • docs/JIT_WORKSPACE_DESIGN.md
  • examples/JitCompiler/BasicUsageExample.cs
  • examples/JitCompiler/README.md
  • src/AiDotNet.Generators/TestScaffoldGenerator.cs
  • src/AutoML/AutoMLModelBase.cs
  • src/CausalInference/CausalModelBase.cs
  • src/Classification/ClassifierBase.cs
  • src/Classification/MultiLabel/MultiLabelClassifierBase.cs
  • src/Diffusion/DiffusionModelBase.cs
  • src/Diffusion/NoisePredictors/NoisePredictorBase.cs
  • src/Diffusion/VAE/VAEModelBase.cs
  • src/DistributedTraining/ShardedModelBase.cs
  • src/Enums/OperationType.cs
  • src/Helpers/UsingsHelper.cs
  • src/InferenceOptimization/ARCHITECTURE.md
  • src/InferenceOptimization/Core/GraphBuilder.cs
  • src/InferenceOptimization/Core/GraphOptimizer.cs
  • src/InferenceOptimization/Core/IOptimizationGraph.cs
  • src/InferenceOptimization/Core/OptimizationGraph.cs
  • src/InferenceOptimization/Core/OptimizationLevel.cs
  • src/InferenceOptimization/Core/OptimizationNode.cs
  • src/InferenceOptimization/Core/OptimizationOptions.cs
  • src/InferenceOptimization/CustomOperatorRegistry.cs
  • src/InferenceOptimization/ICustomOperator.cs
  • src/InferenceOptimization/IR/Common/IRTypes.cs
  • src/InferenceOptimization/IR/HighLevel/HLIRGraph.cs
  • src/InferenceOptimization/IR/HighLevel/HLIRNode.cs
  • src/InferenceOptimization/IR/IIRCompiler.cs
  • src/InferenceOptimization/IR/LowLevel/LLIRGraph.cs
  • src/InferenceOptimization/IR/LowLevel/LLIROp.cs
  • src/InferenceOptimization/IR/Lowering/HLIRToLLIRLowering.cs
  • src/InferenceOptimization/Kernels/AttentionKernel.cs
  • src/InferenceOptimization/Kernels/ConvolutionKernel.cs
  • src/InferenceOptimization/Kernels/GemmKernel.cs
  • src/InferenceOptimization/OptimizationInitializer.cs
  • src/InferenceOptimization/Passes/AlgebraicSimplificationPass.cs
  • src/InferenceOptimization/Passes/CommonSubexpressionEliminationPass.cs
  • src/InferenceOptimization/Passes/ConstantFoldingPass.cs
  • src/InferenceOptimization/Passes/ConvBatchNormFusionPass.cs
  • src/InferenceOptimization/Passes/ConvBatchNormReLUFusionPass.cs
  • src/InferenceOptimization/Passes/DeadCodeEliminationPass.cs
  • src/InferenceOptimization/Passes/ElementwiseFusionPass.cs
  • src/InferenceOptimization/Passes/IOptimizationPass.cs
  • src/InferenceOptimization/Passes/InPlaceOptimizationPass.cs
  • src/InferenceOptimization/Passes/LayoutOptimizationPass.cs
  • src/InferenceOptimization/Passes/MatMulBiasActivationFusionPass.cs
  • src/InferenceOptimization/Passes/MatMulBiasFusionPass.cs
  • src/InferenceOptimization/Passes/MemoryReuseOptimizationPass.cs
  • src/InferenceOptimization/Passes/MultiHeadAttentionFusionPass.cs
  • src/InferenceOptimization/Passes/OptimizationPassBase.cs
  • src/InferenceOptimization/Passes/StrengthReductionPass.cs
  • src/InferenceOptimization/README.md
  • src/Models/Results/AiModelResult.cs
  • src/NeuralNetworks/Layers/DeformableConvolutionalLayer.cs
  • src/NeuralNetworks/Layers/GraphAttentionLayer.cs
  • src/NeuralNetworks/Layers/GraphIsomorphismLayer.cs
  • src/NeuralNetworks/Layers/GraphSAGELayer.cs
  • src/NeuralNetworks/Layers/LayerBase.cs
  • src/NeuralNetworks/Layers/PrincipalNeighbourhoodAggregationLayer.cs
  • src/NeuralNetworks/Layers/SparseLinearLayer.cs
  • src/NeuralNetworks/Layers/SpyNetLayer.cs
  • src/NeuralNetworks/Layers/SqueezeAndExcitationLayer.cs
  • src/NeuralNetworks/NeuralNetworkBase.cs
  • src/NeuralNetworks/SyntheticData/MedSynthGenerator.cs
  • src/NeuralNetworks/SyntheticData/MisGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/SyntheticTabularGeneratorBase.cs
  • src/NeuralNetworks/SyntheticData/TapeLayerBridge.cs
  • src/NeuralNetworks/SyntheticData/TimeGANGenerator.cs
  • src/OnlineLearning/OnlineLearningModelBase.cs
  • src/Regression/DecisionTreeAsyncRegressionBase.cs
  • src/Regression/DecisionTreeRegressionBase.cs
  • src/Regression/NonLinearRegressionBase.cs
  • src/Regression/RegressionBase.cs
  • src/ReinforcementLearning/Agents/ReinforcementLearningAgentBase.cs
  • src/SurvivalAnalysis/SurvivalModelBase.cs
  • src/TimeSeries/NBEATSBlock.cs
  • src/TimeSeries/TimeSeriesModelBase.cs
  • src/UncertaintyQuantification/Layers/BayesianDenseLayer.cs
  • src/UncertaintyQuantification/Layers/MCDropoutLayer.cs
  • tests/AiDotNet.Tests/Benchmarks/JIT_BENCHMARKS_README.md
  • tests/AiDotNet.Tests/GlobalUsings.cs
  • tests/AiDotNet.Tests/InferenceOptimization/AttentionKernelValidationTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/CacheOptimizerTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/ConvolutionKernelValidationTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/GemmKernelValidationTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/HLIRTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/HLIRToLLIRLoweringTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/IRTypesTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/LLIRTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/OptimizationGraphTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/OptimizationPassTests.cs
  • tests/AiDotNet.Tests/InferenceOptimization/SimdKernelsTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/InferenceOptimization/InferenceOptimizationDeepMathIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/InferenceOptimization/InferenceOptimizationIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/LoRA/LoRAIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/MixedPrecision/MixedPrecisionIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/Regression/KernelRegressionIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/ReinforcementLearning/BaseClassesIntegrationTests.cs
  • tests/AiDotNet.Tests/MergedPRBugFixTests.cs
  • tests/AiDotNet.Tests/UnitTests/Inference/QuantizedAttentionTests.cs
  • tests/AiDotNet.Tests/UnitTests/NeuralNetworks/Layers/RotaryPositionalEncodingLayerTests.cs
💤 Files with no reviewable changes (91)
  • src/NeuralNetworks/Layers/SqueezeAndExcitationLayer.cs
  • src/Helpers/UsingsHelper.cs
  • docs/JIT-Compiler-Usage-Guide.md
  • src/InferenceOptimization/ARCHITECTURE.md
  • docs/JIT_COMPILATION_PATTERN_GUIDE.md
  • src/NeuralNetworks/Layers/GraphSAGELayer.cs
  • src/InferenceOptimization/Core/OptimizationLevel.cs
  • src/Diffusion/NoisePredictors/NoisePredictorBase.cs
  • src/CausalInference/CausalModelBase.cs
  • AiDotNetBenchmarkTests/InferenceOptimization/AttentionBenchmark.cs
  • src/Classification/ClassifierBase.cs
  • src/InferenceOptimization/README.md
  • examples/JitCompiler/README.md
  • src/NeuralNetworks/Layers/GraphIsomorphismLayer.cs
  • tests/AiDotNet.Tests/InferenceOptimization/OptimizationGraphTests.cs
  • src/Diffusion/DiffusionModelBase.cs
  • src/DistributedTraining/ShardedModelBase.cs
  • src/Classification/MultiLabel/MultiLabelClassifierBase.cs
  • src/NeuralNetworks/Layers/SparseLinearLayer.cs
  • src/InferenceOptimization/OptimizationInitializer.cs
  • tests/AiDotNet.Tests/Benchmarks/JIT_BENCHMARKS_README.md
  • src/AutoML/AutoMLModelBase.cs
  • docs/JIT_ACTIVATION_MAPPING.md
  • src/InferenceOptimization/IR/HighLevel/HLIRNode.cs
  • src/Diffusion/VAE/VAEModelBase.cs
  • src/NeuralNetworks/Layers/DeformableConvolutionalLayer.cs
  • tests/AiDotNet.Tests/InferenceOptimization/GemmKernelValidationTests.cs
  • src/NeuralNetworks/Layers/GraphAttentionLayer.cs
  • src/NeuralNetworks/Layers/PrincipalNeighbourhoodAggregationLayer.cs
  • docs/JIT_WORKSPACE_DESIGN.md
  • src/InferenceOptimization/Passes/ConstantFoldingPass.cs
  • src/OnlineLearning/OnlineLearningModelBase.cs
  • src/InferenceOptimization/Passes/DeadCodeEliminationPass.cs
  • src/SurvivalAnalysis/SurvivalModelBase.cs
  • src/UncertaintyQuantification/Layers/MCDropoutLayer.cs
  • src/InferenceOptimization/Kernels/GemmKernel.cs
  • src/InferenceOptimization/Core/OptimizationOptions.cs
  • src/UncertaintyQuantification/Layers/BayesianDenseLayer.cs
  • src/InferenceOptimization/Core/GraphBuilder.cs
  • tests/AiDotNet.Tests/InferenceOptimization/AttentionKernelValidationTests.cs
  • src/InferenceOptimization/Passes/InPlaceOptimizationPass.cs
  • src/InferenceOptimization/Passes/IOptimizationPass.cs
  • tests/AiDotNet.Tests/GlobalUsings.cs
  • src/InferenceOptimization/Passes/ConvBatchNormFusionPass.cs
  • tests/AiDotNet.Tests/InferenceOptimization/CacheOptimizerTests.cs
  • src/InferenceOptimization/ICustomOperator.cs
  • src/NeuralNetworks/Layers/SpyNetLayer.cs
  • AiDotNetBenchmarkTests/InferenceOptimization/SimdBenchmark.cs
  • src/InferenceOptimization/Passes/LayoutOptimizationPass.cs
  • src/AiDotNet.Generators/TestScaffoldGenerator.cs
  • tests/AiDotNet.Tests/InferenceOptimization/ConvolutionKernelValidationTests.cs
  • src/InferenceOptimization/Passes/MemoryReuseOptimizationPass.cs
  • examples/JitCompiler/BasicUsageExample.cs
  • src/Regression/RegressionBase.cs
  • src/InferenceOptimization/IR/HighLevel/HLIRGraph.cs
  • src/ReinforcementLearning/Agents/ReinforcementLearningAgentBase.cs
  • src/Regression/DecisionTreeRegressionBase.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/HLIRTests.cs
  • src/InferenceOptimization/Core/GraphOptimizer.cs
  • src/InferenceOptimization/Passes/CommonSubexpressionEliminationPass.cs
  • src/NeuralNetworks/NeuralNetworkBase.cs
  • src/InferenceOptimization/Passes/MatMulBiasFusionPass.cs
  • src/InferenceOptimization/Passes/ConvBatchNormReLUFusionPass.cs
  • src/InferenceOptimization/Kernels/ConvolutionKernel.cs
  • AiDotNetBenchmarkTests/InferenceOptimization/GemmBenchmark.cs
  • src/InferenceOptimization/Passes/AlgebraicSimplificationPass.cs
  • src/Regression/NonLinearRegressionBase.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/LLIRTests.cs
  • src/NeuralNetworks/Layers/LayerBase.cs
  • src/InferenceOptimization/Passes/MultiHeadAttentionFusionPass.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/HLIRToLLIRLoweringTests.cs
  • src/InferenceOptimization/CustomOperatorRegistry.cs
  • src/InferenceOptimization/Passes/StrengthReductionPass.cs
  • src/InferenceOptimization/Core/OptimizationNode.cs
  • src/InferenceOptimization/IR/Lowering/HLIRToLLIRLowering.cs
  • src/Models/Results/AiModelResult.cs
  • docs/JIT_ROADMAP.md
  • src/InferenceOptimization/Passes/ElementwiseFusionPass.cs
  • src/InferenceOptimization/Core/IOptimizationGraph.cs
  • src/InferenceOptimization/Passes/MatMulBiasActivationFusionPass.cs
  • src/Regression/DecisionTreeAsyncRegressionBase.cs
  • tests/AiDotNet.Tests/InferenceOptimization/IR/IRTypesTests.cs
  • src/NeuralNetworks/SyntheticData/SyntheticTabularGeneratorBase.cs
  • src/InferenceOptimization/Kernels/AttentionKernel.cs
  • src/NeuralNetworks/SyntheticData/TapeLayerBridge.cs
  • src/InferenceOptimization/IR/Common/IRTypes.cs
  • src/InferenceOptimization/IR/IIRCompiler.cs
  • src/InferenceOptimization/Core/OptimizationGraph.cs
  • src/InferenceOptimization/Passes/OptimizationPassBase.cs
  • src/InferenceOptimization/IR/LowLevel/LLIROp.cs
  • src/InferenceOptimization/IR/LowLevel/LLIRGraph.cs

Comment thread src/TimeSeries/NBEATSBlock.cs
Comment thread src/TimeSeries/NBEATSBlock.cs Outdated
Comment thread src/TimeSeries/NBEATSBlock.cs Outdated
Newer Tensors release while this PR was in flight. Brings the work
after 0.42.x (0.43, 0.44, 0.45, 0.46). Backward-compatible API — no
source changes required.

Build: net10.0 + net471 both green, 0 errors.
Auto-compile regression tests (CompileForwardTests +
CompiledModelHostTests, 14 total): all pass on both TFMs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Three review comments from CodeRabbit, all on src/TimeSeries/NBEATSBlock.cs:

1. (Major) ParameterCount / GetParameters / SetParameters ignored the
   trainable V_b / V_f bases in generic mode — only fc weights + biases
   were exported/imported. That made parameter round-trips drop learned
   basis state. Fixed: include the bases in all three APIs when
   _useInterpretableBasis == false, and also re-register them in
   ReRegisterParameters so the SetParameters tensor swap doesn't drop
   them from the trainable registry.

2. (Major) Constructor validated lookbackWindow / forecastHorizon /
   hiddenLayerSize / numHiddenLayers but accepted thetaSizeBackcast,
   thetaSizeForecast, and polynomialDegree without validation. Invalid
   values deferred failure to tensor allocation/math paths where
   diagnosis is much harder. Added explicit checks: both theta sizes
   must be positive; polynomialDegree must be non-negative when
   useInterpretableBasis is true.

3. (Critical) UpdateParameters(T learningRate) was an empty override
   that silently ignored update calls — the kind of silent no-op that
   becomes an accuracy regression you can only find by bisecting.
   Replaced with a fail-fast InvalidOperationException pointing
   callers at the tape-based training path (CompiledTapeTrainingStep),
   so misuse is caught at the training boundary instead of producing
   silently-undertrained models.

Build: net10.0 + net471 + tests all green, 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ooples pushed a commit that referenced this pull request Apr 18, 2026
Three review comments from CodeRabbit, all on src/TimeSeries/NBEATSBlock.cs:

1. (Major) ParameterCount / GetParameters / SetParameters ignored the
   trainable V_b / V_f bases in generic mode — only fc weights + biases
   were exported/imported. That made parameter round-trips drop learned
   basis state. Fixed: include the bases in all three APIs when
   _useInterpretableBasis == false, and also re-register them in
   ReRegisterParameters so the SetParameters tensor swap doesn't drop
   them from the trainable registry.

2. (Major) Constructor validated lookbackWindow / forecastHorizon /
   hiddenLayerSize / numHiddenLayers but accepted thetaSizeBackcast,
   thetaSizeForecast, and polynomialDegree without validation. Invalid
   values deferred failure to tensor allocation/math paths where
   diagnosis is much harder. Added explicit checks: both theta sizes
   must be positive; polynomialDegree must be non-negative when
   useInterpretableBasis is true.

3. (Critical) UpdateParameters(T learningRate) was an empty override
   that silently ignored update calls — the kind of silent no-op that
   becomes an accuracy regression you can only find by bisecting.
   Replaced with a fail-fast InvalidOperationException pointing
   callers at the tape-based training path (CompiledTapeTrainingStep),
   so misuse is caught at the training boundary instead of producing
   silently-undertrained models.

Build: net10.0 + net471 + tests all green, 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/TimeSeries/NBEATSBlock.cs`:
- Around line 462-463: ForwardInternal/ApplyBasisExpansion's generic branch
returns theta directly, causing learned basis tensors
(_basisBackcast/_basisForecast) to be ignored during inference and parameter
round-trips; update ApplyBasisExpansion so the generic branch explicitly
multiplies theta by the matching basis matrix (use _basisBackcast for
thetaBackcast and _basisForecast for thetaForecast) instead of returning theta,
or refactor ForwardInternal to call the same multiplication path used by
Forward()/ForwardTape(); ensure the same fix is applied to the other
ApplyBasisExpansion usages referenced (the region covering the second
occurrence) so PredictSingle, GetParameters and SetParameters remain consistent
with training.
- Around line 149-159: The current validations in NBEATSBlock only reject
negative polynomialDegree but do not prevent thetaSizeBackcast/thetaSizeForecast
from being larger than the interpretable basis length, which causes dead
parameters; update the constructor/validation to, when useInterpretableBasis is
true, either throw ArgumentException if thetaSizeBackcast or thetaSizeForecast >
polynomialDegree + 1 or automatically cap/derive theta sizes to polynomialDegree
+ 1; specifically check thetaSizeBackcast and thetaSizeForecast against
_polynomialDegree + 1 (or derive newThetaSizeBackcast/newThetaSizeForecast from
polynomialDegree + 1) before the block builds and before ApplyBasisExpansion is
used so no trainable weights are created that cannot influence the basis.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fd294780-48f4-4e04-96ae-1a81dcf86de0

📥 Commits

Reviewing files that changed from the base of the PR and between dee2de1 and 9087cc7.

📒 Files selected for processing (1)
  • src/TimeSeries/NBEATSBlock.cs

Comment thread src/TimeSeries/NBEATSBlock.cs
Comment thread src/TimeSeries/NBEATSBlock.cs Outdated
1. (Major) Interpretable theta sizes weren't validated against
   polynomialDegree + 1. ComputeBasisTensor + ApplyBasisExpansion both
   cap usable rows at polynomialDegree + 1, so oversized thetaSizeBackcast
   / thetaSizeForecast silently allocated dead trainable weights that
   couldn't influence the output. Added explicit checks for
   interpretable mode.

2. (Critical) ForwardInternal's generic branch in ApplyBasisExpansion
   returned theta directly instead of multiplying by the learned V_b /
   V_f basis tensors. With the Phase 1 fix that made those bases
   round-trip through GetParameters/SetParameters, PredictSingle would
   diverge from both Forward() (which uses _basisBackcast/_basisForecast
   via matmul) and from loaded-model state. Changed
   ApplyBasisExpansion to take a basis tensor argument and multiply
   by it in the generic branch, matching training and tape paths per
   Oreshkin et al. 2020 §3.2.

Build: net10.0 clean, 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ooples pushed a commit that referenced this pull request Apr 18, 2026
1. (Major) Interpretable theta sizes weren't validated against
   polynomialDegree + 1. ComputeBasisTensor + ApplyBasisExpansion both
   cap usable rows at polynomialDegree + 1, so oversized thetaSizeBackcast
   / thetaSizeForecast silently allocated dead trainable weights that
   couldn't influence the output. Added explicit checks for
   interpretable mode.

2. (Critical) ForwardInternal's generic branch in ApplyBasisExpansion
   returned theta directly instead of multiplying by the learned V_b /
   V_f basis tensors. With the Phase 1 fix that made those bases
   round-trip through GetParameters/SetParameters, PredictSingle would
   diverge from both Forward() (which uses _basisBackcast/_basisForecast
   via matmul) and from loaded-model state. Changed
   ApplyBasisExpansion to take a basis tensor argument and multiply
   by it in the generic branch, matching training and tape paths per
   Oreshkin et al. 2020 §3.2.

Build: net10.0 clean, 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/TimeSeries/NBEATSBlock.cs`:
- Around line 122-139: Validate lookbackWindow and forecastHorizon before
invoking the LayerBase<T> constructor in NBEATSBlock by moving the checks out of
the constructor initializer: add private static helper methods (e.g.,
CreateInputShape(int lookbackWindow) and CreateOutputShape(int lookbackWindow,
int forecastHorizon)) that perform the ArgumentException checks for
lookbackWindow and forecastHorizon and return the int[] shapes, and use these
helpers in the base(...) call; ensure the output shape uses a checked sum
(checked(lookbackWindow + forecastHorizon)) to guard overflow and keep all
validation logic in the helpers so LayerBase<T> only receives already-validated
shapes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c49c1033-7ace-456a-bec9-af6898c5706e

📥 Commits

Reviewing files that changed from the base of the PR and between 9087cc7 and b93d683.

📒 Files selected for processing (1)
  • src/TimeSeries/NBEATSBlock.cs

Comment thread src/TimeSeries/NBEATSBlock.cs Outdated
franklinic and others added 3 commits April 18, 2026 10:16
…+ empty IJitCompilable regions

Sweep #1 of the end-to-end JIT audit. The IJitCompilable interface no
longer exists (removed with the JitCompiler). Every remaining reference
was either a stale region marker with no content, or a vestigial
SupportsJitCompilation property that nothing reads.

Removed:
- SupportsJitCompilation property on 11 model base classes (AutoML,
  CausalInference, Classification, MultiLabelClassification, Diffusion,
  NoisePredictor, VAE, DistributedTraining/ShardedModelBase,
  NeuralNetworkBase, OnlineLearning, Survival). Kept on
  IActivationFunction / IVectorActivationFunction implementations since
  LoRA / SqueezeAndExcitation / HyperbolicLinear / SparseLinear still
  consult those for activation-graph fallback (live code path).
- 21 empty #region IJitCompilable Override markers across the
  SyntheticData generators (AutoDiffTab, CausalGAN, CopulaGAN,
  CTABGANPlus, CTGAN, DPCTGAN, FinDiff, GOGGLE, MedSynth, MisGAN,
  OCTGAN, PATEGAN, REaLTabFormer, TabDDPM, TabFlow, TableGAN, TabLLMGen,
  TabSyn, TabTransformerGen, TimeGAN, TVAE).
- 4 empty #region IJitCompilable Implementation Override markers in
  Regression (AdaBoostR2, ExtremelyRandomizedTrees, GradientBoosting,
  RandomForest) and TransferLearning (TransferRandomForest).
- ExpressionTree.BuildComputationGraph (private method with only
  recursive self-calls; nothing external called it after JitCompiler
  removal).
- VectorModel.VectorToTensor (private method inside #region
  IJitCompilable Implementation; only defined, never referenced inside
  or outside the file).
- SuperNet.ExportOperationGraph + SuperNet.Forward (both dead, only
  existed to satisfy the removed IJitCompilable interface).

Build: net10.0 + net471 both green, 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…lable xmldoc

Audit A: continues the dead JIT-scaffolding sweep from 010bc09 / fb9ebb2.
After removal in prior commits of the JitCompiler / InferenceOptimization IR /
ExportComputationGraph surface, these eight layer files still carried a closed
chain of private BuildComputationGraph() methods that only called each other
(zero external callers), plus xmldoc remarks referencing IJitCompilable on
interfaces that were removed. All of it is dead.

- 8 neural-network layers: remove private BuildComputationGraph chain
  (DenseBlock, InvertedResidual, RRDB, RRDBNetGenerator, ResidualDense,
   SqueezeAndExcitation, Transition, UNetDiscriminator)
- 5 KnowledgeDistillation teacher-model xmldocs: strip IJitCompilable
  references; note Tensors' AutoTracer handles auto-compile transparently
- DeepReinforcementLearningAgentBase: same xmldoc fix + point to
  TensorCodecOptions.Current.EnableCompilation for opt-out
- InterfaceGuard / IFullModel: scrub IJitCompilable from the remarks list

Build: net10.0 + net471 clean (0 errors).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
After the production-side IJitCompilable removal in prior commits, test
mocks, testconsole examples, the benchmark harness, and the golden-standard
pattern doc still carried SupportsJitCompilation + ExportComputationGraph
stubs for a removed interface — purely orphan code that compiled only
because no interface required those members.

This sweep removes all of them (29 test files + 3 testconsole examples +
1 benchmark helper + GOLDEN_STANDARD_PATTERNS.md). The only remaining
SupportsJitCompilation references are on IActivationFunction /
IVectorActivationFunction, which are part of the live ComputationNode
graph-mode autodiff path (distinct from the removed JIT compiler).

Build: net10.0 + net471 clean across src/, tests/, testconsole/, and
AiDotNetBenchmarkTests/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/ReinforcementLearning/Agents/DeepReinforcementLearningAgentBase.cs (1)

117-139: ⚠️ Potential issue | 🔴 Critical

Blocking: Remove GetPolicyNetworkForJit() — dead code after JIT removal.

The method at line 135 is a permanent null stub that always returns null after JIT compilation was removed. This is a placeholder pattern that violates production-readiness standards: it exposes a virtual extension point with misleading XML docs ("Override this method…", "enables JIT compilation support…") but unconditionally returns null.

Verification confirms no derived classes override this method anywhere in the codebase, so it is safe to delete entirely. Remove the section header (lines 117–118) and the method (lines 135–139).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ReinforcementLearning/Agents/DeepReinforcementLearningAgentBase.cs`
around lines 117 - 139, Delete the dead virtual method GetPolicyNetworkForJit()
and its preceding "JIT Compilation Support" comment block and XML doc (the
entire protected virtual INeuralNetworkModel<T>? GetPolicyNetworkForJit()
declaration and associated remarks), since it always returns null and is not
overridden; also remove any remaining references/usages if present, rebuild the
project and run tests to confirm nothing depended on this extension point.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Helpers/InterfaceGuard.cs`:
- Line 9: The InterfaceGuard helper class is public but should be internal per
facade guidelines; change the class declaration for InterfaceGuard to internal
so its visibility is limited (ensure no public API signatures expose
InterfaceGuard—if any methods in AiModelBuilder or AiModelResult reference it
publicly, update those signatures or create internal overloads). Verify that no
external consumers rely on InterfaceGuard, run build/tests, and adjust any
using/assembly visibility (InternalsVisibleTo) if required for unit tests.

In `@src/KnowledgeDistillation/Teachers/PretrainedTeacherModel.cs`:
- Around line 15-19: The XML doc for PretrainedTeacherModel overstates behavior
by claiming inference "auto-compiles via Tensors' AutoTracer"—update the summary
to say the type invokes the provided forward-pass delegate (Func<...>) and that
any compilation or tracing behavior depends on the implementation of that
delegate and underlying tensor runtime; remove guarantees about AutoTracer or
automatic compilation and instead note that repeated input shapes may allow
backends to optimize if the delegate supports it. Reference the
PretrainedTeacherModel type and its constructor/forward-pass delegate in the
revised wording.

In `@src/KnowledgeDistillation/Teachers/QuantizedTeacherModel.cs`:
- Around line 56-58: The XML doc for the QuantizedTeacherModel<T> constructor
overstates behavior by guaranteeing AutoTracer/auto-compilation of the wrapped
base teacher; update the constructor/class remarks to remove absolutes and
instead state that dynamic quantization operates per-batch and that any
AutoTracer/auto-compilation behavior depends on the wrapped base teacher's
implementation (e.g., "may trigger AutoTracer/auto-compilation if the underlying
ITeacher implementation and input-shape patterns permit it"). Locate the XML
summary/remarks for QuantizedTeacherModel<T> and replace the definitive phrasing
about guaranteed auto-compilation with a conditional/descriptive statement
referencing the wrapped baseTeacher.

In `@src/KnowledgeDistillation/Teachers/SelfTeacherModel.cs`:
- Around line 84-85: Update the XML docs on the GetLogits method of
SelfTeacherModel<T> to match its throw-only behavior: change the <summary> to
state GetLogits is not supported for SelfTeacherModel<T> and callers must use
GetCachedPrediction, update the <returns> to either be removed or to state that
it does not return logits (it always throws), and update the <exception> tag to
document that GetLogits throws NotSupportedException (or the specific exception
type thrown) with a brief reason and a pointer to GetCachedPrediction for
obtaining precomputed predictions.

In `@src/KnowledgeDistillation/Teachers/TransformerTeacherModel.cs`:
- Around line 16-20: Update the XML remarks for the TransformerTeacherModel
class/ctor to avoid promising auto-compilation semantics: clarify that the class
simply invokes the provided forward-pass delegate (the Func<> passed into the
constructor) and that any AutoTracer or compilation behavior is dependent on the
concrete delegate implementation rather than guaranteed by
TransformerTeacherModel. Replace the current sentence referencing "auto-compiles
via Tensors' AutoTracer" with language like "may leverage underlying model or
tensor library auto-compilation when the provided delegate triggers such
behavior; behavior depends on the delegate implementation."

---

Outside diff comments:
In `@src/ReinforcementLearning/Agents/DeepReinforcementLearningAgentBase.cs`:
- Around line 117-139: Delete the dead virtual method GetPolicyNetworkForJit()
and its preceding "JIT Compilation Support" comment block and XML doc (the
entire protected virtual INeuralNetworkModel<T>? GetPolicyNetworkForJit()
declaration and associated remarks), since it always returns null and is not
overridden; also remove any remaining references/usages if present, rebuild the
project and run tests to confirm nothing depended on this extension point.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: de292526-e99a-41c4-aebc-7d78eb700430

📥 Commits

Reviewing files that changed from the base of the PR and between b93d683 and 09abdeb.

📒 Files selected for processing (88)
  • AiDotNetBenchmarkTests/Helpers/MockNeuralNetwork.cs
  • docs/GOLDEN_STANDARD_PATTERNS.md
  • src/AutoML/AutoMLModelBase.cs
  • src/CausalInference/CausalModelBase.cs
  • src/Classification/ClassifierBase.cs
  • src/Classification/MultiLabel/MultiLabelClassifierBase.cs
  • src/Diffusion/DiffusionModelBase.cs
  • src/Diffusion/NoisePredictors/NoisePredictorBase.cs
  • src/Diffusion/VAE/VAEModelBase.cs
  • src/DistributedTraining/ShardedModelBase.cs
  • src/Helpers/InterfaceGuard.cs
  • src/Interfaces/IFullModel.cs
  • src/KnowledgeDistillation/Teachers/OnlineTeacherModel.cs
  • src/KnowledgeDistillation/Teachers/PretrainedTeacherModel.cs
  • src/KnowledgeDistillation/Teachers/QuantizedTeacherModel.cs
  • src/KnowledgeDistillation/Teachers/SelfTeacherModel.cs
  • src/KnowledgeDistillation/Teachers/TransformerTeacherModel.cs
  • src/LinearAlgebra/ExpressionTree.cs
  • src/Models/VectorModel.cs
  • src/NeuralNetworks/Layers/DenseBlockLayer.cs
  • src/NeuralNetworks/Layers/InvertedResidualBlock.cs
  • src/NeuralNetworks/Layers/RRDBLayer.cs
  • src/NeuralNetworks/Layers/RRDBNetGenerator.cs
  • src/NeuralNetworks/Layers/ResidualDenseBlock.cs
  • src/NeuralNetworks/Layers/SqueezeAndExcitationLayer.cs
  • src/NeuralNetworks/Layers/TransitionLayer.cs
  • src/NeuralNetworks/Layers/UNetDiscriminator.cs
  • src/NeuralNetworks/NeuralNetworkBase.cs
  • src/NeuralNetworks/SuperNet.cs
  • src/NeuralNetworks/SyntheticData/AutoDiffTabGenerator.cs
  • src/NeuralNetworks/SyntheticData/CTABGANPlusGenerator.cs
  • src/NeuralNetworks/SyntheticData/CTGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/CausalGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/CopulaGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/DPCTGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/FinDiffGenerator.cs
  • src/NeuralNetworks/SyntheticData/GOGGLEGenerator.cs
  • src/NeuralNetworks/SyntheticData/MedSynthGenerator.cs
  • src/NeuralNetworks/SyntheticData/MisGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/OCTGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/PATEGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/REaLTabFormerGenerator.cs
  • src/NeuralNetworks/SyntheticData/TVAEGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabDDPMGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabFlowGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabLLMGenGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabSynGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabTransformerGenGenerator.cs
  • src/NeuralNetworks/SyntheticData/TableGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/TimeGANGenerator.cs
  • src/OnlineLearning/OnlineLearningModelBase.cs
  • src/Regression/AdaBoostR2Regression.cs
  • src/Regression/ExtremelyRandomizedTreesRegression.cs
  • src/Regression/GradientBoostingRegression.cs
  • src/Regression/RandomForestRegression.cs
  • src/ReinforcementLearning/Agents/DeepReinforcementLearningAgentBase.cs
  • src/SurvivalAnalysis/SurvivalModelBase.cs
  • src/TransferLearning/Algorithms/TransferRandomForest.cs
  • testconsole/Examples/KnowledgeDistillationExample.cs
  • testconsole/Examples/MetaLearning/SimpleMetaModel.cs
  • testconsole/Examples/SimpleKnowledgeDistillationExample.cs
  • tests/AiDotNet.Tests/AdversarialRobustness/CROWNVerificationTests.cs
  • tests/AiDotNet.Tests/AdversarialRobustness/IntervalBoundPropagationTests.cs
  • tests/AiDotNet.Tests/Helpers/ActiveLearningTestHelper.cs
  • tests/AiDotNet.Tests/Helpers/ContinualLearningTestHelper.cs
  • tests/AiDotNet.Tests/Helpers/MockFullModel.cs
  • tests/AiDotNet.Tests/Helpers/MockNeuralNetwork.cs
  • tests/AiDotNet.Tests/IntegrationTests/ActiveLearning/ActiveLearningDeepMathIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/ActiveLearning/ActiveLearningIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/AdversarialRobustness/AdversarialRobustnessDeepMathIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/AdversarialRobustness/AdversarialRobustnessIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/ContinualLearning/ContinualLearningDeepMathIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/DistributedTraining/DistributedTrainingIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/DistributedTraining/PipelineParallelismIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/FederatedLearning/FederatedLearningDeepMathIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/FineTuning/FineTuningIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/MetaLearning/MetaLearningTestModels.cs
  • tests/AiDotNet.Tests/IntegrationTests/Quantization/QuantizationIntegrationTests.cs
  • tests/AiDotNet.Tests/IntegrationTests/TransferLearning/TransferLearningAlgorithmsIntegrationTests.cs
  • tests/AiDotNet.Tests/UnitTests/AdversarialRobustness/AdversarialAttackTests.cs
  • tests/AiDotNet.Tests/UnitTests/AdversarialRobustness/AdversarialTrainingTests.cs
  • tests/AiDotNet.Tests/UnitTests/AdversarialRobustness/RandomizedSmoothingTests.cs
  • tests/AiDotNet.Tests/UnitTests/ContinualLearning/ElasticWeightConsolidationTests.cs
  • tests/AiDotNet.Tests/UnitTests/Genetics/ModelIndividualTests.cs
  • tests/AiDotNet.Tests/UnitTests/KnowledgeDistillation/TeacherModelFactoryTests.cs
  • tests/AiDotNet.Tests/UnitTests/Layers/AdvancedAlgebraLayerTests.cs
  • tests/AiDotNet.Tests/UnitTests/MetaLearning/Helpers/MatrixMockModel.cs
  • tests/AiDotNet.Tests/UnitTests/MetaLearning/Helpers/SimpleMockModel.cs
💤 Files with no reviewable changes (48)
  • src/Interfaces/IFullModel.cs
  • src/Regression/RandomForestRegression.cs
  • src/NeuralNetworks/SyntheticData/TableGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/GOGGLEGenerator.cs
  • src/NeuralNetworks/SyntheticData/FinDiffGenerator.cs
  • src/NeuralNetworks/SyntheticData/TVAEGenerator.cs
  • src/NeuralNetworks/SyntheticData/DPCTGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/CTGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/CausalGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabLLMGenGenerator.cs
  • src/Regression/ExtremelyRandomizedTreesRegression.cs
  • src/NeuralNetworks/SyntheticData/OCTGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/REaLTabFormerGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabTransformerGenGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabFlowGenerator.cs
  • src/NeuralNetworks/SyntheticData/AutoDiffTabGenerator.cs
  • src/NeuralNetworks/SyntheticData/PATEGANGenerator.cs
  • src/NeuralNetworks/SyntheticData/TabDDPMGenerator.cs
  • src/Models/VectorModel.cs
  • src/KnowledgeDistillation/Teachers/OnlineTeacherModel.cs
  • src/Regression/AdaBoostR2Regression.cs
  • src/LinearAlgebra/ExpressionTree.cs
  • src/NeuralNetworks/SyntheticData/TabSynGenerator.cs
  • src/NeuralNetworks/SuperNet.cs
  • src/NeuralNetworks/Layers/RRDBLayer.cs
  • AiDotNetBenchmarkTests/Helpers/MockNeuralNetwork.cs
  • src/NeuralNetworks/Layers/DenseBlockLayer.cs
  • src/Diffusion/NoisePredictors/NoisePredictorBase.cs
  • src/CausalInference/CausalModelBase.cs
  • src/NeuralNetworks/Layers/ResidualDenseBlock.cs
  • src/NeuralNetworks/Layers/InvertedResidualBlock.cs
  • src/NeuralNetworks/Layers/TransitionLayer.cs
  • src/NeuralNetworks/SyntheticData/CopulaGANGenerator.cs
  • src/DistributedTraining/ShardedModelBase.cs
  • src/OnlineLearning/OnlineLearningModelBase.cs
  • src/NeuralNetworks/Layers/SqueezeAndExcitationLayer.cs
  • src/AutoML/AutoMLModelBase.cs
  • src/SurvivalAnalysis/SurvivalModelBase.cs
  • docs/GOLDEN_STANDARD_PATTERNS.md
  • src/NeuralNetworks/Layers/RRDBNetGenerator.cs
  • src/Classification/MultiLabel/MultiLabelClassifierBase.cs
  • src/NeuralNetworks/SyntheticData/CTABGANPlusGenerator.cs
  • src/Diffusion/DiffusionModelBase.cs
  • src/Regression/GradientBoostingRegression.cs
  • src/NeuralNetworks/Layers/UNetDiscriminator.cs
  • src/Classification/ClassifierBase.cs
  • src/NeuralNetworks/NeuralNetworkBase.cs
  • src/Diffusion/VAE/VAEModelBase.cs

Comment thread src/Helpers/InterfaceGuard.cs Outdated
Comment thread src/KnowledgeDistillation/Teachers/PretrainedTeacherModel.cs
Comment thread src/KnowledgeDistillation/Teachers/QuantizedTeacherModel.cs
Comment thread src/KnowledgeDistillation/Teachers/SelfTeacherModel.cs Outdated
Comment thread src/KnowledgeDistillation/Teachers/TransformerTeacherModel.cs
franklinic and others added 5 commits April 18, 2026 11:08
…ers from CI

Deep Audit A found 5 dangling references to deleted test namespaces in CI and
test-sharding configs. These filters targeted tests that were deleted in the
JIT/InferenceOptimization sweep — now no-ops that confuse CI dashboards.

- .github/workflows/sonarcloud.yml:
  - Unit-06 shard: drop UnitTests.JitCompiler (deleted); rename "JIT/KD/..." -> "KD/..."
  - Exclusion filter: drop UnitTests.JitCompiler (no longer emits tests)
  - Drop "Other - InferenceOptimization" shard entirely (namespace deleted)
- scripts/run-tests-sharded.ps1:
  - Drop "JitCompiler" from unitNamespaceRoots
  - Rename Unit-07 shard "Interpretability/JIT/KD" -> "Interpretability/KD"
  - Drop shard 13 "InferenceOptimization" (namespace deleted); renumber PromptEngineering -> 13

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…c-batch compile (gaps 2+5)

Part of the Tensors-0.46.0 parity work (closes 2 of 14 gaps; see Tensors
issues #197 + #198 for the two gaps that need upstream Tensors features).

## Gap 5 — acceleration diagnostics (PlatformDetector + NativeLibraryDetector)

Tensors already ships PlatformDetector (SIMD level, cache sizes, GPU
support flags) and NativeLibraryDetector (OpenBLAS / CLBlast / cuDNN /
MKL availability). AiDotNet was ignoring both — users had no visibility
into which acceleration path was actually engaged.

- src/Diagnostics/AccelerationDiagnostics.cs — new facade wrapping both
  detectors. GetReport() returns a human-readable summary; GetSnapshot()
  returns a structured AccelerationSnapshot for programmatic assertions.
- AiModelBuilder.ReportAccelerationStatus(Action<string>? logger) — opt-in
  builder method. Runs after ApplyGpuConfiguration so the snapshot reflects
  the engine state the built model will actually see.
- AiModelResult.AccelerationSnapshot — new property on every AiModelResult.
  7 construction sites updated via AttachDiagnostics() helper.

## Gap 2 — SymbolicShape for dynamic batch/seq-len compile keys

CompiledModelHost keyed the compile cache on concrete shape via
GetOrCompileInference(shape, forward). Every batch-size change forced a
fresh trace+compile — wasteful for real inference traffic where request
batches vary. Tensors exposes SymbolicShape.BatchDynamic /
BatchAndSeqDynamic / AllDynamic + a 3-arg GetOrCompileInference overload
for exactly this case.

- src/NeuralNetworks/CompiledModelHost.cs: new SymbolicShapeMode enum
  (Static / BatchDynamic / BatchAndSeqDynamic / AllDynamic). Default =
  BatchDynamic (matches PyTorch torch.compile(dynamic=True) default).
- Predict() builds a SymbolicShape from mode + concrete shape and calls
  the 3-arg overload, falling back to the 2-arg concrete overload when
  rank is too small (e.g. 1-D scalar input with BatchDynamic requested).

## Verify

dotnet build -f net10.0 — clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… (gap 1)

PyTorch-parity equivalent: torch.jit.save + torch.jit.load. Before this
change AiDotNet recompiled every forward-pass plan on every process start —
wasteful for production serving where warm inference latency matters.

Tensors 0.46.0 already ships everything needed: ICompiledPlan.SaveAsync,
CompiledPlanLoader.LoadInferenceAsync, PlanCompatibilityInfo for hardware-
fingerprint gating. We just weren't wiring it.

## Public API

    await new PredictionModelBuilder<float, Tensor<float>, Tensor<float>>()
        .ConfigureModel(myNet)
        .ConfigurePlanCaching(@"C:\PlanCache")   // NEW
        .BuildAsync();

Plans are saved under modelTypeName_T_v{structureVersion}_s{shapeHash}.plan.
Per-(model, T, version, shape) — one directory can host multiple models
without collision. Loads that fail PlanCompatibilityInfo fall through to
a fresh compile silently.

## Files

- src/NeuralNetworks/PlanCache.cs: new. Static Current, directory-based
  storage, atomic writes (tmp + rename). Shape hash = SHA256 of int32[].
- src/NeuralNetworks/CompiledModelHost.cs:
  - ctor now accepts optional modelIdentity — null = disk caching off
  - new fields: _diskCheckedShapes (one load attempt per shape-version),
    _preloadedPlans (in-memory cache of disk-loaded plans)
  - Predict(): before GetOrCompileInference, call TryUseDiskCachedPlan.
    If hit, skip compile entirely.
  - After fresh compile, fire-and-forget save via Task.Run so Predict
    doesn't block on IO.
- src/NeuralNetworks/NeuralNetworkBase.cs: _compileHost is now assigned
  in the ctor so GetType().FullName reflects the concrete subclass —
  different model types don't collide on disk keys.
- src/Diffusion/NoisePredictors/NoisePredictorBase.cs: same change.
- src/AiModelBuilder.cs + src/Interfaces/IAiModelBuilder.cs: new
  ConfigurePlanCaching(directory) fluent method.

## Verify

dotnet build -f net10.0 — clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…filing (gaps 6/7/12)

## Gap 12 — Fused GEMM+Bias+Activation (already mostly wired; completing)

Audit confirmed the major linear layers (DenseLayer, FullyConnectedLayer,
and several others) already dispatch through Engine.FusedLinear /
FusedLinearGpu for CPU + GPU paths.

The notable miss was FeedForwardLayer.Forward, which was doing separate
TensorMatMul + Reshape + TensorBroadcastAdd + ApplyActivation calls (4 kernel
launches per forward). Refactored to use Engine.FusedLinear(input, weights,
biases, fusedActivation) with the standard pre-activation tape-safe fallback
for training.

- src/NeuralNetworks/Layers/FeedForwardLayer.cs: Forward() rewritten.
  Mirror of DenseLayer's fused-inference path.

## Gap 7 — Tensors per-op profiling (orthogonal to existing AiDotNet ProfilerSession)

AiDotNet already has its own ProfilerSession / ProfileReport / AiModelResult.
ProfilingReport surfacing HIGHER-level workflow timings (Welford stats,
hierarchical call trees, reservoir percentiles, memory tracking — richer
than Tensors' simpler per-op profiler). Tensors has no parity with that
feature set, so we keep it.

What was missing: visibility into LOWER-level tensor-op kernel timings.
Tensors ships PerformanceProfiler.Instance which wraps every engine op in
an IDisposable scope — useful for finding which kernel (MatMul, Softmax,
LayerNorm) is the actual bottleneck.

- src/Diagnostics/ProfilingReport.cs: new. TensorsOperationProfile wraps
  PerformanceProfiler output. FormatSummary formats top-N ops.
- src/AiModelBuilder.cs + src/Interfaces/IAiModelBuilder.cs: new
  EnableTensorsOpProfiling() fluent method.
- src/Models/Results/AiModelResult.Diagnostics.cs: new
  TensorsOperationProfile property. Sits alongside existing ProfilingReport
  (not replacing it).

## Verify

dotnet build -f net10.0 — clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ting (gaps 9+14)

## Gap 9 — autotune cache diagnostics

Tensors ships AutotuneCache (Helpers.Autotune namespace) with per-kernel
autotune storage. Users couldn't see whether it was active. Filed Tensors
issue #200 for the WarmupCommonKernelsAsync convenience; added diagnostics
surface here so users at least see the cache path + hardware fingerprint.

- src/Diagnostics/AccelerationDiagnostics.cs: GetReport now emits
  AutotuneCache.DefaultCachePath + CurrentHardwareFingerprint.
  AccelerationSnapshot carries both as AutotuneCachePath / AutotuneHardwareFingerprint.

## Gap 14 — subclass Predict() routing through PredictCompiled

11 NeuralNetwork subclasses overrode Predict as literally `return Forward(input);`,
bypassing the base's PredictCompiled auto-compile path. Refactored each to
override PredictEager (the base's compile-lambda eager fallback) instead,
keeping Forward as the implementation but routing through CompiledModelHost.

After: every Predict on these 11 models goes through _compileHost.Predict,
which traces → compiles → replays (and triggers disk caching via PlanCache
when configured, from Gap 1).

Files touched:
- src/NeuralNetworks/ConvolutionalNeuralNetwork.cs
- src/NeuralNetworks/EfficientNetNetwork.cs
- src/NeuralNetworks/FastText.cs
- src/NeuralNetworks/GloVe.cs
- src/NeuralNetworks/MobileNetV2Network.cs
- src/NeuralNetworks/ResNetNetwork.cs
- src/NeuralNetworks/SiameseNeuralNetwork.cs
- src/NeuralNetworks/UNet3D.cs
- src/NeuralNetworks/VGGNetwork.cs
- src/NeuralNetworks/VoxelCNN.cs
- src/NeuralNetworks/Word2Vec.cs

Forward methods unchanged — they still have their GPU-resident fast path
(TryForwardGpuOptimized etc.) and shape-validation logic. The base's
PredictCompiled treats Forward as the eager fallback but AutoTracer fires
on first call regardless.

## Verify

- dotnet build -f net10.0 — clean
- dotnet build -f net471 — clean
- dotnet test CompiledTapeTrainingStep + FusedOptimizer — 9/9 passing

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- NBEATSBlock ctor: extract CreateInputShape / CreateOutputShape static
  factories that validate lookbackWindow / forecastHorizon BEFORE the
  base(...) call. Invalid values now surface as ArgumentException with
  the right nameof(...) tag instead of a downstream LayerBase<T> shape
  error.
- InterfaceGuard: class visibility reduced from public to internal to
  match the AiDotNet facade pattern. InternalsVisibleTo on src/AiDotNet.csproj
  already grants access to AiDotNetTests / AiDotNetTestConsole / AiDotNet.Serving /
  AiDotNetBenchmarkTests, so the 58 existing test call sites still compile.
  Doc remark added explaining the visibility choice.
- PretrainedTeacherModel + TransformerTeacherModel: reworded "auto-compiles
  via Tensors' AutoTracer" remarks. The wrapper only invokes the delegate;
  whether auto-compile actually happens depends entirely on what's inside
  the delegate. Removed the unconditional guarantee and added a note that
  external paths (ONNX, REST, etc.) won't pick up engine optimizations.
- SelfTeacherModel.GetLogits: rewrote XML-doc so summary/returns/exception
  match the throw-only behavior (method has no underlying model to run and
  always throws InvalidOperationException). Previous summary said "Gets
  logits from the underlying model" which was misleading.

Verify: dotnet build net10.0 + net471 — 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ooples pushed a commit that referenced this pull request Apr 19, 2026
- NBEATSBlock ctor: extract CreateInputShape / CreateOutputShape static
  factories that validate lookbackWindow / forecastHorizon BEFORE the
  base(...) call. Invalid values now surface as ArgumentException with
  the right nameof(...) tag instead of a downstream LayerBase<T> shape
  error.
- InterfaceGuard: class visibility reduced from public to internal to
  match the AiDotNet facade pattern. InternalsVisibleTo on src/AiDotNet.csproj
  already grants access to AiDotNetTests / AiDotNetTestConsole / AiDotNet.Serving /
  AiDotNetBenchmarkTests, so the 58 existing test call sites still compile.
  Doc remark added explaining the visibility choice.
- PretrainedTeacherModel + TransformerTeacherModel: reworded "auto-compiles
  via Tensors' AutoTracer" remarks. The wrapper only invokes the delegate;
  whether auto-compile actually happens depends entirely on what's inside
  the delegate. Removed the unconditional guarantee and added a note that
  external paths (ONNX, REST, etc.) won't pick up engine optimizations.
- SelfTeacherModel.GetLogits: rewrote XML-doc so summary/returns/exception
  match the throw-only behavior (method has no underlying model to run and
  always throws InvalidOperationException). Previous summary said "Gets
  logits from the underlying model" which was misleading.

Verify: dotnet build net10.0 + net471 — 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ooples ooples force-pushed the chore/remove-dead-jit-scaffolding branch from 565c4ef to aa04444 Compare April 19, 2026 15:11
@ooples
Copy link
Copy Markdown
Owner Author

ooples commented Apr 19, 2026

Closing temporarily to re-trigger CI on rewritten branch history.

@ooples ooples closed this Apr 19, 2026
@ooples
Copy link
Copy Markdown
Owner Author

ooples commented Apr 19, 2026

Reopening to re-trigger CI.

@ooples ooples reopened this Apr 19, 2026
@ooples ooples force-pushed the chore/remove-dead-jit-scaffolding branch from df660f8 to 49251a6 Compare April 19, 2026 15:25
Resolves conflicts:
- Directory.Packages.props: take AiDotNet.Tensors 0.46.1 from master,
  keep AiDotNet.Native.OneDNN 0.46.0 for ecosystem alignment.
- src/NeuralNetworks/MobileNetV2Network.cs: keep both overrides --
  GetNamedLayerActivations (master, 3D->4D probe shape) and
  PredictEager (HEAD, compiled-plan routing). Master's Predict
  override was superseded by PredictEager + base-class routing.
@ooples ooples force-pushed the chore/remove-dead-jit-scaffolding branch from 49251a6 to fbd9016 Compare April 19, 2026 15:31
@ooples ooples merged commit 4fe35b0 into master Apr 20, 2026
28 of 44 checks passed
@ooples ooples deleted the chore/remove-dead-jit-scaffolding branch April 20, 2026 01:33
ooples added a commit that referenced this pull request Apr 20, 2026
…Forward

PR #1155 replaced `public override Tensor<T> Predict(Tensor<T> input) =>
Forward(input)` with `protected override Tensor<T> PredictEager(Tensor<T>
input) => Forward(input)` in 11 network classes. That reroutes Predict
through `NeuralNetworkBase.PredictCompiled` → `CompiledModelHost.Predict`
→ the compiled-replay plan.

The compiled-replay plan silently truncates the forward pass for the
affected models: on a ResNet-18 with 3×32×32 input the plan returns a
shape-[64] tensor (output of the first conv block's 64 channels)
instead of the expected shape-[10] logits. The net effect is wrong
output for every `Predict` call on these 11 model classes.

Verified with a per-call diagnostic:
  Forward direct shape:     [10]
  Predict compile-off shape: [10]
  Predict compile-on shape:  [64]   ← the regression

Root cause is in the tracer / compiled-replay machinery (the tracer
does not capture the shape-conditional control flow in Forward —
rank-3 → rank-4 promotion, final Reshape, etc.). That's a larger
infrastructure fix; this commit restores master's previous behavior so
`Predict` calls Forward directly, matching the pre-#1155 contract.

Affected models (all had master's `public override Predict` changed
to `protected override PredictEager` by #1155):
  - ResNetNetwork, VGGNetwork, EfficientNetNetwork, MobileNetV2Network,
    ConvolutionalNeuralNetwork, UNet3D, VoxelCNN
  - FastText, GloVe, Word2Vec, SiameseNeuralNetwork

Unblocks CI on every open PR that merges master (PR #1163, PR #1165).
Once the compiled-plan tracer is hardened to preserve shape-conditional
control flow, these overrides can be removed again.
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.

perf: JIT compiler integration for zero-allocation diffusion model forward passes

2 participants