mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-28 20:10:05 +08:00
Added structured config support (#58)
* added typed config; idealy would convert graph to typed too.... * added graph as config
This commit is contained in:
1 parent
d65b50a0e3
commit
ee4e6b24f4
11 files changed
+199
-41
No files matched your search
@@ -0,0 +1,149 @@
|
||||
# Copyright 2022 The Plenoptix Team. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Structured config classes"""
|
||||
|
||||
from dataclasses import MISSING, dataclass
|
||||
from typing import Any, Dict, Optional
|
||||
from omegaconf import DictConfig
|
||||
|
||||
|
||||
@dataclass
|
||||
class MachineConfig:
|
||||
"""Configuration of machine setup"""
|
||||
|
||||
seed: int = MISSING
|
||||
num_gpus: int = MISSING
|
||||
num_machines: int = MISSING
|
||||
machine_rank: int = MISSING
|
||||
dist_url: str = MISSING
|
||||
|
||||
|
||||
@dataclass
|
||||
class LoggingConfig:
|
||||
"""Configuration of loggers and profilers"""
|
||||
|
||||
steps_per_log: int = MISSING
|
||||
max_buffer_size: int = MISSING
|
||||
writer: Dict[str, Any] = MISSING
|
||||
enable_profiler: bool = MISSING
|
||||
|
||||
|
||||
@dataclass
|
||||
class ResumeTrainConfig:
|
||||
"""Configuration for loading previous checkpoints"""
|
||||
|
||||
load_dir: Optional[str] = None
|
||||
load_step: Optional[int] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class TrainerConfig:
|
||||
"""Configuration for training regimen"""
|
||||
|
||||
model_dir: str = MISSING
|
||||
steps_per_save: int = MISSING
|
||||
steps_per_test: int = MISSING
|
||||
max_num_iterations: int = MISSING
|
||||
# additional optional parameters here
|
||||
resume_train: Optional[ResumeTrainConfig] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class DatasetInputsConfig:
|
||||
"""Configuration for dataset specification"""
|
||||
|
||||
data_directory: str = MISSING
|
||||
dataset_format: str = MISSING
|
||||
downscale_factor: int = MISSING
|
||||
alpha_color: str = MISSING
|
||||
|
||||
|
||||
@dataclass
|
||||
class ImageDatasetConfig:
|
||||
"""Configuration for type of dataset to instantiate"""
|
||||
|
||||
_target_: str = MISSING
|
||||
|
||||
|
||||
@dataclass
|
||||
class DataConfig:
|
||||
"""Configuration for train/eval datasets"""
|
||||
|
||||
dataset_inputs_train: DatasetInputsConfig = MISSING
|
||||
image_dataset_train: ImageDatasetConfig = MISSING
|
||||
dataloader_train: Dict[str, Any] = MISSING
|
||||
dataset_inputs_eval: DatasetInputsConfig = MISSING
|
||||
image_dataset_eval: ImageDatasetConfig = MISSING
|
||||
dataloader_eval: Dict[str, Any] = MISSING
|
||||
# additional optional parameters here
|
||||
pixel_sampler: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class GraphConfig:
|
||||
"""Configuration for graph instantiation"""
|
||||
|
||||
_target_: str = MISSING
|
||||
collider_config: Dict[str, Any] = MISSING
|
||||
num_coarse_samples: int = MISSING
|
||||
num_importance_samples: int = MISSING
|
||||
loss_coefficients: Dict[str, Any] = MISSING
|
||||
# additional optional parameters here
|
||||
field_implementation: Optional[str] = "torch"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
"""Full config contents"""
|
||||
|
||||
machine: MachineConfig = MISSING
|
||||
logging: LoggingConfig = MISSING
|
||||
trainer: TrainerConfig = MISSING
|
||||
experiment_name: str = MISSING
|
||||
method_name: str = MISSING
|
||||
data: DataConfig = MISSING
|
||||
graph: GraphConfig = MISSING
|
||||
optimizers: Dict[str, Any] = MISSING
|
||||
# additional optional parameters here
|
||||
hydra: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
def setup_config(config: DictConfig) -> Config:
|
||||
"""helper that creates a typed config from the DictConfig
|
||||
|
||||
Args:
|
||||
config (DictConfig): configuration to convert
|
||||
|
||||
Returns:
|
||||
Config: typed version of the input configuration
|
||||
"""
|
||||
machine = MachineConfig(**config.machine)
|
||||
logging = LoggingConfig(**config.logging)
|
||||
trainer = TrainerConfig(**config.trainer)
|
||||
experiment_name = config.experiment_name
|
||||
method_name = config.method_name
|
||||
data = DataConfig(**config.data)
|
||||
graph = GraphConfig(**config.graph)
|
||||
optimizers = config.optimizers
|
||||
return Config(
|
||||
machine=machine,
|
||||
logging=logging,
|
||||
trainer=trainer,
|
||||
experiment_name=experiment_name,
|
||||
method_name=method_name,
|
||||
data=data,
|
||||
graph=graph,
|
||||
optimizers=optimizers,
|
||||
)
|
||||
@@ -19,9 +19,8 @@ import logging
|
||||
import time
|
||||
from typing import Callable
|
||||
|
||||
from omegaconf import DictConfig
|
||||
|
||||
from pyrad.utils import comms
|
||||
from pyrad.utils.config import LoggingConfig
|
||||
from pyrad.utils.decorators import check_main_thread, check_profiler_enabled, decorate_all
|
||||
|
||||
PROFILER = []
|
||||
@@ -41,13 +40,13 @@ def time_function(func: Callable) -> Callable:
|
||||
return wrapper
|
||||
|
||||
|
||||
def flush_profiler(config: DictConfig):
|
||||
def flush_profiler(config: LoggingConfig):
|
||||
"""Method that checks if profiler is enabled before flushing"""
|
||||
if config.enable_profiler and PROFILER:
|
||||
PROFILER[0].print_profile()
|
||||
|
||||
|
||||
def setup_profiler(config: DictConfig):
|
||||
def setup_profiler(config: LoggingConfig):
|
||||
"""Initialization of profilers"""
|
||||
if comms.is_main_process():
|
||||
PROFILER.append(Profiler(config))
|
||||
@@ -57,7 +56,7 @@ def setup_profiler(config: DictConfig):
|
||||
class Profiler:
|
||||
"""Profiler class"""
|
||||
|
||||
def __init__(self, config: DictConfig):
|
||||
def __init__(self, config: LoggingConfig):
|
||||
self.config = config
|
||||
self.profiler_dict = {}
|
||||
|
||||
|
||||
@@ -28,9 +28,10 @@ import imageio
|
||||
import numpy as np
|
||||
import torch
|
||||
import wandb
|
||||
from omegaconf import DictConfig, ListConfig
|
||||
from omegaconf import ListConfig
|
||||
from torch.utils.tensorboard import SummaryWriter
|
||||
from torchtyping import TensorType
|
||||
from pyrad.utils.config import LoggingConfig
|
||||
|
||||
from pyrad.utils.decorators import check_main_thread, decorate_all
|
||||
|
||||
@@ -134,12 +135,11 @@ def write_out_storage():
|
||||
|
||||
|
||||
@check_main_thread
|
||||
def setup_event_writers(config: DictConfig) -> None:
|
||||
def setup_event_writers(config: LoggingConfig, max_iter: int) -> None:
|
||||
"""Initialization of all event writers specified in config"""
|
||||
logging_configs = config.logging.writer
|
||||
for writer_type in logging_configs:
|
||||
for writer_type in config.writer:
|
||||
writer_class = getattr(sys.modules[__name__], writer_type)
|
||||
writer_config = logging_configs[writer_type]
|
||||
writer_config = config.writer[writer_type]
|
||||
if writer_type == "LocalWriter":
|
||||
curr_writer = writer_class(writer_config.log_dir, writer_config.stats_to_track, writer_config.max_log_size)
|
||||
else:
|
||||
@@ -147,9 +147,9 @@ def setup_event_writers(config: DictConfig) -> None:
|
||||
EVENT_WRITERS.append(curr_writer)
|
||||
|
||||
## configure all the global buffer basic information
|
||||
GLOBAL_BUFFER["max_iter"] = config.trainer.max_num_iterations
|
||||
GLOBAL_BUFFER["max_buffer_size"] = config.logging.max_buffer_size
|
||||
GLOBAL_BUFFER["steps_per_log"] = config.logging.steps_per_log
|
||||
GLOBAL_BUFFER["max_iter"] = max_iter
|
||||
GLOBAL_BUFFER["max_buffer_size"] = config.max_buffer_size
|
||||
GLOBAL_BUFFER["steps_per_log"] = config.steps_per_log
|
||||
GLOBAL_BUFFER["events"] = {}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user