Skip to content

bug: CLI fix for --load-pattern + --target-qps#237

Open
viraatc wants to merge 1 commit intomainfrom
feat/viraatc-fix1
Open

bug: CLI fix for --load-pattern + --target-qps#237
viraatc wants to merge 1 commit intomainfrom
feat/viraatc-fix1

Conversation

@viraatc
Copy link
Copy Markdown
Collaborator

@viraatc viraatc commented Apr 1, 2026

What does this PR do?

Fixes CLI crash when --load-pattern + --target-qps are used together (IndexError: tuple index out of range), and adds test coverage to prevent regressions.

Bug fix

  • LoadPattern.type used alias= instead of name= on cyclopts.Parameter, and class was missing @cyclopts.Parameter(name="*") — caused cyclopts to fail resolving --load-pattern into a config key path.

Test coverage

  • test_cli.py: Hypothesis fuzz tests auto-discover all CLI flags from assemble_argument_collection() and test 4000 random combinations (up to 10 flags each) across offline + online/poisson + online/concurrency. Validated: catches this bug in 1.62s.
  • test_benchmark_command.py: Added test_concurrency_benchmark with streaming on/off — all 3 execution modes now covered.
  • hypothesis==6.151.10 added to test deps, schema_fuzz pytest marker.

CI & tooling

  • schema-updated CI job: triggers on PRs touching schema.py/config.py/cli.py — runs fuzz tests + validates YAML templates.
  • regenerate_templates.py: auto-generates YAML templates from schema defaults + overrides. Pre-commit hook regenerates locally on schema.py changes (skipped in CI).
  • Templates excluded from prettier to avoid formatting conflicts.

Type of change

  • Bug fix
  • Tests added/updated

Copilot AI review requested due to automatic review settings April 1, 2026 21:56
@viraatc viraatc requested a review from a team as a code owner April 1, 2026 21:56
@github-actions github-actions bot requested review from arekay-nv and nvzhihanj April 1, 2026 21:57
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a cyclopts CLI parsing crash triggered when --load-pattern is combined with load-pattern subfields like --target-qps / --concurrency in the online benchmark command.

Changes:

  • Annotates LoadPattern to adjust how cyclopts maps nested parameters (@cyclopts.Parameter(name="*")).
  • Updates the CLI parameter definition for LoadPattern.type to avoid the prior name collision.
Comments suppressed due to low confidence (1)

src/inference_endpoint/config/schema.py:360

  • This change is a regression fix for a CLI crash when combining --load-pattern with nested load-pattern fields (e.g. --target-qps). There’s existing automated test coverage for config validation in tests/unit/commands/test_benchmark.py, but no test currently exercises cyclopts parsing for this flag combination.

Add a regression test that parses benchmark online ... --load-pattern poisson --target-qps 100 (or directly parses OnlineBenchmarkConfig via cyclopts) and asserts it no longer raises and that config.settings.load_pattern.type/target_qps are set as expected.

@cyclopts.Parameter(name="*")
class LoadPattern(BaseModel):
    """Load pattern configuration.

    Different patterns use target_qps differently:
    - max_throughput: target_qps used for calculating total queries (offline, optional with default)
    - poisson: target_qps sets scheduler rate (online, required - validated)
    - concurrency: issue at fixed target_concurrency (online, required - validated)
    """

    model_config = ConfigDict(extra="forbid", frozen=True)

    type: Annotated[
        LoadPatternType,
        cyclopts.Parameter(name="--load-pattern", help="Load pattern type"),
    ] = LoadPatternType.MAX_THROUGHPUT
    target_qps: Annotated[
        float | None, cyclopts.Parameter(alias="--target-qps", help="Target QPS")
    ] = Field(None, gt=0)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the LoadPattern class in the configuration schema by applying a class-level cyclopts.Parameter decorator and updating the type field's parameter definition to use the name argument instead of alias. I have no feedback to provide.

Copy link
Copy Markdown
Collaborator

@arekay-nv arekay-nv left a comment

Choose a reason for hiding this comment

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

Can we also add a test for this - seems like a change that shouldn't have gone in.

@viraatc viraatc force-pushed the feat/viraatc-fix1 branch from 90fe9c8 to 80a79ef Compare April 3, 2026 10:56
Copilot AI review requested due to automatic review settings April 3, 2026 10:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings April 3, 2026 11:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings April 3, 2026 11:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

viraatc

This comment was marked as duplicate.

Copy link
Copy Markdown
Collaborator Author

@viraatc viraatc left a comment

Choose a reason for hiding this comment

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

duplicate

@viraatc
Copy link
Copy Markdown
Collaborator Author

viraatc commented Apr 3, 2026

