Skip to content

test(lora): align LoRAValidationTests with the resolved-shape adapter contract - #1506

Merged
ooples merged 1 commit into
masterfrom
test/lora-validation-resolved-shape-contract
Jun 5, 2026
Merged

ooples merged 1 commit into
masterfrom
test/lora-validation-resolved-shape-contract

Conversation

@ooples

@ooples ooples commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the 9 master-red LoRAValidationTests failures by settling the lazy-shape design question and aligning the tests with the resolved-shape adapter contract. Test-only change — no production code is touched.

The design question

Should ApplyLoRA (and direct adapter construction) wrap a layer whose input shape is still unresolved?

Decision: no — and that was already decided, in three pieces:

The 9 failing tests predate the lazy-DenseLayer refactor: each declares int inputSize = 5; and then never uses it, constructing new DenseLayer<double>(outputSize) (lazy). The unresolved base made:

  • adapters fall back to the outSize*2 heuristic → DoRA Forward rejected the [batch, 5] test input ("Flat index is out of range"), VeRA rejected its shared matrices ("required 20×4" vs the 5×4 the test initialized);
  • MergeToOriginalLayer index past the unmaterialized base's empty parameter vector (ArgumentOutOfRangeException);
  • the DefaultLoRAConfiguration Create/Throw tests see the guard's pass-through instead of the expected adapter type.

Changes

  • Materialize each test's base layer to its declared inputSize via the public ResolveFromShape API (what the production warmup achieves) — restoring the tests' original intent. The outputSize > inputSize merge/forward indexing coverage now genuinely exercises real weight matrices.
  • New regression test DefaultLoRAConfiguration_LazyUnresolvedLayer_ReturnsUnchanged pins the design decision: a shape-unresolved layer passes through ApplyLoRA untouched.

Verification

  • LoRAValidationTests 23/23 (was 14/23 on master).
  • Combined LoRAValidationTests + Bucket10_LoRA + ConvBatchNormFoldTests run: 28/28.
  • No production code changed; the merge/forward "matrix indexing fix" checks pass against real matrices, confirming those production paths are correct.

Related: PR #1493 independently widens the ApplyLoRA guard to the TryDeclareShape oracle so ctor-determined layers (MultiHeadAttention) are admitted; that change and this one are compatible — lazy DenseLayer is skipped under both.

🤖 Generated with Claude Code

… contract

Nine LoRAValidationTests were red on master because they fed adapters a
LAZY DenseLayer(outputSize) — every test even declares `int inputSize`
and then never uses it, a leftover from before DenseLayer's lazy-init
refactor. An unresolved base has no weight matrix, so:
- the adapters fell back to the NON-authoritative outSize*2 input-dim
  heuristic (ParameterCount-readiness only, per review #1368 — never
  meant to size real adapters), making DoRA's Forward reject the
  [batch, inputSize] test input and VeRA reject its shared matrices
  ("required 20x4" vs the 5x4 the test initialized);
- MergeToOriginalLayer indexed past the unmaterialized base layer's
  empty parameter vector (ArgumentOutOfRangeException);
- DefaultLoRAConfiguration.ApplyLoRA correctly skipped the lazy layer
  (the #1345 guard), so the Creates/Throws tests saw an unchanged
  DenseLayer instead of the expected adapter type.

Design decision, now pinned by a new test
(DefaultLoRAConfiguration_LazyUnresolvedLayer_ReturnsUnchanged):
shape-UNRESOLVED layers pass through ApplyLoRA untouched — wrapping
from fabricated dims was explicitly rejected in review #1368, and the
production pipeline (AiModelBuilder) resolves shapes via the warmup
forward / TryDeclareShape oracle (#1370) before the LoRA pass.

Fix: materialize each test's base layer to its declared inputSize via
the public ResolveFromShape API (exactly what the production pipeline's
warmup achieves), restoring the tests' original intent — the
outputSize > inputSize merge/forward indexing coverage now actually
exercises real weight matrices. All 23 LoRAValidationTests pass; no
production code changes needed.

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

vercel Bot commented Jun 4, 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 4, 2026 11:29pm
aidotnet-playground-api Ready Ready Preview, Comment Jun 4, 2026 11:29pm

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ooples, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 38 minutes and 31 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8f7fecd3-66cb-4378-980d-78dc39444340

📥 Commits

Reviewing files that changed from the base of the PR and between ae9c42c and 1011000.

📒 Files selected for processing (1)
  • tests/AiDotNet.Tests/UnitTests/LoRA/LoRAValidationTests.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/lora-validation-resolved-shape-contract

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

@ooples
ooples merged commit fbb5d39 into master Jun 5, 2026
36 of 45 checks passed
@ooples
ooples deleted the test/lora-validation-resolved-shape-contract branch June 5, 2026 15:20

This branch was successfully deployed

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

2 participants