Streaming Inference API
Function
Processes streaming inference.
This API is scheduled for deprecation. The OpenAI API is recommended.
Format
Operation type: POST
URL: https://{ip}:{port}/v2/models/${MODEL_NAME}[/versions/${MODEL_VERSION}]/generate_stream
- Replace {ip} and {port} with the IP address and port number of the service plane, that is, ipAddress and port.
- The ${MODEL_NAME} field specifies the name of the model to be queried.
- The [/versions/${MODEL_VERSION}] field is not supported currently and is not passed.
Request Parameters
Parameter |
Mandatory/Optional |
Description |
Value |
|
|---|---|---|---|---|
id |
Optional |
Request ID. |
The value is a string of a maximum of 256 characters. Only underscores (_), hyphens (-), uppercase letters, lowercase letters, and digits are allowed. |
|
text_input |
Mandatory |
Inference request content. The value is of the string type for a single-modal text model and of the list type for a multimodal model. |
|
|
- |
type |
Optional |
Inference request content type. |
Instructions for using multimedia files:
NOTE:
Security warning:
|
text |
Optional |
The inference request content is text. |
The value cannot be empty. Both Chinese and English are supported. |
|
image_url |
Optional |
Indicates that the inference request content is an image. |
Local JPG, PNG, JPEG, and Base64-encoded JPG images can be imported in URL format. Both HTTP and HTTPS protocols are supported. Currently, the maximum size of an image is 40 MB. |
|
video_url |
Optional |
Indicates that the inference request content is a video. |
Local MP4, AVI, and WMV videos can be imported in URL format. Both HTTP and HTTPS protocols are supported. Currently, the maximum size of a video file is 512 MB. |
|
audio_url |
Optional |
The inference request content is audio. |
Local MP3, WAV, and FLAC audio files can be imported in URL format. Both HTTP and HTTPS protocols are supported. Currently, the maximum size of an audio file is 40 MB. |
|
parameters |
Optional |
Parameters related to model inference postprocessing. |
- |
|
- |
details |
Optional |
Whether to return the detailed inference output result. |
The value is of the Boolean type. The default value is false. |
do_sample |
Optional |
Whether to perform sampling. |
The value is of the Boolean type. If this parameter is not passed, other postprocessing parameters determine whether sampling should be performed.
|
|
max_new_tokens |
Optional |
Specifies the maximum number of tokens that can be generated during inference. The number of generated tokens is also affected by the maxIterTimes parameter in the configuration file. The number of inference tokens is less than or equal to the value of Min(maxIterTimes, max_new_tokens). |
The value is of the int type. The value range is (0, 2147483647]. The default value is 20. |
|
repetition_penalty |
Optional |
Repetition penalty used to reduce the probability of duplicate fragments during text generation. It penalizes previously generated text, making the model more inclined to choose new, non-repeated content. |
The value is of the float type. The default value is 1.0. The value must be greater than 0.0.
It is recommended that the maximum value be set to 2.0. The value depends on the model. |
|
seed |
Optional |
Specifies the random seed of the inference process. The same seed value ensures the reproducibility of the inference result, and different seed values improve the randomness of the inference result. |
The value is of the uint64_t type. The value range is (0, 18446744073709551615]. If this parameter is not passed, the system generates a random seed value. When the value of seed is close to the maximum value, a warning is generated, which does not affect normal use. To delete the warning, decrease the value of seed. |
|
temperature |
Optional |
Controls the randomness of generation. Higher values produce more diversified outputs. |
The value is of the float type. The value is greater than 1e-6. The default value is 1.0. A larger value indicates greater randomness of the result. You are advised to use a value greater than or equal to 0.001. If the value is less than 0.001, the text quality may be poor. It is recommended that the maximum value be set to 2.0. The value depends on the model. |
|
top_k |
Optional |
Controls the vocabulary range considered during model generation. Only k candidate words with the highest probability are selected. |
The value is of the int32_t type. The value range is (0, 2147483647]. If the field is not set, the default value is determined by the backend model.
If the value is greater than or equal to vocabSize, the default value is vocabSize. The value of vocabSize is the same as that of vocab_size or padded_vocab_size in the config.json file in the modelWeightPath directory. If vocab_size or padded_vocab_size does not exist, the default value 0 is used. You are advised to add vocab_size or padded_vocab_size to the config.json file. Otherwise, the inference may fail. |
|
top_p |
Optional |
Controls the vocabulary range considered during model generation and selects candidate words using the cumulative probability until it exceeds a given threshold. This parameter can also control the diversity of generated results. |
The value is of the float type. The value range is (1e-6, 1.0]. The default value is 1.0. |
|
batch_size |
Optional |
Batch size of the inference request. |
The value is of the int type. The value range is (0, 2147483647]. The default value is 1. |
|
typical_p |
Optional |
Decoding output probability distribution exponent. Currently, postprocessing is not supported. |
The value is of the float type. The value range is (0.0, 1.0]. If this field is not set, -1.0 is used by default, indicating that this operation is not performed. However, you cannot set this field to -1.0. |
|
watermark |
Optional |
Indicates whether to add a model watermark. Currently, postprocessing is not supported. |
The value is of the Boolean type. The default value is false.
|
|
priority |
Optional |
Request priority. |
The value is of the uint64_t type. The value range is [1, 5]. The default value is 5. A smaller value indicates a higher priority. The highest priority is 1. |
|
timeout |
Optional |
Waiting time. If times out, a request is disconnected. |
The value is of the uint64_t type. The value range is (0, 3600] (unit: second). The default value is 600. |
|
firstTokenCost |
Optional |
Time that the first token of a request consumes. |
The value is of the size_t type. This field is used only in PD recomputation scenarios. The value range is [0, 18446744073709551615]. |
|
decodeTime |
Optional |
Decode time before a request is recomputed. |
The value is of the std::vector<size_t> type. This field is used only in PD recomputation scenarios. The value range is [0, 18446744073709551615]. |
|
Usage Example
Request example:
POST https://{ip}:{port}/v2/models/llama3-70b/generate_stream
Request body:
- Single-modal text model:
{ "id":"a123", "text_input": "My name is Olivier and I", "parameters": { "details": true, "do_sample": true, "max_new_tokens":5, "repetition_penalty": 1.1, "seed": 123, "temperature": 1, "top_k": 10, "top_p": 0.99, "batch_size":100, "typical_p": 0.5, "watermark": false, "priority": 5, "timeout": 10 } }
- Multimodal model:
Change the value of image_url as needed.
{ "id":"a123", "text_input": [ {"type": "text", "text": "My name is Olivier and I"}, { "type": "image_url", "image_url": "/xxxx/test.png" } ], "parameters": { "details": true, "do_sample": true, "max_new_tokens":20, "repetition_penalty": 1.1, "seed": 123, "temperature": 1, "top_k": 10, "top_p": 0.99, "batch_size":100, "typical_p": 0.5, "watermark": false, "priority": 5, "timeout": 10 } }
Response example:
- Response example 1:
data:{"id":"a123","model_name":"llama3-70b","model_version":null,"text_output":"live","details":{"generated_tokens":1,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":5082},"prefill_time":28,"decode_time":null} data:{"id":"a123","model_name":"llama3-70b","model_version":null,"text_output":" in","details":{"generated_tokens":2,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":36},"prefill_time":null,"decode_time":9} data:{"id":"a123","model_name":"llama3-70b","model_version":null,"text_output":" Paris","details":{"generated_tokens":3,"first_token_cost":null,"decode_cost":null,[3681,8]],"batch_size":1,"queue_wait_time":30},"prefill_time":null,"decode_time":8} data:{"id":"a123","model_name":"llama3-70b","model_version":null,"text_output":",","details":{"generated_tokens":4,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":23},"prefill_time":null,"decode_time":7} data:{"id":"a123","model_name":"llama3-70b","model_version":null,"text_output":" France","details":{"finish_reason":"length","generated_tokens":5,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":24},"prefill_time":null,"decode_time":7} - Response example 2 (fullTextEnabled = true):
data:{"id":"endpoint_common_20","model_name":"llama3-70b","model_version":null,"text_output":"'m","details":{"generated_tokens":1,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":5092},"prefill_time":41.68000030517578,"decode_time":null} data:{"id":"endpoint_common_20","model_name":"llama3-70b","model_version":null,"text_output":"'m from","details":{"generated_tokens":2,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":43},"prefill_time":null,"decode_time":20.440000534057617} data:{"id":"endpoint_common_20","model_name":"llama3-70b","model_version":null,"text_output":"'m from France","details":{"generated_tokens":3,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":27},"prefill_time":null,"decode_time":12.175999641418457} data:{"id":"endpoint_common_20","model_name":"llama3-70b","model_version":null,"text_output":"'m from France.","details":{"generated_tokens":4,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":26},"prefill_time":null,"decode_time":12.128000259399414} data:{"id":"endpoint_common_20","model_name":"llama3-70b","model_version":null,"text_output":"'m from France. I","details":{"finish_reason":"length","generated_tokens":5,"first_token_cost":null,"decode_cost":null,"batch_size":1,"queue_wait_time":26},"prefill_time":null,"decode_time":12.458000183105469}
Output Description
Return Value |
Type |
Description |
||
|---|---|---|---|---|
data |
Object |
Result returned by a single inference. |
||
- |
id |
String |
Request ID. |
|
model_name |
String |
Model name. |
||
model_version |
String |
Model version. |
||
text_output |
String |
Returned inference result. |
||
details |
Object |
Inference details result. |
||
- |
finish_reason |
String |
End cause, which is returned only in the last inference result.
|
|
generated_tokens |
Integer |
Number of tokens in the inference result. Total number of tokens in the Prefill and Decode inference results. When the maximum inference length of a request is the value of maxIterTimes, the value of generated_tokens in the response of the Decode node is the value of maxIterTimes plus 1, that is, the number of first tokens in the Prefill inference result is added. |
||
first_token_cost |
List[token] |
Time when the first token is generated, which is returned by text inference. The unit is ms. Currently, the data is not collected, and null is returned. |
||
decode_cost |
Integer |
Decode duration, in milliseconds. Currently, the data is not collected, and null is returned. |
||
batch_size |
Integer |
Batch size for streaming inference. |
||
queue_wait_time |
Integer |
Queue waiting time, in μs. |
||
prefill_time |
Float |
Time To First Token (TTFT), in milliseconds. |
||
decode_time |
Float |
Token latency of non-first tokens, in milliseconds. |
||