mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-03 22:38:48 +08:00
add individual grad_scaler config (#1762)
* add individual grad_scaler config * reword the description * Update trainer.py --------- Co-authored-by: Matthew Tancik <mattt4001@gmail.com>
This commit is contained in:
1 parent
1d92cea2e3
commit
817e2caabf
1 file changed
+5
-1
@@ -75,6 +75,8 @@ class TrainerConfig(ExperimentConfig):
|
|||||||
"""Maximum number of iterations to run."""
|
"""Maximum number of iterations to run."""
|
||||||
mixed_precision: bool = False
|
mixed_precision: bool = False
|
||||||
"""Whether or not to use mixed precision for training."""
|
"""Whether or not to use mixed precision for training."""
|
||||||
|
use_grad_scaler: bool = False
|
||||||
|
"""Use gradient scaler even if the automatic mixed precision is disabled."""
|
||||||
save_only_latest_checkpoint: bool = True
|
save_only_latest_checkpoint: bool = True
|
||||||
"""Whether to only save the latest checkpoint or all checkpoints."""
|
"""Whether to only save the latest checkpoint or all checkpoints."""
|
||||||
# optional parameters if we want to resume training
|
# optional parameters if we want to resume training
|
||||||
@@ -118,13 +120,15 @@ class Trainer:
|
|||||||
self.world_size = world_size
|
self.world_size = world_size
|
||||||
self.device: TORCH_DEVICE = "cpu" if world_size == 0 else f"cuda:{local_rank}"
|
self.device: TORCH_DEVICE = "cpu" if world_size == 0 else f"cuda:{local_rank}"
|
||||||
self.mixed_precision: bool = self.config.mixed_precision
|
self.mixed_precision: bool = self.config.mixed_precision
|
||||||
|
self.use_grad_scaler: bool = self.mixed_precision or self.config.use_grad_scaler
|
||||||
self.training_state: Literal["training", "paused", "completed"] = "training"
|
self.training_state: Literal["training", "paused", "completed"] = "training"
|
||||||
|
|
||||||
if self.device == "cpu":
|
if self.device == "cpu":
|
||||||
self.mixed_precision = False
|
self.mixed_precision = False
|
||||||
CONSOLE.print("Mixed precision is disabled for CPU training.")
|
CONSOLE.print("Mixed precision is disabled for CPU training.")
|
||||||
self._start_step: int = 0
|
self._start_step: int = 0
|
||||||
# optimizers
|
# optimizers
|
||||||
self.grad_scaler = GradScaler(enabled=self.mixed_precision)
|
self.grad_scaler = GradScaler(enabled=self.use_grad_scaler)
|
||||||
|
|
||||||
self.base_dir: Path = config.get_base_dir()
|
self.base_dir: Path = config.get_base_dir()
|
||||||
# directory to save checkpoints
|
# directory to save checkpoints
|
||||||
|
|||||||
Reference in new issue
Block a user