提供文本推理处理功能。
操作类型:POST
URL:https://{ip}:{port}/v2/models/${MODEL_NAME}[/versions/${MODEL_VERSION}]/generate
参数 |
是否必选 |
说明 |
取值要求 |
---|---|---|---|
id |
可选 |
请求id。 |
stirng,非空。 |
text_input |
必选 |
推理请求文本。 |
非空,0KB<字符数<=512KB,支持中英文。tokenizer之后的token数量<=(maxSeqLen-maxIterTimes)和max_position_embeddings之间的较小值(相关参数从配置文件中获取)。 |
parameters |
可选 |
模型推理后处理相关参数。 |
- |
details |
可选 |
是否返回推理详细输出结果。 |
bool类型,默认值false。 |
do_sample |
可选 |
是否做sampling。 |
bool类型,默认值false。 |
max_new_tokens |
可选 |
允许推理生成的最大token个数。该字段受到配置文件maxIterTimes参数影响,推理token个数<=maxIterTimes。 |
int32_t类型,取值范围(0, maxIterTimes]。默认值20。 |
repetition_penalty |
可选 |
重复惩罚用于减少在文本生成过程中出现重复片段的概率。它对之前已经生成的文本进行惩罚,使得模型更倾向于选择新的、不重复的内容。 |
float类型,大于0,默认值1.0。
建议最大值取2,同时视模型而定。 |
seed |
可选 |
用于指定推理过程的随机种子,相同的seed值可以确保推理结果的可重现性,不同的seed值会提升推理结果的随机性。 |
uint_64类型,取值范围(0, 18446744073709551615],不传递该参数,系统会产生一个随机seed值。 |
temperature |
可选 |
控制生成的随机性,较高的值会产生更多样化的输出。 |
float类型,大于0,默认值1.0。 取值越大,结果的随机性越大。推荐使用大于或等于0.001的值,小于0.001可能会导致文本质量不佳。 建议最大值取2,同时视模型而定。 |
top_k |
可选 |
控制模型生成过程中考虑的词汇范围,只从概率最高的k个候选词中选择。使用限制请参见使用限制。 |
int32_t类型,取值范围[0, 2147483647]&&[0, vocabSize),默认值0。 vocabSize是从modelWeightPath路径下的config.json文件中读取的vocab_size或者padded_vocab_size的值,若不存在则vocabSize取默认值0。建议用户在config.json文件中添加vocab_size或者padded_vocab_size参数,否则可能导致推理失败。 |
top_p |
可选 |
控制模型生成过程中考虑的词汇范围,使用累计概率选择候选词,直到累计概率超过给定的阈值。该参数也可以控制生成结果的多样性,它基于累积概率选择候选词,直到累计概率超过给定的阈值为止。 |
float类型,取值范围(0.0, 1.0],默认值1.0。 |
batch_size |
可选 |
推理请求batch_size。 |
int32_t类型,大于0,默认值1。 |
typical_p |
可选 |
解码输出概率分布指数。 当前后处理不支持。 |
float类型,取值范围(0.0, 1.0],默认值-1.0。 字段未设置时,默认值使用-1.0来表示不进行该项处理,但是不可主动设置为-1.0。 |
watermark |
可选 |
是否带模型水印。 当前后处理不支持。 |
bool类型,默认值false。
|
perf_stat |
可选 |
是否打开性能统计。 |
bool类型,默认值false。
|
请求样例:
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":250, "repetition_penalty": 1.1, "seed": 123, "temperature": 1, "top_k": 10, "top_p": 0.99, "batch_size":100, "typical_p": 0.5, "watermark": false, "perf_stat": false } }
响应样例:
{ "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 |
推理返回结果。 |
details |
object |
推理details结果。 |
finish_reason |
string |
推理结束原因。
|
generated_tokens |
int |
推理产生token数量。 |
first_token_cost |
List[token] |
文本推理返回,首token产生时间,单位:ms,当前未统计该数据,返回null。 |
decode_cost |
int |
decode时间,单位:ms,当前未统计该数据,返回null。 |