# mindspore_lite_llm **Repository Path**: ybf521/mindspore_lite_llm ## Basic Information - **Project Name**: mindspore_lite_llm - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-10 - **Last Updated**: 2025-10-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MindSporeLite AI助手 基于MindSporeLite构建的LLM推理AI助手 ### 模型信息 qwen2.5-0.5B,采用w2e4量化算法进行4bit量化,模型大小约260M. ### 运行示例 ![img.png](images/zhaiyao_demo.gif) ### 环境依赖 + DevEco Studio版本>=5.0 + SDK更新到API 11或以上 + 手机系统HarmonyOS 5.0或以上 ### 工程目录: ```text ├───AppScope // 应用全局配置信息 ├───entry │ ├───libs │ │ └───arm64-v8a │ │ └───liblite-turbo.so // MSLite大模型推理so │ └───src │ └───main │ ├───cpp // c++模块代码,对接LLM推理接口 │ ├───ets // ArkTS源码文件 │ └───resources // 资源文件 │ ├───base │ ├───dark │ └───resfile ├───hvigor ├───build-profile.json5 // 构建配置文件 ├───code-linter.json5 ├───hvigor ├───hvigorfile.ts // 编译构建任务脚本 ├───oh-package.json5 // 依赖库的信息 ├───oh-package-lock.json5 └───README.md ``` 有关应用程序包的更多信息,可以参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/application-package-overview - entry/src/main/ets/pages/Index.ets, 主要包含页面绘制和输出流生成控制。 - entry/src/main/cpp, 主要包含LLM推理接口对接代码。 ### MSLite提供的LLM推理接口 LLM推理接口头文件在目录entry/src/main/cpp/include ```text ├───include ├───llm.h ├───llm_config.h └───tokenizer.h // 分词器接口 ``` 1. llm.h提供了Build和Generate接口 > int Build(const LLMConfig &cfg); > 编译模型 > int Generate(const std::vector &input_ids, int *output_ids, bool is_prefill); > 根据输入id生成下一个token 2. llm_config.h推理相关的配置 ```c++ int64_t max_length; // 最大序列长度 int64_t vocab_size; // 词表长度 int hidden_size; // 隐藏层维度 std::string prefill_model_path; // prefill模型路径 std::string decode_model_path; // decode模型路径 std::string backend; // 推理后端, NNRT std::string device; // 执行设备, CPU, NPU std::string embedding_bin_path; // embedding层权重 std::string sin_bin_path; // ROPE中sine std::string cos_bin_path; // ROPE中cosine ``` ### Demo编译安装 1. 配置签名信息 在File-Project Structure-Signing Configs配置签名 ![img_1.png](images/img_1.png) 2. 编译运行 ![img.png](images/img.png)