Download tools/q4k.c from HelloSun/sdcpp_zimage_opt: direct link, hf CLI and curl.
- Browser
- Download file 660 Bytes
-
https://huggingface.co/HelloSun/sdcpp_zimage_opt/resolve/main/tools/q4k.c
- Command line
-
hf download hf://HelloSun/sdcpp_zimage_opt/tools/q4k.c
-
curl -L -o q4k.c https://huggingface.co/HelloSun/sdcpp_zimage_opt/resolve/main/tools/q4k.c
660 Bytes
| 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; | |
| } | |