Skip to content

Commit 7c2856a

Browse files
authored
Support custom argument parsing by yaml file (#521)
1 parent d03419a commit 7c2856a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

slime/utils/arguments.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from typing import Any, Dict
55

6+
import yaml
67
from transformers import AutoConfig
78

89
from slime.backends.sglang_utils.arguments import add_sglang_arguments
@@ -1009,6 +1010,12 @@ def add_sglang_tp_size():
10091010
# For megatron
10101011
parser = add_custom_megatron_plugins_arguments(parser)
10111012
try:
1013+
parser.add_argument(
1014+
"--custom-config-path",
1015+
type=str,
1016+
default=None,
1017+
help="Path to the YAML config for custom function arguments.",
1018+
)
10121019
parser.add_argument("--padded-vocab-size", type=int, default=None)
10131020
except:
10141021
pass
@@ -1231,6 +1238,15 @@ def slime_validate_args(args):
12311238
"num_epoch is not set, but num_rollout is not set, " "please set --num-rollout or --num-epoch"
12321239
)
12331240

1241+
if args.custom_config_path:
1242+
with open(args.custom_config_path, "r") as f:
1243+
data = yaml.safe_load(f) or {}
1244+
for k, v in data.items():
1245+
if not hasattr(args, k):
1246+
setattr(args, k, v)
1247+
else:
1248+
print(f"Warning: Argument {k} is already set to {getattr(args, k)}, will not override with {v}.")
1249+
12341250

12351251
def hf_validate_args(args, hf_config):
12361252
equal = lambda x, y: x == y

0 commit comments

Comments
 (0)