Skip to content

Evolution of nvbench compare that uses bulk data#386

Open
oleksandr-pavlyk wants to merge 106 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:nvbench-compare-process-bulk-data
Open

Evolution of nvbench compare that uses bulk data#386
oleksandr-pavlyk wants to merge 106 commits into
NVIDIA:mainfrom
oleksandr-pavlyk:nvbench-compare-process-bulk-data

Conversation

@oleksandr-pavlyk

@oleksandr-pavlyk oleksandr-pavlyk commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

This PR contains only Python changes.

  • Main change: add python/scripts/nvbench_compare_robust.py
    • structured timing data extraction
    • robust timing intervals
    • bulk sample loading
    • device pairing/filtering
    • benchmark-axis scoped filtering
    • comparison thresholds
    • presets/TOML config
    • display modes
    • plotting validation
    • bulk-debug python script output for further bulk data analysis
  • Document docs/nvbench_compare_robust.md documenting usage of nvbench_compare_robust and its decision logic
  • All scripts load their 3rd-party dependent packages lazily, and raise a dedicated exception with informative message on how to install them (Indicate script dependencies in cuda.bench package metadata #384). Optional dependencies are advertised in wheel metadata as cuda-bench[tools].
  • The location of scripts in Python wheel has changed, but this is transparent to users of installed cuda-bench ([Skill]: Report and interpret benchmark results #390).
  • The legacy decision tree remains available: python/scripts/nvbench_compare.py
    • the only change applied to it is to support lazy loading of third-party dependency packages

Closes #319
Closes #320
Closes #393
Closes #384

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the nvbench-compare-process-bulk-data branch from f18d48d to f0db899 Compare June 29, 2026 19:59
@oleksandr-pavlyk

This comment was marked as outdated.

@coderabbitai

This comment was marked as outdated.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added robust NVBench comparison with interval-based FAST, SLOW, SAME, and undecided results.
    • Added configurable thresholds, presets, TOML configuration, device and benchmark filters, plotting, and bulk-debug output.
    • Split comparison commands into legacy and robust variants.
  • Improvements
    • Optional plotting and reporting tools now load only when needed.
    • Missing optional tools provide clear installation guidance and proper error codes.
  • Documentation
    • Added comprehensive documentation for robust comparison behavior and configuration.
  • Bug Fixes
    • Improved validation and handling of malformed benchmark data and invalid command-line options.

Walkthrough

Changes

NVBench comparison tools

Layer / File(s) Summary
Packaged scripts and optional tooling
python/pyproject.toml, python/scripts/nvbench_tooling_deps.py, python/scripts/nvbench_histogram.py, python/scripts/nvbench_plot_bwutil.py, python/scripts/nvbench_walltime.py
Adds optional dependency groups, cuda.bench.scripts entry points, shared missing-tooling errors, and lazy imports with explicit exit codes.
Robust comparison data and configuration
python/scripts/nvbench_compare_robust.py
Adds validated input parsing, TOML thresholds and presets, timing models, bulk-data extraction, and interval construction.
Evidence-gated timing decisions
python/scripts/nvbench_compare_robust.py
Classifies timing comparisons using interval gaps, bulk evidence, summary statistics, cycle confirmation, and explicit decision reasons.
Robust comparison execution and CLI
python/scripts/nvbench_compare_robust.py
Adds filtering, device pairing, table and plot output, bulk-debug generation, CLI validation, file orchestration, and aggregate summaries.
Legacy comparison pipeline
python/scripts/nvbench_compare.py
Refactors legacy comparison around typed timing data, ordered filters, device selection, structured statistics, lazy plotting, and validated JSON orchestration.
Comparison validation and reference material
python/test/test_nvbench_compare_legacy.py, python/test/test_nvbench_compare_robust.py, python/test/test_nvbench_tooling_deps.py, docs/nvbench_compare_robust.md
Adds extensive comparison, packaging, dependency, CLI, and output tests, plus robust comparison and configuration documentation.

Assessment against linked issues

Objective Addressed Explanation
Distribution-based regression decision tree and evidence sufficiency [#319]
Integrate distribution-based comparison into nvbench_compare.py [#320] The robust implementation is introduced as a separate nvbench_compare_robust.py entry point rather than integrated into nvbench_compare.py.
Install scripts under the descriptive cuda.bench.scripts package [#393]
Declare script extras and gracefully handle missing optional dependencies [#384]

Suggested reviewers: gevtushenko


Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]

This comment was marked as resolved.

@oleksandr-pavlyk
oleksandr-pavlyk force-pushed the nvbench-compare-process-bulk-data branch 2 times, most recently from 42927d9 to a240460 Compare June 30, 2026 11:41
@oleksandr-pavlyk

This comment was marked as outdated.

@coderabbitai

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

@oleksandr-pavlyk oleksandr-pavlyk added python type: enhancement New feature or request. labels Jun 30, 2026
@oleksandr-pavlyk oleksandr-pavlyk self-assigned this Jun 30, 2026
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 30, 2026
@oleksandr-pavlyk oleksandr-pavlyk moved this from Todo to In Progress in CCCL Jun 30, 2026
@jrhemstad
jrhemstad requested a review from gevtushenko June 30, 2026 15:52
Teach nvbench_compare to parse GPU timing summaries into structured values and
prefer the robust median/IQR summaries when both compared measurements provide
them. Fall back to the existing mean/stdev summaries when robust summaries are
not available.

Classify comparisons with the larger available relative noise estimate instead
of the smaller one, keep unavailable noise distinct from encoded infinite noise,
and report improvements separately from regressions. Keep the process exit code
as success for completed comparisons; regression counts are reported in the
summary instead of being used as the process status.

Make plotting tolerate unavailable noise by leaving gaps in confidence bands,
sort plotted series by the plotted axis, and avoid reusing pyplot state across
plot calls.

Add focused Python tests for robust-summary preference, unavailable-noise
classification, non-finite timing centers, plot-along handling when the selected
axis is absent, and the exit-code contract.
Teach nvbench_compare to keep the order of --benchmark and --axis arguments so
axis filters can apply either globally or to the most recent benchmark. Build a
filter plan from the ordered CLI arguments and apply the same plan to table
output and plotting labels.

Add explicit --reference-devices and --compare-devices filters. The filters
accept all, a single device id, or a comma-separated list of ids; ordered lists
and duplicates are preserved so selected reference and compare devices can be
paired by position. Device-section mismatches remain fatal for unfiltered
all-vs-all comparisons, but become warnings when the user explicitly selects
devices and the selected device counts match.

Match duplicate benchmark states by occurrence within each filtered device
section instead of matching only by state name across the whole benchmark. This
keeps repeated axis values and filtered duplicate states aligned between the
reference and compare inputs, and reports mismatched occurrence counts instead
of silently dropping extra states.

Add Python tests for duplicate-state matching, axis filtering before matching,
device filter parsing and validation, explicit cross-device pairing, and
benchmark-scoped axis filters.

Original commit messages folded into this change:

Tweaks for nvbench_compare

1. When JSON files contain multiple entries with the same name and axis values,
   make sure that scripts compares corresponding entries.

   Previous logic would extract the first entry from ref data, and would compare
   measurements for each state in cmp against the first entry from ref. The
   change introduces a counter to know which nth entry we process for a
   particular axis value, and retrieve corresponding entry in ref.

Scope occurrence matching by device.

Device pairing in nvbench_compare.py is strictly index-based under
--ignore-devices, reused IDs in a different order no longer pair against the
wrong reference device.

Require devices in ref and cmp to have the same cardinality

Handle mismatch when number of duplicates in ref data is not same as in cmp data

Use pytest monkeypatch fixture to pretend third-party package dependencies are
available during test run for nvbench_compare without introducing test-time
dependency

Added the happy-path test and fixed its direct-call setup by initializing the
device globals that main() normally populates.

Fix to filter-before-matching.

 - compare_benches() now pairs devices by selected position instead of taking a
   device id.
 - For each device pair, compare_benches() now builds:
     - ref_device_states: matching reference device and axis filters
     - cmp_device_states: matching compare device and axis filters
 - State occurrence counts and duplicate occurrence matching now operate only
   on those filtered per-device lists.
 - Removed the later matches_axis_filters() skip inside the compare-state loop
   because filtering now happens before matching.

Added a regression test where ref/cmp have duplicate state names in opposite
order, and --axis keeps only one of them. The test verifies the kept compare
state is matched against the kept reference state, not the first unfiltered
occurrence.

Introduce device filtering in nvbench_compare

 - --reference-devices all|ID|ID,ID,...
 - --compare-devices all|ID|ID,ID,...
 - Integer lists preserve order and duplicates.
 - Requested IDs are validated against the file-level device list.
 - Filtered reference/compare device counts must match before comparison.
 - compare_benches() pairs selected reference and compare devices by position.
 - Each benchmark validates that requested device IDs are present in its own
   devices list.

Implemented benchmark-scoped --axis handling.

  - --axis and --benchmark now share an ordered argparse action, so their
    relative CLI order is preserved.
  - -a before any -b becomes a global axis filter.
  - -a after -b <name> applies to that most recent benchmark only.
  - Repeated -b entries are treated as separate filter scopes and combined as
    alternatives for that benchmark.
  - Device filtering remains global and is applied independently.

Allow non-matching devices for explicit device selection

Now the device-section equality check remains fatal only for unfiltered
all-vs-all comparisons. If either --reference-devices or --compare-devices is
explicit, mismatched selected device metadata is printed as a warning, but
comparison proceeds after the selected device counts have been validated.

Fix for resolve_benchmark_device_ids, add comments

The return value of resolve_benchmark_device_ids now always owns its list.

Use monkeypatch class in set_test_devices helper

Stricted device id validation

Test for device id validation
Introduce GpuTimingData, SummaryComparison, ComparisonStats, and
ComparisonRunData to make timing extraction, classification, and run-level
state explicit.

Load sample-time and SM-frequency bulk data from JSON binary output into
GpuTimingData when available, preserving count validation between paired
sample and frequency arrays.

Move GPU timing comparison logic into compare_gpu_timings(), prefer robust
median/IQR data when available, and fall back to mean/stdev summaries otherwise.
Keep missing or invalid noise on the unknown path.

Replace module-level comparison counters and selected-device globals with
per-run data passed into compare_benches(). Update tests to validate timing
classification, bulk-data loading, device pairing, filtered duplicate matching,
and summary counters through the new structures.
It is not emitted just yet, but the code becomes ready for it
when it starts being emitted
Store JSON-bin sample time and frequency metadata in GpuTimingData instead of
reading the binary files during summary extraction.

Add Float32BinarySource and lazy cached accessors for samples and frequencies.
Use np.fromfile by default, but allow tests and alternate callers to inject a
float32 reader returning any buffer-compatible object convertable to "<f4" data
type.

Treat optional bulk-data failures as unavailable evidence instead of aborting
comparison: unreadable files, invalid buffers, count mismatches, and mismatched
sample/frequency metadata now emit RuntimeWarning and return None.

Update nvbench_compare tests to verify lazy loading, cache reuse, injected
reader behavior, warning-based degradation, and count mismatch handling.
Its intent is to be cheaply retrievable metric of average
SM clock frequence over entire sample
The quantile values are not currently used, but plumbed through
Implemented the clear-gap comparison, with the log-distance-equivalent
algebra and pessimistic SM-clock fallback.

What changed:

 - Added TimingInterval and interval construction from summaries:
    - robust interval: [min, q3], centered at median
    - fallback interval: clipped [mean - stdev, mean + stdev] intersected with [min, max]
 - Added CLEAR_GAP_RELATIVE_THRESHOLD = 0.005.
 - FAST gap uses:

   (ref.lower - cmp.upper) / cmp.upper >= delta
   which is equivalent to log(ref.lower / cmp.upper) >= log(1 + delta).
 - SLOW gap uses:

   (cmp.lower - ref.upper) / ref.upper >= delta
 - FAST/SLOW now requires SM clock summaries on both sides and the same clear-gap result after scaling intervals by sm_clock_rate_mean.
 - If intervals are missing, overlap, fail the gap threshold, have missing/invalid clock summaries, or time/cycle comparison disagrees, status is UNDECIDED.
 - Existing center/noise values are still computed and displayed, but no longer drive FAST/SLOW/SAME classification.

Updated tests to cover:

 - center/noise-only comparisons becoming UNDECIDED
 - clear FAST/SLOW with matching clock evidence
 - missing clock fallback to UNDECIDED
 - frequency-shift disagreement becoming UNDECIDED
 - regression reporting with robust interval and clock evidence
If SLOW/FAST check returned undecided, we attempt conservative
SAME check based on summary data alone (bulk data are not read)

Reference and compare measurements are considered SAME if
   - both centers are positive finite values;
   - abs(ref - cmp) / min(ref, cmp) <= 0.5%.
     This is equivalent to max(ref, cmp) / min(ref, cmp) <= 1 + delta;
   - interval overlap must cover at least 50% of the smaller interval;
   - relative dispersion must be finite on both sides and no more than 2%;
   - if SM clock summaries are available, the same check must also pass in cycle space.

Otherwise UNDECIDED remains working decision, to be refined by further checks
- Add DecisionReason(code, message) and internal
  TimingDecision(status, reason).
- SummaryComparison now carries reason
- ComparisonStats now aggregates undecided reasons.
- Final summary prints a reason breakdown only when
  undecided reasons exist, e.g.:

  - Undecided   (comparison requires more evidence): 3
    - Reasons:
      - noise_too_high: 2 (relative dispersion is too
                           high to declare same)
      - weak_interval_overlap: 1 (timing intervals do not
                 overlap strongly enough to declare same)
Add a bulk-data SAME path to nvbench_compare for cases where summary
intervals do not provide a clear FAST/SLOW decision. The new path compares
sample times and SM-clock-adjusted cycles with symmetric nearest-neighbor
coverage over unique values and sample counts.

The comparison now requires both sample-weight coverage and unique-support
coverage to pass before declaring SAME. If bulk data is available but coverage
does not pass, the result remains UNDECIDED instead of falling back to the
summary-only SAME rule.

Also improve undecided diagnostics by aggregating reason codes while preserving
the most severe representative detail, including observed coverage values and
thresholds for bulk support mismatches.

Add tests for:
 - bulk data confirming SAME despite changed mode weights;
 - bulk time mismatch overriding summary-only SAME;
 - cycle coverage vetoing time-only agreement;
 - sample-weight and unique-support coverage diagnostics;
 - aggregation of undecided reason details.
Mention nvbench-compare-legacy abd nvbench-compare-robust.
State that the document is about the robust script from now on.
Instead of hard-coding script name in the exception message,
using `sys.argv[0]` to get the name a user used to call the tool.
@oleksandr-pavlyk

This comment was marked as outdated.

@coderabbitai

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

Since nvbench_compare.py with legacy decision tree and legacy display
formatter are preserved, it makes sense to remove `--display legacy`.

Instead we introduce `--display simple` as requested during presentation.
This display centers, percent interval span, and % center difference.
Device metadata is now validated before the early continue that skips
rendering when threshold filtering removes all rows and there is
no --plot-along data. This prevents malformed benchmark device references
from affecting stats while avoiding validation.
@oleksandr-pavlyk oleksandr-pavlyk changed the title Nvbench compare process bulk data Evolution of nvbench compare that uses bulk data Jul 17, 2026
@oleksandr-pavlyk

Copy link
Copy Markdown
Collaborator Author

@bernhardmgruber @gevtushenko In response to feedback:

  • nvbench_compare.py now uses legacy decision tree, but does contain changes to support:
    • benchmark scoping of axis specifications, aligning behavior with that of NVBench-instrumented benchmarks
    • device filtering via new options --reference-devices/--compare-devices
    • bug fixes
  • nvbench_compare_robust.py - new script that uses bulk data, new decision tree, and new AMBG (undecided) comparison status
    • --display simple is added, although it is not the default mode

Please give it a go.

@oleksandr-pavlyk

Copy link
Copy Markdown
Collaborator Author

Per @gevtushenko , restored nvbench_compare.py as in main, with the only change being support for lazy loading of third-party tools to retain fix for #384

@oleksandr-pavlyk oleksandr-pavlyk moved this from In Progress to In Review in CCCL Jul 17, 2026
Comment thread python/scripts/nvbench_compare.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python type: enhancement New feature or request.

Projects

Status: In Review

2 participants