Source-linked AI summary

Anatomy of a Quantized Agent: VRAM Stability and Forecasting in Code-Synthesis Agentic Workloads

Anubhab Banerjee

arXiv:2608.15117v1cs.AIcs.DCcs.LG

TL;DR

Peak-VRAM forecasting for dynamic, quantized LLM agents remains empirically under-tested. This study evaluates calibrated closed-form and learned predictors on 1,920 AgentK trajectories, finding that calibrated analytical accounting matches or beats learned regression on three of four backbones while memory variance is generally low.

  • Problem

    Whether conventional closed-form VRAM decompositions remain valid for agentic tool loops with dynamic trajectories and weight quantization is an open empirical question.

  • Method

    The study compares closed-form and empirical predictors using 1,920 AgentK traces across four Q4 K M backbones, with VRAM measurements and trajectory data.

  • Results

    2.2–4.4% test MAPE enables calibrated B5 to match or outperform learned B2 on three of four backbones, while compile success ranges from 5.7% to 62.0%.

  • Takeaways & Limitations

    Peak-memory variance is low under weight-dominated Q4 K M, so complex prompt-feature predictors offer negligible practical benefit over simple baselines.

Abstract

from arXiv · show

Analytical models of peak VRAM consumption for LLM inference decompose memory into weight-storage, KV-cache, and activation terms parameterized by step count, tool invocations, and context expansion. We evaluate this decomposition empirically within a strictly scoped measurement study: a LangGraph-based CUDA-kernel-synthesis agent (AgentK), a 4-bit quantization family (Q4 K M), a single NVIDIA H100 GPU, and four LLM backbones across 1,920 trajectories. Focusing on peak-memory forecasting behavior, we report two primary observations. First, closed-form analytical models achieve competitive accuracy when provided with two empirical constants: loaded-weight VRAM and a fixed activation-memory overhead. Supplied with live GPU readings and ground-truth trajectory parameters, the closed-form model matches or outperforms the best learned baseline on three of the four backbones (test MAPE 2.2-4.4% vs. 3.4-6.5%, p = 0.76). The exception is the smallest backbone (Phi-4-mini), where minimal VRAM variance (CV 0.3%) causes dynamic modeling to underperform simple regression. Second, compile success strictly bifurcates by backbone capacity (from 5.7% for Phi-4-mini to 62.0% for Qwen2.5-Coder-14B), demonstrating that functional code synthesis remains constrained by intrinsic LLM capabilities rather than available memory. Furthermore, because overall peak-memory variance is remarkably low across all backbones (CV 0.3-9.4%), learned prompt-feature regression offers statistically insignificant improvements over a constant-mean baseline. Consequently, we find no justification for deploying complex predictive VRAM models in highly quantized, weight-dominated regimes. We release the evaluated corpus and anonymized framework to support replication.

I. INTRODUCTION

This study tests whether closed-form VRAM forecasting extends from conventional inference to quantized, tool-driven agentic workloads. Across a tightly scoped AgentK evaluation, calibrated analytical models compete with learned predictors, while compile success varies with backbone capacity and memory remains highly stable.

  • Agentic workloads complicate conventional VRAM forecasting through variable steps, tool branching, context expansion, and 4-bit quantization.
  • 1,920 complete AgentK trajectories across four LLM backbones compare analytical, oracle-fed, and empirical ML predictors on held-out data.
  • 2.2–4.4% test MAPE on three backbones shows calibrated B5 matches or outperforms learned regression, requiring live loaded-weight VRAM and fixed activation overhead.
  • 5.7%, 10.4%, 36.7%, and 62.0% compile-success rates strictly bifurcate by backbone capacity across Phi-4-mini, Mistral-7B, Qwen2.5-Coder-7B, and Qwen2.5-Coder-14B.
  • 0.3–9.4% peak-VRAM CV indicates high stability across tasks, limiting the benefit of prompt-feature regression over simpler baselines.
  • The study is deliberately limited to AgentK, Q4 K M, one NVIDIA H100 80 GB GPU, and CUDA-kernel synthesis, while releasing scoped code and data for replication.

III. METHOD

The method constructs a closed-form peak-VRAM model by estimating context growth over agent steps and summing weights, KV cache, and activations. Peak memory is obtained by evaluating this decomposition at the terminal step under monotonic growth.

  • The forecasting problem is peak VRAM prediction before execution for schedulers and admission controllers.
  • Context length L(t) is modeled as a linear interpolation of base prompt tokens, per-step reasoning expansion, and expected tool-return tokens.
  • Tool contribution uses invocation probability P(T_i) and historical mean return length µ_tool,i, distributed smoothly across the agent lifecycle.
  • M_KV(t) = 2 · L(t) · n_layers · n_heads · d_head · b_precision accounts for key-value cache memory at each step.
  • M_VRAM(t) = M_weights + M_KV(t) + M_act sums static weights, dynamic KV cache, and activation overhead, with terminal evaluation yielding M_peak.

