MCPcopy Create free account
hub / github.com/Niko1221/Strata / q8split_bf16

Method q8split_bf16

engine/src/split/src/model.cpp:458–476  ·  view source on GitHub ↗

bf16 values [n] as the split int8 layout (per 32 values: d = amax / 127, ggml's rounding)

Source from the content-addressed store, hash-verified

456 }
457 // bf16 values [n] as the split int8 layout (per 32 values: d = amax / 127, ggml's rounding)
458 Q8S q8split_bf16(const uint16_t* v, size_t n) {
459 std::vector<int8_t> q(n);
460 std::vector<uint16_t> d(n / 32);
461 for (size_t b = 0; b < n / 32; ++b) {
462 float x[32], amax = 0.f;
463 for (int j = 0; j < 32; ++j) {
464 const uint32_t u = (uint32_t) v[b * 32 + j] << 16;
465 std::memcpy(&x[j], &u, 4);
466 amax = std::max(amax, std::fabs(x[j]));
467 }
468 const float dd = amax / 127.0f, id = dd > 0.f ? 1.0f / dd : 0.f;
469 for (int j = 0; j < 32; ++j) q[b * 32 + j] = (int8_t) std::lround(x[j] * id);
470 d[b] = f32_to_f16(dd);
471 }
472 Q8S s;
473 s.q = put<int8_t>(q.data(), q.size());
474 s.d = put<uint16_t>(d.data(), d.size() * 2);
475 return s;
476 }
477 // a whole Q8_0 tensor as int8 values and f16 scales
478 Q8S q8split(const Tensor& t) {
479 if (t.type != T_Q8_0) throw std::runtime_error(t.name + ": q8split needs Q8_0");

Callers 1

load_mtp_cardFunction · 0.80

Calls 5

memcpyFunction · 0.85
f32_to_f16Function · 0.70
maxFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected