[Feature] Support stopping the inference for the corresponding request in the online service after a disconnection request.
Motivation
:bulb: If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)
:bulb: 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)
In the current code structure, when a request disconnects from the online inference service, the resources and ongoing inference occupied by that request in FastDeploy are not immediately terminated or released. Therefore, corresponding logic needs to be implemented to capture the request interruption and release the associated resources to stop the inference.
Modifications
-
API Layer Unification (API 层的统一引入)
-
Decorator Definition and Application:
- In the
utilsmodule, add or enhance thewith_cancellationdecorator to uniformly handle the cancellation logic for all requests (e.g., listening for HTTP disconnection). - Apply the
@with_cancellationdecorator uniformly to all external interfaces in the API layer (e.g.,chat,completions,score, etc.).
- In the
-
Decorator Definition and Application:
-
Exception Handling and Notification (异常捕获与通知)
-
Exception Capture:
- Within the Handler logic, capture the
asyncio.CancelledErrorexception thrown by the@with_cancellationdecorator.
- Within the Handler logic, capture the
-
ZMQ Communication:
- After capturing the exception, use the ZeroMQ (zmq) message queue to send the relevant cancellation information to the backend Engine Service, notifying it to stop the inference task.
-
Exception Capture:
-
Engine Layer Cancellation Handling (EngineService) (引擎层中断处理)
-
Request Retrieval:
- The
EngineServicemodifies its receiving logic in the existing request thread to receive the cancellation request message via ZMQ.
- The
-
Core Cancellation Function:
- Introduce a new core function,
abort_requests, specifically responsible for handling the received cancellation requests, implementing the stopping of inference and resource reclamation.
- Introduce a new core function,
-
Request Retrieval:
-
Resource Cleanup and Scheduling (
abort_requestsDetails) (资源清理与调度)- Inside the
abort_requestsfunction, the following key steps will be executed to ensure the request is fully terminated and resources are recovered:-
Result Construction: Construct the final
RequestOutputresult and place it into the scheduler's output queue. -
Task Cleanup: Clear the corresponding tasks and flags for the request from the
tasks_listandstop_flagsstructures. -
Resource Release:
- Use the resource manager to release the KV Cache blocks occupied by the request.
- Remove the request record from data structures such as the request dictionary.
-
Result Construction: Construct the final
- Inside the
Usage or Command
Accuracy Tests
Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]] - You can add new tags based on the PR content, but the semantics must be clear.
- Tag list: [
- [x] Format your code, run
pre-commitbefore commit. - [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [x] Provide accuracy results.
- [x] If the current PR is submitting to the
releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.
Thanks for your contribution!
Codecov Report
:x: Patch coverage is 89.00000% with 11 lines in your changes missing coverage. Please review.
:warning: Please upload report for BASE (develop@8acdd9f). Learn more about missing BASE report.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| fastdeploy/engine/common_engine.py | 9.09% | 10 Missing :warning: |
| fastdeploy/output/token_processor.py | 96.29% | 0 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #5320 +/- ##
==========================================
Coverage ? 65.80%
==========================================
Files ? 330
Lines ? 41901
Branches ? 6422
==========================================
Hits ? 27572
Misses ? 12262
Partials ? 2067
| Flag | Coverage Δ | |
|---|---|---|
| GPU | 65.80% <89.00%> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.
:white_check_mark: qwes5s5
:x: root
root seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.