B. Measurement Protocol and AgentK

The measurement protocol instruments AgentK to capture both VRAM trajectories and node-level execution traces. Quantized-memory terms are calibrated using live GPU measurements and run-specific cache metadata rather than standard byte-width assumptions.

  • AgentK is instrumented with per-run VRAM sampling and per-node execution tracing for CUDA-kernel synthesis workloads.
  • Q4 K M inference requires adapting standard VRAM accounting to quantized weights, cache precision, and activation overhead.
  • Loaded weights are measured from live GPU memory after residency, alongside on-disk GGUF size for comparison.
  • Cache precision b_precision is set dynamically from each run’s cache_type_k and cache_type_v metadata.
  • Activation overhead is measured once per backbone as start-of-generation VRAM minus reported weight size and treated as constant.

IV. EXPERIMENTAL SETUP

The experiment evaluates 1,920 AgentK traces spanning four quantized backbones and a 300-prompt suite, using held-out comparisons among closed-form and empirical predictors. The setup emphasizes forecasting accuracy while excluding an unevaluated multi-task baseline from final analysis.

  • 1,920 instrumented runs cover four Q4 K M backbones and 300 prompts from KernelBench and synthetic clean-execution and retry-provoking suites.
  • 540 runs are collected for each of three backbones and 300 for Phi-4-mini through base configurations and context/cache sweeps.
  • A stratified 70/15/15 split produces 1,416 training, 234 validation, and 270 test trace rows globally.
  • Five predictors are compared on held-out data, including worst-case closed form, prompt-length regression, direct-goal regression, constant mean, and partially oracle-fed closed form.
  • B4 is omitted because it is neither trained nor evaluated on this trace corpus.
  • The primary objective is empirical comparison of B0 and B5 against B1–B3, not advocacy for a learned-proxy architecture.

C. Metrics and Statistical Tests

The study evaluates forecasting accuracy and operational risk with four metrics, paired sign tests, confidence intervals, and distinct treatment of empirical versus analytical upper bounds. Results show calibrated closed-form predictions are competitive, but their undercoverage is not directly comparable to interval-based empirical models.

  • Metrics: Four metrics—MAPE, MAE, upper-bound undercoverage, and OAW—measure forecast precision, statistical risk, and capacity utilization.OAW is expressed relative to the full 80 GB H100 capacity ceiling.
  • Statistical tests: Paired sign tests compare per-row absolute percentage errors after excluding ties, using an exact two-sided binomial test.The reported test uses p = 0.5 under scipy.stats.
  • Calibration: A single live GPU measurement per backbone supplies Mweights and Mact, but prevents confidence intervals for those calibration constants.The measurements are confined to the training split, avoiding test-set leakage.
  • Operational interpretation: B5 undercoverage of 0.22–0.57 evaluates a bare point prediction and is not directly comparable to empirical models’ interval-based rates.Empirical bounds include zα = 1.96 and fitted residual variation; B5 does not.
  • Forecast results: 2.20–4.44 % MAPE is achieved by B5, which uses true step counts and reasoning-expansion trajectories.B5 lowers MAPE relative to B2 on three of four backbones.
  • Forecast results: 0–6.7 % of test rows exceed B0’s point prediction, while B0 yields 4.85–14.96 % MAPE.B0 is described as a worst-case bound.

B. Retry-Count Distribution

The final corpus uses an expanded retry ceiling to capture natural agent halting, while token counts remain highly heavy-tailed and compile success varies sharply by backbone capacity. The resulting distributions provide trajectory context for interpreting memory and correctness measurements.

  • Retry-count distribution: retry_budget=6 eliminates censoring in the final corpus, even though the maximum observed retry count remains 3.The expanded ceiling prevents premature termination at the retry limit.
  • Ntrue tail characterization: Ntrue has a heavy-tailed distribution: the modal bin is Ntrue=6, while individual runs reach 29,488 tokens across four orders of magnitude.The modal bin contains 153 of 1,920 rows.
  • Ntrue tail characterization: 0.05 % of runs have Ntrue=0 after adversarial prompts and the expanded retry budget suppress short-circuiting.This corresponds to 1 of 1,920 runs.
  • Ntrue tail characterization: 3,033 training-split overdispersion invalidates modeling token generation with a simple Poisson head in this regime.The reported quantity is the variance-to-mean ratio of Ntrue.
  • Compile-success rates: 5.7 %, 10.4 %, 36.7 %, and 62.0 % are the compile-success rates for Phi-4-mini, Mistral-7B, Qwen2.5-Coder-7B, and Qwen2.5-Coder-14B.The capacity-driven ordering remains consistent across prompt categories.
  • VRAM versus correctness: Peak VRAM and compile success are statistically insignificant within three backbones; Qwen2.5-Coder-7B shows a minor positive correlation of r = 0.133, p = 0.0019.The correlation is based on n = 540 for Qwen2.5-Coder-7B.

