File size: 660 Bytes
111541a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "ggml.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char**argv){
    if(argc<3) return 2;
    long nrows=atol(argv[1]), np=atol(argv[2]);
    long n=nrows*np;
    float *src=malloc(n*sizeof(float));
    if(fread(src,sizeof(float),n,stdin)!=(size_t)n){fprintf(stderr,"read fail\n");return 3;}
    size_t nb=ggml_row_size(GGML_TYPE_Q4_K,np);
    unsigned char *dst=malloc(nb*nrows);
    ggml_quantize_init(GGML_TYPE_Q4_K);
    size_t got=ggml_quantize_chunk(GGML_TYPE_Q4_K,src,dst,0,nrows,np,NULL);
    if(got!=nb*nrows){fprintf(stderr,"quant size mismatch %zu %zu\n",got,nb*nrows);return 4;}
    fwrite(dst,1,got,stdout);
    return 0;
}