From 88691aeee6d8c308e3abef6dea9caf3f8e85a5db Mon Sep 17 00:00:00 2001 From: Mickus Timothee Date: Mon, 2 Oct 2023 18:15:57 +0300 Subject: [PATCH 1/2] halt and catch fire for unknown args --- mammoth/utils/parse.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mammoth/utils/parse.py b/mammoth/utils/parse.py index 54056cf9..54a485c3 100644 --- a/mammoth/utils/parse.py +++ b/mammoth/utils/parse.py @@ -269,6 +269,12 @@ def defaults(cls, *args): defaults = dummy_parser.parse_known_args([])[0] return defaults + def parse_known_args(self): + opts, unknown = super().parse_known_args() + if unknown: + raise ValueError(f'unknown arguments provided:\n{unknown}') + return opts, unknown + @classmethod def update_model_opts(cls, model_opts): cls._validate_adapters(model_opts) From e5e3534c894f332939605d3a152726df38696c23 Mon Sep 17 00:00:00 2001 From: Mickus Timothee Date: Mon, 2 Oct 2023 18:20:12 +0300 Subject: [PATCH 2/2] pytest compliance --- mammoth/tests/test_models.py | 2 +- mammoth/utils/parse.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mammoth/tests/test_models.py b/mammoth/tests/test_models.py index 089ca796..aea9355f 100644 --- a/mammoth/tests/test_models.py +++ b/mammoth/tests/test_models.py @@ -14,7 +14,7 @@ mammoth.opts._add_train_general_opts(parser) # -data option is required, but not used in this test, so dummy. -opts = parser.parse_known_args(['-tasks', 'dummy', '-node_rank', '0', '-model_dim', '500'])[0] +opts = parser.parse_known_args(['-tasks', 'dummy', '-node_rank', '0', '-model_dim', '500'], strict=False)[0] class TestModel(unittest.TestCase): diff --git a/mammoth/utils/parse.py b/mammoth/utils/parse.py index 54a485c3..79a000f7 100644 --- a/mammoth/utils/parse.py +++ b/mammoth/utils/parse.py @@ -269,9 +269,9 @@ def defaults(cls, *args): defaults = dummy_parser.parse_known_args([])[0] return defaults - def parse_known_args(self): - opts, unknown = super().parse_known_args() - if unknown: + def parse_known_args(self, *args, strict=True, **kwargs): + opts, unknown = super().parse_known_args(*args, **kwargs) + if strict and unknown: raise ValueError(f'unknown arguments provided:\n{unknown}') return opts, unknown