MCPcopy Create free account
hub / github.com/antirez/ds4 / parse_expert_tensor

Function parse_expert_tensor

gguf-tools/deepseek4-quantize.c:881–896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

879 if (n_out) *n_out = out_dim * in_dim;
880 return out;
881}
882
883static float *dequant_fp4_weight(const st_value *w, const st_value *scale, int64_t *n_out) {
884 static const float fp4_table[16] = {
885 0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 3.0f, 4.0f, 6.0f,
886 0.0f, -0.5f, -1.0f, -1.5f, -2.0f, -3.0f, -4.0f, -6.0f,
887 };
888 if (strcmp(w->dtype, "I8") != 0 || strcmp(scale->dtype, "F8_E8M0") != 0) die("bad FP4 weight/scale dtype");
889 if (w->n_dims != 2 || scale->n_dims != 2) die("FP4 tensor must be 2D");
890 const int64_t out_dim = w->shape[0];
891 const int64_t packed_in = w->shape[1];
892 if (packed_in < 0 || packed_in > INT64_MAX / 2) die("FP4 shape is too large");
893 const int64_t in_dim = packed_in * 2;
894 if (in_dim % 32) die("FP4 in_dim is not divisible by 32");
895 const int64_t n_blocks = in_dim / 32;
896 if (scale->shape[0] != out_dim || scale->shape[1] != n_blocks) die("FP4 scale shape mismatch");
897 /* As in dequant_fp8_weight: cross-check the on-disk buffer sizes (from
898 * data_offsets) against the shape-driven indexing so a small data range
899 * under a large declared shape cannot drive an out-of-bounds read. The I8

Callers 3

policy_typeFunction · 0.85
generate_expertFunction · 0.85
generate_tensorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected