Skip to content

Add runtime model compilation options - #75

Merged
mbsantiago merged 11 commits into
mainfrom
feat/compile-model
Aug 8, 2026
Merged

Add runtime model compilation options#75
mbsantiago merged 11 commits into
mainfrom
feat/compile-model

Conversation

@mbsantiago

@mbsantiago mbsantiago commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add opt-in runtime compilation for training and inference via compile_model
  • Compile the detector used by training and prediction
  • Add BatDetect2API.compile() and compile_model=True options for API construction
  • Allow passing a pre-built Lightning logger into the training workflow
  • Add eta_min support to the cosine annealing scheduler config
  • Document the new runtime compilation options

Testing

  • just test
  • just docs

Full test result: 522 passed

Copilot AI lite review requested due to automatic review settings August 8, 2026 11:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds opt-in runtime compilation support across training and inference, exposing compilation controls via configs and the v2 API, and documents the new options.

Changes:

  • Introduces compile_model runtime option for both training (TrainingConfig) and inference (InferenceConfig), plus BatDetect2API.compile() and constructor flags to auto-compile.
  • Adds float32 matmul precision control for training runs and supports providing a pre-built Lightning logger.
  • Extends cosine annealing scheduler config with eta_min, updates tests, and documents the new runtime options.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_train/test_lightning.py Refactors smoke config creation and adds tests for training-time compilation + matmul precision.
tests/test_inference/test_batch.py Adds batch inference tests for compile-on-demand and no-recompile behavior.
tests/test_api_v2/test_api_v2.py Adds API-level tests for explicit compilation and compile-on-construction.
tests/conftest.py Adds a fixture to record detector compilation/call behavior; minor waveform generation refactor.
src/batdetect2/train/train.py Adds optional Lightning logger injection, matmul precision setting, and optional detector compilation.
src/batdetect2/train/schedulers.py Adds eta_min support to cosine annealing scheduler config/builder.
src/batdetect2/train/config.py Adds runtime fields (compile_model, matmul precision) to TrainingConfig.
src/batdetect2/models/init.py Adds compile_model() helper and exports it.
src/batdetect2/inference/config.py Adds compile_model flag to InferenceConfig.
src/batdetect2/inference/batch.py Compiles the detector prior to batch inference when requested.
src/batdetect2/api_v2.py Adds BatDetect2API.compile(), compile-on-construction flags, and supports passing a pre-built train logger.
justfile Adds -v to the example training invocation.
docs/source/reference/configs/training/training-config.md Documents training runtime compilation and matmul precision options.
docs/source/reference/configs/inference/inference-config.md Documents inference runtime compilation and API entry points.
docs/source/reference/api.md Documents compile-on-construction and explicit compilation via API.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/batdetect2/train/train.py Outdated
Comment on lines +211 to +216
if train_config.precision is not None:
logger.info(
"Setting float32 matmul precision to {}",
train_config.precision,
)
torch.set_float32_matmul_precision(train_config.precision)
Comment on lines 43 to 46
class TrainingConfig(BaseConfig):
compile_model: bool = False
precision: Literal["medium", "high"] | None = None
train_loader: TrainLoaderConfig = Field(default_factory=TrainLoaderConfig)
@mbsantiago
mbsantiago merged commit bbe89e2 into main Aug 8, 2026
4 checks passed
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