diff --git a/docs/profiling_test.py b/docs/profiling_test.py index 0fb9f659..31cd2f20 100644 --- a/docs/profiling_test.py +++ b/docs/profiling_test.py @@ -118,7 +118,7 @@ def test_notebook_commands_dont_cause_errors(experiment_dictconfig: DictConfig): config = resolve_dictconfig(experiment_dictconfig) # check for any errors when actually instantiating the components. # _experiment = _setup_experiment(config) - setup_logging(config) + setup_logging(log_level=config.log_level) lightning.seed_everything(config.seed, workers=True) _trainer = instantiate_trainer(config) datamodule = instantiate_datamodule(config.datamodule) diff --git a/project/conftest.py b/project/conftest.py index 3769b066..b240ff92 100644 --- a/project/conftest.py +++ b/project/conftest.py @@ -289,7 +289,7 @@ def algorithm( def trainer( experiment_config: Config, ) -> pl.Trainer: - setup_logging(experiment_config) + setup_logging(log_level=experiment_config.log_level) lightning.seed_everything(experiment_config.seed, workers=True) return instantiate_trainer(experiment_config) diff --git a/project/experiment.py b/project/experiment.py index aef75c67..b6998926 100644 --- a/project/experiment.py +++ b/project/experiment.py @@ -14,7 +14,6 @@ import copy import functools import logging -import os from logging import getLogger as get_logger from typing import Any @@ -44,10 +43,11 @@ instantiate = hydra_zen.instantiate -def setup_logging(experiment_config: Config) -> None: - LOGLEVEL = os.environ.get("LOGLEVEL", "info").upper() +def setup_logging(log_level: str, global_log_level: str = "WARNING") -> None: + from project.main import PROJECT_NAME + logging.basicConfig( - level=LOGLEVEL, + level=global_log_level.upper(), # format="%(asctime)s - %(levelname)s - %(message)s", format="%(message)s", datefmt="[%X]", @@ -62,12 +62,8 @@ def setup_logging(experiment_config: Config) -> None: ], ) - root_logger = logging.getLogger("project") - - if experiment_config.debug: - root_logger.setLevel(logging.INFO) - elif experiment_config.verbose: - root_logger.setLevel(logging.DEBUG) + project_logger = logging.getLogger(PROJECT_NAME) + project_logger.setLevel(log_level.upper()) def instantiate_trainer(experiment_config: Config) -> Trainer: diff --git a/project/main.py b/project/main.py index 282dda3e..da6b7dd1 100644 --- a/project/main.py +++ b/project/main.py @@ -45,14 +45,16 @@ logger = get_logger(__name__) PROJECT_NAME = Path(__file__).parent.name - add_configs_to_hydra_store() +setup_logging(log_level="INFO", global_log_level="ERROR") + auto_schema_plugin.config = auto_schema_plugin.AutoSchemaPluginConfig( schemas_dir=REPO_ROOTDIR / ".schemas", regen_schemas=False, stop_on_error=False, quiet=True, + verbose=False, add_headers=False, # don't fallback to adding headers if we can't use vscode settings file. ) @@ -81,12 +83,13 @@ def main(dict_config: DictConfig) -> dict: # Resolve all the interpolations in the configs. config: Config = resolve_dictconfig(dict_config) - # Now we instantiate the components. + setup_logging( + log_level=config.log_level, + global_log_level="DEBUG" if config.debug else "INFO" if config.verbose else "WARNING", + ) # seed the random number generators, so the weights that are # constructed are deterministic and reproducible. - - setup_logging(config) lightning.seed_everything(seed=config.seed, workers=True) # Create the Trainer diff --git a/project/utils/hydra_config_utils.py b/project/utils/hydra_config_utils.py index 4458b0c7..1f4e38de 100644 --- a/project/utils/hydra_config_utils.py +++ b/project/utils/hydra_config_utils.py @@ -1,3 +1,4 @@ +import functools import importlib import inspect import typing @@ -12,15 +13,31 @@ logger = get_logger(__name__) +@functools.cache def get_config_loader(): from hydra._internal.config_loader_impl import ConfigLoaderImpl from hydra._internal.utils import create_automatic_config_search_path from project.main import PROJECT_NAME + # TODO: This (loading a config) is actually taking a long time, in part because this is + # triggering the hydra-auto-schema plugin to add schemas to all the yaml files. + AutoSchemaPlugin = None + backup = None + try: + from hydra_plugins.hydra_auto_schema.auto_schema_plugin import ( # type: ignore + AutoSchemaPlugin, + ) + + backup = AutoSchemaPlugin._ALREADY_DID + AutoSchemaPlugin._ALREADY_DID = True + except ImportError: + pass search_path = create_automatic_config_search_path( calling_file=None, calling_module=None, config_path=f"pkg://{PROJECT_NAME}.configs" ) + if AutoSchemaPlugin is not None: + AutoSchemaPlugin._ALREADY_DID = backup config_loader = ConfigLoaderImpl(config_search_path=search_path) return config_loader diff --git a/pyproject.toml b/pyproject.toml index d2e8e291..dd6f3b42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ "mkdocstrings[python]>=0.26.2", "remote-slurm-executor", "watchdog>=5.0.3", - "hydra-auto-schema>=0.0.3", + "hydra-auto-schema>=0.0.4", ] readme = "README.md" requires-python = ">= 3.10" diff --git a/uv.lock b/uv.lock index b6933c65..72853646 100644 --- a/uv.lock +++ b/uv.lock @@ -1425,7 +1425,7 @@ wheels = [ [[package]] name = "hydra-auto-schema" -version = "0.0.3" +version = "0.0.4" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "docstring-parser" }, @@ -1437,9 +1437,9 @@ dependencies = [ { name = "tqdm" }, { name = "watchdog" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/82/0b/0fb5615fc7b6f1313fbb25a1b6a9402d07291876c0c0a41ca7ba02709a27/hydra_auto_schema-0.0.3.tar.gz", hash = "sha256:32918b6026a9e2eb0d7b4226a12b0a28f7346168551b2553e09aab650f77ae02", size = 51587 } +sdist = { url = "https://files.pythonhosted.org/packages/f4/1a/5c103128641fe165c6253e77fe7fbcd1c54a5633dfaa6a972f40612558ed/hydra_auto_schema-0.0.4.tar.gz", hash = "sha256:e28745530b089ac61c3c9ad4c4a4a38ddbd72128d432f2b4ebc7937fd37dc652", size = 59134 } wheels = [ - { url = "https://files.pythonhosted.org/packages/39/bc/f67466ab7ec7f5b78331222973cd74b2f90fe4c6a83d348b3035bda51462/hydra_auto_schema-0.0.3-py3-none-any.whl", hash = "sha256:86db1ae2ad260e41081ecc89397014a878eeee0bc06a7b8df2cb916ac6f794ea", size = 24909 }, + { url = "https://files.pythonhosted.org/packages/a7/e2/c6e696094d9aa099498b85fb79f4a936284ed91a3b42cec9e6106f170c69/hydra_auto_schema-0.0.4-py3-none-any.whl", hash = "sha256:4aa3cc2c86bacb22c7abdbd2c438a2ed695c403dee33779200d948e7de832b16", size = 28220 }, ] [[package]] @@ -3943,7 +3943,7 @@ requires-dist = [ { name = "gdown", specifier = ">=5.2.0" }, { name = "gymnasium", extras = ["classic-control"], specifier = ">=0.29.1" }, { name = "gymnax", git = "https://www.github.com/lebrice/gymnax?rev=fix-classic-control-rendering" }, - { name = "hydra-auto-schema", specifier = ">=0.0.3" }, + { name = "hydra-auto-schema", specifier = ">=0.0.4" }, { name = "hydra-colorlog", specifier = ">=1.2.0" }, { name = "hydra-core", specifier = ">=1.3.2" }, { name = "hydra-orion-sweeper", specifier = ">=1.6.4" },