E. Numerical Correctness and Empirical Baselines (F3)

Numerical correctness could not be evaluated reliably because every compiled-kernel wrapper run failed before torch.allclose. Within VRAM forecasting, learned regression offers only modest, statistically uncertain gains over a constant mean, while calibrated analytical modeling remains structurally sound.

  • Numerical correctness: 149 compiled kernels all failed before numerical evaluation, so numerical_correct_kbench=False reflects the testing harness rather than LLM mathematics.Failures included JIT-build, torch.load, argument-limit, and timeout errors.
  • Empirical baselines: B2 reduces aggregate MAPE by a modest 6–8 % on three of four backbones, but the improvements have overlapping 95 % confidence intervals.The comparison is against the constant-mean baseline B3.
  • Empirical baselines: 57 % higher relative error makes B2 worse than B3 on Phi-4-mini, with 0.24 % versus 0.16 % MAPE.The low-variance backbone causes regression to fit noise rather than meaningful variation.
  • Variance analysis: Prompt family and retry count explain at most 12.6 % of peak-VRAM variance, leaving 87.4 % to 100 % as unexplained residual noise.The ANOVA partitions variance across categorical factors and residual noise.
  • Variance analysis: A constant-mean baseline performs well because static weights dominate, while calibrated B5 anchors to the same floor and makes small dynamic adjustments.This explains why low variance does not invalidate the closed-form model.

VI. DISCUSSION

The discussion finds that calibrated closed-form VRAM accounting is competitive with learned regression in three backbones, while weight-dominated stability limits deployment value and scope remains narrow.

  • Forecasting implications: B5 matches or beats B2 on three of four backbones when supplied with ground-truth N, E and live-measured Mweights and Mact.Because N and E are known only after execution, B5 requires an upstream predictor for admission-time deployment.
  • Forecasting implications: Q4 K M’s static weight floor makes dynamic runtime changes small, allowing the constant-mean baseline to remain competitive.Prompt features and retries explain less than 12.6% of total variance, leaving little variation for complex models to capture.
  • Forecasting implications: Phi-4-mini has near-zero peak-VRAM variance (CV 0.32%), so B5’s sensitivity to step counts introduces error on an effectively flat target.This establishes a boundary where simple regression can outperform dynamic modeling.
  • Operational choice: Admission-time deployment must choose among B0, B3, or B2 unless a separate proxy predicts N and E before execution.If that proxy exists, the closed-form accounting step is not the system bottleneck.
  • Scope: Numerical correctness was not measurable because all 149 wrapped rows failed before torch.allclose could execute.The paper attributes this limitation to the tracing harness format rather than underlying model capabilities.
  • Scope: Final-corpus trajectory correlation is undefined for 94% of traces because Q4 K M imposes a near-constant boundary VRAM floor.An earlier pilot reported r = 0.21 on n = 846, but that result does not apply to the final corpus.
  • Model qualification: B5 is only partially oracle-fed because no ground-truth tool-return total exists; the tool-return term is set to zero to avoid double-counting against E.Despite this conservative choice, B5 matches or beats B2 on three of four backbones.

APPENDIX A LIST OF ABBREVIATIONS

AgentK is a cyclic LangGraph agent whose pipeline routes prompts through specialized nodes and uses bounded compiler-feedback retries; node traversals define trajectory counts.

  • Pipeline Stages: AgentK is a five-node cyclic graph with a Critic-to-Generator feedback loop bounded by retry_budget.Four nodes execute at most once per task, while the feedback edge enables deliberate retries.
  • Pipeline Stages: The Planner classifies prompts as in-scope or out-of-scope and short-circuits excluded prompts before generation cost is incurred.Its output is a schema-constrained boolean routing decision.
  • Pipeline Stages: The Analyzer retrieves top-k reference-documentation passages and produces technical analysis of memory access, parallelism, and bottlenecks.This retrieval is the tool invocation Ti referenced in Equation 1.
  • Pipeline Stages: The Optimizer converts free-form analysis into a schema-constrained optimization strategy for downstream generation.Typed launch-configuration and memory-placement fields replace unconstrained free text.
  • Pipeline Stages: The Generator synthesizes source code and, during retries, receives failing code plus exact compiler diagnostics.It is instructed to address every reported error.
  • Pipeline Stages: The Critic invokes the reference compiler, terminating successfully on compilation or feeding diagnostics back until retry_budget is exhausted.Each Generator or Critic traversal contributes to N and Ntrue.

B. Retry Loop and Trace Boundaries

AgentK’s retry structure makes trajectory length and completion-token counts vary substantially, while ordinary prompt and retry variation explains little peak-VRAM variance. Under Q4 K M, static weights dominate memory, with configuration sweeps providing the main predictable exception.

  • Retry Loop and Trace Boundaries: Each Planner, Analyzer, and Optimizer runs at most once, while Generator and Critic can repeat up to the retry budget.Every node execution contributes to N and completion tokens contribute to Ntrue.
  • Variance Decomposition: 87% or more of standard per-backbone Mpeak,true variance remains unexplained after grouping by prompt family and retry count.The maximum explained fraction is η2 = 0.126 for Phi-4-mini; other cases reach η2 ≤5.6%.
  • Memory Stability: Under Q4 K M, static model weights establish a nearly immovable memory baseline, making dynamic KV-cache and activation fluctuations comparatively small.This weight-term dominance explains why constant-mean forecasting performs effectively.
  • Configuration Sweeps: η2 ≈0.91–1.00 for configuration-sweep rows shows that nctx and cache-type settings explain nearly all variance when weights are fixed.This sweep-induced variation is distinct from natural task-level variation in the standard corpus.
  • Baseline Forecasting: Live measurements of Mweights and Mact let the closed-form model track the dominant weight term while applying small dynamic corrections.With this calibration, it matches or beats the learned baseline on three of four backbones.

APPENDIX D DATASHEET: AGENTK EVALUATION CORPUS

The AgentK evaluation corpus is a controlled collection of 1,920 traced CUDA-kernel-synthesis runs designed for peak-VRAM characterization, not general code-generation benchmarking. Its fixed hardware, quantization, and task scope support reproducible VRAM analysis but constrain broader claims.

  • Motivation: Each row records one instrumented AgentK execution with per-run VRAM telemetry and compile-outcome labels under controlled settings.The dataset was created specifically for peak-VRAM behavior in quantized-LLM agentic workloads.
  • Composition: 1,920 runs cover four LLM backbones and 300 unique CUDA-kernel-synthesis prompts.Each instance is a traced trajectory containing the backbone, prompt, inference configuration, and hardware-sweep flag.
  • Collection process: Data collection used one NVIDIA H100 80 GB GPU with MIG disabled and pinned software dependencies and KernelBench inputs.The collection process used the AgentK tracing harness and a reproducibility artifact.
  • Preprocessing, cleaning, and labeling: N_true sums completion tokens across node events, while N_nodes_true preserves the discrete node-execution count for trajectory indexing.These definitions distinguish token volume from execution count in downstream analysis.
  • Uses: The corpus is suitable for VRAM forecasting and telemetry research but not for evaluating LLM code-generation quality at scale.Compile success is only a coarse proxy, and none of 149 wrapped rows reached torch.allclose.

APPENDIX E REPRODUCING TABLE II WITHOUT A GPU

The artifact enables GPU-free reproduction of Table II by distributing frozen predictions and a deterministic metric-recalculation script. Exact retraining of B2 can still vary slightly across hardware, so frozen outputs are the verification reference.

  • Reproducing Table II Without a GPU: Frozen parquet files provide exact test-split predictions for verifying Table II without a GPU, retraining, or network access.The files accompany a standalone recalculation script.
  • Prediction Artifacts: Each backbone-method file contains Mpeak_pred and Mupper_pred for every test-split prompt.For analytical models B0 and B5, Mupper_pred equals Mpeak_pred.
  • How to Reproduce: python scripts/reproduce_table2.py deterministically regenerates test ordering, joins ground truth with predictions, computes metrics, and outputs the table body.The generated output matches Table II to the final reported digit.
  • B2 Determinism: B2 retraining can show sub-0.01% MAPE drift across machines because of hardware-specific floating-point non-associativity in GPU reductions.The recorded seed controls initialization and data-loader shuffling, but does not eliminate this hardware effect.
  • Code Pointers: The implementation applies live-VRAM calibration constants rather than raw on-disk file sizes.This behavior is located in src/baselines/common.py::accounting_dict and the Q4 calibration configuration.
Loading 2608.15117v1…