Skip to content

[Common] Benchmarkable Unit Tests - #3408

Draft
denera wants to merge 1 commit into
NVIDIA:mainfrom
denera:common/benchmarkable-unit-test-infrastructure
Draft

[Common] Benchmarkable Unit Tests#3408
denera wants to merge 1 commit into
NVIDIA:mainfrom
denera:common/benchmarkable-unit-test-infrastructure

Conversation

@denera

@denera denera commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR introduces a new transformer_engine.common.testing submodule that defines a new unified standard for implementing Transformer Engine unit tests that are also benchmarkable to avoid duplicate implementations between separate test and benchmark implementations.

tests/jax/test_softmax.py and tests/pytorch/test_fused_rose.py have been ported as demonstrative examples, but a complete porting of all existing unit tests as well as a re-write of existing benchmarking scripts are deferred to follow-up PRs.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@denera
denera requested a review from ptrendx August 19, 2026 23:38
@denera denera self-assigned this Aug 19, 2026
A test returns a Case (setup/evaluate/reference/verify) instead of asserting
inline, so one test serves as both a correctness test and a benchmark. Default
pytest runs evaluate and reference once each and lets verify assert.
--nvte-benchmark times them over repeated runs for median metrics, gating each
point on a one-time correctness check first, and writes JSON/JSONL/CSV reports
that transformer_engine.common.testing.compare diffs against a baseline to flag
regressions.

@benchmark(argnames, values) marks a test Case-bearing and declares the values
one axis takes when benchmarking. Those values are substituted into the test's
existing pytest.mark.parametrize rather than adding an axis, so undeclared axes
keep their correctness values and correctness-mode node IDs are unchanged.
@benchmark.skip and @benchmark.skipif mark a Case-bearing test that is never
benchmarked, which is how a correctness-only Case is written. On a class the
declaration is shared by every test method, and each method's return value
decides: a Case is run by the harness, None is left to pytest.

The plugin autoloads as the nvte-benchmark pytest11 entry point, and its options
carry an --nvte- prefix to stay out of pytest-benchmark's namespace. Standard QA
suites run default pytest and so never benchmark.

This lays the foundation and converts two tests as narrow examples; porting the
rest of the suite and migrating the standalone benchmark scripts follow
separately.

Added:
  transformer_engine/common/testing/__init__.py
  transformer_engine/common/testing/case.py         Case contract, axis renderer
  transformer_engine/common/testing/decorator.py    the benchmark decorator
  transformer_engine/common/testing/declaration.py  axis declarations
  transformer_engine/common/testing/plugin.py       pytest hooks, mode selection
  transformer_engine/common/testing/runner.py       Case execution and records
  transformer_engine/common/testing/timing.py       wall-clock sampler
  transformer_engine/common/testing/device.py       cuda-python device access
  transformer_engine/common/testing/artifacts.py    report writers
  transformer_engine/common/testing/compare.py      baseline comparison CLI
  docs/examples/benchmarkable_tests.rst

Modified:
  setup.py                          nvte-benchmark entry point, cuda-python dep
  pyproject.toml                    a returning test is an error, not a warning
  tests/jax/pytest.ini              the same, for the JAX suites' -c runs
  docs/index.rst                    toctree entry
  tests/pytorch/test_fused_rope.py  converted in place as an example
  tests/jax/test_softmax.py         converted in place as an example

Signed-off-by: Alp Dener <adener@nvidia.com>
@denera
denera force-pushed the common/benchmarkable-unit-test-infrastructure branch from 3df6140 to 1803f57 Compare August 19, 2026 23:42
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