27#elif defined(__SSE2__)
30#elif defined(__ARM_NEON)
40 for (;
i <=
n - 8;
i += 8) {
53#elif defined(__SSE2__)
56 for (;
i <=
n - 4;
i += 4) {
68#elif defined(__ARM_NEON)
71 for (;
i <=
n - 4;
i += 4) {
85 for (
int i = 0;
i <
n; ++
i) {
97 for (;
i <=
n - 8;
i += 8) {
106#elif defined(__SSE2__)
109 for (;
i <=
n - 4;
i += 4) {
118#elif defined(__ARM_NEON)
121 for (;
i <=
n - 4;
i += 4) {
131 for (
int i = 0;
i <
n; ++
i) {
139 std::memcpy(&
bits, &
val,
sizeof(
float));
141 bits += 0x7FFF + ((
bits >> 16) & 1);
151 if (
is_nan)
return std::numeric_limits<float>::quiet_NaN();
156 : std::numeric_limits<float>::infinity();
169#pragma omp parallel for
179 throw std::runtime_error(
"Byte vector size mismatch for uint16_t conversion");
191 auto max_it = std::max_element(
v.begin(),
v.end());
195 " at index: " + std::to_string(
max_idx));
201#pragma omp parallel for
213 std::stringstream
ss;
216 ss <<
name <<
": size=" <<
v.size();
221 ss << (
i > 0 ?
" " :
"") << std::fixed << std::setprecision(4) <<
v[
i];
225 float minv = *std::min_element(
v.begin(),
v.end());
226 float maxv = *std::max_element(
v.begin(),
v.end());
227 double sum = std::accumulate(
v.begin(),
v.end(), 0.0);
229 bool all_finite = std::all_of(
v.begin(),
v.end(), [](
float x) { return std::isfinite(x); });
231 <<
", finite=" << (
all_finite ?
"yes" :
"NO");
241 std::stringstream
ss;
258 ss <<
name <<
": size=" <<
v.size();
263 ss << (
i > 0 ?
" " :
"") << std::fixed << std::setprecision(4) <<
v[
i];
271 ss << (
i > 0 ?
" " :
"") << std::fixed << std::setprecision(4)
276 ss <<
" (... tail overlaps head ...)";
279 float minv = *std::min_element(
v.begin(),
v.end());
280 float maxv = *std::max_element(
v.begin(),
v.end());
281 double sum = std::accumulate(
v.begin(),
v.end(), 0.0);
283 bool all_finite = std::all_of(
v.begin(),
v.end(), [](
float x) { return std::isfinite(x); });
285 <<
", finite=" << (
all_finite ?
"yes" :
"NO");
295 const std::vector<float>&
vec_f32,
299 throw std::runtime_error(
300 "matvec_q8_0_f32_vector_cpu: cols (" + std::to_string(
cols) +
301 ") must be divisible by GGML_QK8_0 (" + std::to_string(
GGML_QK8_0) +
")");
304 throw std::runtime_error(
305 "matvec_q8_0_f32_vector_cpu: vec_f32 size mismatch. Expected " +
306 std::to_string(
cols) +
", got " + std::to_string(
vec_f32.size()));
311 throw std::runtime_error(
312 "matvec_q8_0_f32_vector_cpu: mat_q8_0 size mismatch. Expected " +
321#pragma omp parallel for private(dequantized_block)
356 double acc[8] = {0, 0, 0, 0, 0, 0, 0, 0};
358 for (;
i + 8 <=
n;
i += 8)
366 const std::vector<float>&
vec_f32,
371 "matvec_f32_f32_vector_cpu: Input matrix or vector is empty.");
377 "matvec_f32_f32_vector_cpu: Matrix dimensions mismatch. Expected " +
378 std::to_string((
size_t)
rows *
cols) +
", got " +
379 std::to_string(
mat_f32.size()));
385 "matvec_f32_f32_vector_cpu: Vector dimension mismatch. Expected " +
386 std::to_string(
cols) +
", got " + std::to_string(
vec_f32.size()));
400 const std::vector<float>&
vec_f32,
404 throw std::runtime_error(
"matvec_q8k_f32_vector_cpu: cols must be divisible by GGML_QK_K");
410 throw std::runtime_error(
"matvec_q8k_f32_vector_cpu: mat_q8k size mismatch");
413 throw std::runtime_error(
"matvec_q8k_f32_vector_cpu: vec_f32 size mismatch");
429 std::vector<float>&
x,
441 Logger::error(
"RoPE apply_rope_vector: head_dim must be even. head_dim: " + std::to_string(
head_dim));
455 Logger::warning(
"RoPE apply_rope_vector: freq_idx out of bounds. pos: " +
457 ", i: " + std::to_string(
i) +
", calculated freq_idx: " + std::to_string(
freq_idx) +
458 ", all_freqs_cis.size(): " + std::to_string(
all_freqs_cis.size()));
477 Logger::warning(
"RoPE apply_rope_vector: x index out of bounds. x.size(): " + std::to_string(
x.size()) +
478 ", x0_idx: " + std::to_string(
x0_idx) +
", x1_idx: " + std::to_string(
x1_idx));
504 Logger::error(
"apply_rope_batch_cpu: q_batch size mismatch. Expected " +
509 Logger::error(
"apply_rope_batch_cpu: k_batch size mismatch. Expected " +
514 Logger::error(
"apply_rope_batch_cpu: head_dim must be even for RoPE.");
523 ") is out of range [0, " + std::to_string(
max_pos_embeddings -1) +
"]. Skipping RoPE for this token.");
534 Logger::warning(
"[ROPE_BATCH_CPU] Q - Token " + std::to_string(
t) +
", Head " + std::to_string(
h) +
535 ", DimPair " + std::to_string(
i) +
": freq_idx (" + std::to_string(
freq_idx) +
536 ") out of bounds for all_freqs_cis.size (" + std::to_string(
all_freqs_cis.size()) +
"). Skipping pair.");
555 Logger::warning(
"[ROPE_BATCH_CPU] Q - Token " + std::to_string(
t) +
", Head " + std::to_string(
h) +
556 ", DimPair " + std::to_string(
i) +
": q_batch index out of bounds. q_batch.size(): " + std::to_string(
q_batch.size()) +
557 ", idx0: " + std::to_string(
idx0) +
", idx1: " + std::to_string(
idx1) +
". Skipping pair.");
576 Logger::warning(
"[ROPE_BATCH_CPU] K - Token " + std::to_string(
t) +
", Head " + std::to_string(
h) +
577 ", DimPair " + std::to_string(
i) +
": freq_idx (" + std::to_string(
freq_idx) +
578 ") out of bounds for all_freqs_cis.size (" + std::to_string(
all_freqs_cis.size()) +
"). Skipping pair.");
597 Logger::warning(
"[ROPE_BATCH_CPU] K - Token " + std::to_string(
t) +
", Head " + std::to_string(
h) +
598 ", DimPair " + std::to_string(
i) +
": k_batch index out of bounds. k_batch.size(): " + std::to_string(
k_batch.size()) +
599 ", idx0: " + std::to_string(
idx0) +
", idx1: " + std::to_string(
idx1) +
". Skipping pair.");
614 const std::vector<float>& weight,
619 if (
x_batch.empty() ||
x_batch.size() != (
size_t)
num_tokens * hidden_size || weight.size() != (
size_t)hidden_size) {
620 Logger::error(
"[RMSNORM_BATCH_CPU] RMSNorm batch size mismatch or empty input. x_batch.size(): " + std::to_string(
x_batch.size()) +
621 ", expected x_batch: " + std::to_string((
size_t)
num_tokens * hidden_size) +
622 ", weight.size(): " + std::to_string(weight.size()) +
623 ", expected weight: " + std::to_string((
size_t)hidden_size));
629#pragma omp parallel for
634 for (
int i = 0;
i < hidden_size; ++
i) {
642 for (
int i = 0;
i < hidden_size; ++
i) {
649 const std::vector<float>& weight,
650 std::vector<float>&
out,
float eps) {
651 if (
x.empty() ||
x.size() != weight.size()) {
652 Logger::error(
"RMSNorm vector size mismatch or empty input.");
653 out.assign(
x.size(), 0.0f);
656 out.resize(
x.size());
660#pragma omp parallel for reduction(+ : ssq)
662 ssq +=
static_cast<double>(
x[
i]) *
static_cast<double>(
x[
i]);
669#pragma omp parallel for
676 std::vector<float>&
out) {
677 if (
x.empty())
return;
678 out.resize(
x.size());
682 for (
size_t i = 1;
i <
n; ++
i) {
687 for (
size_t i = 0;
i <
n; ++
i) {
694#pragma omp parallel for
711 std::vector<float>
r(E);
713 std::vector<int>
sel;
714 std::vector<char>
taken(E, 0);
715 for (
int j = 0;
j <
k &&
j < E; ++
j) {
717 for (
int e = 0;
e < E; ++
e)
722 std::sort(
sel.begin(),
sel.end());
723 std::vector<float>
gate(E, 0.0f);
725 float mx = -std::numeric_limits<float>::infinity();
729 for (
int e :
sel)
z += std::exp(
static_cast<double>(
r[
e] -
mx));
730 for (
int e :
sel)
gate[
e] =
static_cast<float>(std::exp(
static_cast<double>(
r[
e] -
mx)) /
z);
732 for (
int e = 0;
e < E; ++
e)
mx = std::max(
mx,
r[
e]);
735 for (
int e :
sel)
gate[
e] =
static_cast<float>(std::exp(
static_cast<double>(
r[
e] -
mx)) /
z);
738 std::fill(
out,
out + d, 0.0f);
739 std::vector<float>
h(
d_ff);
743 const float*
u =
up_exps +
static_cast<size_t>(
e) *
d_ff * d;
745 for (
int i = 0;
i <
d_ff; ++
i) {
746 const float gv =
static_cast<float>(
dot_f32_as_f64(g +
static_cast<size_t>(
i) * d,
x, d));
748 h[
i] =
gv * (1.0f / (1.0f + std::exp(-
gv))) *
uv;
750 for (
int o = 0;
o < d; ++
o)
767 moe_ffn_f32_cpu(
x, d,
d_ff, E,
k,
router,
gate_exps,
up_exps,
down_exps,
out,
renorm);
770 std::vector<float>
r(E),
sc(E),
c(E);
773 for (
int e = 0;
e < E; ++
e)
sc[
e] = 1.0f / (1.0f + std::exp(-
r[
e]));
775 float mx = -std::numeric_limits<float>::infinity();
776 for (
int e = 0;
e < E; ++
e)
mx = std::max(
mx,
r[
e]);
778 for (
int e = 0;
e < E; ++
e) {
782 for (
int e = 0;
e < E; ++
e)
sc[
e] =
sc[
e] /
z;
785 std::vector<char>
cand(E, 1);
789 for (
int g = 0; g <
groups_n; ++g) {
790 float a = -std::numeric_limits<float>::infinity(),
b = -std::numeric_limits<float>::infinity();
791 for (
int e = g *
per;
e < (g + 1) *
per; ++
e) {
795 }
else if (
c[
e] >
b) {
810 std::vector<int>
sel;
811 std::vector<char>
taken(E, 0);
812 for (
int j = 0;
j <
k; ++
j) {
814 for (
int e = 0;
e < E; ++
e)
820 std::sort(
sel.begin(),
sel.end());
821 std::vector<float>
gate(E, 0.0f);
825 std::fill(
out,
out + d, 0.0f);
826 std::vector<float>
h(
d_ff);
830 const float*
u =
up_exps +
static_cast<size_t>(
e) *
d_ff * d;
832 for (
int i = 0;
i <
d_ff; ++
i) {
833 const float gv =
static_cast<float>(
dot_f32_as_f64(g +
static_cast<size_t>(
i) * d,
x, d));
835 h[
i] =
gv * (1.0f / (1.0f + std::exp(-
gv))) *
uv;
837 for (
int o = 0;
o < d; ++
o)
843 if (
x.size() !=
out.size())
out.resize(
x.size());
844#pragma omp parallel for
852 if (
x.size() !=
out.size())
out.resize(
x.size());
854#pragma omp parallel for
861 if (
x.size() !=
out.size())
out.resize(
x.size());
862 const float sqrt_2_pi = 0.7978845608028654f;
863 const float coeff = 0.044715f;
864#pragma omp parallel for
881 Logger::error(
"[MATMUL_F32_BATCH_CPU] Input matrix or batch_input_activations is empty.");
886 Logger::error(
"[MATMUL_F32_BATCH_CPU] Matrix dimensions mismatch. Expected " +
894 "[MATMUL_F32_BATCH_CPU] Batch input activations dimension mismatch. Expected " +
920 thread_local std::vector<float>
w_row;
931 const std::vector<float>&
vec_f32,
935 throw std::runtime_error(
936 "matvec_q6k_f32_vector_cpu: cols (" + std::to_string(
cols) +
937 ") must be divisible by GGML_QK_K (" + std::to_string(
GGML_QK_K) +
")");
940 throw std::runtime_error(
941 "matvec_q6k_f32_vector_cpu: vec_f32 size mismatch. Expected " +
942 std::to_string(
cols) +
", got " + std::to_string(
vec_f32.size()));
947 throw std::runtime_error(
948 "matvec_q6k_f32_vector_cpu: mat_q6k size mismatch. Expected " +
950 std::to_string(
mat_q6k.size()));
956#pragma omp parallel for private(dequantized_block)
984 const std::vector<float>&
vec_f32,
988 throw std::runtime_error(
989 "matvec_q4k_f32_vector_cpu: cols (" + std::to_string(
cols) +
990 ") must be divisible by GGML_QK_K (" + std::to_string(
GGML_QK_K) +
")");
993 throw std::runtime_error(
994 "matvec_q4k_f32_vector_cpu: vec_f32 size mismatch. Expected " +
995 std::to_string(
cols) +
", got " + std::to_string(
vec_f32.size()));
1000 throw std::runtime_error(
1001 "matvec_q4k_f32_vector_cpu: mat_q4k size mismatch. Expected " +
1003 std::to_string(
mat_q4k.size()));
1009#pragma omp parallel for private(dequantized_block)
1037 const std::vector<block_q8_0>&
mat_q8_0,
1045 Logger::error(
"[MATMUL_Q8_0_BATCH_CPU] Input matrix or batch_input_activations is empty.");
1051 Logger::error(
"[MATMUL_Q8_0_BATCH_CPU] batch_input_activations size mismatch. Expected " +
1060#pragma omp parallel for
1075 const std::vector<block_q8_K>&
mat_q8k,
1083 throw std::runtime_error(
"matmul_q8k_f32_batch_cpu: input_dim (" + std::to_string(
input_dim) +
1084 ") must be divisible by GGML_QK_K (" + std::to_string(
GGML_QK_K) +
")");
1089 throw std::runtime_error(
"matmul_q8k_f32_batch_cpu: batch_input_activations size mismatch. Expected " +
1096 throw std::runtime_error(
"matmul_q8k_f32_batch_cpu: mat_q8k size mismatch. Expected " +
1118 const std::vector<block_q6_K>&
mat_q6k,
1126 Logger::error(
"[MATMUL_Q6K_BATCH_CPU] Input matrix or batch_input_activations is empty.");
1132 Logger::error(
"[MATMUL_Q6K_BATCH_CPU] batch_input_activations size mismatch. Expected " +
1141#pragma omp parallel for
1156 const std::vector<block_q4_K>&
mat_q4k,
1164 Logger::error(
"[MATMUL_Q4K_BATCH_CPU] Input matrix or batch_input_activations is empty.");
1169 Logger::error(
"[MATMUL_Q4K_BATCH_CPU] batch_input_activations size mismatch. Expected " +
1178#pragma omp parallel for
1193 const std::vector<float>&
vec_f32,
1197 Logger::error(
"matvec_bf16_f32_vector_cpu: Size mismatch. Mat: " +
1198 std::to_string(
mat_bf16.size()) +
" (Expected " +
1200 "), Vec: " + std::to_string(
vec_f32.size()) +
" (Expected " +
1201 std::to_string(
cols) +
")");
1207#pragma omp parallel for
1216 static_cast<double>(weight) *
static_cast<double>(
vec_f32[
c_idx]);
1228 const std::vector<float>&
V,
1229 std::vector<float>&
out,
int seq_len,
int head_dim) {
1230 if (
probs.size() != seq_len ||
V.size() != (
size_t)seq_len *
head_dim) {
1231 Logger::error(
"weighted_sum_probs_v: Size mismatch. Probs: " +
1232 std::to_string(
probs.size()) +
" (Expected " +
1233 std::to_string(seq_len) +
1234 "), V: " + std::to_string(
V.size()) +
" (Expected " +
1235 std::to_string(seq_len *
head_dim) +
")");
1241#pragma omp parallel for
1245 for (
int i = 0;
i < seq_len; ++
i) {
1246 double term =
static_cast<double>(
probs[
i]) *
1254 out[
j] =
static_cast<float>(
sum);
1259 const std::vector<float>& K,
1260 std::vector<float>& scores,
int seq_len,
1262 if (
Q.empty() || K.empty())
return;
1263 scores.resize(seq_len);
1268#pragma omp parallel for collapse(1)
1275 double term =
static_cast<double>(
Q[
j]) *
static_cast<double>(K[
k_offset +
j]);
1291 float minv = *std::min_element(
v.begin(),
v.end());
1292 float maxv = *std::max_element(
v.begin(),
v.end());
1293 float mean = std::accumulate(
v.begin(),
v.end(), 0.0f) /
v.size();
1295 std::all_of(
v.begin(),
v.end(), [](
float x) { return std::isfinite(x); });
1297 std::to_string(
maxv) +
", mean=" + std::to_string(
mean) +
1298 ", all_finite=" + (
all_finite ?
"yes" :
"no"));
1306 Logger::info(
"write_vector_to_file Enter: Address of vec.data() on entry: " +
1307 std::to_string(
reinterpret_cast<uintptr_t>(
vec.data())));
1314 outfile.write(
reinterpret_cast<const char*
>(
vec.data()),
1315 vec.size() *
sizeof(
float));
1326 if (!
infile)
throw std::runtime_error(
"Failed to open " +
filename);
1328 infile.read(
reinterpret_cast<char*
>(
flat.data()),
1329 flat.size() *
sizeof(
float));
1331 throw std::runtime_error(
"Failed to read all data from " +
filename);
1333 std::vector<float>(hidden_size));
1335 for (
int h = 0;
h < hidden_size; ++
h) {
1347 std::stringstream
ss;
1349 for (
size_t i = 0;
i <
count; ++
i) {
1350 if (
i > 0)
ss <<
", ";
1351 ss << std::fixed << std::setprecision(6) <<
ptr[
i];
1358 const std::vector<float>&
v,
1365 std::stringstream
ss;
1367 ss <<
": size=" <<
v.size();
1373 ss << (
i > 0 ?
" " :
"") << std::fixed << std::setprecision(6) <<
v[
i];
1378 float minv = *std::min_element(
v.begin(),
v.end());
1379 float maxv = *std::max_element(
v.begin(),
v.end());
1380 double sum = std::accumulate(
v.begin(),
v.end(), 0.0);
1382 bool all_finite = std::all_of(
v.begin(),
v.end(), [](
float x) { return std::isfinite(x); });
1385 <<
", finite=" << (
all_finite ?
"yes" :
"NO");
static void debug(const std::string &message)
static void warning(const std::string &message)
static void info(const std::string &message)
static void error(const std::string &message)
constexpr size_t GGML_QK8_0
constexpr size_t GGML_QK_K
Block size constants for different quantization formats.
Logging utilities for the TinyLlama implementation.
Constants used throughout the TinyLlama model implementation.
constexpr float MIN_SCALE
constexpr float ATTENTION_SCALE_BASE
constexpr float MAX_SCALE
constexpr uint16_t SIGN_BIT
constexpr uint16_t NEG_ZERO
constexpr uint16_t EXPONENT_MASK
constexpr uint16_t MANTISSA_MASK
void parallel_for(int64_t n, F &&fn)
constexpr float MIN_NORM_EPS
void dequantize_q4_k_m(const block_q4_K *qblock, float *output, int num_weights_in_block, bool log_this_block)
void dequantize_q8_0_block(const block_q8_0 *qblock, float *output)
Dequantizes a Q8_0 block to float32.
void dequantize_q8_k(const std::vector< block_q8_K > &q_data, std::vector< float > &x, int n, bool log_this_block)
void dequantize_q6_k(const block_q6_K *qblock, float *output, int num_weights_in_block, bool log_this_block)
Weight quantization structures and functions for model compression.
4-bit K-quantized block structure
6-bit K-quantized block structure
Simple 8-bit quantized block structure.
void log_raw_float_pointer(const std::string &name, const float *ptr, size_t count)
static double dot_f32_as_f64(const float *a, const float *b, int n)
void apply_rope_vector(std::vector< float > &x, int num_heads, int head_dim, int current_token_pos, const std::vector< std::pair< float, float > > &all_freqs_cis, int max_pos_embeddings, bool use_adjacent_pairing)
float bfloat16_to_float32(uint16_t bf16)
void log_vector_summary(const std::string &name, const std::vector< float > &v, int head_count)
std::vector< uint16_t > uint8_vector_to_uint16_vector(const std::vector< uint8_t > &bytes, size_t numel)
std::vector< float > bfloat16_vector_to_float32(const std::vector< uint16_t > &bf16_vec)
void matvec_q8k_f32_vector_cpu(const std::vector< block_q8_K > &mat_q8k, const std::vector< float > &vec_f32, std::vector< float > &out_f32, int rows, int cols, bool log_first_block)
void matvec_q6k_f32_vector_cpu(const std::vector< block_q6_K > &mat_q6k, const std::vector< float > &vec_f32, std::vector< float > &out_f32, int rows, int cols, bool log_first_block)
void log_vector_summary_with_tail(const std::string &name, const std::vector< float > &v, int head_count, int tail_count)
void matvec_bf16_f32_vector_cpu(const std::vector< uint16_t > &mat_bf16, const std::vector< float > &vec_f32, std::vector< float > &out_f32, int rows, int cols)
void matvec_f32_f32_vector_cpu(const std::vector< float > &mat_f32, const std::vector< float > &vec_f32, std::vector< float > &out_f32, int rows, int cols)
void simd_scaled_add(float *dst, const float *src, float scale, int n)
void log_vector_summary_detailed(const std::string &name, const std::vector< float > &v, int current_pos, int current_layer, int N)
void moe_ffn_routed_f32_cpu(const float *x, int d, int d_ff, int E, int k, const float *router, const float *gate_exps, const float *up_exps, const float *down_exps, float *out, bool renorm, bool sigmoid, const float *bias, int groups_n, int groups_top)
void matmul_q4k_f32_batch_cpu(const std::vector< block_q4_K > &mat_q4k, const std::vector< float > &batch_input_activations, std::vector< float > &batch_output_activations, int num_tokens, int output_dim, int input_dim)
void matmul_rows_f32_batch_cpu(const std::function< void(int64_t, float *)> &row_fn, const float *batch_input_activations, float *batch_output_activations, int num_tokens, int output_dim, int input_dim)
std::vector< float > bf16vec_to_float_vec(const std::vector< uint16_t > &v_bf16)
bool write_vector_to_file(const std::string &filename, const std::vector< float > &vec)
void softmax_vector_cpu(const std::vector< float > &x, std::vector< float > &out)
void gelu_cpu(const std::vector< float > &x, std::vector< float > &out)
int argmax(const std::vector< float > &v)
float simd_dot_product(const float *a, const float *b, int n)
void matvec_q4k_f32_vector_cpu(const std::vector< block_q4_K > &mat_q4k, const std::vector< float > &vec_f32, std::vector< float > &out_f32, int rows, int cols, bool log_first_block)
void matmul_q8_0_f32_batch_cpu(const std::vector< block_q8_0 > &mat_q8_0, const std::vector< float > &batch_input_activations, std::vector< float > &batch_output_activations, int num_tokens, int output_dim, int input_dim)
void apply_rope_batch_cpu(std::vector< float > &q_batch, std::vector< float > &k_batch, int num_tokens, int num_q_heads, int num_kv_heads, int head_dim, int start_pos_in_sequence, const std::vector< std::pair< float, float > > &all_freqs_cis, int max_pos_embeddings, bool use_adjacent_pairing)
void calculate_attention_scores(const std::vector< float > &Q, const std::vector< float > &K, std::vector< float > &scores, int seq_len, int head_dim, float scale)
std::vector< std::vector< float > > load_rmsnorm_bin(const std::string &filename, int num_tokens, int hidden_size)
void weighted_sum_probs_v(const std::vector< float > &probs, const std::vector< float > &V, std::vector< float > &out, int seq_len, int head_dim)
void matmul_f32_f32_batch_cpu(const std::vector< float > &mat_weights, const std::vector< float > &batch_input_activations, std::vector< float > &batch_output_activations, int num_tokens, int output_dim, int input_dim)
void gelu_new_cpu(const std::vector< float > &x, std::vector< float > &out)
void silu_cpu(const std::vector< float > &x, std::vector< float > &out)
void matmul_q8k_f32_batch_cpu(const std::vector< block_q8_K > &mat_q8k, const std::vector< float > &batch_input_activations, std::vector< float > &batch_output_activations, int num_tokens, int output_dim, int input_dim)
void matmul_q6k_f32_batch_cpu(const std::vector< block_q6_K > &mat_q6k, const std::vector< float > &batch_input_activations, std::vector< float > &batch_output_activations, int num_tokens, int output_dim, int input_dim)
void moe_ffn_f32_cpu(const float *x, int d, int d_ff, int E, int k, const float *router, const float *gate_exps, const float *up_exps, const float *down_exps, float *out, bool renorm)
void rmsnorm_batch_cpu(const std::vector< float > &x_batch, const std::vector< float > &weight, std::vector< float > &out_batch, int num_tokens, int hidden_size, float eps)
void log_vec_stats(const std::string &name, const std::vector< float > &v)
void rmsnorm_vector_cpu(const std::vector< float > &x, const std::vector< float > &weight, std::vector< float > &out, float eps)
void matvec_q8_0_f32_vector_cpu(const std::vector< block_q8_0 > &mat_q8_0, const std::vector< float > &vec_f32, std::vector< float > &out_f32, int rows, int cols, bool log_first_block)
uint16_t float32_to_bfloat16(float val)