mirror of
https://github.com/macaodha/batdetect2.git
synced 2026-08-21 18:50:10 +02:00
refactor: remove ambiguous training precision option
This commit is contained in:
parent
c8f0f2bee1
commit
586e78814f
@ -9,8 +9,6 @@ Defined in `batdetect2.train.config`.
|
||||
|
||||
- `compile_model`
|
||||
- compile the detector before training starts. This is off by default.
|
||||
- `precision`
|
||||
- optional float32 matrix multiplication precision setting passed to PyTorch.
|
||||
- `train_loader`
|
||||
- training data loading and clipping settings.
|
||||
- `val_loader`
|
||||
@ -37,8 +35,7 @@ Use `TrainingConfig` when you want to change things like:
|
||||
- batch size,
|
||||
- augmentation,
|
||||
- optimiser and scheduler settings,
|
||||
- runtime options such as model compilation and matrix multiplication
|
||||
precision,
|
||||
- runtime options such as model compilation,
|
||||
- number of epochs,
|
||||
- validation frequency,
|
||||
- checkpoint behaviour.
|
||||
@ -50,9 +47,6 @@ training. This can help on longer runs with stable tensor shapes, but it may be
|
||||
slower for short CPU-only experiments because PyTorch has to compile the graph
|
||||
before it can reuse it.
|
||||
|
||||
Use `precision` to set PyTorch's float32 matrix multiplication precision before
|
||||
training starts. Supported values are `medium` and `high`.
|
||||
|
||||
Example files live under `example_data/configs/`, including
|
||||
`example_data/configs/training.yaml`.
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from batdetect2.core.configs import BaseConfig
|
||||
@ -42,7 +40,6 @@ class PLTrainerConfig(BaseConfig):
|
||||
|
||||
class TrainingConfig(BaseConfig):
|
||||
compile_model: bool = False
|
||||
precision: Literal["medium", "high"] | None = None
|
||||
train_loader: TrainLoaderConfig = Field(default_factory=TrainLoaderConfig)
|
||||
val_loader: ValLoaderConfig = Field(default_factory=ValLoaderConfig)
|
||||
optimizer: OptimizerConfig = Field(default_factory=AdamOptimizerConfig)
|
||||
|
||||
@ -2,7 +2,6 @@ from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import torch
|
||||
from lightning import Trainer, seed_everything
|
||||
from lightning.pytorch.loggers import Logger
|
||||
from loguru import logger
|
||||
@ -208,13 +207,6 @@ def run_train(
|
||||
run_name=run_name,
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
if train_config.compile_model:
|
||||
logger.info("Compiling detector...")
|
||||
compile_model(module.model)
|
||||
|
||||
@ -349,33 +349,6 @@ def test_run_train_compiles_detector_when_train_config_requests_compile(
|
||||
assert recorder.call_count > 0
|
||||
|
||||
|
||||
@pytest.mark.slow
|
||||
def test_run_train_sets_float32_matmul_precision(
|
||||
tmp_path: Path,
|
||||
example_annotations: list[data.ClipAnnotation],
|
||||
) -> None:
|
||||
original_precision = torch.get_float32_matmul_precision()
|
||||
train_config = build_fast_train_config()
|
||||
train_config.precision = "high"
|
||||
|
||||
try:
|
||||
run_train(
|
||||
train_annotations=example_annotations[:1],
|
||||
val_annotations=example_annotations[:1],
|
||||
train_config=train_config,
|
||||
num_epochs=1,
|
||||
train_workers=0,
|
||||
val_workers=0,
|
||||
checkpoint_dir=tmp_path / "checkpoints",
|
||||
log_dir=tmp_path / "logs",
|
||||
seed=0,
|
||||
)
|
||||
|
||||
assert torch.get_float32_matmul_precision() == "high"
|
||||
finally:
|
||||
torch.set_float32_matmul_precision(original_precision)
|
||||
|
||||
|
||||
def test_build_training_module_uses_provided_model() -> None:
|
||||
targets = build_targets(TargetConfig())
|
||||
roi_mapper = build_roi_mapping(TargetConfig().roi)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user