tritonserver HTTPServer does not detect EOF/connection close unless response is streaming
Description
When a user performs a long-running inference request via HTTPServer, they may lose connection or intentionally abort the connection (ctrl-c from curl).
Ideally, the HTTP server will detect this and flag the request as cancelled (such as setting Request::is_cancelled_).
However, at least on Linux, we found that the HTTPServer does not call triton::server::HTTPAPIServer::InferRequestClass::RequestFiniHook until something (such as a streaming response) attempts to write to the connection.
Triton Information
v2.43.00 compiled with
./build.py --enable-all --enable-nvtx --enable-gpu --quiet --no-container-interactive --build-type=Debug
Reproduced on Ubuntu 24.04 on NVIDIA GeForce RTX 2070 and also H100.
Are you using the Triton container or did you build it yourself?
Reproduced both on tensorrtllm_backend container and on our own build.
To Reproduce Steps to reproduce the behavior.
Describe the models (framework, inputs, outputs), ideally include the model configuration file (if using an ensemble include the model configuration file for that as well).
I am using the example from tensorrtllm_backend/all_models/inflight_batcher_llm example with the TinyLlama/TinyLlama-1.1B-Chat-v0.1 model using max_batch_size=2 decoupled_mode=true and accumulate_tokens=true
$ diff -ur tensorrtllm_backend/all_models/inflight_batcher_llm/tensorrt_llm_bls/ /data/tinyllama_backend/tensorrt_llm_bls/
diff -ur tensorrtllm_backend/all_models/inflight_batcher_llm/tensorrt_llm_bls/1/model.py /data/tinyllama_backend/tensorrt_llm_bls/1/model.py
--- tensorrtllm_backend/all_models/inflight_batcher_llm/tensorrt_llm_bls/1/model.py 2024-03-25 15:34:08.381629507 -0700
+++ /data/tinyllama_backend/tensorrt_llm_bls/1/model.py 2024-04-05 16:16:30.963840112 -0700
@@ -310,6 +310,7 @@
#Loop over the trtllm responses
for trtllm_response in trtllm_responses:
+ print("Cancelled: " + str(request.is_cancelled()))
if trtllm_response.has_error():
raise pb_utils.TritonModelException(
diff -ur tensorrtllm_backend/all_models/inflight_batcher_llm/tensorrt_llm_bls/config.pbtxt /data/tinyllama_backend/tensorrt_llm_bls/config.pbtxt
--- tensorrtllm_backend/all_models/inflight_batcher_llm/tensorrt_llm_bls/config.pbtxt 2024-03-25 15:34:08.381629507 -0700
+++ /data/tinyllama_backend/tensorrt_llm_bls/config.pbtxt 2024-03-29 18:39:43.838353004 -0700
@@ -26,10 +26,10 @@
name: "tensorrt_llm_bls"
backend: "python"
-max_batch_size: ${triton_max_batch_size}
+max_batch_size: 2
model_transaction_policy {
- decoupled: ${decoupled_mode}
+ decoupled: true
}
input [
@@ -209,13 +209,13 @@
parameters: {
key: "accumulate_tokens"
value: {
- string_value: "${accumulate_tokens}"
+ string_value: "true"
}
}
instance_group [
{
- count: ${bls_instance_count}
+ count: 2
kind : KIND_CPU
}
]To reproduce, send a generate request to the tensorrt_llm_bls, both with and without stream, and compare what happens when interrupting curl.
curl -d '{"text_input": "Hello\n", "max_tokens": 900, "bad_words": "", "stop_words":[],"stream":false,"stop":true}' http://localhost:8000/v2/models/tensorrt_llm_bls/generate; echo
^CThe server will wait until all 900 tokens have been generated, then will print "Cancelled: False" to the log. This is incorrect.
To compare, generate_stream behaves correctly, I believe due to libevent writing to the socket
curl -d '{"text_input": "Hello\n", "max_tokens": 900, "bad_words": "", "stop_words":[],"stream":true,"stop":true}' http://localhost:8000/v2/models/tensorrt_llm_bls/generate_stream; echo
^CWhen streaming, the server prints cancelled: True after the ctrl-C
Cancelled: False
Cancelled: False
Cancelled: True
Cancelled: TrueExpected behavior As soon as the HTTP connection is closed, libevent should be able to inform evhtp about the EOF event, and it IsCancelled should return true.
Source: triton-inference-server/server