代码拉取完成,页面将自动刷新
cd usr/local/lib/python3.7/site-packages/msmodelslim/pytorch/weight_compression/compress_graph/
sudo bash build.sh {CANN包安装路径}/ascend-toolkit/latest
chmod -R 550 build
from msmodeslim.pytorch.weight_compression import CompressConfig, Compressor
由于压缩工具调用的压缩函数已将大部分配置参数固定,因此在工具层面无需设置很多参数。
class CompressConfig:
""" The configuration for LLM weight compression """
def __init__(self,
do_pseudo_sparse=False, # whether to do pseudo sparse before compression
sparse_ratio=1, # percentile of non-zero values after pseudo sparse
is_debug=False, # print the compression ratio for each weight if is_debug is True
compress_disable_layers = [], # the layers in compress_disable_layers will not be compressed and directly saved in compress_output
record_detail_root='./', # the save path for the temporary data
multiprocess_num=1) -> object: # multiprocess num
compress_config = CompressConfig(do_pseudo_sparse=False, sparse_ratio=1, is_debug=True, record_detail_root=save_root, multiprocess_num=8)
compressor = Compressor(compress_config, path_save)
compress_weight, compress_index, compress_info = compressor.run()
说明:
compressor.run()
有一个参数bool: weight_transpose
,默认为False
,即是否开启权重转置。目前已知chatGLM2-6B无需开启权重转置#check current limit
ulimit -n
#raise limit to 65535
ulimit -n 65535
调用C编译后的压缩函数,通过文件的形式进行交互,完成权重压缩过程。
compressor.export(compress_weight, weight_root)
compressor.export(compress_index, index_root)
compressor.export(compress_info, info_root, dtype=np.int64) # info数据为int64格式需要特别声明,否则默认将会保存为int8的格式
说明:权重压缩工具在加载输入的权重文件时,存在一定的反序列化攻击安全风险。权重压缩工具通过界面提示操作存在反序列化攻击的安全风险,在加载前用户交互确认加载的权重文件无风险后,再进行后续操作。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。