oellm_build工具

oellm_build工具是地瓜提供的将原始浮点模型映射为量化模型的工具。基于原始浮点模型、json配置文件(可选)和校准数据(可选)完成模型的量化及编译,最终生成可用于部署的*.hbm模型。

使用方法

usage: oellm_build [-h] --model_name MODEL_NAME --march {nash-e,nash-m} --input_model_path INPUT_MODEL_PATH --output_model_path OUTPUT_MODEL_PATH [--cache_len CACHE_LEN] [--chunk_size CHUNK_SIZE] [--device DEVICE] [--calib_text_path CALIB_TEXT_PATH] [--calib_conversation_path CALIB_CONVERSATION_PATH] Compile a Large Language Model for deployment on hardware. options: -h, --help show this help message and exit --model_name MODEL_NAME Model name. Supported models and their marches: - deepseek-qwen-1_5b: nash-e, nash-m - deepseek-qwen-7b: nash-e, nash-m - qwen2_5-1_5b: nash-e, nash-m - qwen2_5-7b: nash-e, nash-m - internlm2-1_8b: nash-e, nash-m - qwen2_5-omni-3b: nash-e, nash-m --march {nash-e,nash-m} Target hardware architecture for compilation. (Required) --input_model_path INPUT_MODEL_PATH Path to the source model directory. (Required) --output_model_path OUTPUT_MODEL_PATH Path to save the compiled model. (Required) --cache_len CACHE_LEN Maximum sequence length for the KV-cache. (default: 4096). Note: cache_len must be an integer multiple of chunk_size. --chunk_size CHUNK_SIZE Number of tokens per prefill chunk. (default: 256) --device DEVICE Compute device: 'cpu' (default), 'cuda'/'cuda:0', or 'cuda:<index>'. Using CUDA on x86 can accelerate calibration. --calib_text_path CALIB_TEXT_PATH Path to the calibration JSON file or directory of JSON files. (Optional) --calib_conversation_path CALIB_CONVERSATION_PATH Path to the conversation for Qwen2.5-Omni. (Optional)

命令行参数

参数名称参数说明可选/必选
--model_name

参数描述:模型名称。
参数类型string
取值范围deepseek-qwen-1_5bdeepseek-qwen-7bqwen2_5-1_5bqwen2_5-7binternlm2-1_8bqwen2_5-omni-3b
默认配置:无。

必选
--input_model_path

参数描述:指定浮点模型路径。
参数类型string
取值范围:无。
默认配置:无。

必选
--output_model_path

参数描述:用于保存量化编译后生成的模型路径。
参数类型string
取值范围:无。
默认配置:无。

必选
--march

参数描述:指定产生出上板模型需要支持的平台结构。
参数类型string
取值范围:S100对应nash-e,S100P对应nash-m
默认配置:无。

必选
--calib_text_path

参数描述:用于设置文本calibrate数据所在路径,支持配置单个json文件路径或者文件夹路径。
参数类型string
取值范围:无。
默认配置:无。
相关配置文件说明/示例,请参考 json配置文件说明 小节。
注意:如果不配置此参数,则使用默认的数据集进行校验。

可选
当模型为Qwen2.5-Omni模型时,配置不生效,无需配置。

--calib_conversation_path

参数描述:用于设置校准数据所在路径,仅支持配置单个json路径或者文件夹路径。
参数类型string
取值范围:无。
默认配置:无。
相关配置文件说明/示例,请参考 json配置文件说明 小节。
注意::当模型属于S100/S100P平台所支持的类型且为Qwen2.5-Omni模型时,可按需配置此参数。如果不配置,则使用默认的数据集进行校验。

可选
--chunk_size

参数描述:用于指定输入chunk size。
参数类型int
取值范围[128, 2048]
默认配置256
注意::当模型为Qwen2.5-Omni时,chunk_size仅支持256

可选
--cache_len

参数描述:用于指定kv cache大小。
参数类型int
取值范围[256, 4096]
默认配置4096
注意:

  • 当模型为Qwen2.5-Omni时,cache_len仅支持2048
  • cache_len的值必须大于chunk_size且cache_len必须是chunk_size的整数倍。

可选
--device

参数描述:用于设置使用的计算设备。
参数类型String
取值范围'cpu''cuda'(等同于'cuda:0')、'cuda:\<index>'
默认配置'cpu'
参考示例:使用 GPU 1时为'cuda:1'

可选

json配置文件说明

  1. 文本calibrate数据json配置文件,参考示例如下:

    [ {"text": "<|User|>请展开描述人工智能的未来发展。<|Assistant|><think>从技术、伦理、产业发展等角度深入分析,并预测可能的发展趋势。</think><|Assistant|>"}, {"text": "<|User|>写一首关于春天的七言绝句。<|Assistant|><think>围绕春天的意象,如风、花、鸟、柳,构建诗句。</think><|Assistant|>"} ]
  2. Qwen2.5-Omni模型所需calibrate数据json配置文件,参考示例如下:

    [ { "conversation": [ { "role": "system", "content": [ {"type": "text", "text": "You are Qwen, a virtual human developed by the Qwen Team, Alibaba Group, capable of perceiving auditory and visual inputs, as well as generating text and speech."} ] }, { "role": "user", "content": [ {"type": "text", "text": "使用中文回复"}, {"type": "video", "video": "./draw.mp4"}, {"type": "image", "image": "./images/image4.jpg"}, {"type": "audio", "audio": "./audios/audio2.mp3"} ] } ] } ]

