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

Function make_act

engine/src/quant/selfcheck.cpp:75–103  ·  view source on GitHub ↗

A random activation row: values in [-3, 3], scale 1.

Source from the content-addressed store, hash-verified

73
74// A random activation row: values in [-3, 3], scale 1.
75std::vector<uint8_t> make_act(Type act, int n, Rng& r) {
76 const TypeInfo* ti = type_info(act);
77 const size_t nb = (size_t) (n / ti->blck);
78 std::vector<uint8_t> row(nb * ti->bytes);
79 auto q = [&r] { return (int8_t) ((int) (r.next() % 7) - 3); };
80 for (size_t i = 0; i < nb; ++i) {
81 if (act == Type::Q8_0) {
82 block_q8_0* b = blk<block_q8_0>(row, i);
83 b->d = kH1;
84 for (int j = 0; j < QK8_0; ++j) b->qs[j] = q();
85 } else if (act == Type::Q8_1) {
86 block_q8_1* b = blk<block_q8_1>(row, i);
87 int sum = 0;
88 for (int j = 0; j < QK8_1; ++j) sum += b->qs[j] = q();
89 b->d = kH1;
90 b->s = fp32_to_fp16((float) sum);
91 } else {
92 block_q8_K* b = blk<block_q8_K>(row, i);
93 b->d = 1.0f;
94 for (int j = 0; j < QK_K; ++j) b->qs[j] = q();
95 for (int g = 0; g < QK_K / 16; ++g) {
96 int sum = 0;
97 for (int j = 0; j < 16; ++j) sum += b->qs[g * 16 + j];
98 b->bsums[g] = (int16_t) sum;
99 }
100 }
101 }
102 return row;
103}
104
105bool same_float(float a, float b) { return std::memcmp(&a, &b, sizeof a) == 0 || (a == b) || (a != a && b != b); }
106

Callers 1

check_dotFunction · 0.70

Calls 4

fp32_to_fp16Function · 0.85
type_infoFunction · 0.70
qFunction · 0.50
nextMethod · 0.45

Tested by

no test coverage detected