Skip to content

Update tl.dot precision handling - #3

Open
GMNGeoffrey wants to merge 6 commits into
mainfrom
users/gmngeoffrey/tl-dot-wrapper
Open

GMNGeoffrey wants to merge 6 commits into
mainfrom
users/gmngeoffrey/tl-dot-wrapper

Conversation

@GMNGeoffrey

@GMNGeoffrey GMNGeoffrey commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

I had a chance to take another look at this when updating OF3 to do something similar (aqlaboratory/openfold-3#457) and reworked some of it. Bring those improvements back here. Some stuff is just wording I like better for function naming and docs. The material changes:

  • Only use bf16x3 when we think it's actually faster than ieee. Since this is a software emulation, Triton reports this as available on lots of hardware (presumably anything with bf16) where it's actually not faster than ieee. I hadn't realized this when I wrote the original version of the precision stuff. Instead, we only use this where we believe it's faster (gfx94, gfx95, and sm >= 8). For now this is more or less a copy of torch.cuda.is_tf32_supported, but we reimplement it because Torch's function is not available prior to 2.7 and in 2.7 it returns False on ROCm across the board. When we drop support for <=2.7, we could consider using Torch's setting instead, but should probably check that it's really answering the same question we're trying to ask. In the OF3 PR, I used Torch's function. I only realized the problem with it for older versions when creating this PR. One notable exclusion from the list is gfx1151. In my local tests on my laptop, bf16x3 is actually a speedup here, but for now we're deferring to Torch.
  • Require a precision for tl.dot with a wrapper function and Ruff ban for the API, replacing the gross test doing source inspection. I think this is cleaner, more robust, and provides quicker feedback.
  • Break the shim's dependency on the main package testutil. I realized it would be nice to run tests from an sdist, and this doesn't work with a cross-dependency like that. Instead the shim mocks the torch precision setting, which is fine because it's just testing the error handling there anyways.

The commits are laid out for ease of review one-by-one as I separated out mechanical things to be quickly scanned.

GMNGeoffrey and others added 6 commits November 3, 2026 14:38
The module exists only for the Triton kernels, so it lives with them.
Its tests move to match. No change beyond the module path at the import
sites for git rename tracking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
I had a chance to redo this when updating OF3 to do something similar
(aqlaboratory/openfold-3#457) and reworked some
of the naming for clarity and better consistency with Triton and Torch:

- `matmul_precision()` -> `current_dot_precision()`
- `torch_precision()` -> `torch_fp32_precision()`
- consistent usage of `dot_precision` for the resolved mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As in the previous commit. I had a chance to redo this when updating OF3
to do something similar (aqlaboratory/openfold-3#457) and reworked some
of the documentation. Bring those updates back over and remove
unnecessary diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Left unset, `tl.dot` picks a reduced-precision mode for fp32 operands
wherever the target has one. `tl_dot` makes the mode a required argument
so a lint rule can ban bare `tl.dot` calls. The wrapper inlines
completely during compilation. Triton's JIT does not support
keyword-only parameters, so `input_precision` precedes the optional
`acc` positionally.

Tested with a minimal kernel including that ieee is more accurate than
tf32. The no-setting test now stubs torch, so it no longer depends on
the global precision other tests leave behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mechanical: every kernel `tl.dot` becomes `tl_dot`, and the two call
sites that passed `acc` positionally now pass it by keyword, since
`tl_dot` takes `input_precision` before `acc`. Ruff's banned-api rule
(TID251) rejects `tl.dot` anywhere else, so a call site can't leave off
the precision. This replaces the gross test that parsed the package
source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since bf16x3 is a software emulation, Triton reports it available on
many targets where it is not faster than ieee. Following torch's tf32
setting there makes kernels slower and less accurate for no benefit, so
the setting is now honored only on devices with a fast reduced-precision
dot.

`has_fast_reduced_precision_fp32_dot` mirrors
torch.cuda.is_tf32_supported as of torch 2.8 (gfx94x/gfx95x on ROCm, sm
>= 8.0 on CUDA). We reimplement it because torch's implementation varies
by version: it's absent before 2.7, and False for all of ROCm in 2.7.
Ours also checks that cuda is available.

Tests that check how the setting is read and plumbed now mock the fast
dot setting so they can work independent of hardware. Those comparing
tf32 with ieee outputs skip mock the "is faster" piece so that they
still exercise a (potentially slow) reduced precision dot where
available.

The shim's precision tests now mock the effective torch setting instead
of setting it, so the don't need a GPU and remove the dependency on the
main package testutil helpers (which would break tests run from an
sdist).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GMNGeoffrey
GMNGeoffrey requested a review from singagan as a code owner November 3, 2026 23:06
@GMNGeoffrey GMNGeoffrey changed the title Users/gmngeoffrey/tl dot wrapper Update tl.dot precision handling Nov 3, 2026

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