Repository navigation
test(cli): forbid clap env bindings on overrides_with flag pairs - #2622
Merged
Merged
Conversation
inureyes
force-pushed
the
test/issue-2618-clap-env-override-guard
branch
from
October 26, 2026 09:15
6c022b9 to
d34249a
Compare
inureyes
added a commit
that referenced
this pull request
Oct 26, 2026
clap 4.6.7 counts an env-sourced value as present and registers every overrides_with partner as a direct conflict, so an env binding on either half of a --x / --no-x pair turns VAR=... plus the other half into a parse error (#2609). #2612 removed env from six pairs; nothing stopped a new arg from reintroducing it. - Add mlxcel::cli::env_bound_override_args, which walks a clap Command and its subcommands and lists every arg that binds an env variable while it overrides, or is overridden by, another arg. clap has no public override getter, so the helper reads the overrides field from the Arg Debug output and panics if the field disappears. A self-test on synthetic env + overrides_with args pins the parse. - Assert an empty result for Cli::command() in src/main_tests.rs and in the mlxcel-server tests module. - Route LLAMA_ARG_MODELS_AUTOLOAD through apply_boolish_pair_env. An invalid value is now a startup error with the same message as the other five pairs (b10621 throws on invalid pair values), and the y/t/n/f spellings the old parser rejected are accepted. Both startup call sites (mlxcel-server and mlxcel serve) return the error. Closes #2618
clap 4.6.7 prints `help` and `long_help` before `settings` and `overrides` in an Arg's Debug output, so scanning from the first `overrides: [` substring could read help text that happened to contain it as the override list, and the guard would miss a real env + overrides_with pair without panicking. The scan now starts after `, settings: ArgFlags(` and looks for `, overrides: [`. The new self-test puts that lookalike string in help text; it fails with the previous scan and passes now. The technical report's gap entry is updated to match. Refs #2618
inureyes
force-pushed
the
test/issue-2618-clap-env-override-guard
branch
from
October 26, 2026 09:26
1210624 to
b06f867
Compare
Member
Author
|
Pre-merge follow-up from the orchestrator review:
|
inureyes
marked this pull request as ready for review
October 26, 2026 09:26
5 tasks done
inureyes
added a commit
that referenced
this pull request
Oct 26, 2026
## Summary Widens the remaining 32-bit offsets in the ROCm gather QMV paths to `int64_t` (follow-up to ml-explore/mlx#4738) and settles the suspected grid-z launch limit: **z cap ruled out** on gfx1151, so launch geometry is unchanged. ## Grid-z result The decisive test (unsorted `gather_qmm`, bf16, affine 4-bit, group 64, E=128, M=1, N=K=64, B=65,537, every element against a host reference) passes with the launch geometry unchanged, as does the same shape through the bf16 8-bit warp-shared, bf16 mxfp4 and f32 per-row kernels. The first pre-fix run of the bf16 affine cases quantized the weights in f32, so `gather_qmm` promoted them to the f32 per-row kernel; review fixed the weights to quantize in the activation dtype and each case now asserts the output dtype, and the corrected bf16 cases pass. The widening touches none of the bf16 kernels those cases reach, so they exercise the same batch-in-z launch the code had before. A standalone `hipLaunchKernel` probe (ROCm 7.15, HIP runtime 71526333) ran grids of 65,537, 262,144 and 16,777,216 blocks in z and 65,537 and 262,144 in y, every block executing, although `hipDeviceProp_t::maxGridSize` and `rocminfo` report 65535 for y and z. The limit that applies is 2^32 - 1 threads per dimension (LOCAL_FIXES item 11). The B = 65,537 tests stay as a regression guard. ## Changes - `gather_qmv_kernel` (`qmm.hip`), `gather_qmv_tiled_kernel` and `gather_qmv_tiled_6bit_kernel` (`qmv_tiled_kernel.hip`) compute the output index in `int64_t`; the opt-in 4/8-bit tiled kernel also widens `rhs_idx * N * w_stride` and `lhs_idx * M * K`. - `gemv_gather_impl` (`gemms/gemv.hip`) offsets its output by `int64_t(indices_idx) * rows`. - The dead `quantized/qmv_kernel.hip` is dropped, and the stale comment in `qdequant.hpp` now names its real user. README backend count is 110. - `LOCAL_FIXES.md` item 61 (60 was taken by #2623). No core file changed, so `CORE_RESIDUAL.diff` is untouched. - New `tests/rocm_hip_grid_clamp/gather_qmv.rs` module: the four B = 65,537 cases, plus an `#[ignore]` f32 test (N=65,536, K=64, B=32,769, 2^31 + 2^16 output elements) checking rows 0, 32,767 and 32,768 against the host. ## Test plan - [x] `rocm_hip_grid_clamp`, all 13 fast tests pass under `rocm_gpu_guard.sh --hold`; after the review fix and the rebase onto main, the `gather` filter (5 fast tests) passes again - [x] The ignored >2^31 test passes with the fix (5.8 s). Negative control: with `gather_qmv_kernel`'s 32-bit index restored, it fails with `hipErrorIllegalAddress` in `gather_qmv_kernel<float, float, 4, 64, true>` (dispatch grid `[256, 256, 32769]`) - [x] mlxcel-core lib `gather` (41) and `quantized` (42) filters, and `rocm_gather_qmm_expert_batched` (2), pass - [x] `make verify-llama-compat verify-env-var-docs verify-kernel-port-dispatch verify-kernel-dtype-keys verify-rocm-overlay` and `rocm_overlay.py drift` pass - [x] `cargo clippy --profile test-fast --features rocm -p mlxcel -p mlxcel-core --lib --tests -- -D warnings` is clean The full fast set and the ignored test ran on the pre-rebase base (1cb18cc); the rebase onto main added #2622 and #2623, which do not touch these kernels. The overlay and contract checks were re-run after the rebase. The item 46 record says HIP refuses y grids past 65535 blocks; this runtime did not reproduce that, and item 61 and the test header now say so while leaving the item 46 caps in place. Follow-ups not in scope: `gemv_batched` and `gemv_batched_inline` in `gemms/gemv.hip` still form `batch_idx * rows` in `int` (not gather paths); no B = 65,537 case covers the bf16 6-bit tiled gather kernel; the tiled gather kernels clamp an out-of-range expert to 0 where the other gather kernels write zeros. Closes #2620
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #2609 / #2612, both items of #2618 in one PR.
1. Guard against
env+overrides_withclap 4.6.7 counts an env-sourced value as present and treats
overridesas direct conflicts, so anenvbinding on either half of a--x/--no-xpair makesVAR=... --other-halfa parse error. Nothing stopped a new arg from reintroducing the binding #2612 removed.mlxcel::cli::env_bound_override_args(src/cli/mod.rs) walks aCommandand every subcommand and returns each arg whoseget_env()isSomeand that overrides, or is overridden by, another arg in the same command. clap has no public override getter, so it reads theoverrides: [...]field from theArgDebugoutput and panics when that field is missing or unterminated, so a clap format change fails loudly instead of turning the guard into a no-op.cli::env_override_guard_testsbuild syntheticenv+overrides_withcommands and check env on the overriding half, on the overridden half, no false positives (pair without env, env without pair), and subcommand walking.no_arg_combines_clap_env_with_overrides_withinsrc/main_tests.rs(Cli::command()ofmlxcel) and in thetestsmodule ofsrc/bin/mlx_server.rsassert an empty result. No allowlist.2. Autoload invalid values
env_fallback_models_autoloadnow goes throughapply_boolish_pair_envand returnsanyhow::Result<()>.LLAMA_ARG_MODELS_AUTOLOAD=maybeis a startup error with the same message as the other five pairs (LLAMA_ARG_MODELS_AUTOLOAD has an invalid boolean value "maybe"), and they/t/n/fspellings are accepted. Both startup call sites (build_startup_inputinmlxcel-server,run_serve_asyncinmlxcel serve) propagate it with?. The error formatting is shared withapply_bool_pair_env_bindingsthrough one helper.Guard demonstration
With
env = "LLAMA_ARG_MODELS_AUTOLOAD"temporarily re-added tomlxcel serve --models-autoload(src/main.rs) andenv = "LLAMA_ARG_CACHE_PROMPT"re-added to--cache-prompt(src/cli/cache_args.rs), both guard tests fail and name the offenders:With the bindings removed again (this PR), both pass.
Test plan
cargo test --profile test-fast --lib cli::(291 passed, including the 4 guard self-tests)cargo test --profile test-fast --lib server::cli_input(155 passed;models_autoload_env_rejects_an_unparseable_value,models_autoload_env_accepts_boolish_spellings)cargo test --profile test-fast --bin mlxcel --bin mlxcel-server(316 + 39 passed)cargo test --profile test-fast --test cli_help_consistency(27 passed)cargo clippy --profile test-fast --bin mlxcel --bin mlxcel-server --lib --tests -- -D warnings,cargo fmt --all -- --checkmake verify-llama-compat,make verify-env-var-docsLLAMA_ARG_MODELS_AUTOLOAD=maybe mlxcel-server --models-dir <dir>andmlxcel serve --models-dir <dir>both exit withError: LLAMA_ARG_MODELS_AUTOLOAD has an invalid boolean value "maybe"make verifynot run in this unit (CPU-only worktree on a shared host); left to the merge gate.Closes #2618