Skip to content

Commit d26a5fe

Browse files
fix: optimize FP16 to FP32 Casting
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 2278801 commit d26a5fe

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

.jules/bolt.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@
4949
## 2025-02-14 - Optimize regex substitution loops with search fast-path
5050
**Learning:** Using `re.search` as a fast-path condition before executing a `re.subn` loop significantly improves performance (e.g., ~50% faster for clean text) because `re.search` is highly optimized in C and avoids the overhead of substitution checks when no matches exist.
5151
**Action:** Always implement an initial `search` or string-matching fast-path before performing iterative regex substitutions or replacements, especially on hot paths like text sanitization.
52+
## 2024-05-24 - Defer Tensor Casting
53+
**Learning:** Casting massive full-vocab output tensors from FP16 to FP32 before slicing causes huge memory allocation overhead.
54+
**Action:** Extract the needed scalar logits first, then let np.subtract handle the cast on the small slice.

qwen3_embed/rerank/cross_encoder/qwen3_cross_encoder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,6 @@ def _onnx_embed_texts(self, texts: list[str], **kwargs: Any) -> OnnxOutputContex
289289
outputs = self.model.run(self.ONNX_OUTPUT_NAMES, onnx_input)
290290
model_output = outputs[0]
291291

292-
if getattr(model_output, "dtype", None) == np.float16:
293-
model_output = model_output.astype(np.float32) # type: ignore[unresolved-attribute]
294-
295292
# batch=1 with no padding: the yes/no token is the last position. The mask
296293
# (all ones) is passed for the full-vocab variant; the YesNo variant ignores
297294
# it (output already collapsed to (1, 2)).

0 commit comments

Comments
 (0)