A half-precision CrossEncoder reranker on Sentence Transformers v5 gave several top passages identical scores; why, and what does v6 change?
answer
- few values just below 1.0
- Sigmoid computed in half precision
- upcast before the activation
- predict and rank, Sentence Transformers v6
- Identity activation sidesteps saturation
basics
~20 sIn Sentence Transformers v5 a float16 or bfloat16 reranker applied its Sigmoid in half precision, which saturates: strongly relevant passages rounded to the same value near 1.0 and tied. Since v6, predict and rank upcast scores to float32 before the activation.
solid answer
~40 sHalf-precision formats have very few representable values just below 1.0, so once a Sigmoid pushes several strong logits toward 1.0 they round to the same number and the reranker can no longer order the best candidates. Through Sentence Transformers v5.x the activation ran in the model's dtype, so a reranker loaded with `model.half()` or `model.bfloat16()` — or a checkpoint stored in fp16, which Transformers v5 loads in that dtype by default — tied its top results. Sentence Transformers v6 changed `predict` and `rank` to upcast scores to `float32` before applying `activation_fn`, so the same model returns distinct, better-ordered scores. On an older release, score with `activation_fn=torch.nn.Identity()` to rank on logits, or run the model in float32. In v6 the default numpy output was already `float32`; only tensor outputs change dtype.
go deeper
Recall that half-precision rerankers can give several top passages the same score, and that Sentence Transformers v6 upcasts scores to float32 before the activation.
Explain why Sigmoid near 1.0 runs out of representable half-precision values, and how ranking on logits with an Identity activation avoids it.
Show you diagnose ties by comparing Sigmoid scores with logits, notice fp16 checkpoints loading in their stored dtype, and pick v6 or a call-level Identity activation.
Weigh half-precision throughput against score resolution for rerankers and set a policy for verifying ranking quality after dependency upgrades that change dtypes.
## The symptom You serve a reranker in **half precision** to save GPU memory and time. Results look fine until someone notices that the top three or four passages for many queries share **exactly the same score**, often something like `1.0` or `0.9995`. The order among them is then arbitrary, and the passage the model actually preferred may not come first. ## Why half precision ties at the top A CrossEncoder outputs a **logit** per pair, then `predict` applies its `activation_fn`. For a single-label reranker whose checkpoint does not name another activation, that is **`torch.nn.Sigmoid()`**, which maps a logit into the range 0 to 1. Sigmoid compresses large logits toward 1.0: a logit of 6 maps to about 0.9975, a logit of 9 to about 0.9999. Those values differ in the fourth decimal place. Half-precision formats cannot represent that difference: - **float16** has only about three decimal digits of precision; just below 1.0 its representable values are roughly 0.0005 apart. - **bfloat16** keeps float32's range but has even fewer mantissa bits; its steps just below 1.0 are roughly 0.004 apart. So once several strong logits go through Sigmoid **in half precision**, they round onto the same representable value. The migration guide puts it directly: *a sigmoid in half precision saturates and ties the top candidates together.* ## What Sentence Transformers v6 changed | | v5.x | v6 | |---|---|---| | Activation computed in | the model's dtype (fp16 / bf16 when loaded that way) | **float32**: scores are upcast first | | Top candidates under Sigmoid | can tie | distinct, far better ordered | | `predict` default numpy output dtype | float32 | float32 (unchanged) | | `predict(convert_to_tensor=True)` dtype | the model's dtype | float32 | | `rank` score type | `numpy.float32` scalar (or 0-d tensor) | Python `float` | In `predict`, any floating-point score narrower than 32 bits is converted with `.float()` *before* `activation_fn` runs. `rank` calls `predict`, so it gets the same fix, and v6 additionally returns its scores as Python floats, with `convert_to_numpy` / `convert_to_tensor` on `rank` reduced to deprecated no-ops. Note what the upcast does **not** do: the logits themselves were still produced by a half-precision forward pass. The change stops the *activation* from destroying the remaining resolution; it does not make a half-precision model compute like a float32 one. ## How you end up in half precision without asking - Calling **`model.half()`** or **`model.bfloat16()`**, as the efficiency docs suggest for GPU inference. - Loading a checkpoint **stored in fp16**. The Sentence Transformers efficiency docs note that such checkpoints (for example `mixedbread-ai/mxbai-rerank-large-v1`) load in that dtype by default since Transformers v5 — so upgrading Transformers alone can change your reranker's precision. ## Workarounds on releases before v6 1. **Rank on logits.** Pass `activation_fn=torch.nn.Identity()` to `predict` or `rank` (since v5.4 a call-level activation applies only to that call). Ordering by logits is what Sigmoid would produce anyway, without the saturation. 2. **Upcast before the activation yourself.** Call `predict(..., activation_fn=torch.nn.Identity(), convert_to_tensor=True)`, convert the tensor with `.float()`, then apply `torch.sigmoid` if you need 0 to 1 values. 3. **Run in float32** on hardware where the speed difference does not matter. The docs also warn that half precision is much slower on CPU, so a CPU deployment should not use it at all. ## Checking an upgrade before it ships The v6 change alters scores, not just types, so treat it as a behaviour change: - Note the new floors from the migration guide: Sentence Transformers v6 requires Transformers v5, torch 2.2 or later and huggingface-hub v1.x, so the reranker's dependencies move together. - Re-run a fixed set of queries before and after the upgrade and compare the **top-k ordering**, not just a single metric. - Search the code for `rank(..., convert_to_tensor=True)` or `convert_to_numpy=` on `rank`: those now only log a deprecation warning, and any caller expecting a tensor or numpy scalar receives Python floats. ## How to confirm the diagnosis - Count exact ties among the top-k scores per query across a sample of queries. - Re-run the same queries with `activation_fn=torch.nn.Identity()`: if the logits differ where the Sigmoid scores tied, saturation is the cause. - Check `model.activation_fn` and the model's parameter dtype to see what the checkpoint actually loaded.
- Does the v6 upcast make a float16 reranker produce the same scores as running it in float32?No. The forward pass still runs in half precision, so the logits carry half-precision rounding. v6 only converts those logits to float32 before the activation, which stops Sigmoid from collapsing strong candidates onto one value. Exact float32 parity needs a float32 forward pass.
- Why would a v6 upgrade change the dtype of predict's output only for some callers?The default numpy output was already float32, because predict converted each score with `.float()` before building the array. Callers using `convert_to_tensor=True` or `convert_to_numpy=False` used to receive the model's half-precision dtype and now receive float32 tensors.
- Tied scores mean the passages are equally relevant
- Upgrading to v6 makes a float16 forward pass match float32
- Adding Sigmoid fixes ties in half precision
- Half precision speeds up CrossEncoder inference on CPU too
- The v6 change alters which passage has the highest logit
Assumes Sentence Transformers v6.0 or later, where predict and rank upcast scores to float32 before the activation and rank returns Python floats; v5.x behaves differently.