Add runtime model compilation options - #75
Merged
Conversation
…nto feat/compile-model
There was a problem hiding this comment.
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_modelruntime option for both training (TrainingConfig) and inference (InferenceConfig), plusBatDetect2API.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 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compile_modelBatDetect2API.compile()andcompile_model=Trueoptions for API constructioneta_minsupport to the cosine annealing scheduler configTesting
just testjust docsFull test result:
522 passed