Home

Awesome

llm-export

English

llm-export是一个llm模型导出工具,能够将llm模型导出为onnx和mnn模型。

安装

# pip install
pip install llmexport

# git install
pip install git+https://github.com/wangzhaode/llm-export@master

# local install
git clone https://github.com/wangzhaode/llm-export && cd llm-export/
pip install .

用法

  1. 下载模型
git clone https://huggingface.co/Qwen/Qwen2-1.5B-Instruct
# 如果huggingface下载慢可以使用modelscope
git clone https://modelscope.cn/qwen/Qwen2-1.5B-Instruct.git
  1. 测试模型
# 测试文本输入
llmexport --path Qwen2-1.5B-Instruct --test "你好"
# 测试图像文本
llmexport --path Qwen2-VL-2B-Instruct  --test "<img>https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg</img>介绍一下图片里的内容"
  1. 导出模型
# 将Qwen2-1.5B-Instruct导出为onnx模型
llmexport --path Qwen2-1.5B-Instruct --export onnx
# 将Qwen2-1.5B-Instruct导出为mnn模型, 量化参数为4bit, blokc-wise = 128
llmexport --path Qwen2-1.5B-Instruct --export mnn --quant_bit 4 --quant_block 128

功能

参数

usage: llmexport.py [-h] --path PATH [--type TYPE] [--lora_path LORA_PATH] [--dst_path DST_PATH] [--test TEST] [--export EXPORT]
                    [--skip_slim] [--quant_bit QUANT_BIT] [--quant_block QUANT_BLOCK] [--lm_quant_bit LM_QUANT_BIT]
                    [--mnnconvert MNNCONVERT]

llm_exporter

options:
  -h, --help            show this help message and exit
  --path PATH           path(`str` or `os.PathLike`):
                        Can be either:
                        	- A string, the *model id* of a pretrained model like `THUDM/chatglm-6b`. [TODO]
                        	- A path to a *directory* clone from repo like `../chatglm-6b`.
  --type TYPE           type(`str`, *optional*):
                        	The pretrain llm model type.
  --lora_path LORA_PATH
                        lora path, defaut is `None` mean not apply lora.
  --dst_path DST_PATH   export onnx/mnn model to path, defaut is `./model`.
  --test TEST           test model inference with query `TEST`.
  --export EXPORT       export model to an onnx/mnn model.
  --skip_slim           Whether or not to skip onnx-slim.
  --quant_bit QUANT_BIT
                        mnn quant bit, 4 or 8, default is 4.
  --quant_block QUANT_BLOCK
                        mnn quant block, default is 0 mean channle-wise.
  --lm_quant_bit LM_QUANT_BIT
                        mnn lm_head quant bit, 4 or 8, default is `quant_bit`.
  --mnnconvert MNNCONVERT
                        local mnnconvert path, if invalid, using pymnn.

模型下载

ModelModelScopeHugging Face
Qwen-VL-ChatQ4_1Q4_1
Baichuan2-7B-ChatQ4_1Q4_1
bge-large-zhQ4_1Q4_1
chatglm-6bQ4_1Q4_1
chatglm2-6bQ4_1Q4_1
chatglm3-6bQ4_1Q4_1
codegeex2-6bQ4_1Q4_1
deepseek-llm-7b-chatQ4_1Q4_1
gemma-2-2b-itQ4_1Q4_1
glm-4-9b-chatQ4_1Q4_1
gte_sentence-embedding_multilingual-baseQ4_1Q4_1
internlm-chat-7bQ4_1Q4_1
Llama-2-7b-chatQ4_1Q4_1
Llama-3-8B-InstructQ4_1Q4_1
Llama-3.2-1B-InstructQ4_1Q4_1
Llama-3.2-3B-InstructQ4_1Q4_1
OpenELM-1_1B-InstructQ4_1Q4_1
OpenELM-270M-InstructQ4_1Q4_1
OpenELM-3B-InstructQ8_1Q8_1
OpenELM-450M-InstructQ4_1Q4_1
phi-2Q4_1Q4_1
qwen/Qwen-1_8B-ChatQ4_1Q4_1
Qwen-7B-ChatQ4_1Q4_1
Qwen1.5-0.5B-ChatQ4_1Q4_1
Qwen1.5-1.8B-ChatQ4_1Q4_1
Qwen1.5-4B-ChatQ4_1Q4_1
Qwen1.5-7B-ChatQ4_1Q4_1
Qwen2-0.5B-InstructQ4_1Q4_1
Qwen2-1.5B-InstructQ4_1Q4_1
Qwen2-7B-InstructQ4_1Q4_1
Qwen2-VL-2B-InstructQ4_1Q4_1
Qwen2-VL-7B-InstructQ4_1Q4_1
Qwen2.5-0.5B-InstructQ4_1Q4_1
Qwen2.5-1.5B-InstructQ4_1Q4_1
Qwen2.5-3B-InstructQ4_1Q4_1
Qwen2.5-7B-InstructQ4_1Q4_1
Qwen2.5-Coder-1.5B-InstructQ4_1Q4_1
Qwen2.5-Coder-7B-InstructQ4_1Q4_1
Qwen2.5-Math-1.5B-InstructQ4_1Q4_1
Qwen2.5-Math-7B-InstructQ4_1Q4_1
reader-lm-0.5bQ4_1Q4_1
reader-lm-1.5bQ4_1Q4_1
TinyLlama-1.1B-Chat-v1.0Q4_1Q4_1
Yi-6B-ChatQ4_1Q4_1
MobileLLM-125MQ4_1Q4_1
MobileLLM-350MQ4_1Q4_1
MobileLLM-600MQ4_1Q4_1
MobileLLM-1BQ4_1Q4_1
SmolLM2-135M-InstructQ4_1Q4_1
SmolLM2-360M-InstructQ4_1Q4_1
SmolLM2-1.7B-InstructQ4_1Q4_1