配置文件参数说明:

(1) 当"role""system"时,content列表中的第一个元素必须是文本元素,且包含text字段,否则会在格式化模板时访问不到text而报错。

注解

支持在同一conversation中存在多个system消息,但是首条必须是文本元素,且包含text字段。除首条以外,其他system消息支持类型包含textaudioimagevideo

(2) 当"role""user"时,content列表中支持类型包含textaudioimagevideo。具体规则如下:

注解

content列表支持两种消息组织形式:

  1. 同一类型的消息:可包含单个或多个(如多个text消息、多个image消息,多个video消息,多个audio消息)。

  2. 不同类型的消息:可将多种类型组合(如text+image+audio消息搭配)。

  • content列表中类型为"text"时:

    • 格式限制:无特殊格式要求,纯文本、带标点的句子、短句指令、长段落等均支持。

    • 来源支持:无固定来源限制。

    • 参考示例

    [ { "conversation": [ { "role": "user", "content": [ {"type": "text", "text": "使用中文回复"} ] } ] } ]
  • content列表中类型为"video"时:

    • 格式限制MP4MKV

    • 来源支持:本地视频文件、本地文件URL(file://)、网络URL(http(s)://)。

    • 参考示例

    [ { "conversation": [ { "role": "user", "content": [ {"type": "video", "video": "./draw.mp4"}, //本地视频文件 {"type": "video", "video": "file://server/audios/draw.mp4"}, //本地文件URL {"type": "video", "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-Omni/draw.mp4"} //网络URL ] } ] } ]
  • content列表中类型为"image"时:

    • 格式限制PNGJPGJPEGBMP

    • 来源支持:本地图像文件、本地文件URL(file://)、网络URL(http(s)://)、Data URI。

    • 参考示例

    [ { "conversation": [ { "role": "user", "content": [ {"type": "image", "image": "./images/image4.jpg"}, //本地图像文件 {"type": "image", "image": "file://server/audios/image1.jpg"}, //本地文件URL {"type": "image", "image": "https://huggingface.co/OpenGVLab/InternVL2-1B/blob/main/examples/image1.jpg"}, //网络URL {"type": "image", "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIHWP4//8/AwAI/AL+4J4fNQAAAABJRU5ErkJggg=="} //Data URI ] } ] } ]
  • content列表中类型为"audio"时:

    • 格式限制WAVMP3FLAC

    • 来源支持:本地音频文件、本地文件URL(file://)、网络URL(http(s)://)、Data URI。

    • 参考示例

    [ { "conversation": [ { "role": "user", "content": [ {"type": "audio", "audio": "./audios/audio2.mp3"}, //本地音频文件 {"type": "audio", "audio": "file://server/audios/image1.flac"}, //本地文件URL {"type": "audio", "audio": "https://huggingface.co/datasets/hf-internal-testing/dummy-flac-single-example/blob/main/example.flac"}, //网络URL {"type": "audio", "audio": "data:audio/wav;base64,xxxxx...AA"} //Data URI ] } ] } ]

使用示例

  • DeepSeek-R1-Distill-Qwen模型使用oellm_build工具进行模型量化,参考命令如下:

    oellm_build \ --model_name ${model_name} \ --input_model_path ${input_model_path} \ --output_model_path ${output_model_path} \ --march ${march} \ --calib_text_path ${calib_text_path} \ --chunk_size ${chunk_size} \ --cache_len ${cache_len}
  • DeepSeek-R1-Distill-Qwen模型使用oellm_build工具进行模型量化,并对量化生成的HBM模型进行一致性校验,参考命令如下:

    oellm_build \ --model_name ${model_name} \ --input_model_path ${input_model_path} \ --output_model_path ${output_model_path} \ --march ${march} \ --calib_text_path ${calib_text_path} \ --chunk_size ${chunk_size} \ --cache_len ${cache_len} \ --verifier \ --remote_ip ${march} \
  • InternLM2模型使用oellm_build工具进行模型量化,参考命令如下:

    oellm_build \ --model_name ${model_name} \ --input_model_path ${input_model_path} \ --output_model_path ${output_model_path} \ --march ${march} \ --calib_text_path ${calib_text_path} \ --chunk_size ${chunk_size} \ --cache_len ${cache_len}
  • Qwen2.5模型使用oellm_build工具进行模型量化,参考命令如下:

    oellm_build \ --model_name ${model_name} \ --input_model_path ${input_model_path} \ --output_model_path ${output_model_path} \ --march ${march} \ --calib_text_path ${calib_text_path} \ --chunk_size ${chunk_size} \ --cache_len ${cache_len}
  • Qwen2.5-Omni模型使用oellm_build工具进行模型量化,参考命令如下:

    oellm_build \ --model_name ${model_name} \ --input_model_path ${input_model_path} \ --output_model_path ${output_model_path} \ --calib_conversation_path ${calib_conversation_path} \ --march ${march} \ --chunk_size ${chunk_size} \ --cache_len ${cache_len}