From 7214bf53d22ee2fbfe292e2232dbec8cdaedb837 Mon Sep 17 00:00:00 2001 From: "Kim, Vinnam" Date: Mon, 27 May 2024 19:01:55 +0900 Subject: [PATCH] Fix Signed-off-by: Kim, Vinnam --- docker/Dockerfile.cuda | 4 ---- src/otx/algo/modules/base_module.py | 2 +- src/otx/engine/hpo/hpo_api.py | 2 +- src/otx/hpo/search_space.py | 21 +++++++++++++++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile.cuda b/docker/Dockerfile.cuda index 56511de5843..c90fde54c38 100644 --- a/docker/Dockerfile.cuda +++ b/docker/Dockerfile.cuda @@ -50,7 +50,6 @@ RUN pip install --user --no-cache-dir --require-hashes --no-deps -r /tmp/require FROM install_packages AS download_pretrained_weights -USER non-root WORKDIR ${NON_ROOT_HOME} COPY docker/download_pretrained_weights.py download_pretrained_weights.py @@ -76,6 +75,3 @@ FROM cuda AS cuda_pretrained_ready ARG TORCH_CACHE=/home/non-root/.cache/torch COPY --chown=10001 --from=download_pretrained_weights ${TORCH_CACHE} ${TORCH_CACHE} - -USER non-root -WORKDIR ${NON_ROOT_HOME} diff --git a/src/otx/algo/modules/base_module.py b/src/otx/algo/modules/base_module.py index 1734124f3be..5a46d914060 100644 --- a/src/otx/algo/modules/base_module.py +++ b/src/otx/algo/modules/base_module.py @@ -157,7 +157,7 @@ def _dump_init_info(self) -> None: with_file_handler = False # dump the information to the logger file if there is a `FileHandler` for handler in logger.handlers: - if isinstance(handler, FileHandler): + if isinstance(handler, FileHandler) and handler.stream is not None: handler.stream.write("Name of parameter - Initialization information\n") for name, param in self.named_parameters(): handler.stream.write( diff --git a/src/otx/engine/hpo/hpo_api.py b/src/otx/engine/hpo/hpo_api.py index aca4b2edff2..429ceb5d408 100644 --- a/src/otx/engine/hpo/hpo_api.py +++ b/src/otx/engine/hpo/hpo_api.py @@ -70,7 +70,7 @@ def execute_hpo( engine.model.patch_optimizer_and_scheduler_for_hpo() hpo_workdir = Path(engine.work_dir) / "hpo" - hpo_workdir.mkdir(exist_ok=True) + hpo_workdir.mkdir(parents=True, exist_ok=True) hpo_configurator = HPOConfigurator( engine=engine, max_epochs=max_epochs, diff --git a/src/otx/hpo/search_space.py b/src/otx/hpo/search_space.py index 912e7efccf6..6b4754b7dbc 100644 --- a/src/otx/hpo/search_space.py +++ b/src/otx/hpo/search_space.py @@ -14,7 +14,13 @@ logger = logging.getLogger() -AVAILABLE_SEARCH_SPACE_TYPE = ["uniform", "quniform", "loguniform", "qloguniform", "choice"] +AVAILABLE_SEARCH_SPACE_TYPE = [ + "uniform", + "quniform", + "loguniform", + "qloguniform", + "choice", +] class SingleSearchSpace: @@ -58,7 +64,9 @@ def __init__( self._check_all_value_is_right() @property - def type(self) -> Literal["uniform", "loguniform", "quniform", "qloguniform", "choice"]: # noqa: A003 + def type( # noqa: A003 + self, + ) -> Literal["uniform", "loguniform", "quniform", "qloguniform", "choice"]: """Type of hyper parameter in search space.""" return self._type @@ -309,8 +317,13 @@ def __init__( ) -> None: self.search_space: dict[str, SingleSearchSpace] = {} - for key, val in search_space.items(): # pylint: disable=too-many-nested-blocks - self.search_space[key] = SingleSearchSpace(**val) + try: + for key, val in search_space.items(): # pylint: disable=too-many-nested-blocks + self.search_space[key] = SingleSearchSpace(**val) + except Exception: + msg = f"Failed to create SingleSearchSpace. key={key}, val={val}" + logging.exception(msg) + raise def __getitem__(self, key: str) -> SingleSearchSpace: """Get search space by key."""