文本推理接口

提供文本推理处理功能。

接口格式

操作类型:POST

URL:https://{ip}:{port}/v2/models/${MODEL_NAME}[/versions/${MODEL_VERSION}]/generate

请求参数

参数

是否必选

说明

取值要求

id

可选

请求id。

stirng,非空。

text_input

必选

推理请求文本。

非空,0<字符数<=16000,支持中英文。tokenizer之后的token数量<=maxSeqLen-maxIterTimes(配置文件读取)。

details

可选

是否返回推理详细输出结果。

bool类型,默认值false。

do_sample

可选

是否做sampling。

bool类型,默认值false。

max_new_tokens

可选

允许的最大新标记数目。控制从模型生成的文本中添加到最终输出中的最大词汇数量。该字段受到GIMIS配置文件maxIterTimes参数影响,推理token输出长度<=maxIterTimes。

int类型,取值范围(0, maxIterTimes]。默认值20。

repetition_penalty

可选

重复惩罚用于减少在文本生成过程中出现重复片段的概率。它对之前已经生成的文本进行惩罚,使得模型更倾向于选择新的、不重复的内容。

float类型,大于0,默认值1.0。

  • 1.0表示不进行重复度惩罚。
  • 大于1.0表示对重复进行惩罚。

seed

可选

用于指定推理过程的随机种子,相同的seed值可以确保推理结果的可重现性,不同的seed值会提升推理结果的随机性。

uint_64类型,取值范围(0, 18446744073709551615],不传递该参数,系统会产生一个随机seed值。

temperature

可选

控制生成的随机性,较高的值会产生更多样化的输出。

float类型,大于0,默认值1.0。

  • 1.0表示不进行计算。
  • 大于1.0表示输出随机性提高。

top_k

可选

控制模型生成过程中考虑的词汇范围,只从概率最高的k个候选词中选择。使用限制请参见使用限制

int类型,取值范围[0, 2147483647]&&[0, vocabSize),默认值0。

vocabSize是从modelWeightPath路径下的config.json文件中读取的vocab_size值,若不存在则vocabSize取默认值0。

top_p

可选

控制模型生成过程中考虑的词汇范围,使用累计概率选择候选词,直到累计概率超过给定的阈值。该参数也可以控制生成结果的多样性,它基于累积概率选择候选词,直到累计概率超过给定的阈值为止。

float类型,取值范围(0, 1],默认值1.0。

batch_size

可选

推理请求batch_size。

int类型,大于0,默认值1。

[/versions/${MODEL_VERSION}]字段暂不支持,不传递。

使用样例

请求样例:

POST https://<ip>:<port>/v2/models/llama_65b/generate

请求消息体:

{
  "id":"a123",
  "text_input": "My name is Olivier and I",
  "parameters": {
    "details": true,
    "do_sample": true,
    "max_new_tokens":200,
    "repetition_penalty": 1.1,
    "seed": 123,
    "temperature": 1,
    "top_k": 2147483647,
    "top_p": 0.99,
    "batch_size":100
  }
}

响应样例:

{
 "id":"a123",
 "model_name": "llama_65b",
 "model_version": null,
 "text_output": "am living in South of France.\nI have been addicted to Jurassic Park since very young. I played some video game versions but especially the great first pinball model from William which reminds me a lot of JPOG1 by song (deluxe). Unfortunately, it stopped working and has been unprofitable for a long time before being exchanged for another game. Fortunately there was the computer version. Nevertheless, it came out only on PC in 2003 when mine was too weak... It's just been a couple of months that the game came out on Mac (a whole 15 years late) with the Version 0.91JAMS ! I know this may be a little antique with the realistic animations and versions today, but the memories are very deep-seated . So thank you all rebuilders for keeping alive wonderful games like this one.\nSince then, I try to keep me updated about this game and test if possible later Alpha. Thank you so much for your work!</s>",
 "details": {
  "finish_reason": "eos_token",
  "generated_tokens": 221,
  "first_token_cost": null,
  "decode_cost": null
 }
}

输出说明

返回值

类型

说明

id

string

请求id。

model_name

string

模型名称。

model_version

string

模型版本。当前未统计该数据,返回null。

text_output

string

推理返回结果。

finish_reason

string

推理结束原因。

generated_tokens

int

推理产生token数量。

first_token_cost

List[token]

文本推理返回,首token产生时间,单位:ms,当前未统计该数据,返回null。

decode_cost

int

decode时间,单位:ms,当前未统计该数据,返回null。