Repository navigation
fix(families): build siglip, dinov2 and vit at fp32 only - #1838
Conversation
All three accepted precision=fp16 while shipping fp32 manifests, so an fp16 bundle could be built that nothing in the repo ever compared against the reference. Measured through the binary, fp16 is further off than each family's own E2E gate allows: family gated quantity correct fp32 all-fp16 gate weakest break siglip embedding maxabs 2.1e-07 3.6e-04 1e-04 8.4e-04 dinov2 feature maxabs 4.5e-04 1.01 5e-03 6.2e-02 vit logit maxabs 1.0e-05 6.9e-03 2e-03 1.9e-02 For dinov2 fp16's error is sixteen times larger than the defect the gate exists to catch, so an fp16 gate would pass a build with the wrong GELU in it. Widening the attention softmax to fp32 was measured and recovers nothing: the loss is in the matmuls, not in a reduction taken too narrowly, and the layer norms already compute in fp32. So build() accepts fp32 and refuses the rest, carrying each family's own numbers where someone deciding to re-enable fp16 will read them. A unit test per family pins the refusal. The fp16 branches are removed rather than left unreachable; at fp32 they were no-ops, and the E2E parity figures are unchanged at 1.001e-05, 4.539e-04 and 2.086e-07. Signed-off-by: Zhenshan Xie <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
A vit build without --precision is now fp16 instead of fp32. #1838 made vit fp32-only because the fp32 logit tolerance could not separate fp16 noise from the tanh-GELU defect; #2009 added the fp16 graph with its own gate (logit tolerance 3e-2 plus the tanh-GELU share check), so that reason no longer holds. Measured with the family build path (batch 1, CUDA graph, interleaved medians of 3 builds x 7 rounds), TensorRT 11.4: GPU fp32 ms fp16 ms speedup B200 1.908 0.381 5.00x B300 1.835 0.431 4.26x On 2000 ImageNet validation images fp16 top-1 is 80.85% to 80.95% (HF float32 80.95%), mean logit cosine 0.999996, and no non-finite output on the images or on stress inputs (noise up to sigma 100, constant and checkerboard images). --precision fp32 still builds the unchanged fp32 network. The fp32, fp16 and fp8 E2E cases and their thresholds are unchanged. Signed-off-by: Zhenshan Xie <[email protected]>
Accept --precision fp16 and make it the family default; --precision fp32 still builds the fp32 network, unchanged. The fp16 engine keeps float32 I/O and float32 layer-norm statistics, so the runtime and the bundle contract do not change. fp8 still requires fp32. #1838 made the family fp32-only because the fp32 feature tolerance (5e-3) cannot tell fp16 noise (0.35 to 1.16 on the E2E image) from the tanh-GELU defect it must catch (6.2e-02). The new fp16 E2E case uses an fp16 feature tolerance (3.0) plus a check that the engine is closer to the exact-GELU reference than to a tanh-GELU reference. A new test builds a correct, a tanh-GELU and a bilinear-position-table fp16 engine and shows only the first passes. dinov2-base, batch 1, TensorRT 11.4: fp16 is 5.2x (B200) and 4.6x (B300) faster than fp32, the plan is half the size, kNN top-1 stays within 0.2 points of the float32 reference, and no output is non-finite on real or stress inputs. Signed-off-by: Zhenshan Xie <[email protected]>
Background
families/siglip,families/dinov2andfamilies/viteach acceptprecision=fp16in their builder and each ship an fp32 manifest, becausefp32 is the only precision any of their numbers were taken at. Three PRs in
a row carried the same line in their own Remaining Gaps:
This is that measurement. It says refuse.
An accepted-but-unmeasured precision is worse than an unsupported one: the
build succeeds, the bundle looks ordinary, and nothing in the repo ever
compares it against the reference.
Exit Criteria
exists to catch, not just against zero.
tools/testsandtools/tests/test_architecture.pypass.ruffclean.Implementation
What fp16 is worth, measured
Each family was built at fp16 and fp32 from the same checkpoint and run
through the
trtmcbinary against the same reference:In all three, fp16's own error is above the tolerance the gate uses. To
admit fp16 the tolerance would have to be raised past fp16's noise while
staying below the break, and the room left is:
larger. An fp16 gate would pass a build with the wrong GELU in it. This
one is not a judgement call.
call of the three, and still thin enough that another image could invert
it.
Cosine stays above 0.9999 in every fp16 row, which is one more entry in the
list of reasons these families do not gate on cosine.
The rescue that does not work
The usual explanation for a bad fp16 transformer is a reduction taken too
narrowly. That was checked rather than assumed. The layer norms and the L2
normalisations in these families already compute in fp32 -
_as_float32in each family's
graph.pycasts up for the statistics and back after. Theremaining narrow reduction is the attention softmax, so it was widened to
fp32 and measured:
It moves nothing. The loss is in the matmuls and the residual stream, which
is to say it is what fp16 costs on these graphs, not a defect in how they
are built. There is no cheap fix to find.
So the builders refuse it
build()in each family now acceptsfp32and refuses everything else,with the family's own numbers written where someone deciding to re-enable it
will read them. The fp16 branches are removed rather than left unreachable,
so no one reads them as a working path. A unit test per family pins the
refusal.
This is a deliberate narrowing. These three stay fp32-only until someone
qualifies fp16 against a gate that can still catch a wrong GELU - which for
dinov2 means a different kind of gate, not a looser number.
Change categories
Validation
Commands and Results
families/{vit,dinov2,siglip}/testsunitall checks passedtools/tests/test_architecture.pytools/testsruff check .The fp32 path is unchanged, number for number. Every E2E figure above is
identical to the one in the PR that merged that family: 1.001e-05,
4.539e-04 and 2.086e-07. The removed casts were already no-ops at fp32 - the
code read
out = tensor if tensor.dtype == float32 else cast(...)- so thisis a deletion of a dead branch, and the parity numbers confirm it.
No C++ changed, so
clang-formatis unaffected.Hardware, Environment, and Revisions
google/siglip-base-patch16-224,facebook/dinov2-base,google/vit-base-patch16-224Not Run / Remaining Gaps
this change and is not offered after; the refusal message names whatever
was asked for rather than claiming anything about bf16.
checkpoint each family qualifies. A larger variant could be worse, not
better.
families already refuse
fp32_layers, and a per-layer precision planwould need its own qualification.
needs a gate that survives fp16's noise and still fails on a wrong GELU.
For dinov2 that is a different kind of gate, not a looser threshold.
Contributor Self-Review
Notes For Future Readers
The useful thing here is not the decision, it is the comparison that made
it. "fp16 is close enough" is normally argued from cosine or from the
prediction surviving, and both are available in these numbers: cosine never
drops below 0.9999, and vit's top-1 is unchanged at fp16. Neither tells you
whether the engine is correct. The question that decides it is how fp16's
error compares to the smallest defect your gate is supposed to catch, and
for dinov2 the answer is that fp16 is sixteen times larger than the defect.
If you re-enable fp16 in one of these families, put that ratio in the PR.
Risk level
Six files, all under the three families. No shared header, task contract,
CLI or build-system file is touched. No manifest changes, because all three
already shipped fp32. The only behaviour change visible outside the
builders is that a build request asking for fp16 now raises instead of
producing an unqualified bundle, and no manifest, test or adapter in the
repo asks for one.
🤖 Generated with Claude Code