RK3588: NPU: Update to 0.9.6 version

This commit is contained in:
yml 2024-07-01 14:00:08 +08:00 committed by baiywt
parent c634cba69c
commit 70a7eec8c2
5 changed files with 100 additions and 29 deletions

View File

@ -12,4 +12,4 @@ SKIP_BOOTSPLASH="yes" # Skip boot splash patch, conflicts with CONFIG_VT=yes
DISTRIB_TYPE_LEGACY="bullseye bookworm bionic focal jammy" DISTRIB_TYPE_LEGACY="bullseye bookworm bionic focal jammy"
DISTRIB_TYPE_CURRENT="bullseye bookworm jammy" DISTRIB_TYPE_CURRENT="bullseye bookworm jammy"
BOOTFS_TYPE="fat" BOOTFS_TYPE="fat"
REVISION="1.0.2" REVISION="1.0.4"

View File

@ -4378,7 +4378,7 @@ CONFIG_VIDEO_GC8034=y
# CONFIG_VIDEO_HI847 is not set # CONFIG_VIDEO_HI847 is not set
# CONFIG_VIDEO_IMX208 is not set # CONFIG_VIDEO_IMX208 is not set
# CONFIG_VIDEO_IMX214 is not set # CONFIG_VIDEO_IMX214 is not set
# CONFIG_VIDEO_IMX219 is not set CONFIG_VIDEO_IMX219=y
# CONFIG_VIDEO_IMX258 is not set # CONFIG_VIDEO_IMX258 is not set
# CONFIG_VIDEO_IMX274 is not set # CONFIG_VIDEO_IMX274 is not set
# CONFIG_VIDEO_IMX290 is not set # CONFIG_VIDEO_IMX290 is not set
@ -4447,7 +4447,7 @@ CONFIG_VIDEO_OV4689=y
CONFIG_VIDEO_OV50C40=y CONFIG_VIDEO_OV50C40=y
# CONFIG_VIDEO_OV5640 is not set # CONFIG_VIDEO_OV5640 is not set
# CONFIG_VIDEO_OV5645 is not set # CONFIG_VIDEO_OV5645 is not set
# CONFIG_VIDEO_OV5647 is not set CONFIG_VIDEO_OV5647=y
# CONFIG_VIDEO_OV5648 is not set # CONFIG_VIDEO_OV5648 is not set
# CONFIG_VIDEO_OV5670 is not set # CONFIG_VIDEO_OV5670 is not set
# CONFIG_VIDEO_OV5675 is not set # CONFIG_VIDEO_OV5675 is not set

View File