Review Council — Multi-AI Code Review

Reviewed by: Claude (Codex ran but produced investigation output, not structured findings) | Depth: standard

Found 3 issues across 3 files:

  • 1 high (fixed)
  • 1 medium (already fixed)
  • 1 low (deferred)
# File Line Severity Category Summary
1 scripts/regenerate_templates.py 95 high error-handling Pre-commit hook exited 0 on template generation failure — stale files could slip through. Fixed: now tracks failures and sys.exit(1).
2 .github/workflows/test.yml 61 medium security Unpinned action SHAs in schema-updated job. Already fixed in latest push.
3 tests/integration/commands/test_cli.py 76 low testing Optional union types (`float

Also addressed all Copilot review comments (pinned SHAs, quoted pip install, heredoc for inline Python, expanded pre-commit files: regex, added except comment).

Copilot AI review requested due to automatic review settings April 3, 2026 12:14
@viraatc viraatc force-pushed the feat/viraatc-fix1 branch from 8915750 to ffb87d9 Compare April 3, 2026 12:16
Copy link
Copy Markdown
Collaborator Author

@viraatc viraatc left a comment

Choose a reason for hiding this comment

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

added new schema-updated CI:

  1. fuzz tests on CLI in CI
  2. template validated against schema default in CI

NOTE: template now includes all supported fields

  1. was pending items from past.
    ++ @rashid for thoughts?

@pytest.mark.schema_fuzz
@pytest.mark.slow
@hyp_settings(max_examples=2000, deadline=5000)
@given(tokens=online_tokens())
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fuzz test catches 53f08fc

The bug caused --load-pattern poisson --target-qps 100 to crash:

$ inference-endpoint benchmark online \
    --endpoints http://localhost:8000 --model m --dataset d.pkl \
    --load-pattern poisson --target-qps 100

IndexError: tuple index out of range

Reverted the fix and ran this test — Hypothesis finds it in 1.62s:

E   IndexError: tuple index out of range
E   Falsifying example: test_online_cli_no_crash(
E       tokens=['benchmark', 'online', '--endpoints', 'http://h:80',
E        '--model', 'm', '--dataset', 'd.pkl',
E        '--load-pattern', 'poisson', '--target-qps', '100',
E        '--name', 'test-val'],
E   )
============================== 1 failed in 1.62s ===============================

type: offline
model_params:
name: "meta-llama/Llama-3.1-8B-Instruct"
name: '<MODEL_NAME eg: meta-llama/Llama-3.1-8B-Instruct>'
Copy link
Copy Markdown
Collaborator Author

@viraatc viraatc Apr 3, 2026

Choose a reason for hiding this comment

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

Templates auto-generated from schema defaults by scripts/regenerate_templates.py.
Full YAML spec with placeholder overrides (model name, dataset)

Pre-commit validates templates are valid locally.
CI checks if they're up to date — if stale it will suggest to, run python scripts/regenerate_templates.py.

Is this overkill? Should we drop?

pip install -e ".[dev,test,performance]"
pip-audit

schema-updated:
Copy link
Copy Markdown
Collaborator Author

@viraatc viraatc Apr 3, 2026

Choose a reason for hiding this comment

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

new schema-updated CI job:
triggers on PRs touching schema.py/config.py/cli.py.

- id: validate-templates
name: Validate YAML templates against schema
entry: python -c "from pathlib import Path; from inference_endpoint.config.schema import BenchmarkConfig; [BenchmarkConfig.from_yaml_file(f) for f in sorted(Path('src/inference_endpoint/config/templates').glob('*.yaml'))]"
- id: check-templates
Copy link
Copy Markdown
Collaborator Author

@viraatc viraatc Apr 3, 2026

Choose a reason for hiding this comment

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

reuse --check mode

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Bug: LoadPattern.type had alias= instead of name= on cyclopts.Parameter,
and class was missing @cyclopts.Parameter(name="*"). This caused any CLI
invocation with --load-pattern to crash with IndexError.

Tests:
- Hypothesis fuzz tests auto-discover all CLI flags from cyclopts
  assemble_argument_collection() and test 4000 random combinations
  (offline + online/poisson + online/concurrency)
- Added test_concurrency_benchmark with streaming on/off
- hypothesis==6.151.10 added to test deps, schema_fuzz pytest marker

CI & tooling:
- schema-updated CI job: fuzz tests + template validation on schema changes
- regenerate_templates.py: auto-generates YAML templates from schema defaults
- Pre-commit checks templates are up to date (--check mode)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@viraatc viraatc force-pushed the feat/viraatc-fix1 branch from ffb87d9 to b781ff7 Compare April 3, 2026 12:21
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.

3 participants