Commit 17bfde3
committed
fix(hpc/gguf): F16 → F32 produces IEEE quiet NaN (QNaN) instead of SNaN
The f16_to_f32 primitive was producing signaling NaN (SNaN) for all NaN
inputs because it OR'd the shifted mantissa payload through without
setting the F32 quiet-NaN bit (bit 22 of the mantissa field = 0x00400000).
IEEE 754 recommends F16 → F32 NaN conversion preserves the payload AND
sets the quiet bit, matching reference implementations like the `half`
crate. SNaN produces implementation-defined behavior in some libm paths;
QNaN propagates cleanly.
Caught by the new regression probe in
lance-graph/crates/thinking-engine/examples/probe_jina_v5_safetensors.rs
step 1, which round-trips all 65,536 F16 bit patterns against
`half::f16::from_bits().to_f32()` as the IEEE-correct reference. Before
the fix, 2046 NaN patterns mismatched (bit 22 clear instead of set).
After the fix all 65,536 patterns round-trip bit-exact, covering ±0,
subnormals, normals, ±∞, and every NaN payload.
Finite values were unaffected by the bug and are unchanged. The only
behavioral change is that NaN inputs now produce QNaN instead of SNaN.
Premature-dismissal concern: any calibration measurement that touched
NaN values in the source through this primitive may have been
instrument-drift-limited. Earlier negative conclusions about γ+φ Regime
C (ρ=1.000 no-op) and CLAM HHTL correlations may be retest candidates
after this fix — see lance-graph/.claude/agents/workspace-primer.md
Rule 22 for the retest list.
Also corrects the ModelSource::JinaV5 docstring in hpc/jina/runtime.rs:
- Removes the backwards F16-range claim ("F16 max ~65504 overflows
BF16 range" — wrong; BF16 has MORE exponent bits than F16, so
F16 values fit inside BF16 range with ~33 orders of magnitude of
headroom; the lossy step is a 3-bit mantissa truncation, not an
exponent-range issue).
- Replaces the "F32 transient pipe" framing with the "F32 is a method,
not a buffer" doctrine: F16 source bytes are the ground truth,
upcast runs inline with zero Vec<f32> allocation, F32 values exist
only in registers or stack windows during active computation.
- Records the verified finding that the downloaded Jina v5
safetensors at data/jina-v5-onnx/model.safetensors is BF16, not
F16 as earlier canonical notes claimed.
https://claude.ai/code/session_019RzHP8tpJu55ESTxhfUy1A1 parent d8b7b8e commit 17bfde3
2 files changed
Lines changed: 79 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
442 | | - | |
443 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
444 | 462 | | |
445 | 463 | | |
446 | 464 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
55 | 62 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
61 | 69 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 70 | + | |
65 | 71 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
69 | 78 | | |
70 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
71 | 88 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
77 | 94 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
82 | 101 | | |
83 | | - | |
84 | | - | |
85 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
86 | 106 | | |
87 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
88 | 112 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 113 | + | |
94 | 114 | | |
95 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
96 | 121 | | |
97 | 122 | | |
98 | 123 | | |
| |||
0 commit comments