# Sophon-Models **Repository Path**: saturn-cloud/sophon-models ## Basic Information - **Project Name**: Sophon-Models - **Description**: 自训练模型转换成bmodel - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-10 - **Last Updated**: 2026-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 模型转换(适用:SE110S-WA32/SE110S-WB16/SE110S-WC08) ## 一、本项目作用 * 将模型文件转换成算能模型格式; * 模型转换流程,将pytorch训练出的模型:.pt----->.onnx----->.bmodel ## 二、项目运行步骤 ### 2.1 拉取项目 ``` cd Sophon-Models git clone https://github.com/sophgo/tpu-mlir.git (有点大,比较耗时) git clone https://github.com/sophgo/sophon-demo.git git clone https://github.com/sophgo/LLM-TPU.git ``` ### 2.2 加载镜像 * 如果没有docker镜像,则加载docker镜像: ``` docker pull sophgo/tpuc_dev:v3.4 ``` 或者 ``` docker pull uhub.service.ucloud.cn/ucas/tpuc_dev:v3.4 ``` * 如果拉取失败,可以使用 ``` wget https://sophon-assets.sophon.cn/sophon-prod-s3/drive/25/04/15/16/tpuc_dev_v3.4.tar.gz docker load -i tpuc_dev_v3.4.tar.gz ``` ### 2.3 启动容器 * 执行```sh 0_start_docker.sh```脚本命令,进入容器内,注意里面的docker镜像名称; ### 2.4 编译 * 进入容器后,执行```./1_bianyi.sh```进行编译,不能用```sh 1_bianyi.sh```,这一步比较耗时,耐心等待; ### 2.5 激活环境: ``` cd ./tpu-mlir source envsetup.sh ``` *** ## 三、模型转换示例 * 模型转换与量化参考:https://github.com/sophgo/tpu-mlir * 具体的模型转换参考: https://github.com/sophgo/sophon-demo/tree/release/sample 和 https://github.com/sophgo/LLM-TPU/tree/main/models ### 3.1 基于1684X的Qwen3VL-2B模型转换 * 下载模型文件: ``` modelscope download --model Qwen/Qwen3-VL-2B-Instruct mkdir -p /workspace/models/LLM cd /workspace/models/LLM mv /root/.cache/modelscope/hub/models/Qwen/Qwen3-VL-2B-Instruct ./ ``` * 模型转换: ``` llm_convert.py -m /workspace/models/LLM/Qwen3-VL-2B-Instruct/ -s 2048 --max_input_length 1024 --quantize w4bf16 -c bm1684x --out_dir qwen3vl_2b --max_pixels 768,768 ``` * 备注: 如果在上面转换过程中发生报错,报错如下: ``` Traceback (most recent call last): File "/workspace/tpu-mlir/python/tools/llm_convert.py", line 110, in config = AutoConfig.from_pretrained(args.model_path, trust_remote_code=True) File "/usr/local/lib/python3.10/dist-packages/transformers/models/auto/configuration_auto.py", line 998, in from_pretrained config_class = CONFIG_MAPPING[config_dict["model_type"]] File "/usr/local/lib/python3.10/dist-packages/transformers/models/auto/configuration_auto.py", line 710, in __getitem__ raise KeyError(key) KeyError: 'qwen3_vl' ``` 则升级transformers/torch,然后再执行转换脚本 ``` pip3 install transformers torchvision -U -i https://mirrors.aliyun.com/pypi/simple/ ``` ### 3.2 基于1684X的Yolov8s模型转换 * 使用pytorch训练好的yolov8s.pt模型转换成yolov8s.onnx格式; * 将转换好的onnx模型文件放置该项目文件夹下,执行转换脚本,下面的示例脚本中是./Led_Rec/led_rec_yolov8s.onnx; ``` model_transform.py --model_name yolov8s --model_def ./Led_Rec/led_rec_yolov8s.onnx --input_shapes [[1,3,640,640]] --mean 0.0,0.0,0.0 --scale 0.0039216,0.0039216,0.0039216 --pixel_format rgb --mlir ./Led_Rec/led_rec.mlir model_deploy.py --mlir ./Led_Rec/led_rec.mlir --quantize F16 --processor bm1684x --model ./Led_Rec/led_rec_yolov8s_fp16.bmodel ```