huggingface / huggingface/candle
test_gelu_operation fails on Apple Silicon (1 ULP f32 precision mismatch)
- Dominant language
- Rust
- Stars
- 21k
- Forks
- 1.8k
- Avg merge
- 16h 42m
- Merged PRs (30d)
- 25
Description
**Describe the bug**
`cargo test test_gelu_operation` fails on Apple Silicon (tested on M4 Mac Mini) with a 1 ULP difference in `gelu_erf`:
```
assertion left == right failed
left: [[0.0, 0.8413447], [1.9544997, 2.9959502]]
right: [[0.0, 0.8413448], [1.9544997, 2.9959502]]
```
The expected value `0.8413448` is the x86 rounding of `GELU(1.0) = x · 0.5 · (1 + erf(x / √2))` = `0.841344745...`. Apple Silicon rounds the same f32 value to `0.8413447`. Both are valid representations of the true value.
**Reproduction**
```
cargo test -p candle-onnx -- test_gelu_operation
```
**Expected behavior**
Tests should pass on all architectures.
**Suggested fix**
Use `to_vec2_round(z, 4)` instead of exact `to_vec2::` comparison, matching the pattern already used by `test_sin_operation` and `test_cos_operation`.
Contributor guide
No contributing guide indexed for this repository
Research direction
Run `cargo test -p candle-onnx -- test_gelu_operation` and inspect the `test_gelu_operation` test alongside the rounding pattern in `test_sin_operation` and `test_cos_operation`. Done means the GELU test accepts the valid 1 ULP f32 results and passes on Apple Silicon and x86.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100