mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 22:56:03 +08:00
Config restructure (#283)
* starting docs for pipelines * working on an example * clearing output * starting to implement config changes and add documentation * wip: removed cicular imports; porting basic config into python; todo: get python setups workin * circular imports again * wip: pausing at dataloader sort of working * break for today * running vanilla * wip need to get all the config docs working * laptop about to die * instant ngp working * added all configs for all methods; not tested yet: [mipnerf360, nerfw, semantic_nerf] * unpacking later * done with pylinting * mostly done. just need to do docs and one test * added import order to docs * fixing near/far plane and other config things * making loggers also instantiable via configs * docs * lint * making --help work with dcargs * moving configs back into flat * convert list to tuples; fixed post init function with mutable params * lint * made run_eval and benchmarking scripts compatible with new config/dcargs * lint * added option to load configs from presaved config Co-authored-by: evonneng <evonne_ng@berkeley.edu>
This commit is contained in:
1 parent
e0856e3afc
commit
7e9a56fac4
46 files changed
+987
-916
No files matched your search
+31
-33
@@ -3,25 +3,22 @@ run_train_nerf.py
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pickle
|
||||
import random
|
||||
import socket
|
||||
import traceback
|
||||
from datetime import timedelta
|
||||
from typing import Any, Callable
|
||||
from typing import Any, Callable, Optional
|
||||
|
||||
import hydra
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.distributed as dist
|
||||
import torch.multiprocessing as mp
|
||||
import yaml
|
||||
from hydra.core.config_store import ConfigStore
|
||||
from omegaconf import DictConfig
|
||||
|
||||
from nerfactory.configs import base as cfg
|
||||
from nerfactory.configs.utils import cli_from_base_configs
|
||||
from nerfactory.engine.trainer import train_loop
|
||||
from nerfactory.utils import comms, profiler
|
||||
from nerfactory.utils.config import Config, setup_config
|
||||
|
||||
logging.basicConfig(format="[%(filename)s:%(lineno)d] %(message)s", level=logging.DEBUG)
|
||||
|
||||
@@ -54,7 +51,7 @@ def _distributed_worker(
|
||||
num_gpus_per_machine: int,
|
||||
machine_rank: int,
|
||||
dist_url: str,
|
||||
config: Config,
|
||||
config: cfg.Config,
|
||||
timeout: timedelta = DEFAULT_TIMEOUT,
|
||||
) -> Any:
|
||||
"""Spawned distributed worker that handles the initialization of process group and handles the
|
||||
@@ -89,8 +86,7 @@ def _distributed_worker(
|
||||
timeout=timeout,
|
||||
)
|
||||
except Exception as e:
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.error("Process group URL: %s", dist_url)
|
||||
logging.error("Process group URL: %s", dist_url)
|
||||
raise e
|
||||
|
||||
assert comms._LOCAL_PROCESS_GROUP is None # pylint: disable=protected-access
|
||||
@@ -118,7 +114,7 @@ def launch(
|
||||
num_machines: int = 1,
|
||||
machine_rank: int = 0,
|
||||
dist_url: str = "auto",
|
||||
config: Config = None,
|
||||
config: Optional[cfg.Config] = None,
|
||||
timeout: timedelta = DEFAULT_TIMEOUT,
|
||||
) -> None:
|
||||
"""Function that spawns muliple processes to call on main_func
|
||||
@@ -153,8 +149,7 @@ def launch(
|
||||
port = _find_free_port()
|
||||
dist_url = f"tcp://127.0.0.1:{port}"
|
||||
if num_machines > 1 and dist_url.startswith("file://"):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.warning("file:// is not a reliable init_method in multi-machine jobs. Prefer tcp://")
|
||||
logging.warning("file:// is not a reliable init_method in multi-machine jobs. Prefer tcp://")
|
||||
|
||||
process_context = mp.spawn(
|
||||
_distributed_worker,
|
||||
@@ -173,34 +168,18 @@ def launch(
|
||||
try:
|
||||
process_context.join()
|
||||
except KeyboardInterrupt:
|
||||
logger = logging.getLogger(__name__)
|
||||
for i, process in enumerate(process_context.processes):
|
||||
if process.is_alive():
|
||||
logger.info("Terminating process %s", str(i))
|
||||
logging.info("Terminating process %s", str(i))
|
||||
process.terminate()
|
||||
process.join()
|
||||
logger.info("Process %s finished", str(i))
|
||||
logging.info("Process %s finished", str(i))
|
||||
finally:
|
||||
profiler.flush_profiler(config.logging)
|
||||
|
||||
|
||||
cs = ConfigStore.instance()
|
||||
cs.store(name="graph_default", node=Config)
|
||||
|
||||
|
||||
@hydra.main(version_base="1.2", config_path="../configs", config_name="graph_default.yaml")
|
||||
def main(config: DictConfig):
|
||||
def main(config: cfg.Config) -> None:
|
||||
"""Main function."""
|
||||
config = setup_config(config) # converting to typed config
|
||||
|
||||
unrolled_path = os.path.join(os.getcwd(), ".hydra/config.yaml")
|
||||
if os.path.exists(unrolled_path):
|
||||
with open(unrolled_path, encoding="utf8") as f:
|
||||
unrolled_config = yaml.safe_load(f)
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("Printing current config setup")
|
||||
print(yaml.dump(unrolled_config, sort_keys=False, default_flow_style=False))
|
||||
|
||||
launch(
|
||||
train_loop,
|
||||
config.machine.num_gpus,
|
||||
@@ -212,4 +191,23 @@ def main(config: DictConfig):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main() # pylint: disable=no-value-for-parameter
|
||||
from nerfactory.configs.base_configs import base_configs
|
||||
|
||||
instantiated_config = cli_from_base_configs(base_configs)
|
||||
if instantiated_config.trainer.load_config:
|
||||
logging.info(f"Loading pre-set config to: {instantiated_config.trainer.load_config}")
|
||||
with open(instantiated_config.trainer.load_config, "rb") as f:
|
||||
instantiated_config = pickle.load(f)
|
||||
# log and save config
|
||||
logging.info("Printing current config setup")
|
||||
print(instantiated_config)
|
||||
config_pickle_path = instantiated_config.base_dir / "config.pkl"
|
||||
config_json_path = instantiated_config.base_dir / "config.txt"
|
||||
logging.info(f"Saving instance of config to: {config_pickle_path}")
|
||||
logging.info(f"Saving human-readable config to: {config_json_path}")
|
||||
config_pickle_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(config_pickle_path, "wb") as f:
|
||||
pickle.dump(instantiated_config, f)
|
||||
with open(config_json_path, "w", encoding="utf8") as f:
|
||||
f.write(str(instantiated_config))
|
||||
main(config=instantiated_config)
|
||||
Reference in new issue
Block a user