Skip to content

[Draft] Add internal MatMulNBits core operation-count estimator - #33467

Draft
Tommaso Adani (tadani3) wants to merge 14 commits into
mainfrom
tommasoadani/matmul_flop
Draft

Tommaso Adani (tadani3) wants to merge 14 commits into
mainfrom
tommasoadani/matmul_flop

Conversation

@tadani3

@tadani3 Tommaso Adani (tadani3) commented Oct 19, 2026 •

Copy link
Copy Markdown

Description

Adds an internal, metadata-only estimator for the core dense-equivalent operation
count of com.microsoft::MatMulNBits (schema version 1).

This is an initial foundation for contrib-op compute estimation, not a complete
user-facing FLOP-reporting feature.

The implementation:

  • Calculates 2 × M × N × K, where M is the product of the input's leading
    dimensions and multiply-add counts as two operations.
  • Provides a checked shape-based estimator and an adapter for resolved graph nodes.
  • Returns an explicit unavailable reason for unknown shapes, invalid metadata,
    unsupported operators/versions, or overflow.
  • Includes unit tests, graph-adapter tests, and a phased rollout document.

The count covers only the logical matrix-multiplication core. It excludes bias,
dequantization, packing, conversions, padding, and route-specific extra work.
For this quantized operator, the result is dense-equivalent operations, not
a count of actual floating-point instructions executed.

Out of scope: graph-wide reporting, runtime instrumentation, public APIs,
execution timing, FLOP/s, and changes to dispatch, placement, or allocation.

Validation

CPU Debug build passed:
cmake --build build\Windows\FlopEstimate --config Debug --target onnxruntime_provider_test --parallel 2

From the build output directory, the following passed 25 tests:
.\onnxruntime_provider_test.exe --gtest_filter="MatMulNBitsComputeEstimate*:MatMulNBits.Float32_4b_Accuracy0:MatMulNBits.Float32_4b_Accuracy4_Batch:MatMulNBits.LegacyShape_4b"

  • 8 pure estimator tests.
  • 14 graph-adapter tests.
  • 3 existing MatMulNBits smoke tests.

The 8 pure estimator tests also passed in a standalone build with
ORT_MINIMAL_BUILD and ORT_NO_EXCEPTIONS enabled.
Lint checks passed for the new sources; git diff --check passed.
CUDA validation was not run; the estimator has no CUDA dependency.

Motivation and Context

Establish a small, testable counting contract before adding model-wide reports
or measured throughput. This gives later reporting work a shared formula and
explicit handling of unavailable estimates, without changing inference behavior.

The design draws on the separation of metadata adapters and estimation arithmetic
used by the memory-estimation work tracked in #29775. Compute counts remain
independent of memory accounting and budget enforcement; this PR does not
implement or close that roadmap.

Draft review feedback requested:

  • Is core dense-equivalent work the right initial counting convention?
  • Are the estimator location, result type, and unavailable reasons appropriate?
  • What internal reporting surface should the next increment expose?

This branch has not been deployed

No deployments
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