Skip to content

fix(families): build siglip, dinov2 and vit at fp32 only - #1838

Merged
zhenshanx-nv merged 1 commit into
NVIDIA:mainfrom
zhenshanx-nv:zhenshanx-nv/fp16-precision
Oct 23, 2026
Merged

zhenshanx-nv merged 1 commit into
NVIDIA:mainfrom
zhenshanx-nv:zhenshanx-nv/fp16-precision

Conversation

@zhenshanx-nv

Copy link
Copy Markdown
Collaborator

Background

families/siglip, families/dinov2 and families/vit each accept
precision=fp16 in their builder and each ship an fp32 manifest, because
fp32 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:

fp16 is accepted by the builder but not measured. A separate
measurement should either qualify fp16 or make the builder refuse it.

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

  • fp16 is measured through the shipped path, not reasoned about.
  • The measurement is compared against the defect each family's E2E gate
    exists to catch, not just against zero.
  • The obvious rescue - a wider softmax - is tried and reported.
  • Whatever is decided is enforced in code and pinned by a unit test.
  • The fp32 path is shown to be unchanged, number for number.
  • tools/tests and tools/tests/test_architecture.py pass.
  • ruff clean.

Implementation

What fp16 is worth, measured

Each family was built at fp16 and fp32 from the same checkpoint and run
through the trtmc binary against the same reference:

family quantity gated correct fp32 all-fp16 gate tolerance weakest defect the gate catches
siglip embedding maxabs 2.1e-07 3.6e-04 1e-04 8.4e-04 (exact GELU)
siglip relevance logit 3.6e-06 9.9e-03 2e-03 -
dinov2 feature maxabs 4.5e-04 1.01 5e-03 6.2e-02 (tanh GELU)
vit logit maxabs 1.0e-05 6.9e-03 2e-03 1.9e-02 (tanh GELU)

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:

  • dinov2: none. fp16 is 1.01 where the break is 0.062 - sixteen times
    larger. An fp16 gate would pass a build with the wrong GELU in it. This
    one is not a judgement call.
  • siglip: 2.3x. 3.6e-04 noise against an 8.4e-04 break.
  • vit: 2.8x. 6.9e-03 noise against a 1.9e-02 break. This is the closest
    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_float32
in each family's graph.py casts up for the statistics and back after. The
remaining narrow reduction is the attention softmax, so it was widened to
fp32 and measured:

family fp16 as shipped fp16 + fp32 softmax
vit 6.94e-03 6.89e-03
dinov2 1.24 1.26

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 accepts fp32 and 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

  • Model or runtime behavior
  • Public API
  • ABI
  • Bundle or artifact format
  • Dependencies
  • Documentation only
  • CI or developer tooling

Validation

Commands and Results

check result
families/{vit,dinov2,siglip}/tests unit 57 passed (3 new)
E2E collect-only 3 collected
C++ preprocess tests all three all checks passed
vit E2E through the binary logit maxabs 1.001e-05, cosine 1.00000000, top-1 817
dinov2 E2E through the binary feature maxabs 4.539e-04, cosine 1.00000000
siglip E2E through the binary image maxabs 2.086e-07, logit maxabs 3.631e-06
tools/tests/test_architecture.py 56 passed
tools/tests 673 passed
ruff check . All checks passed

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 this
is a deletion of a dead branch, and the parity numbers confirm it.

No C++ changed, so clang-format is unaffected.

Hardware, Environment, and Revisions

item value
GPU NVIDIA H100 NVL
CUDA 13.0
TensorRT 11.1.0.106
torch 2.12.0+cu130
transformers 5.2.0
checkpoints google/siglip-base-patch16-224, facebook/dinov2-base, google/vit-base-patch16-224

Not Run / Remaining Gaps

  • bf16 was not measured. It was not offered by these families before
    this change and is not offered after; the refusal message names whatever
    was asked for rather than claiming anything about bf16.
  • One checkpoint per family. The fp16 numbers are from the base
    checkpoint each family qualifies. A larger variant could be worse, not
    better.
  • No attempt was made to build a mixed-precision engine. All three
    families already refuse fp32_layers, and a per-layer precision plan
    would need its own qualification.
  • This does not make fp16 impossible, only unqualified. Re-enabling it
    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

  • I have completed a self-review of this change.

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

  • Low
  • Medium
  • High

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

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]>
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 12168b8 and 834d799.

📒 Files selected for processing: 6
  • families/dinov2/model.py
  • families/dinov2/tests/test_model.py
  • families/siglip/model.py
  • families/siglip/tests/test_model.py
  • families/vit/model.py
  • families/vit/tests/test_model.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

📝 Summary

Summary

SigLIP, DINOv2, and ViT builders now accept only fp32. Each builder raises NotImplementedError with "fp32 only" for other precision requests. The engine-building functions no longer accept a precision argument and build with fp32 weights and tensors. Each family adds a test for the fp16 refusal.

The PR objectives report that shipped-path fp16 measurements exceeded each family’s E2E gate tolerance, and that widening attention softmax to fp32 did not materially improve accuracy. They also report unchanged fp32 E2E figures. These measurements and validation results are author-reported; the supplied repository inspection did not independently verify them.

