mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-06 15:59:16 +08:00
Changed Graph to nn.ModuleDict; Added DDP logic to seup_graph; locallyrunning DDP
This commit is contained in:
1 parent
b2220fef28
commit
b8e2713643
5 files changed
+17
-18
No files matched your search
@@ -39,7 +39,7 @@ class MLP(FieldModule):
|
||||
self.out_activation = out_activation
|
||||
self.net = None
|
||||
|
||||
def build_model(self) -> None:
|
||||
def build_nn_modules(self) -> None:
|
||||
"""Initialize mulilayer perceptron."""
|
||||
layers = []
|
||||
for i in range(self.num_layers):
|
||||
|
||||
@@ -30,7 +30,7 @@ class Node:
|
||||
return hash(self.name)
|
||||
|
||||
|
||||
class Graph(nn.Module):
|
||||
class Graph(nn.ModuleDict):
|
||||
"""_summary_"""
|
||||
|
||||
def __init__(self, modules_config: DictConfig) -> None:
|
||||
@@ -40,20 +40,19 @@ class Graph(nn.Module):
|
||||
self.roots = self.construct_graph()
|
||||
self.module_order = self.get_module_order()
|
||||
|
||||
self.modules = {}
|
||||
# initialize graph with known input dimensions; set default in_dim to 0
|
||||
for module_name, module_dict in modules_config.items():
|
||||
module = getattr(importlib.import_module("mattport.nerf.field_modules"), module_dict.class_name)
|
||||
if not module_dict.meta_data.in_dim:
|
||||
module_dict.meta_data.in_dim = 0
|
||||
self.modules[module_name] = module(**module_dict.meta_data)
|
||||
self[module_name] = module(**module_dict.meta_data)
|
||||
|
||||
# calculate input dimensions based on module dependencies
|
||||
for root in self.roots:
|
||||
self.get_in_dim(root)
|
||||
|
||||
# instantiate torch.nn members of network
|
||||
for _, module in self.modules.items():
|
||||
for _, module in self.items():
|
||||
module.build_nn_modules()
|
||||
|
||||
def get_in_dim(self, curr_node: Node) -> None:
|
||||
@@ -66,8 +65,8 @@ class Graph(nn.Module):
|
||||
if len(curr_node.parents) > 0:
|
||||
in_dim = 0
|
||||
for parent_name in curr_node.parents.keys():
|
||||
in_dim += self.modules[parent_name].get_out_dim()
|
||||
self.modules[curr_node.name].set_in_dim(in_dim)
|
||||
in_dim += self[parent_name].get_out_dim()
|
||||
self[curr_node.name].set_in_dim(in_dim)
|
||||
self.modules_config[curr_node.name].meta_data.in_dim = in_dim
|
||||
|
||||
for child_node in curr_node.children.values():
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Code to train model.
|
||||
"""
|
||||
from omegaconf import DictConfig
|
||||
import torch.distributed as dist
|
||||
from torch.nn.parallel import DistributedDataParallel as DDP
|
||||
|
||||
@@ -12,7 +13,7 @@ from mattport.nerf.optimizer import Optimizer
|
||||
class Trainer:
|
||||
"""Training class"""
|
||||
|
||||
def __init__(self, local_rank: int, world_size: int, config: dict):
|
||||
def __init__(self, local_rank: int, world_size: int, config: DictConfig):
|
||||
self.local_rank = local_rank
|
||||
self.world_size = world_size
|
||||
self.config = config
|
||||
@@ -31,11 +32,10 @@ class Trainer:
|
||||
|
||||
def setup_graph(self):
|
||||
"""_summary_"""
|
||||
self.graph = Graph(self.config).to(self.device)
|
||||
self.graph = Graph(self.config.network).to(self.device)
|
||||
if self.world_size > 1:
|
||||
self.graph = DDP(self.graph, device_ids=[self.local_rank])
|
||||
dist.barrier(device_ids=[self.local_rank])
|
||||
raise NotImplementedError
|
||||
|
||||
def setup_optimizer(self):
|
||||
"""_summary_"""
|
||||
|
||||
Reference in new issue
Block a user