Skip to content

Commit

Permalink
Add config logging to loggers and checkpoints. Remove args_file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibro45 committed Jan 16, 2024
1 parent 9497a45 commit 4fa5dc7
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions lighter/utils/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,18 @@ def parse_config(**kwargs):

# Check that a config file is specified.
if "config_file" not in kwargs:
raise ValueError("No config file specified. Exiting.")

# Load config from `config_file`
config = ConfigParser.load_config_files(kwargs["config_file"])
if "project" in config:
import_module_from_path("project", config["project"])
raise ValueError("--config_file not specified. Exiting.")

# Parse the config file(s).
parser = ConfigParser()
parser.read_config(kwargs["config_file"])

if "args_file" in kwargs:
args = ConfigParser.load_config_file(kwargs["args_file"])
parser.update(pairs=args)

parser.read_config(kwargs.pop("config_file"))
parser.update(pairs=kwargs)

# Import the project folder as a module, if specified.
project = parser.get("project", None)
if project is not None:
import_module_from_path("project", project)

return parser


Expand All @@ -60,13 +56,14 @@ def run_trainer_method(method: Dict, **kwargs: Any):
trainer = parser.get_parsed_content("trainer")
system = parser.get_parsed_content("system")

# Intialize config to be used by other modules
for callback in trainer.callbacks:
if hasattr(callback, "config"):
callback.config = parser.get()
config = parser.get()
config.pop("_meta_")
# Save the config to model checkpoints under the "hyper_parameters" key.
system.save_hyperparameters(config)
# Log the config.
trainer.logger.log_hyperparams(config)

# Run the Trainer method.
if not hasattr(trainer, method):
raise ValueError(f"Trainer has no method named {method}.")

getattr(trainer, method)(system)

0 comments on commit 4fa5dc7

Please sign in to comment.