Architecture impact

  • Family-owned files: The supplied change summary identifies model and test files within the DINOv2, SigLIP, and ViT families.
  • Shared surfaces and dependency direction: The supplied change summary identifies no shared-file changes or new dependencies. The engine-builder signatures changed within the family modules.
  • Affected consumers: The first repository search returned many unrelated functions with similar names. It did not establish whether external consumers call these specific functions or pass the removed precision argument.
  • Unresolved blast-radius questions: The objectives report that bf16, larger checkpoints, and mixed-precision engines were not measured. Consumer compatibility also remains unverified.
  • Review outcome: HUMAN REVIEW REQUIRED. The review contract requires resolving material compatibility and blast-radius questions. The available inspection did not establish those facts. No current review findings or finding counts were supplied.

DINOv2, SigLIP, and ViT engine builders now use FP32 without precision selection. Their build functions reject requests for other precisions with NotImplementedError. Tests cover FP16 request rejection for each model.

Changes: FP32-only model builds

Layer / File(s) Summary
FP32 engine construction
families/dinov2/model.py, families/siglip/model.py, families/vit/model.py
The engine builders use FP32, disable TF32, and mark output tensors directly without conditional output casts.
FP32 build contract
families/dinov2/model.py, families/dinov2/tests/test_model.py, families/siglip/model.py, families/siglip/tests/test_model.py, families/vit/model.py, families/vit/tests/test_model.py
The build functions reject non-FP32 precision requests with NotImplementedError. The tests check that FP16 requests are rejected.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: ⚪ Minimal · up to 834d7

The checked-in build and E2E paths remain aligned with FP32-only support. No identified issue blocks merging after normal checks.

Pre-merge checks: Passed 8 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 35.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 8 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: restricting SigLIP, DINOv2, and ViT builds to fp32 precision.
Description check Passed The description is complete and directly aligned with the implementation. It covers the background, exit criteria, affected components, behavior change, validation results, environment, remaining gaps…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Family Ownership Boundary Passed The authoritative diff contains only families/dinov2/{model.py,tests/test_model.py}, families/siglip/{model.py,tests/test_model.py}, and families/vit/{model.py,tests/test_model.py}. Each changed…
Shared Semantic Neutrality Passed PASS. The pull-request diff changes only families/{dinov2,siglip,vit}/model.py and their family-owned tests/test_model.py files. No shared code outside the excluded model-owned Python, runtime, C+…
Benchmark Validation Integrity Passed PASS: The pull request does not change benchmark accounting or validation semantics. The three affected E2E paths are unchanged from base, and each still compares the native output with the fp32 refer…
Shared Change Blast Radius Passed The check is not applicable. The pull request changes only six files under families/dinov2, families/siglip, and families/vit. It does not change shared code, tooling, catalogs, examples, benchm…
Full details: Description check

Explanation

The description is complete and directly aligned with the implementation. It covers the background, exit criteria, affected components, behavior change, validation results, environment, remaining gaps, self-review, and risk.

Full details: Family Ownership Boundary

Explanation

The authoritative diff contains only families/dinov2/{model.py,tests/test_model.py}, families/siglip/{model.py,tests/test_model.py}, and families/vit/{model.py,tests/test_model.py}. Each changed model imports only its own family modules. Each new test imports its own family model plus the shared tensorrt_model_connect.BuildRequest contract. No changed line imports another family or adds fixtures, reference code, comparators, or validation artifacts from another family. No family registry, switch, source list, or strategy map changed.

Full details: Shared Semantic Neutrality

Explanation

PASS. The pull-request diff changes only families/{dinov2,siglip,vit}/model.py and their family-owned tests/test_model.py files. No shared code outside the excluded model-owned Python, runtime, C++ test, E2E, or family-tool directories changed. Therefore, this check has no changed shared semantic decision to assess.

Full details: Benchmark Validation Integrity

Explanation

PASS: The pull request does not change benchmark accounting or validation semantics. The three affected E2E paths are unchanged from base, and each still compares the native output with the fp32 reference using shape checks, max-absolute error, cosine, and task-specific output validation. The manifests for SigLIP, DINOv2, and ViT all request fp32. The model changes make the already-fp32 path explicit and reject unqualified fp16; one refusal test covers each family. No timing region, synchronization, transfer, reduction, aggregation, or serialization comparison is changed or applied to only one side.

Full details: Shared Change Blast Radius

Explanation

The check is not applicable. The pull request changes only six files under families/dinov2, families/siglip, and families/vit. It does not change shared code, tooling, catalogs, examples, benchmarks, or validation infrastructure. The changed builder APIs are used only by their owning family modules, and no external module references them.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@zhenshanx-nv zhenshanx-nv added the run-internal-ci Maintainer-approved dispatch to internal CI label Oct 23, 2026
@github-actions github-actions Bot removed the run-internal-ci Maintainer-approved dispatch to internal CI label Oct 23, 2026
@zhenshanx-nv
zhenshanx-nv merged commit 472c868 into NVIDIA:main Oct 23, 2026
37 checks passed
zhenshanx-nv added a commit that referenced this pull request Nov 10, 2026
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]>
zhenshanx-nv added a commit that referenced this pull request Nov 10, 2026
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]>
@coderabbitai coderabbitai Bot mentioned this pull request Nov 12, 2026
3 of 11 tasks
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