diff --git a/nemo_run/cli/cli_parser.py b/nemo_run/cli/cli_parser.py index 9ceb5e47..b2522d85 100644 --- a/nemo_run/cli/cli_parser.py +++ b/nemo_run/cli/cli_parser.py @@ -1253,13 +1253,35 @@ def parse_single_factory(factory_str): return factory_fn() # Check if the value is a list - list_match = re.match(r"^\s*\[(.*)\]\s*$", value) - if list_match: + if value.startswith("[") and value.endswith("]"): # Check if arg_type is List[T], if so get T if get_origin(arg_type) is list: arg_type = get_args(arg_type)[0] - items = re.findall(r"([^,]+(?:\([^)]*\))?)", list_match.group(1)) - return [parse_single_factory(item.strip()) for item in items] + + # Parse list with nested structure handling + inner = value.strip("[] ") + elements = [] + current = "" + nesting = 0 + + # Parse character by character to handle nested structures + for char in inner: + if char == "," and nesting == 0: + if current.strip(): + elements.append(current.strip()) + current = "" + else: + if char in "([{": + nesting += 1 + elif char in ")]}": + nesting -= 1 + current += char + + # Add the last element if it exists + if current.strip(): + elements.append(current.strip()) + + return [parse_single_factory(item.strip()) for item in elements] return parse_single_factory(value)