Skip to content

Commit

Permalink
Allow reading remote configs (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioangatop authored Mar 7, 2024
1 parent 9d99887 commit b2d5df8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/eva/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
import sys
import warnings

import jsonargparse
from loguru import logger


def _configure_jsonargparse() -> None:
"""Configures the `jsonargparse` library."""
jsonargparse.set_config_read_mode(
urls_enabled=True,
fsspec_enabled=True,
)


def _initialize_logger() -> None:
"""Initializes, manipulates and customizes the logger.
Expand Down Expand Up @@ -44,6 +53,7 @@ def _enable_mps_fallback() -> None:

def setup() -> None:
"""Sets up the environment before the module is imported."""
_configure_jsonargparse()
_initialize_logger()
_suppress_warnings()
_enable_mps_fallback()
Expand Down
13 changes: 9 additions & 4 deletions src/eva/trainers/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from datetime import datetime

from lightning_fabric.utilities import cloud_io
from loguru import logger


Expand Down Expand Up @@ -33,7 +34,7 @@ def _generate_config_hash(max_hash_len: int = 8) -> str:
config_path = _fetch_config_path()
if config_path is None:
logger.warning(
"No or multiple configuration file found from command line arguments."
"No or multiple configuration file found from command line arguments. "
"No configuration hash code will created for this experiment."
)
return ""
Expand All @@ -50,7 +51,8 @@ def _fetch_config_path() -> str | None:
Returns:
The path to the configuration file.
"""
config_paths = [f for f in sys.argv if f.endswith(".yaml")]
inputs = sys.argv
config_paths = [inputs[i + 1] for i, arg in enumerate(inputs) if arg == "--config"]
if len(config_paths) == 0 or len(config_paths) > 1:
# TODO combine the multiple configuration files
# and produced hash for the merged one.
Expand All @@ -69,8 +71,11 @@ def _generate_hash_from_config(path: str, max_hash_len: int = 8) -> str:
Returns:
Hash of the configuration file content.
"""
with open(path, "r") as stream:
config = stream.read().encode("utf-8")
fs = cloud_io.get_filesystem(path)
with fs.open(path, "r") as stream:
config = stream.read()
if isinstance(config, str):
config = config.encode("utf-8")
config_sha256 = hashlib.sha256(config)
hash_id = config_sha256.hexdigest()
return hash_id[:max_hash_len]

0 comments on commit b2d5df8

Please sign in to comment.