HelloSun's picture
Initial EPQ openPangu-2.0-Flash release: sources, patches, report and results
00d4f8c verified
Raw History Blame Contribute Delete
1.58 kB
// Dump one ggml-dequantized row so the NumPy reference can be checked against
// ggml's own dequantizers. usage: ggml_deq <type> <file> <offset> <n>
#include "ggml.h"
#include "ggml-quants.h"
#include <cstdio>
#include <cstdlib>
int main(int argc, char ** argv) {
if (argc < 5) {
fprintf(stderr, "usage: %s <type> <file> <offset> <n>\n", argv[0]);
return 1;
}
const int tt = atoi(argv[1]);
const char * path = argv[2];
const long long off = atoll(argv[3]);
const int n = atoi(argv[4]);
FILE * f = fopen(path, "rb");
if (!f) { perror("open"); return 1; }
const size_t ts = ggml_row_size((ggml_type) tt, n);
void * buf = malloc(ts);
if (fseek(f, (long) off, SEEK_SET) != 0) { fprintf(stderr, "seek\n"); return 1; }
if (fread(buf, 1, ts, f) != ts) { fprintf(stderr, "short read\n"); return 1; }
fclose(f);
float * y = (float *) malloc(sizeof(float) * n);
switch (tt) {
case 11: dequantize_row_q3_K((const block_q3_K *) buf, y, n); break;
case 12: dequantize_row_q4_K((const block_q4_K *) buf, y, n); break;
case 13: dequantize_row_q5_K((const block_q5_K *) buf, y, n); break;
case 14: dequantize_row_q6_K((const block_q6_K *) buf, y, n); break;
case 7: dequantize_row_q5_1((const block_q5_1 *) buf, y, n); break;
case 8: dequantize_row_q8_0((const block_q8_0 *) buf, y, n); break;
default: fprintf(stderr, "type %d not handled\n", tt); return 1;
}
fwrite(y, sizeof(float), n, stdout);
free(y);
free(buf);
return 0;
}