Skip to content

Add no_cache scenario and --history-len to FlexKV inference benchmark - #486

Open
Clebrate wants to merge 2 commits into
NVIDIA:mainfrom
Clebrate:FlexKV_benchmark
Open

Clebrate wants to merge 2 commits into
NVIDIA:mainfrom
Clebrate:FlexKV_benchmark

Conversation

@Clebrate

@Clebrate Clebrate commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR extends the FlexKV HSTU inference benchmark with a no_cache path and a --history-len CLI flag, so no-cache, naive GPU-hit, and naive CPU-hit can be compared on the same request shape.

  • --scenarios now accepts gpu_hit, cpu_hit, ssd_hit, and no_cache. no_cache must be run by itself; it uses forward_nokvcache and does not start FlexKV.
  • --history-len controls the cached/recomputed prefix (default 1024). Timed length is still history_len + append_history_len unless --only-onboard.

Example (CPU-only FlexKV, no SSD config):

cd examples/hstu
export PYTHONPATH=${PYTHONPATH}:$(realpath ../)

#no_cache
python3 ./inference/benchmark/inference_benchmark_flexkv.py  --disable-cudagraph  --scenarios no_cache --batch-size 1 --history-len 1024 --append-history-len 0 --timed-iters 10 --only-onboard

#cpu_hit / gpu_hit
python3 ./inference/benchmark/inference_benchmark_flexkv.py  --disable-cudagraph  --scenarios gpu_hit,cpu_hit --batch-size 1 --history-len 1024 --append-history-len 0 --timed-iters 10 --only-onboard

Do not pass --flexkv-config-path unless SSD is intended (ssd_cache_gb: 0 and no ssd_cache_dir keeps SSD off).

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The changes since the previous review appear safe to merge, although the two existing non-blocking CLI-validation findings remain outstanding.

Findings

  1. P2 Empty latency samples crash
  2. P2 Negative history length crashes

Summary

  • Adds a standalone no_cache scenario using forward_nokvcache.
  • Adds configurable history length and per-iteration latency reporting.
  • Corrects request action-feature sizing to include candidate tokens.
  • Makes offload queue access compatible with the backend-owned task collection.
  • Prevents no_cache from being combined with cache-backed scenarios.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Parse benchmark arguments] --> B{Selected scenarios}
    B -->|no_cache only| C[Build model without KV cache]
    C --> D[Run forward_nokvcache]
    B -->|gpu_hit / cpu_hit / ssd_hit| E[Build model with FlexKV]
    E --> F{Scenario}
    F -->|gpu_hit| G[Reuse GPU-resident prefix]
    F -->|cpu_hit| H[Evict from GPU and onboard from CPU]
    F -->|ssd_hit| I[Apply pressure and onboard from SSD]
    D --> J[Report latency samples and summary]
    G --> J
    H --> J
    I --> J
Loading

Reviews (3) · Last reviewed commit: "Fix FlexKV benchmark action length and o..."

Comment on lines +294 to +297
f"[latency] scenario=no_cache batch_size={batch_size} "
f"avg_ms={sum(wall_ms) / len(wall_ms):.4f} "
f"min_ms={min(wall_ms):.4f} max_ms={max(wall_ms):.4f}",
flush=True,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Empty latency samples crash

--timed-iters accepts zero or negative values, which produce no request batches. The new latency summary then divides by len(wall_ms) and calls min and max on the empty list, so any scenario run with --timed-iters 0 crashes instead of completing. Validate that the iteration count is positive before running a scenario. The same aggregation pattern appears in the GPU-hit, CPU-hit, and SSD-hit summaries.

Comment on lines +773 to +774
if args.history_len is not None:
cfg = replace(cfg, history_len=args.history_len)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Negative history length crashes

The new --history-len option accepts negative integers, and the value is later used directly as a tensor dimension in build_request. For example, --history-len -1 aborts request construction before the benchmark can run. Reject negative history lengths during argument validation so users receive a clear error.

Action sequences include candidates so preprocess accepts no_cache.
Drain offload via KVCacheManager.backend when the wrapper has no ongoing_offload_tasks.
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.

1 participant