1 Star 0 Fork 0

frontcold/ChatGLM-6B-Int4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
quantization_kernels_parallel.c 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
朱宇峰 提交于 2年前 . init
#include <omp.h>
void set_num_threads(int n_threads)
{
omp_set_num_threads(n_threads);
}
int get_num_threads()
{
return omp_get_num_threads();
}
void compress_int4_weight(void *weight, void *out, int n, int m)
{
#pragma omp parallel for
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
(*(unsigned char*)(out + sizeof(unsigned char) * (i * m + j))) = ((*(unsigned char*)(weight + sizeof(unsigned char) * (i * (m << 1) + (j << 1)))) << 4);
(*(unsigned char*)(out + sizeof(unsigned char) * (i * m + j))) |= (((*(unsigned char*)(weight + sizeof(unsigned char) * (i * (m << 1) + ((j << 1) | 1)))) & 15));
}
}
}
void extract_int8_weight_to_float(void *weight, void *scale_list, void *out, int n, int m)
{
#pragma omp parallel for
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)
{
#pragma omp parallel for
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
(*(float*)(out + sizeof(float) * (i * (m << 1) + (j << 1)))) = (*(float*)(scale_list + sizeof(float) * i)) * ((*(char*)(weight + sizeof(char) * (i * m + j))) >> 4);
(*(float*)(out + sizeof(float) * (i * (m << 1) + ((j << 1) | 1)))) = (*(float*)(scale_list + sizeof(float) * i)) * (((char)((*(unsigned char*)(weight + sizeof(char) * (i * m + j))) << 4))>> 4);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/frontcold/ChatGLM-6B-Int4.git
git@gitee.com:frontcold/ChatGLM-6B-Int4.git
frontcold
ChatGLM-6B-Int4
ChatGLM-6B-Int4
master

搜索帮助