From 3849998065109cd061d6f16e73d01c2e59faf9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=A6=E6=99=93=E7=8E=B2?= <3174348550@qq.com> Date: Mon, 20 Oct 2025 18:22:04 +0800 Subject: [PATCH] modify contents --- .../lite/docs/source_en/infer/runtime_java.md | 12 +++++------ .../source_zh_cn/infer/quick_start_java.md | 4 ++-- .../docs/source_zh_cn/infer/runtime_cpp.md | 2 +- .../docs/source_zh_cn/infer/runtime_java.md | 20 +++++++++---------- .../source_zh_cn/mindir/benchmark_tool.md | 2 +- docs/lite/docs/source_zh_cn/mindir/build.md | 2 +- .../source_zh_cn/mindir/converter_custom.md | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/lite/docs/source_en/infer/runtime_java.md b/docs/lite/docs/source_en/infer/runtime_java.md index af1add6704..528d32e36c 100644 --- a/docs/lite/docs/source_en/infer/runtime_java.md +++ b/docs/lite/docs/source_en/infer/runtime_java.md @@ -9,8 +9,8 @@ After the model is converted into a `.ms` model by using the MindSpore Lite mode If MindSpore Lite is used in an Android project, you can use [C++ API](https://www.mindspore.cn/lite/api/en/r2.7.1/index.html) or [Java API](https://www.mindspore.cn/lite/api/en/r2.7.1/index.html) to run the inference framework. Compared with C++ APIs, Java APIs can be directly called in the Java class. Users do not need to implement the code at the JNI layer, which is more convenient. To run the MindSpore Lite inference framework, perform the following steps: 1. Load the model (optional): Read the `.ms` model converted by the model conversion tool introduced in [Converting Models for Inference](https://www.mindspore.cn/lite/docs/en/r2.7.1/converter/converter_tool.html) from the file system. -2. Create a configuration context: Create a configuration context [MSContext](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#mscontext) to save some basic configuration parameters required by a model to guide graph build and execution, including `deviceType` (device type), `threadNum` (number of threads), `cpuBindMode` (CPU core binding mode), and `enable_float16` (whether to preferentially use the float16 operator). -3. Build a graph: Before building a graph, the [build](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#build) API of [Model](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#model) needs to be called to build the graph, including graph partition and operator selection and scheduling. This takes a long time. Therefore, it is recommended that with [Model](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#model) created each time, one graph be built. In this case, the inference will be performed for multiple times. +2. Create a configuration context: Create a configuration context [MSContext](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#mscontext) to save some basic configuration parameters to guide graph build and execution, including `deviceType` (device type), `threadNum` (number of threads), `cpuBindMode` (CPU core binding mode), and `enable_float16` (whether to preferentially use the float16 operator). +3. Build a graph: Before building a graph, the [build](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#build) API of [Model](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#model) needs to be called to build the graph, including graph partition and operator selection and scheduling. This takes a long time. It is recommended that with [Model](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#model) created each time, one graph be built. In this case, the inference will be performed for multiple times. 4. Input data: Before the graph is performed, data needs to be filled in to the `Input Tensor`. 5. Perform inference: Use the [Model](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#model) of the [predict](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/model.html#predict) to perform model inference. 6. Obtain the output: After the graph execution is complete, you can obtain the inference result by `outputting the tensor`. @@ -75,13 +75,13 @@ try { ## Creating a Configuration Context -Create the configuration context [MSContext](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#mscontext) to save some basic configuration parameters required by the session to guide graph build and execution. Configure the number of threads, thread affinity and whether to enable heterogeneous parallel inference via the [init](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#init) interface. MindSpore Lite has a built-in thread pool shared by processes. During inference, `threadNum` is used to specify the maximum number of threads in the thread pool. The default value is 2. +Create the configuration context [MSContext](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#mscontext) to save some basic configuration parameters to guide graph build and execution. Configure the number of threads, thread affinity and whether to enable heterogeneous parallel inference via the [init](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#init) interface. MindSpore Lite has a built-in thread pool shared by processes. During inference, `threadNum` is used to specify the maximum number of threads in the thread pool. The default value is 2. MindSpore Lite supports heterogeneous inference. The preferred backend for inference is specified by `deviceType` of [AddDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#adddeviceinfo). Currently, CPU, GPU and Kirin NPU are supported. During graph build, operator selection and scheduling are performed based on the preferred backend. If the backend supports Float16, you can use the Float16 operator first by setting `isEnableFloat16` to `true`. If it is a Kirin NPU backend, you can also set the Kirin NPU frequency value. The default frequency value is 3, and can be set to 1 (low power consumption), 2 (balanced), 3 (high performance), and 4 (extreme performance). ### Configuring the CPU Backend -If the backend to be performed is a CPU, you need to configure [addDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#adddeviceinfo) after `MSContext` is initialized. In addition, the CPU supports the setting of the core binding mode and whether to preferentially use the float16 operator. +If the backend is a CPU, you need to configure [addDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#adddeviceinfo) after `MSContext` is initialized. In addition, the CPU supports the setting of the core binding mode and whether to preferentially use the float16 operator. The following sample code from [MainActivity.java](https://gitee.com/mindspore/mindspore-lite/blob/r2.7.1/mindspore-lite/examples/runtime_java/app/src/main/java/com/mindspore/lite/demo/MainActivity.java#L59) demonstrates how to create a CPU backend, set the CPU core binding mode to large-core priority, and enable float16 inference: @@ -95,7 +95,7 @@ context.addDeviceInfo(DeviceType.DT_CPU, true); ### Configuring the GPU Backend -If the backend to be performed is heterogeneous inference based on CPU and GPU, you need to add successively [GPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_GPUDeviceInfo.html) and [CPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_CPUDeviceInfo.html) when call [addDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#adddeviceinfo), GPU inference will be used first after configuration. In addition, if enable_float16 is set to true, both the GPU and CPU preferentially use the float16 operator. +If the backend is heterogeneous inference based on CPU and GPU, you need to add successively [GPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_GPUDeviceInfo.html) and [CPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_CPUDeviceInfo.html) when call [addDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#adddeviceinfo), GPU inference will be used first after configuration. In addition, if enable_float16 is set to true, both the GPU and CPU preferentially use the float16 operator. The following sample code demonstrates how to create the CPU and GPU heterogeneous inference backend and how to enable float16 inference for the GPU. @@ -110,7 +110,7 @@ context.addDeviceInfo(DeviceType.DT_CPU, true); ### Configuring the Kirin NPU Backend -If the backend to be performed is heterogeneous inference based on CPU and GPU, you need to add successively [KirinNPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_KirinNPUDeviceInfo.html) and [CPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_CPUDeviceInfo.html) when call [addDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#adddeviceinfo), Kirin NPU inference will be used first after configuration. In addition, if enable_float16 is set to true, both the Kirin NPU and CPU preferentially use the float16 operator. +If the backend is heterogeneous inference based on CPU and GPU, you need to add successively [KirinNPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_KirinNPUDeviceInfo.html) and [CPUDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/generate/classmindspore_CPUDeviceInfo.html) when call [addDeviceInfo](https://www.mindspore.cn/lite/api/en/r2.7.1/api_java/mscontext.html#adddeviceinfo), Kirin NPU inference will be used first after configuration. In addition, if enable_float16 is set to true, both the Kirin NPU and CPU preferentially use the float16 operator. The following sample code demonstrates how to create the CPU and Kirin NPU heterogeneous inference backend and how to enable float16 inference for the Kirin NPU. KirinNPUDeviceInfo frequency can be set by `NPUFrequency`. diff --git a/docs/lite/docs/source_zh_cn/infer/quick_start_java.md b/docs/lite/docs/source_zh_cn/infer/quick_start_java.md index a13fcb9499..434561003d 100644 --- a/docs/lite/docs/source_zh_cn/infer/quick_start_java.md +++ b/docs/lite/docs/source_zh_cn/infer/quick_start_java.md @@ -9,7 +9,7 @@ 使用MindSpore Lite执行推理主要包括以下步骤: 1. 模型加载(可选):从文件系统中读取由[模型转换工具](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/converter/converter_tool.html)转换得到的`.ms`模型。 -2. 创建配置上下文:创建配置上下文[MSContext](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#mscontext),保存会话所需的一些基本配置参数,用于指导图编译和图执行。主要包括`deviceType`:设备类型、`threadNum`:线程数、`cpuBindMode`:CPU绑定模式、`enable_float16`:是否优先使用float16算子。 +2. 创建配置上下文:创建配置上下文[MSContext](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#mscontext),保存基本配置参数,用于指导图编译和图执行。主要包括`deviceType`:设备类型、`threadNum`:线程数、`cpuBindMode`:CPU绑定模式、`enable_float16`:是否优先使用float16算子。 3. 图编译:在图执行前,需要调用[Model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#model)的[build](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#build)接口进行图编译,主要进行子图切分、算子选型调度。这部分会耗费较多时间,所以建议[model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#model)创建一次,编译一次,多次执行。 4. 输入数据:图执行之前需要向输入Tensor中填充数据。 5. 执行推理:使用[model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#model)的[predict](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#predict)进行模型推理。 @@ -31,7 +31,7 @@ - 编译构建 - 在`mindspore-lite/examples/quick_start_java`目录下执行[build脚本](https://gitee.com/mindspore/mindspore-lite/blob/r2.7.1/mindspore-lite/examples/quick_start_java/build.sh),将自动下载MindSpore Lite推理框架库以及文模型文件并编译Demo。 + 在`mindspore-lite/examples/quick_start_java`目录下执行[build脚本](https://gitee.com/mindspore/mindspore-lite/blob/r2.7.1/mindspore-lite/examples/quick_start_java/build.sh),将自动下载MindSpore Lite推理框架库以及模型文件并编译Demo。 ```bash bash build.sh diff --git a/docs/lite/docs/source_zh_cn/infer/runtime_cpp.md b/docs/lite/docs/source_zh_cn/infer/runtime_cpp.md index d7c2fae50e..0a702a766d 100644 --- a/docs/lite/docs/source_zh_cn/infer/runtime_cpp.md +++ b/docs/lite/docs/source_zh_cn/infer/runtime_cpp.md @@ -39,7 +39,7 @@ if (model_buf == nullptr) { ## 创建配置上下文 -上下文会保存一些所需的基本配置参数,用于指导模型编译和模型执行,如果用户通过`new`创建[Context](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#context),不再需要时,需要用户通过`delete`释放。一般在创建编译完[Model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#model)后,[Context](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#context)即可释放。 +上下文会保存一些所需的基本配置参数,用于指导模型编译和模型执行。如果用户通过`new`创建[Context](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#context),不再需要时,需要用户通过`delete`释放。一般在创建编译完[Model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#model)后,[Context](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#context)即可释放。 MindSpore Lite默认执行的后端是CPU,Context创建后调用[MutableDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#mutabledeviceinfo)返回后端信息列表的引用,向列表中添加默认的[CPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#cpudeviceinfo)。 diff --git a/docs/lite/docs/source_zh_cn/infer/runtime_java.md b/docs/lite/docs/source_zh_cn/infer/runtime_java.md index 8e103128eb..f45787c6f2 100644 --- a/docs/lite/docs/source_zh_cn/infer/runtime_java.md +++ b/docs/lite/docs/source_zh_cn/infer/runtime_java.md @@ -4,13 +4,13 @@ ## 概述 -通过[MindSpore Lite模型转换工具](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/converter/converter_tool.html)转换成`.ms`模型后,即可在Runtime中执行模型的推理流程。本教程介绍如何使用[JAVA接口](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/index.html)执行推理。 +通过[MindSpore Lite模型转换工具](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/converter/converter_tool.html)转换成`.ms`模型后,即可在Runtime中执行模型的推理流程。本教程介绍如何使用[Java接口](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/index.html)执行推理。 -Android项目中使用MindSpore Lite,可以选择采用[C++ API](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/index.html)或者[Java API](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/index.html)运行推理框架。Java API与C++ API相比较而言,Java API可以直接在Java Class中调用,用户无需实现JNI层的相关代码,具有更好的便捷性。运行MindSpore Lite推理框架主要包括以下步骤: +Android项目中使用MindSpore Lite,可以选择采用[C++ API](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/index.html)或者[Java API](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/index.html)运行推理框架。Java API相比C++ API,前者可以直接在Java Class中调用,用户无需实现JNI层的相关代码,具有更好的便捷性。运行MindSpore Lite推理框架主要包括以下步骤: 1. 模型读取(可选):从文件系统中读取由[模型转换工具](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/converter/converter_tool.html)转换得到的`.ms`模型。 2. 创建配置上下文:创建配置上下文[MSContext](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#mscontext),保存需要的一些基本配置参数,用于指导模型编译和模型执行,包括设备类型、线程数、绑核模式和使能fp16混合精度推理。 -3. 模型创建、加载与编译:执行推理之前,需要调用[Model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#model)的[build](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#build)接口进行模型加载和模型编译,目前支持加载文件和MappedByteBuffer两种方式。模型加载阶段将文件或者buffer解析成运行时的模型。模型编译阶段主要进行算子选型调度、子图切分等过程,该阶段会耗费较多时间,所以建议Model创建一次,编译一次,多次推理。 +3. 模型创建、加载与编译:执行推理之前,需要调用[Model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#model)的[build](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#build)接口进行模型加载和模型编译,目前支持加载文件和MappedByteBuffer两种方式。模型加载阶段将文件或者buffer解析成运行时的模型。模型编译阶段主要进行算子选型调度、子图切分等过程,该阶段会耗费较多时间。建议Model创建一次,编译一次,多次推理。 4. 输入数据:模型执行之前需要向`输入Tensor`中填充数据。 5. 执行推理:使用[Model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#model)的[predict](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#predict)进行模型推理。 6. 获得输出:图执行结束之后,可以通过`输出Tensor`得到推理结果。 @@ -75,13 +75,13 @@ try { ## 创建配置上下文 -创建配置上下文[MSContext](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#mscontext),保存会话所需的一些基本配置参数,用于指导图编译和图执行。通过[init](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#init)接口配置线程数,线程亲和性和是否开启异构并行推理。MindSpore Lite内置一个进程共享的线程池,推理时通过`threadNum`指定线程池的最大线程数,默认为2线程。 +创建配置上下文[MSContext](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#mscontext),保存基本配置参数,用于指导图编译和图执行。通过[init](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#init)接口配置线程数,线程亲和性和是否开启异构并行推理。MindSpore Lite内置一个进程共享的线程池,推理时通过`threadNum`指定线程池的最大线程数,默认为2线程。 MindSpore Lite推理时的后端可调用[AddDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#adddeviceinfo)接口中的`deviceType`指定,目前支持CPU、GPU和Kirin NPU。在进行图编译时,会根据主选后端进行算子选型调度。如果后端支持float16,可通过设置`isEnableFloat16`为`true`后,优先使用float16算子。如果是Kirin NPU后端,还可以设置Kirin NPU频率值。频率值默认为3,可设置为1(低功耗)、2(均衡)、3(高性能)、4(极致性能)。 ### 配置使用CPU后端 -当需要执行的后端为CPU时,`MSContext`初始化后需要在[addDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#adddeviceinfo)中`DeviceType.DT_CPU`,同时CPU支持设置绑核模式以及是否优先使用float16算子。 +当后端为CPU时,`MSContext`初始化后需要在[addDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#adddeviceinfo)中`DeviceType.DT_CPU`,同时CPU支持设置绑核模式以及是否优先使用float16算子。 下面[示例代码](https://gitee.com/mindspore/mindspore-lite/blob/r2.7.1/mindspore-lite/examples/runtime_java/app/src/main/java/com/mindspore/lite/demo/MainActivity.java#L59)演示如何创建CPU后端,同时设定线程数为2、CPU绑核模式为大核优先并且使能float16推理,关闭并行: @@ -95,7 +95,7 @@ context.addDeviceInfo(DeviceType.DT_CPU, true); ### 配置使用GPU后端 -当需要执行的后端为CPU和GPU的异构推理时,`MSContext`创建后需要在[addDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#adddeviceinfo)中先后添加[GPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#gpudeviceinfo)和[CPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#cpudeviceinfo),配置后将会优先使用GPU推理。如果使能float16推理,GPU和CPU都会优先使用float16算子。 +当后端为CPU和GPU的异构推理时,`MSContext`创建后需要在[addDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#adddeviceinfo)中先后添加[GPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#gpudeviceinfo)和[CPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#cpudeviceinfo),配置后将会优先使用GPU推理。如果使能float16推理,GPU和CPU都会优先使用float16算子。 下面代码演示了如何创建CPU与GPU异构推理后端,同时GPU也设定使能float16推理: @@ -110,7 +110,7 @@ context.addDeviceInfo(DeviceType.DT_CPU, true); ### 配置使用Kirin NPU后端 -当需要执行的后端为CPU和GPU的异构推理时,`MSContext`创建后需要在[addDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#adddeviceinfo)中先后添加[KirinNPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#kirinnpudeviceinfo)和[CPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#cpudeviceinfo),配置后将会优先使用Kirin NPU推理。如果使能float16推理,Kirin NPU和CPU都会优先使用float16算子。 +当需要CPU和Kirin NPU异构推理时,`MSContext`创建后需要在[addDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mscontext.html#adddeviceinfo)中先后添加[KirinNPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#kirinnpudeviceinfo)和[CPUDeviceInfo](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_cpp/mindspore.html#cpudeviceinfo),配置后将会优先使用Kirin NPU推理。如果使能float16推理,Kirin NPU和CPU都会优先使用float16算子。 下面代码演示了如何创建CPU与GPU异构推理后端,其中KirinNPUDeviceInfo可通过`NPUFrequency`来设置Kirin NPU频率。 @@ -136,7 +136,7 @@ boolean ret = model.build(filePath, ModelType.MT_MINDIR, msContext); MindSpore Lite Java接口提供`getInputByTensorName`以及`getInputs`两种方法获得输入Tensor,同时支持`byte[]`或者`ByteBuffer`两种类型的数据,通过[setData](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/mstensor.html#setdata)设置输入Tensor的数据。 -1. 使用[getInputByTensorName](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#getinputbytensorname)方法,根据模型输入Tensor的名称来获取模型输入Tensor中连接到输入节点的Tensor,下面[示例代码](https://gitee.com/mindspore/mindspore-lite/blob/r2.7.1/mindspore-lite/examples/runtime_java/app/src/main/java/com/mindspore/lite/demo/MainActivity.java)演示如何调用`getInputByTensorName`获得输入Tensor并填充数据。 +1. 使用[getInputByTensorName](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#getinputbytensorname)方法,根据模型输入Tensor名称获取连接到输入节点的Tensor,下面[示例代码](https://gitee.com/mindspore/mindspore-lite/blob/r2.7.1/mindspore-lite/examples/runtime_java/app/src/main/java/com/mindspore/lite/demo/MainActivity.java)演示如何调用`getInputByTensorName`获得输入Tensor并填充数据。 ```java MSTensor inputTensor = model.getInputByTensorName("2031_2030_1_construct_wrapper:x"); @@ -204,7 +204,7 @@ model.free(); 使用MindSpore Lite进行推理时,如果需要对输入的shape进行Resize,则可以在模型编译`build`之后调用[Model](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html)的[Resize](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#resize)接口,对输入的Tensor重新设置shape。 -> 某些网络是不支持可变维度,会提示错误信息后异常退出,比如,模型中有MatMul算子,并且MatMul的一个输入Tensor是权重,另一个输入Tensor是输入时,调用可变维度接口会导致输入Tensor和权重Tensor的Shape不匹配,最终导致推理失败。 +> 某些网络不支持可变维度,会提示错误信息后异常退出,比如,模型中有MatMul算子,并且MatMul的一个输入Tensor是权重,另一个输入Tensor是输入时,调用可变维度接口会导致输入Tensor和权重Tensor的Shape不匹配,最终导致推理失败。 下面[示例代码](https://gitee.com/mindspore/mindspore-lite/blob/r2.7.1/mindspore-lite/examples/runtime_java/app/src/main/java/com/mindspore/lite/demo/MainActivity.java#L164)演示如何对MindSpore Lite的输入Tensor进行[Resize](https://www.mindspore.cn/lite/api/zh-CN/r2.7.1/api_java/model.html#resize): @@ -216,7 +216,7 @@ bool ret = model.resize(inputs, dims); ### 查看日志 -当推理出现异常的时候,可以通过查看日志信息来定位问题。针对Android平台,采用`Logcat`命令行工具查看MindSpore Lite推理的日志信息,并利用`MS_LITE` 进行筛选。 +当推理出现异常时,可以通过查看日志信息来定位问题。针对Android平台,采用`Logcat`命令行工具查看MindSpore Lite推理的日志信息,并利用`MS_LITE` 进行筛选。 ```bash logcat -s "MS_LITE" diff --git a/docs/lite/docs/source_zh_cn/mindir/benchmark_tool.md b/docs/lite/docs/source_zh_cn/mindir/benchmark_tool.md index 0cf1aaee79..591d1105af 100644 --- a/docs/lite/docs/source_zh_cn/mindir/benchmark_tool.md +++ b/docs/lite/docs/source_zh_cn/mindir/benchmark_tool.md @@ -12,7 +12,7 @@ 使用Benchmark工具,需要进行如下环境准备工作。 -- 编译:Benchmark工具代码在MindSpore Lite源码的`mindspore-lite/tools/benchmark`目录中,参考构建文档中的[环境要求](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/mindir/build.html#环境准备)和[编译示例](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/mindir/build.html#编译示例)执行编译。 +- 编译:Benchmark工具代码在MindSpore Lite源码的`mindspore-lite/tools/benchmark`目录中。参考构建文档中的[环境要求](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/mindir/build.html#环境准备)和[编译示例](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/mindir/build.html#编译示例)执行编译。 - 运行:参考构建文档中的[编译输出](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/mindir/build.html#目录结构),从编译出来的包中获得`benchmark`工具。 diff --git a/docs/lite/docs/source_zh_cn/mindir/build.md b/docs/lite/docs/source_zh_cn/mindir/build.md index ae9574a969..a46c56e005 100644 --- a/docs/lite/docs/source_zh_cn/mindir/build.md +++ b/docs/lite/docs/source_zh_cn/mindir/build.md @@ -90,7 +90,7 @@ git clone -b r2.7.1 https://gitee.com/mindspore/mindspore-lite.git 1. 商用版下载需要申请权限,下载链接即将发布。 - 2. 社区版下载不受限制,下载链接请前往[CANN社区版](https://www.hiascend.com/developer/download/community/result?module=cann),选择`8.2.RC1`版本,以及在[固件与驱动](https://www.hiascend.com/hardware/firmware-drivers?tag=community)链接中获取对应的固件和驱动安装包,安装包的选择与安装方式请参照上述的商用版安装指引文档。 + 2. 社区版下载不受限制,下载链接请前往[CANN社区版](https://www.hiascend.com/developer/download/community/result?module=cann),选择`8.2.RC1`版本,以及在[固件与驱动](https://www.hiascend.com/hardware/firmware-drivers?tag=community)链接中获取对应的固件和驱动安装包。安装包的选择与安装方式请参照上述的商用版安装指引文档。 - 安装包默认安装路径为`/usr/local/Ascend`。安装后确认当前用户有权限访问昇腾AI处理器配套软件包的安装路径,若无权限,需要root用户将当前用户添加到`/usr/local/Ascend`所在的用户组。 - 安装昇腾AI处理器配套软件所包含的whl包。如果之前已经安装过昇腾AI处理器配套软件包,需要先使用如下命令卸载对应的whl包。 diff --git a/docs/lite/docs/source_zh_cn/mindir/converter_custom.md b/docs/lite/docs/source_zh_cn/mindir/converter_custom.md index ef99736b2f..483aafbc4d 100644 --- a/docs/lite/docs/source_zh_cn/mindir/converter_custom.md +++ b/docs/lite/docs/source_zh_cn/mindir/converter_custom.md @@ -22,7 +22,7 @@ MindSpore Lite的[转换工具](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/ 5. 可选属性`optional_input_names`,数据类型为String[],可选输入名是必选输入名的子集; -6. 可选属性`output_num`,数据类型为int,算子有多输出的时且模型中仅使用第一个输出时需要指定; +6. 可选属性`output_num`,数据类型为int,算子有多输出且模型中仅使用第一个输出时需要指定; 7. 如果自定义算子原始属性是`bool`类型,但由于ONNX属性中无`bool`类型,所以需要以String类型的方式接入,值可以设置为`True`、`true`、`False`和`false`其中之一。 @@ -53,7 +53,7 @@ MindSpore Lite的[转换工具](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/ 与[端侧注册机制](https://www.mindspore.cn/lite/docs/zh-CN/r2.7.1/advanced/third_party/converter_register.html)不同的是,注册位置的参数需要更改。 ```c++ -// register customed Pass +// register custom Pass using mindspore::registry::POSITION_ASCEND; REG_PASS(PassTutorial, opt::PassTutorial) REG_SCHEDULED_PASS(POSITION_ASCEND, {"PassTutorial"}) -- Gitee