feat: add --dry-run VRAM/size estimation mode#1958
Conversation
Adds a --dry-run flag that estimates peak block-tuning VRAM, output size, and approximate time from the model config alone (AutoConfig only, no weights). The VRAM estimate is built on auto-round's own block-wise memory model, reusing auto_round.utils.device.estimate_tuning_block_mem and get_moe_memory_ratio per maintainer feedback on intel#1592: - peak memory at decoder-block granularity (card_0 = block I/O cache + layer activations + additional overhead) - block input/output cache excluded when low_gpu_mem_usage is set - MoE handled via get_moe_memory_ratio - robust layer/hidden-size discovery across config field names and nested (text_config etc.) configs Adds unit tests for helper reuse, the low_gpu_mem_usage path, MoE, and layer-count fallbacks. Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
for more information, see https://pre-commit.ci Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Matches the codebase convention (calib_dataset.py, utils/model.py) where every optional modelscope import carries a pylint E0401 disable, since modelscope is not in requirements. Fixes the Code-Scan-AutoRound failure. Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
4649988 to
700c697
Compare
|
Pushed a fix for the two red checks:
|
|
Hi, thanks for the PR! It would be very useful if the estimation is both general and accurate. Could you kindly share some evaluation results demonstrating its accuracy? It would be helpful to include results covering an LLM, a VLM, and an MoE model. |
|
Happy to. Since --dry-run estimates VRAM/size analytically from the model config rather than measuring on hardware, I can put together a table comparing the estimate against the theoretical footprint (param count x bit-width, plus the group/zp/scale overhead the estimator accounts for) for a representative LLM, VLM, and MoE. That validates the estimation math end to end without needing a specific GPU. Where I'd lean on you: confirming the estimate against actual measured peak VRAM on real hardware for those three model classes - you're better set up for that than I am. If a config-vs-theoretical table plus your measured spot-check works, I'll post the table. Which three models would you want represented (so the numbers match something you can cross-check)? |
There was a problem hiding this comment.
Pull request overview
Adds a user-facing --dry-run mode to the auto_round quantize CLI that estimates peak VRAM, output artifact size, and rough runtime using AutoRound’s existing block-wise memory model while loading only the model config (no weights).
Changes:
- Added
auto_round/estimation.pywith config-only, synthetic-block-based estimators and a printable dry-run report. - Added
--dry_run/--dry-runCLI flag and early-exit flow intune()to run estimation without loading weights. - Added CPU unit tests covering estimator behavior, MoE handling,
low_gpu_mem_usage, and CLI flag parsing.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
auto_round/estimation.py |
New estimation utilities: config discovery, synthetic decoder block, VRAM/size/time estimation, and report printing. |
auto_round/cli/parser.py |
Adds --dry_run/--dry-run flag to the quantize CLI parser. |
auto_round/cli/main.py |
Implements dry-run short-circuit path in tune() that prints estimation report and returns. |
test/test_cpu/core/test_estimation.py |
Adds unit tests for estimation helpers and CLI dry-run flag aliases. |
| num_heads = _discover_num_heads(config) | ||
| head_dim = hidden_size // num_heads if num_heads else hidden_size | ||
| num_kv_heads = _discover_num_kv_heads(config, num_heads) | ||
| kv_size = hidden_size if num_kv_heads is None else num_kv_heads * head_dim |
| def estimate_time(num_layers, iters, nsamples, batch_size): | ||
| """Estimate approximate quantization time in seconds.""" | ||
| batches_per_iter = math.ceil(nsamples / batch_size) | ||
| return num_layers * iters * batches_per_iter * _SECS_PER_LAYER_PER_ITER |
| def estimate_output_size(param_count, target_bits, group_size): | ||
| """Estimate output file size in bytes for the quantized model.""" | ||
| weight_bits = param_count * target_bits | ||
| normalized_group_size = _normalize_group_size(group_size) | ||
| if normalized_group_size and normalized_group_size > 0: | ||
| num_groups = math.ceil(param_count / normalized_group_size) | ||
| overhead_bits = num_groups * (16 + target_bits) | ||
| else: | ||
| overhead_bits = 0 | ||
| return int(math.ceil((weight_bits + overhead_bits) / 8)) |
Re-submit of #1592, reworked per your feedback. The VRAM estimate is now built on auto-round's own block-wise memory model instead of a raw parameter count:
auto_round.utils.device.estimate_tuning_block_memandget_moe_memory_ratio(@xin3he'scard_0 = block_input_output + layer_activation + additionalformula).low_gpu_mem_usageis set, and includes it otherwise (@wenhuach21's caching point).get_moe_memory_ratio; layer/hidden-size discovery is robust across config field names and nested configs (text_configetc.) sincenum_hidden_layersdoesn't cover every model (@xin3he).AutoConfigonly, no weights.Unit tests cover helper reuse, the
low_gpu_mem_usagepath, MoE, and layer-count fallbacks (8 passing). Supersedes #1592 (couldn't reopen after the rebase).