pass grad scaler from trainer to pipeline (#1996)

* pass grad sclaer from trainer to pipeline

* lint

* add grad scaler to arg doc

---------

Co-authored-by: Matthew Tancik <tancik@berkeley.edu>
This commit is contained in:
Terrance WangandMatthew Tancik authored and GitHub committed 2023-05-25 09:27:58 -07:00
1 parent f9a88c5aa2
commit a8bce87ada
3 files changed
+13 -2

No files matched your search

+5 -1
View File
@@ -148,7 +148,11 @@ class Trainer:
'inference': does not load any dataset into memory
"""
self.pipeline = self.config.pipeline.setup(
device=self.device, test_mode=test_mode, world_size=self.world_size, local_rank=self.local_rank
device=self.device,
test_mode=test_mode,
world_size=self.world_size,
local_rank=self.local_rank,
grad_scaler=self.grad_scaler,
)
self.optimizers = self.setup_optimizers()
+5
View File
@@ -35,6 +35,7 @@ from rich.progress import (
from torch import nn
from torch.nn import Parameter
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.cuda.amp.grad_scaler import GradScaler
from nerfstudio.configs import base_config as cfg
from nerfstudio.data.datamanagers.base_datamanager import (
@@ -222,6 +223,7 @@ class VanillaPipeline(Pipeline):
'inference': does not load any dataset into memory
world_size: total number of machines available
local_rank: rank of current machine
grad_scaler: gradient scaler used in the trainer
Attributes:
datamanager: The data manager that will be used
@@ -235,6 +237,7 @@ class VanillaPipeline(Pipeline):
test_mode: Literal["test", "val", "inference"] = "val",
world_size: int = 1,
local_rank: int = 0,
grad_scaler: Optional[GradScaler] = None,
):
super().__init__()
self.config = config
@@ -250,6 +253,8 @@ class VanillaPipeline(Pipeline):
scene_box=self.datamanager.train_dataset.scene_box,
num_train_data=len(self.datamanager.train_dataset),
metadata=self.datamanager.train_dataset.metadata,
device=device,
grad_scaler=grad_scaler,
)
self.model.to(device)
+3 -1
View File
@@ -17,9 +17,10 @@ A pipeline that dynamically chooses the number of rays to sample.
"""
from dataclasses import dataclass, field
from typing import Literal, Type
from typing import Literal, Type, Optional
import torch
from torch.cuda.amp.grad_scaler import GradScaler
from nerfstudio.data.datamanagers.base_datamanager import VanillaDataManager
from nerfstudio.pipelines.base_pipeline import VanillaPipeline, VanillaPipelineConfig
@@ -50,6 +51,7 @@ class DynamicBatchPipeline(VanillaPipeline):
test_mode: Literal["test", "val", "inference"] = "val",
world_size: int = 1,
local_rank: int = 0,
grad_scaler: Optional[GradScaler] = None,
):
super().__init__(config, device, test_mode, world_size, local_rank)
assert isinstance(