第三方服务调用此接口执行模型推理。
def forward(self, model_inputs, **kwargs): logits = self.model_wrapper.forward(model_inputs, self.cache_pool.npu_cache, **kwargs) return logits
参数名称 |
是否必选 |
类型 |
默认值 |
描述 |
安全声明 |
---|---|---|---|---|---|
model_inputs |
必选 |
ModelInput |
- |
模型的输入参数。 |
推理强依赖数据的合法性,需由用户保证。 |
**kwargs中的q_lens |
可选 |
List[int] |
- |
在并行解码场景下,单次decode增量输入的token长度。 |
|
**kwargs中的spec_mask |
可选 |
torch.Tensor |
- |
并行解码场景下生成的mask。 |
forward接口中的model_inputs参数通过ModelInput类进行构造。
文件路径:mindie_llm/text_generator/utils/input.py。
ModelInput类的初始化参数说明如下:
参数名称 |
是否必选 |
类型 |
默认值 |
描述 |
安全声明 |
---|---|---|---|---|---|
input_ids |
必选 |
np.ndarray |
- |
输入经过tokenizer后,每个token在词表中的索引。 |
推理强依赖数据的合法性,需由用户保证。 |
position_ids |
必选 |
np.ndarray或None |
- |
Token的位置索引。 |
|
is_prefill |
必选 |
bool |
- |
是否为推理首token阶段。 |
|
block_tables |
必选 |
np.ndarray |
- |
存储每个token和它所使用的KV Cache块之间的映射。 |
|
slots |
必选 |
np.ndarray |
- |
存储每个KV Cache块中实际使用的slots的序号。 |
|
context_length |
必选 |
np.ndarray或List[int] |
- |
batch中每个query的长度。(输入+当前输出的长度。) |
|
max_seq_len |
必选 |
int |
- |
模型支持的最大上下文长度。(即最大可支持的输入+输出的长度。) |
|
prefill_head_indices |
必选 |
np.ndarray或None |
- |
设置此值可根据索引选择性地输出logits。 |
|
query_length |
可选 |
Optional[np.ndarray] |
None |
请求的长度。 |