Skip to content

Commit c98ff66

Browse files
committed
Parse flex kernel options with argparse
1 parent 923ca85 commit c98ff66

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

scripts/train_dflash.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def parse_args():
7070
)
7171
model_group.add_argument(
7272
"--flex-kernel-options-json",
73-
type=str,
73+
type=json.loads,
7474
default=None,
7575
help="JSON dict forwarded as kernel_options when attention-backend=flex_attention.",
7676
)
@@ -382,14 +382,13 @@ def main():
382382
)
383383

384384
args = parse_args()
385-
flex_kernel_options = None
386-
if args.flex_kernel_options_json is not None:
385+
flex_kernel_options = args.flex_kernel_options_json
386+
if flex_kernel_options is not None:
387387
if args.attention_backend != "flex_attention":
388388
raise ValueError(
389389
"--flex-kernel-options-json can only be used when "
390390
"--attention-backend is 'flex_attention'."
391391
)
392-
flex_kernel_options = json.loads(args.flex_kernel_options_json)
393392
if not isinstance(flex_kernel_options, dict):
394393
raise ValueError(
395394
"--flex-kernel-options-json must decode to a JSON object."

scripts/train_domino.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def parse_args():
6767
)
6868
model_group.add_argument(
6969
"--flex-kernel-options-json",
70-
type=str,
70+
type=json.loads,
7171
default=None,
7272
help="JSON dict forwarded as kernel_options when attention-backend=flex_attention.",
7373
)
@@ -451,14 +451,13 @@ def main():
451451
)
452452

453453
args = parse_args()
454-
flex_kernel_options = None
455-
if args.flex_kernel_options_json is not None:
454+
flex_kernel_options = args.flex_kernel_options_json
455+
if flex_kernel_options is not None:
456456
if args.attention_backend != "flex_attention":
457457
raise ValueError(
458458
"--flex-kernel-options-json can only be used when "
459459
"--attention-backend is 'flex_attention'."
460460
)
461-
flex_kernel_options = json.loads(args.flex_kernel_options_json)
462461
if not isinstance(flex_kernel_options, dict):
463462
raise ValueError(
464463
"--flex-kernel-options-json must decode to a JSON object."

0 commit comments

Comments
 (0)