feat(cli): add batch size option#24
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe Changes--batch-size flag: CLI, wiring, and tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/modelinfo/cli.py (1)
55-60: ⚡ Quick winConsider validating that batch size is positive.
The
--batch-sizeargument accepts any integer, including zero or negative values. Sincebatch_sizeis multiplied into the KV cache calculation (kv_cache_bytes = 2 * num_layers * kv_dim * context_length * batch_size * 2), a value less than 1 would produce misleading or incorrect results (zero cache forbatch_size=0, negative cache for negative values).🛡️ Suggested validation
parser.add_argument( "--batch-size", type=int, default=1, help="Batch size for dynamic KV cache footprint calculation.", ) + +def _validate_batch_size(value: int) -> int: + if value < 1: + raise argparse.ArgumentTypeError("batch size must be at least 1") + return valueThen update the argument definition:
parser.add_argument( "--batch-size", - type=int, + type=_validate_batch_size, default=1, help="Batch size for dynamic KV cache footprint calculation.", )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/modelinfo/cli.py` around lines 55 - 60, The `--batch-size` argument in the parser.add_argument call accepts any integer without validation, allowing zero or negative values which produce incorrect KV cache calculations. Add validation to the argument definition to ensure batch_size is a positive integer (greater than 0). This can be done by adding a custom type function that validates the input, or by using the choices parameter with a positive range constraint, so that only valid positive batch sizes are accepted.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/modelinfo/cli.py`:
- Around line 55-60: The `--batch-size` argument in the parser.add_argument call
accepts any integer without validation, allowing zero or negative values which
produce incorrect KV cache calculations. Add validation to the argument
definition to ensure batch_size is a positive integer (greater than 0). This can
be done by adding a custom type function that validates the input, or by using
the choices parameter with a positive range constraint, so that only valid
positive batch sizes are accepted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e66852cc-71c5-4e08-9e90-b61c9a0d5c5d
📒 Files selected for processing (2)
src/modelinfo/cli.pytests/test_cli.py
Add _positive_int type validator for --batch-size to reject zero and negative values, plus regression tests. Addresses CodeRabbit review.
pipe1os
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
your implementation is correct, I will proceed to merge this.
Summary
--batch-sizeCLI option for dynamic KV cache footprint calculationsanalyze_modelintocalculate_footprintFixes #2.
Test Plan
PYTHONPATH=src python3 -m pytest tests/test_cli.py tests/test_calculator.py -qPYTHONPATH=src python3 -m pytest -qPYTHONPATH=src python3 -m compileall -q src testsPYTHONPATH=src python3 -m ruff check src/modelinfo/cli.py tests/test_cli.pyNotes
Summary by CodeRabbit
Release Notes
--batch-sizeCLI option to customize batch size for model analysis and VRAM footprint calculations (default: 1).--batch-sizeis rejected when set to 0 or a negative value.