There was an error while loading. Please reload this page.
1 parent d7a249a commit d6b363aCopy full SHA for d6b363a
3 files changed
common/floats/floats.go
@@ -232,8 +232,7 @@ func ToBF16(values []float32) []uint16 {
232
encoded := make([]uint16, len(values))
233
for i, value := range values {
234
bits := math.Float32bits(value)
235
- roundingBias := uint32(0x7FFF + ((bits >> 16) & 1))
236
- encoded[i] = uint16((bits + roundingBias) >> 16)
+ encoded[i] = uint16(bits >> 16)
237
}
238
return encoded
239
common/floats/floats_test.go
@@ -42,17 +42,17 @@ func TestZero(t *testing.T) {
42
43
func TestToBF16(t *testing.T) {
44
assert.Nil(t, ToBF16(nil))
45
- assert.Equal(t, []uint16{0x0000, 0x3f80, 0xc020, 0x3f8d}, ToBF16([]float32{0, 1, -2.5, 1.1}))
+ assert.Equal(t, []uint16{0x0000, 0x3f80, 0xc020, 0x3f8c}, ToBF16([]float32{0, 1, -2.5, 1.1}))
46
47
48
func TestFromBF16(t *testing.T) {
49
assert.Nil(t, FromBF16(nil))
50
- decoded := FromBF16([]uint16{0x0000, 0x3f80, 0xc020, 0x3f8d})
+ decoded := FromBF16([]uint16{0x0000, 0x3f80, 0xc020, 0x3f8c})
51
assert.Len(t, decoded, 4)
52
assert.Equal(t, uint32(0x00000000), math.Float32bits(decoded[0]))
53
assert.Equal(t, uint32(0x3f800000), math.Float32bits(decoded[1]))
54
assert.Equal(t, uint32(0xc0200000), math.Float32bits(decoded[2]))
55
- assert.Equal(t, uint32(0x3f8d0000), math.Float32bits(decoded[3]))
+ assert.Equal(t, uint32(0x3f8c0000), math.Float32bits(decoded[3]))
56
57
58
func TestAdd(t *testing.T) {
model/ctr/data_test.go
@@ -174,7 +174,7 @@ func TestDataset_Split(t *testing.T) {
174
dataSet.Index.CountUsers() + dataSet.Index.CountItems() + dataSet.Index.CountUserLabels() + 8,
175
0,
176
}, features)
177
- assert.InDeltaSlice(t, []float32{2, 2.1, 2.2}, floats.FromBF16(embeddings[0]), 0.01)
+ assert.InDeltaSlice(t, []float32{2, 2.09375, 2.1875}, floats.FromBF16(embeddings[0]), 0.001)
178
assert.Equal(t, []float32{1, 1, 1, 1, 1, 1, 1, 0.5}, values)
179
assert.Equal(t, float32(-1), target)
180
0 commit comments