Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions CodeEntropy/config/arg_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,32 @@ def merge_configs(self, args, run_config):
if not isinstance(run_config, dict):
raise TypeError("run_config must be a dictionary or None.")

# Step 1: Merge YAML configuration into args
for key, value in run_config.items():
if getattr(args, key, None) is None:
setattr(args, key, value)
# Convert argparse Namespace to dictionary
args_dict = vars(args)

# Reconstruct parser and check which arguments were explicitly provided via CLI
parser = self.setup_argparse()
default_args = parser.parse_args([])
default_dict = vars(default_args)

cli_provided_args = {
key for key, value in args_dict.items() if value != default_dict.get(key)
}

# Step 1: Apply YAML values if CLI didn't explicitly set the argument
for key, yaml_value in run_config.items():
if yaml_value is not None and key not in cli_provided_args:
logger.debug(f"Using YAML value for {key}: {yaml_value}")
setattr(args, key, yaml_value)

# Step 2: Set default values for any missing arguments from `arg_map`
# Step 2: Ensure all arguments have at least their default values
for key, params in self.arg_map.items():
if getattr(args, key, None) is None:
setattr(args, key, params.get("default"))

# Step 3: Override with CLI values if provided
# Step 3: Ensure CLI arguments always take precedence
for key in self.arg_map.keys():
cli_value = getattr(args, key, None)
cli_value = args_dict.get(key)
if cli_value is not None:
run_config[key] = cli_value

Expand Down