Skip to content

Commit

Permalink
makes unknown args available to exp config
Browse files Browse the repository at this point in the history
  • Loading branch information
Safoora Yousefi committed Jan 18, 2025
1 parent 15d156f commit 6910ae0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,23 @@
parser.add_argument(
"--resume_from", type=str, help="The path to the inference_result.jsonl to resume from.", default=None
)
args = parser.parse_args()
init_args = {}

# catch any unknown arguments
args, unknown_args = parser.parse_known_args()
if unknown_args:
# if every other unknown arg starts with "--", parse the unknown args as key-value pairs in a dict
if all(arg.startswith("--") for arg in unknown_args[::2]):
init_args.update(
{arg[len("--") :]: unknown_args[i + 1] for i, arg in enumerate(unknown_args) if i % 2 == 0}
)
logging.info(f"Unknown arguments: {init_args} will be sent to the experiment config class.")
# else, parse the unknown args as is ie. as a list
else:
init_args["unknown_args"] = unknown_args
logging.info(f"Unknown arguments: {unknown_args} will be sent as is to the experiment config class.")

experiment_config_class = args.exp_config
init_args = {}
if args.model_config:
try:
init_args["model_config"] = getattr(model_configs, args.model_config)
Expand Down

0 comments on commit 6910ae0

Please sign in to comment.