typedef struct common_params_sampling_s {
int32_t top_k; // 采样时的top_k,<=0表示使用全部词表
float top_p; // top_p采样,1.0表示不启用
float min_p; // 最小概率阈值,0.0表示不启用
float temp; // 温度系数,<=0.0时贪婪采样
float typ_p; // typical_p采样,1.0表示不启用
int32_t min_keep; // 最小保留token数
int32_t penalty_last_n; // 控制“检查多近的历史”,只在最近n个token里应用重复惩罚
float penalty_repeat; // 重复惩罚系数,越大越不重复
float penalty_freq; // 频率惩罚系数,越大越不重复
float penalty_present; // 在场惩罚系数,只要出现过就惩罚一次
} common_params_sampling_t;
typedef enum xlm_model_type_e {
XLM_MODEL_TYPE_INTERNVL = 0, // 0: internvl (not support yet)
XLM_MODEL_TYPE_DEEPSEEK = 1, // 1: deepseek
XLM_MODEL_TYPE_QWEN = 2, // 2: qwen (not support yet)
XLM_MODEL_TYPE_LLAMA = 3, // 3: llama (not support yet)
XLM_MODEL_TYPE_INTERNLM = 4, // 4: internlm
XLM_MODEL_TYPE_OMNI = 5, // 5: omni
XLM_MODEL_TYPE_QWEN_VL = 6, // 6: qwen-vl (not support yet)
XLM_MODEL_TYPE_QWEN2_5 = 7, // 7: qwen2.5
} xlm_model_type;
typedef struct xlm_common_params_s {
const char *model_path; // 模型文件路径
const char *omni_visual_model_path; // omni visual模型路径
const char *omni_audio_model_path; // omni audio模型路径
const char *omni_text_model_path; // omni text模型路径
bool omni_online_mode; // omni是否为online模式
const char *embed_tokens; // omni embed_tokens路径
const char *token_config_path; // 分词器配置路径
const char *config_path; // 其他配置文件路径
bool k_cache_int8; // 是否使用k int8量化
xlm_model_type model_type; // 模型类型
int32_t context_size; // 上下文长度
common_params_sampling_t sampling; // 采样参数
char *prompt_file; // 外部prompt文件名
char *path_prompt_cache; // prompt缓存文件路径
} xlm_common_params_t;
xlm_create_default_param接口获取默认参数。typedef enum xlm_input_type_e {
XLM_INPUT_PROMPT = 0, // 纯文本prompt输入
XLM_INPUT_TOKEN = 1, // token id输入(暂不支持)
XLM_INPUT_MULTI_MODAL = 2 // 多模态输入
} xlm_input_type;
typedef enum xlm_infer_backend_e {
XLM_INFER_BACKEND_ANY = 0, // 任意核
XLM_INFER_BACKEND_BPU_ANY = 1, // 任意BPU核
XLM_INFER_BACKEND_BPU_0 = 2, // BPU核0
XLM_INFER_BACKEND_BPU_1 = 3, // BPU核1
XLM_INFER_BACKEND_BPU_2 = 4, // BPU核2
XLM_INFER_BACKEND_BPU_3 = 5 // BPU核3
} xlm_infer_backend;
typedef enum xlm_img_preprocess_type_e {
XLM_IMG_PREPROCESS_DYNAMIC = 0, // 动态分辨率(默认)
XLM_IMG_PREPROCESS_NONE = 1 // 无预处理
} xlm_img_preprocess_type;
typedef struct xlm_input_token_s {
int32_t *tokens; // token id数组
int32_t tokens_size; // token数量
} xlm_input_token_t;
typedef struct xlm_input_image_s {
const char *image_path; // 图片路径(二选一)
const uint8_t *image_data; // 图片数据(二选一)
int32_t image_width; // 图片宽度
int32_t image_height; // 图片高度
xlm_img_preprocess_type image_preprocess; // 预处理方式
} xlm_input_image_t;
typedef struct xlm_input_multi_modal_s {
const char *prompt; // 文本prompt
int32_t image_num; // 图片数量
xlm_input_image_t *images; // 图片数组
} xlm_input_multi_modal_t;
多模态输入的结构体。
支持单prompt单图片。
支持单prompt多图片。(当前版本暂未支持)
typedef struct omni_online_video_s {
uint8_t *y_ptr; // nv12的y分量地址
uint8_t *uv_ptr; // nv12的uv分量地址
int32_t width; // nv12的宽度
int32_t height; // nv12的高度
} omni_online_video_t;
typedef struct omni_online_audio_s {
const float *data; // 音频数据首地址
int32_t data_size; // 音频数据长度
} omni_online_audio_t;
typedef struct omni_online_text_s {
const char *system_text; // system文本内容
const char *user_text; // user文本内容
} omni_online_text_t;
typedef enum xlm_priority_type_e {
XLM_PRIORITY_TYPE_NORMAL = 0, // 普通
XLM_PRIORITY_TYPE_HIGH = 1, // 高
XLM_PRIORITY_TYPE_URGENT = 2 // 紧急
} xlm_priority_type_t;
typedef struct xlm_priority_s {
xlm_priority_type_t type; // 优先级类型
int32_t priority; // 仅NORMAL时有效,0~253
} xlm_priority_t;
模型输入请求优先级设置。
抢占关系如下:
XLM_PRIORITY_TYPE_URGENT --抢占--> XLM_PRIORITY_TYPE_HIGH --抢占--> XLM_PRIORITY_TYPE_NORMAL。当优先级同为NORMAL时不会发生抢占,但会根据priority的值在决定谁会优先执行。
typedef struct xlm_ppl_s {
bool load_ckpt; // 是否启用断点续测功能
int32_t text_data_num; // 截断文本到特定长度
int32_t max_length; // 每次送入模型的序列长度
int32_t stride; // 测试步长
const char *testcase_name; // 测试用例的文件名
const char *hbm_path; // 测试模型的路径
} xlm_ppl_t;
typedef struct xlm_lm_request_s {
int32_t request_id; // 请求id,与result返回的结果一一对应
xlm_input_type type; // 输入类型
bool new_chat; // 是否新对话
const char *prompt_json; // omni读取json作为输入
union {
const char *prompt;
xlm_input_token_t token;
xlm_input_multi_modal_t multi_modal_requset;
};
const char *system_prompt;
const char *chat_template;
xlm_infer_backend infer_backend; // 推理后端
xlm_priority_t priority; // 优先级
xlm_ppl_t *ppl; // PPL参数
} xlm_lm_request_t;
typedef struct xlm_input_s {
int32_t request_num; // 请求数量
xlm_lm_request_t *requests; // 请求数组
} xlm_input_t;
typedef struct xlm_model_performance_s {
double vit_cost; // vit cost时间 ms
int64_t prefill_token_num; // prefill token数量
double prefill_tps; // prefill 速度 tokens/s
int64_t decode_token_num; // decode token数量
double decode_tps; // decode速度 tokens/s
double ttft; // time to first token 首字延迟
double tpot; // time per output token 每输出一个token的延迟
} xlm_model_performance_t;
typedef struct xlm_result_s {
char *text; // 推理结果文本
int32_t request_id; // 对应请求id
xlm_model_performance_t performance; // 模型性能数据
} xlm_result_t;
typedef enum xlm_state_e {
XLM_STATE_START = 0, // 开始
XLM_STATE_END = 1, // 结束
XLM_STATE_RUNNING = 2, // 运行中
XLM_STATE_ERROR = 3 // 错误
} xlm_state_t;