Skip to content

Conversation

@qwes5s5
Copy link
Collaborator

@qwes5s5 qwes5s5 commented Dec 1, 2025

Motivation

💡 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)

💡 如若此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 utils module, add or enhance the with_cancellation decorator to uniformly handle the cancellation logic for all requests (e.g., listening for HTTP disconnection).
      • Apply the @with_cancellation decorator uniformly to all external interfaces in the API layer (e.g., chat, completions, score, etc.).
  • Exception Handling and Notification (异常捕获与通知)

    • Exception Capture:
      • Within the Handler logic, capture the asyncio.CancelledError exception thrown by the @with_cancellation decorator.
    • 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.
  • Engine Layer Cancellation Handling (EngineService) (引擎层中断处理)

    • Request Retrieval:
      • The EngineService modifies its receiving logic in the existing request thread to receive the cancellation request message via ZMQ.
    • 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.
  • Resource Cleanup and Scheduling (abort_requests Details) (资源清理与调度)

    • Inside the abort_requests function, the following key steps will be executed to ensure the request is fully terminated and resources are recovered:
      1. Result Construction: Construct the final RequestOutput result and place it into the scheduler's output queue.
      2. Task Cleanup: Clear the corresponding tasks and flags for the request from the tasks_list and stop_flags structures.
      3. 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.

Usage or Command

Accuracy Tests

Checklist

  • 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.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link

paddle-bot bot commented Dec 1, 2025

Thanks for your contribution!

@codecov-commenter
Copy link

codecov-commenter commented Dec 2, 2025

Codecov Report

❌ Patch coverage is 23.80952% with 64 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@9460254). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/engine/common_engine.py 5.00% 19 Missing ⚠️
fastdeploy/entrypoints/engine_client.py 17.64% 14 Missing ⚠️
fastdeploy/entrypoints/openai/utils.py 35.00% 13 Missing ⚠️
fastdeploy/entrypoints/openai/serving_chat.py 0.00% 9 Missing ⚠️
...astdeploy/entrypoints/openai/serving_completion.py 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #5320   +/-   ##
==========================================
  Coverage           ?   59.64%           
==========================================
  Files              ?      325           
  Lines              ?    40364           
  Branches           ?     6110           
==========================================
  Hits               ?    24076           
  Misses             ?    14399           
  Partials           ?     1889           
Flag Coverage Δ
GPU 59.64% <23.80%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@qwes5s5 qwes5s5 force-pushed the request_disconnect branch from a7380f6 to 7480fb7 Compare December 3, 2025 14:43
Copy link
Collaborator

@Jiang-Jia-Jun Jiang-Jia-Jun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的abort看起来只终止了内存队列里面的请求。 对于请求已经正在生成的没有做处理

)
self.token_processor._recycle_resources(
req_id, batch_id, abort_task, abort_res, is_prefill, True
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要考虑引擎的异步性:

  1. resource_manager 停止调度该请求
  2. 确认引擎对应的槽位已经生成完所有的 token
  3. resource manager 回收该请求调度的资源

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants