Skip to content

fix(model): set step interval on learning rate schedulers - #3879

Open
jrusbo wants to merge 2 commits into
open-edge-platform:mainfrom
jrusbo:fix/model/lr-scheduler-step-interval
Open

jrusbo wants to merge 2 commits into
open-edge-platform:mainfrom
jrusbo:fix/model/lr-scheduler-step-interval

Conversation

@jrusbo

@jrusbo jrusbo commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

📝 Description

✨ Changes

  1. EfficientAD:
    StepLR is defined with step_size = int(0.95 * num_steps) (where num_steps is total batch steps). Previously, configure_optimizers() returned {"optimizer": optimizer, "lr_scheduler": scheduler}. In PyTorch Lightning, a raw scheduler object defaults to interval="epoch", causing the scheduler to step only once per epoch instead of once per batch step. Wrapped with {"scheduler": scheduler, "interval": "step"}.
  2. Dinomaly, Inp-Former, U-Flow, UniNet:
    These models returned [optimizer], [scheduler] with step-based configurations. Wrapped with standard dictionary format.
  3. Engine LR Monitoring:
    Auto-attached LearningRateMonitor(logging_interval="step") in Engine when a logger is active, allowing step-level LR updates to be visible in MLflow or TensorBoard....

Note on Review

  • EfficientAD: I am confident in this fix as I have thoroughly tested and verified it on my local setup and dataset.
  • Other models: I do not have the complete environment or datasets to test all models end-to-end. I took the liberty of using an AI assistant to trace similar occurrences and apply the same dictionary repair pattern. I would appreciate it if maintainers could double-check those models during review.

Select what type of change your PR is:

  • 🚀 New feature (non-breaking change which adds functionality)
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔄 Refactor (non-breaking change which refactors the code base)
  • ⚡ Performance improvements
  • 🎨 Style changes (code style/formatting)
  • 🧪 Tests (adding/modifying tests)
  • 📚 Documentation update
  • 📦 Build system changes
  • 🚧 CI/CD configuration
  • 🔧 Chore (general maintenance)
  • 🔒 Security update
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).
  • 🏷️ My PR title follows conventional commit format.

For more information about code review checklists, see the Code Review Checklist.

@jrusbo
jrusbo force-pushed the fix/model/lr-scheduler-step-interval branch 2 times, most recently from 3130bd8 to 44d13f0 Compare October 28, 2026 09:57
@jrusbo

jrusbo commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

The only failures in integration-tests are 4 external URL reachability checks in test_download_urls.py (mvtecad, mvtec_3d, mvtecad2, mvtec_loco) returning HTTP 404 from mydrive.ch.

@jrusbo
jrusbo force-pushed the fix/model/lr-scheduler-step-interval branch 2 times, most recently from dad1729 to 899719a Compare November 11, 2026 14:26
@ashwinvaidya17
ashwinvaidya17 requested a balanced review from Copilot November 12, 2026 08:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

UniNet’s single-epoch scheduler prematurely reduces the learning rate, the new unit test can trigger network downloads, and the scheduler changes lack targeted regression coverage.

3 open issues
What changed in this PR

This PR addresses #3878 by making learning-rate scheduler intervals explicit in five anomaly-detection models and adding automatic learning-rate monitoring to the Engine.

Changes:

  • Configure step-based scheduling, retaining UniNet’s epoch fallback.
  • Attach LearningRateMonitor when logging is enabled, respecting barebones mode and existing monitors.
  • Add callback-registration coverage and changelog entries.
File Description
tests/​unit/​engine/​test_engine.py Tests monitor registration with and without a logger.
src/​anomalib/​models/​image/​uninet/​lightning_model.py Selects step or epoch scheduling and integer milestones.
src/​anomalib/​models/​image/​uflow/​lightning_model.py Sets LinearLR to step per optimizer update.
src/​anomalib/​models/​image/​inp_former/​lightning_model.py Sets warmup/cosine scheduling to step intervals.
src/​anomalib/​models/​image/​efficient_ad/​lightning_model.py Sets StepLR to step intervals and updates return typing.
src/​anomalib/​models/​image/​dinomaly/​lightning_model.py Sets warmup/cosine scheduling to step intervals.
src/​anomalib/​engine/​engine.py Automatically registers learning-rate monitoring when appropriate.
CHANGELOG.md Records scheduler fixes and automatic monitoring.

Review effort: Balanced

Comment thread tests/unit/engine/test_engine.py Resolved
jrusbo and others added 2 commits November 13, 2026 15:39
- Wrap step-based learning rate schedulers with interval="step" across EfficientAd, Dinomaly, InpFormer, Uflow, and UniNet so schedulers decay per batch step instead of per epoch.
- Auto-attach LearningRateMonitor in Engine when a logger is configured.
- Add unit test for engine callback setup.
- Update CHANGELOG.md under Unreleased.

Signed-off-by: Joaquin Rus Bono <jrusbo@gmail.com>
Signed-off-by: Joaquin Rus Bono <joaquin.rus.bono@anticipate.ml>
@jrusbo
jrusbo force-pushed the fix/model/lr-scheduler-step-interval branch from be9a8fc to 2f17083 Compare November 13, 2026 14:39
@ashwinvaidya17
ashwinvaidya17 requested a balanced review from Copilot November 17, 2026 08:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the scheduler-interval fixes and automatic learning-rate monitoring changes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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.

🐞 Step-based LR schedulers in EfficientAD (and other models) default to epoch interval

2 participants