Skip to content

fix(cli): accept negative float flag values in space form (EAI-8243) - #306

Open
r0x0r wants to merge 1 commit into
mainfrom
fix/negative-float-flags-space-form
Open

fix(cli): accept negative float flag values in space form (EAI-8243)#306
r0x0r wants to merge 1 commit into
mainfrom
fix/negative-float-flags-space-form

Conversation

@r0x0r

@r0x0r r0x0r commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

rocm serve --temperature -1 (space-separated form) was rejected by clap with the confusing error unexpected argument '-1', because clap parsed the leading-dash token as a flag rather than a value. Only the equals form (--temperature=-1) reached the range validator that reports the valid range.

This is the classic negative-number-as-flag gotcha, and it affected all float flags that accept a value — not just --temperature. It applied to --temperature and --top-p on both chat and serve.

Fix

Enable clap's allow_negative_numbers on the affected float flags so the space form reaches the value parser. Both forms now validate identically and surface a clear range-validation message instead of an unexpected-argument error.

allow_negative_numbers is preferred over allow_hyphen_values here: it only accepts leading-dash tokens that parse as numbers, so it does not swallow the next flag when a value is missing (the tradeoff called out for --gpu-memory-utilization).

Testing

  • Added regression tests covering both the space form (--temperature -1, --top-p -0.5) and equals form (--temperature=-1, --top-p=-0.5) on chat and serve, asserting they reach ValueValidation (the range validator) rather than being rejected as an unexpected argument.
  • cargo test -p rocm --bin rocm (touched sampling tests pass)
  • cargo clippy -p rocm --all-targets -- -D warnings
  • cargo fmt -p rocm

Behavior is CLI argument parsing only; no GPU hardware is required to exercise it. The new unit tests assert the user-observable error kind for both flag forms.

The space form of negative-number float flags (e.g. `serve --temperature
-1`) was rejected by clap with a confusing "unexpected argument '-1'"
error, because clap parsed the leading-dash token as a flag rather than a
value. Only the equals form (`--temperature=-1`) reached the range
validator that reports the valid range.

Enable `allow_negative_numbers` on the affected float flags
(`--temperature` and `--top-p` on both `chat` and `serve`) so the space
form reaches the value parser and both forms validate identically,
surfacing a clear range-validation message instead of an unexpected
argument error.

Add regression tests covering both the space and equals forms for
`--temperature` and `--top-p` on `chat` and `serve`.

Signed-off-by: Roman Sirokov <roman.sirokov@amd.com>
@r0x0r
r0x0r requested a review from a team as a code owner August 24, 2026 10:44
@r0x0r
r0x0r requested a review from michaelroy-amd August 24, 2026 10:44
@r0x0r r0x0r changed the title fix(cli): accept negative float flag values in space form fix(cli): accept negative float flag values in space form (EAI-8243) Aug 24, 2026
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