Skip to content

fix: resolve duplicate -g flag and type=bool argparse bug in sft.py#1329

Open
vominh1919 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
vominh1919:fix/sft-cli-duplicate-flags
Open

fix: resolve duplicate -g flag and type=bool argparse bug in sft.py#1329
vominh1919 wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
vominh1919:fix/sft-cli-duplicate-flags

Conversation

@vominh1919
Copy link
Copy Markdown

@vominh1919 vominh1919 commented May 10, 2026

Problem

Two bugs in scripts/sft.py's argument parser:

  1. Duplicate -g flag: Both --gradient-accumulation-steps (line 69) and --max-grad-norm (line 73) use -g as their short flag. The second definition shadows the first, so python sft.py -g 4 silently sets max_grad_norm=4.0 instead of gradient_accumulation_steps=4.

  2. type=bool doesn't work in argparse: bool("False") is True in Python — any non-empty string is truthy. The only way to disable --push-to-hub via CLI is --push-to-hub "", which is unintuitive.

Fix

  1. Change --gradient-accumulation-steps short flag from -g to -G (uppercase, since --max-grad-norm already owns -g)
  2. Replace type=bool with action=argparse.BooleanOptionalAction, which provides both --push-to-hub and --no-push-to-hub

Before vs After

Scenario Before After
sft.py -g 4 Sets max_grad_norm=4.0 (wrong!) Sets max_grad_norm=4.0 (correct, -G needed for grad accum)
sft.py -G 4 Error: unrecognized argument Sets gradient_accumulation_steps=4
sft.py --no-push-to-hub Error: unrecognized argument Sets push_to_hub=False
sft.py --push-to-hub False Sets push_to_hub=True (wrong!) N/A — use --no-push-to-hub instead

Tests

Verified syntax with python3 -c "import ast; ast.parse(open('scripts/sft.py').read())"


Note

Low Risk
Low risk: only adjusts CLI argument definitions in scripts/sft.py, changing how flags are parsed but not training logic or data handling.

Overview
Fixes the scripts/sft.py CLI so --gradient-accumulation-steps no longer conflicts with --max-grad-norm by switching its short flag from -g to -G.

Updates --push-to-hub to use argparse.BooleanOptionalAction, enabling --push-to-hub / --no-push-to-hub instead of the broken type=bool parsing.

Reviewed by Cursor Bugbot for commit d2ae717. Bugbot is set up for automated code reviews on this repo. Configure here.

Two bugs in the SFT training script's argument parser:

1. Both --gradient-accumulation-steps and --max-grad-norm use '-g' as
   their short flag. The second definition shadows the first, so
   `python sft.py -g 4` silently sets max_grad_norm=4.0 instead of
   gradient_accumulation_steps=4.

2. `type=bool` doesn't work as expected in argparse — bool('False') is
   True in Python, so --push-to-hub False still sets the value to True.
   Use BooleanOptionalAction instead, which provides --no-push-to-hub.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d2ae717. Configure here.

Comment thread scripts/sft.py
parser.add_argument("--weight-decay", "-w", type=float, default=0.01)
parser.add_argument("--max-grad-norm", "-g", type=float, default=0.1)
parser.add_argument("--push-to-hub", "-p", type=bool, default=True)
parser.add_argument("--push-to-hub", "-p", action=argparse.BooleanOptionalAction, default=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsed push_to_hub value never used in SFTConfig

High Severity

The --push-to-hub argparse fix is incomplete. While the CLI now correctly parses --no-push-to-hub via BooleanOptionalAction, the SFTConfig on line 49 hardcodes push_to_hub=True instead of using args.push_to_hub. This means --no-push-to-hub is silently ignored — the model is always pushed to the hub regardless of the flag.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d2ae717. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant