Enable method config registration from env variable (#1869)

This commit is contained in:
Jonáš Kulhánek authored and GitHub committed 2023-05-04 20:53:52 +02:00
1 parent 9ace02b3ae
commit 971c9eb307
3 files changed
+48

No files matched your search

+21
View File
@@ -16,6 +16,8 @@
Module that keeps all registered plugins and allows for plugin discovery.
"""
import importlib
import os
import sys
import typing as t
@@ -34,6 +36,7 @@ CONSOLE = Console(width=120)
def discover_methods() -> t.Tuple[t.Dict[str, TrainerConfig], t.Dict[str, str]]:
"""
Discovers all methods registered using the `nerfstudio.method_configs` entrypoint.
And also methods in the NERFSTUDIO_METHOD_CONFIGS environment variable.
"""
methods = {}
descriptions = {}
@@ -48,4 +51,22 @@ def discover_methods() -> t.Tuple[t.Dict[str, TrainerConfig], t.Dict[str, str]]:
specification = t.cast(MethodSpecification, specification)
methods[specification.config.method_name] = specification.config
descriptions[specification.config.method_name] = specification.description
if "NERFSTUDIO_METHOD_CONFIGS" in os.environ:
try:
strings = os.environ["NERFSTUDIO_METHOD_CONFIGS"].split(",")
for definition in strings:
if not definition:
continue
name, path = definition.split("=")
CONSOLE.print(f"[bold green]Info: Loading method {name} from environment variable")
module, config_name = path.split(":")
method_config = getattr(importlib.import_module(module), config_name)
assert isinstance(method_config, MethodSpecification)
methods[name] = method_config.config
descriptions[name] = method_config.description
except Exception: # pylint: disable=broad-except
CONSOLE.print_exception()
CONSOLE.print("[bold red]Error: Could not load methods from environment variable NERFSTUDIO_METHOD_CONFIGS")
return methods, descriptions