Instructions to use ljsabc/Fujisaki-int4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ljsabc/Fujisaki-int4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="ljsabc/Fujisaki-int4", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ljsabc/Fujisaki-int4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download quantization_kernels.c from ljsabc/Fujisaki-int4: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/ljsabc/Fujisaki-int4/resolve/main/quantization_kernels.c
- Command line
-
hf download hf://ljsabc/Fujisaki-int4/quantization_kernels.c
-
curl -L -o quantization_kernels.c https://huggingface.co/ljsabc/Fujisaki-int4/resolve/main/quantization_kernels.c
1.16 kB
| void compress_int4_weight(void *weight, void *out, int n, int m) | |
| { | |
| for(int i=0;i<n*m;i++) | |
| { | |
| (*(unsigned char*)(out)) = ((*(unsigned char*)(weight)) << 4); | |
| weight += sizeof(char); | |
| (*(unsigned char*)(out)) |= ((*(unsigned char*)(weight)) & 15); | |
| weight += sizeof(char); | |
| out += sizeof(char); | |
| } | |
| } | |
| void extract_int8_weight_to_float(void *weight, void *scale_list, void *out, int n, int m) | |
| { | |
| for(int i=0;i<n;i++) | |
| for(int j=0;j<m;j++) | |
| (*(float*)(out + sizeof(float) * (i * m + j))) = (*(float*)(scale_list + sizeof(float) * i)) * (*(char*)(weight + sizeof(char) * (i * m + j))); | |
| } | |
| void extract_int4_weight_to_float(void *weight, void *scale_list, void *out, int n, int m) | |
| { | |
| for(int i=0;i<n;i++) | |
| { | |
| for(int j=0;j<m;j++) | |
| { | |
| (*(float*)(out)) = (*(float*)(scale_list)) * ((*(char*)(weight)) >> 4); | |
| out += sizeof(float); | |
| (*(float*)(out)) = (*(float*)(scale_list)) * (((char)((*(unsigned char*)(weight)) << 4))>> 4); | |
| out += sizeof(float); | |
| weight += sizeof(char); | |
| } | |
| scale_list += sizeof(float); | |
| } | |
| } | |