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_DEEPSEEK = 1, // 1: deepseek
XLM_MODEL_TYPE_PI0 = 8, // 8: pi0
XLM_MODEL_TYPE_QWEN3 = 9, // 9: qwen3
XLM_MODEL_TYPE_WHISPER = 10, // 10: whisper
XLM_MODEL_TYPE_VLM = 11 // 11: vlm
} xlm_model_type;
typedef enum xlm_image_data_type_e {
XLM_IMAGE_DATA_TYPE_UINT8 = 0, // uint8数据类型
XLM_IMAGE_DATA_TYPE_FP16 = 1, // float16 数据类型
XLM_IMAGE_DATA_TYPE_FP32 = 2 // float32 数据类型
} xlm_image_data_type;
typedef struct vla_params_s {
const char *siglip_model_path; // vla visual模型路径
const char *paligemma_model_path; // vla vl模型路径
const char *action_model_path; // vla action模型路径
const char *norm_stats_path; // norm stats文件路径
}
typedef struct xlm_common_params_s {
const char *model_path; // 模型路径
vlm_params_t vlm_param; // vlm模型参数
vla_params_t vla_param; // vla模型参数(暂不支持)
const char *token_config_path; // tokenizer路径
const char *config_path; // 配置文件路径
bool k_cache_int8; // 是否使用k int8量化
xlm_model_type model_type; // 模型类型
int32_t context_size; // 上下文大小
int32_t max_img_cnt; // 每个request的最大图像数量
common_params_sampling_t sampling; // 采样参数
char *prompt_file; // 外部prompt文件名
char *path_prompt_cache; // prompt缓存文件路径
} xlm_common_params_t;
xlm_create_default_param接口获取默认参数。max_img_cnt 代表每个request的最大输入图像数量,注意输入图像的总token数不要超过对应模型的cache_len长度。
typedef enum xlm_input_type_e {
XLM_INPUT_PROMPT = 0, // 0: prompt输入
XLM_INPUT_TOKEN = 1, // 1: token id输入 (not support yet)
XLM_INPUT_MULTI_MODAL = 2, // 2: 多模态输入
XLM_INPUT_VLA = 3, // 3: VLA输入
XLM_INPUT_AUDIO = 4, // 4: audio输入
} 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_image_data_type image_data_type; // 图片数据类型
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; // 图片数组
bool has_prompt; // 是否有prompt
} xlm_input_multi_modal_t;
多模态输入的结构体。
支持单prompt单图片。
支持单prompt多图片。
typedef struct xlm_input_vla_s {
// tokens
xlm_input_token_t tokens;
// image
int32_t image_num; // 图片数量,支持单prompt对应多img
xlm_input_image_t *images;
// state
int32_t state_size; // 状态长度
double *state; // 原始状态
float *state_preproc; // 预处理状态
// reset
bool reset; // 重置仿真
} xlm_input_vla_t;
typedef struct xlm_output_embed_s {
union {
uint16_t *data_fp16;
float *data_fp32;
};
double *data_fp64;
// embed
int32_t *embed_shape; // embed尺寸
int32_t embed_dim; // embed维度
} xlm_output_embed_t;
typedef struct xlm_output_vla_s {
int32_t embed_num;
xlm_output_embed_t *embeds;
xlm_output_embed_t *kvcache;
} xlm_output_vla_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_lm_request_s {
int32_t request_id; // 请求id,与result返回的结果一一对应
xlm_input_type type; // 输入类型
bool new_chat; // 是否新对话
const char *prompt_json; // omni读取json作为输入
bool need_partial_result; // 是否需要分段解码结果
union {
const char *prompt; // prompt
xlm_input_token_t token; // token id
xlm_input_multi_modal_t multi_modal_requset; // 多模输入
xlm_input_vla_t vla_request; // vla输入
};
const char *system_prompt;
const char *chat_template;
xlm_infer_backend infer_backend; // 推理后端
xlm_priority_t priority; // 优先级
} xlm_lm_request_t;
typedef struct xlm_input_s {
int32_t request_num; // 请求数量
xlm_lm_request_t *requests; // 请求数组
} xlm_input_t;
typedef struct xlm_online_audio_s {
const float *data; // 音频数据首地址
size_t data_size; // 音频数据长度
} xlm_online_audio_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的延迟
double end_to_end_cost; // end to end cost 端到端耗时
} 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;