@ -207,6 +207,7 @@ prepare_board() {
elif [[ $BOARD =~ orangepi5max|orangepi5ultra ]]; then elif [[ $BOARD =~ orangepi5max|orangepi5ultra ]]; then
rfkill unblock all rfkill unblock all
sleep 2
brcm_patchram_plus --bd_addr_rand --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 \ brcm_patchram_plus --bd_addr_rand --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 \
--baudrate 1500000 --patchram /lib/firmware/SYN43711A0.hcd /dev/ttyS7 & --baudrate 1500000 --patchram /lib/firmware/SYN43711A0.hcd /dev/ttyS7 &
fi fi

View File

@ -5,45 +5,115 @@
extern "C" { extern "C" {
#endif #endif
typedef void* LLMHandle; typedef void* LLMHandle; /* Handle for an instance of a language model. */
/**
* @brief Structure for possible states of an inference call.
*
*/
typedef enum { typedef enum {
LLM_RUN_NORMAL = 0, /*推理状态正常,推理尚未结束*/ LLM_RUN_NORMAL = 0, /* Inference status is normal and inference has not yet finished. */
LLM_RUN_FINISH = 1, /*推理状态正常,推理结束*/ LLM_RUN_FINISH = 1, /* Inference status is normal and inference has finished. */
LLM_RUN_ERROR = 2 /*推理状态异常*/ LLM_RUN_ERROR = 2 /* Inference status is abnormal. */
} LLMCallState; } LLMCallState;
/**
* @brief Structure for setting up parameters for the language model
*
*/
typedef struct { typedef struct {
const char* modelPath; /*模型文件的存放路径*/ const char* model_path; /* Path where the model file is located. */
const char* target_platform; /*模型运行的硬件平台*/ int32_t num_npu_core; /* Number of NPU cores used for model inference. */
int32_t num_npu_core; /*模型推理时使用的 NPU 核心数量*/ int32_t max_context_len; /* Maximum size of the context. */
int32_t max_context_len; /*设置提示上下文的大小*/ int32_t max_new_tokens; /* Maximum number of tokens to generate during model inference. */
int32_t max_new_tokens; /*用于设置模型推理时生成 Token 的数量上限*/ int32_t top_k; /* The number of highest probability tokens to consider for generation. */
float top_p; /* Nucleus sampling: cumulative probability cutoff to use for token selection. */
int32_t top_k; float temperature; /* Hyperparameter to control the randomness of predictions by scaling the logits before applying softmax. */
float top_p; float repeat_penalty; /* Penalty applied to the logits of previously generated tokens, helps prevent repetitive or monotonic text. */
float temperature; float frequency_penalty; /* Penalty for repeating the same word or phrase, reducing the likelihood of repeated content. */
float repeat_penalty; float presence_penalty; /* Penalty or reward for introducing new tokens into the generated text. */
float frequency_penalty; int32_t mirostat; /* Enables mirostat algorithm, where 0 = off, 1 = use mirostat algorithm, 2 = use mirostat 2.0 algorithm. */
float presence_penalty; float mirostat_tau; /* Target entropy (perplexity) for mirostat algorithm, setting the desired complexity of the generated text. */
int32_t mirostat; float mirostat_eta; /* Learning rate for the mirostat algorithm. */
float mirostat_tau; bool logprobs; /* Whether to return the log probabilities for each output token along with their token ids. */
float mirostat_eta; int32_t top_logprobs; /* The number of top tokens for which to return log probabilities, along with their token ids. */
bool use_gpu; /* Flag to indicate whether to use GPU for inference. */
} RKLLMParam; } RKLLMParam;
typedef void(*LLMResultCallback)(const char* result, void* userdata, LLMCallState state); /**
* @brief Structure representing a token with its associated log probability.
*
*/
typedef struct {
float logprob; /* Log probability corresponding to the token ID. */
int id; /* Token ID. */
} Token;
RKLLMParam rkllm_createDefaultParam(); /*初始化RKLLMParam并设置默认参数*/ /**
* @brief Structure to hold the results from the language model inference, including text and token details.
*
*/
typedef struct {
const char* text; /* Decoded text from the inference output. */
Token* tokens; /* Array of Token structures, each containing a log probability and a token ID. */
int num; /* Number of top tokens returned, typically those with the highest probabilities. */
} RKLLMResult;
int rkllm_init(LLMHandle* handle, RKLLMParam param, LLMResultCallback callback); /*模型初始化*/ /**
* @brief Callback function for handling inference results.
*
* @param result A pointer to an RKLLMResult struct containing the inference results.
* @param userdata A pointer to user-defined function or null if no user function was provided.
* @param state The state of the inference process, indicating success, failure, or completion.
*/
typedef void(*LLMResultCallback)(RKLLMResult* result, void* userdata, LLMCallState state);
int rkllm_run(LLMHandle handle, const char* prompt, void* userdata); /*模型推理*/ /**
* @brief Initializes RKLLMParam with default settings.
*
* @return RKLLMParam An RKLLMParam struct with default values set.
*/
RKLLMParam rkllm_createDefaultParam();
int rkllm_destroy(LLMHandle handle); /*模型释放*/ /**
* @brief Initializes the model with specified parameters.
*
* @param handle Pointer to a handle for the language model, which will be initialized by this function.
* @param param An RKLLMParam struct containing all the parameters needed for the model.
* @param callback A function pointer to the callback that handles the results of the inference.
* @return int Returns 0 on success, or a negative error code on failure.
*/
int rkllm_init(LLMHandle* handle, RKLLMParam param, LLMResultCallback callback);
/**
* @brief Releases the model resources.
*
* @param handle The handle to the language model to be destroyed.
* @return int Returns 0 on successful release, or a negative error code if an error occurs.
*/
int rkllm_destroy(LLMHandle handle);
/**
* @brief Runs model inference on the given prompt.
*
* @param handle The handle to the initialized language model.
* @param prompt The text prompt on which to perform inference.
* @param userdata Optional user-defined function that will be passed to the callback.
* @return int Returns 0 on success, or a negative error code if an error occurs during inference.
*/
int rkllm_run(LLMHandle handle, const char* prompt, void* userdata);
/**
* @brief Aborts the current inference process.
*
* @param handle The handle to the language model whose inference is to be aborted.
* @return int Returns 0 if the process is successfully aborted, or a negative error code
* if no process was running or if the abort fails.
*/
int rkllm_abort(LLMHandle handle);
#ifdef __cplusplus #ifdef __cplusplus
} } //extern "C"
#endif #endif
#endif #endif