Skip to content

Conversation

@raayandhar
Copy link
Contributor

@raayandhar raayandhar commented Sep 5, 2025

Description

This is an approach to tackle the problem in issue 5820 where failed requests cause a memory leak. Requests would fail, not transfer, and still consume KV cache resources. Sometimes, on synchronous checks via check_context_transfer_status, we would also hang.

This PR aims to add the support for a ctx/gen configurable kv_transfer_timeout_ms, static across all requests such that if a request has existed on ctx/gen servers longer than the timeout, it would be removed and its resources freed.

Notes

This is largely implemented. However, in its current state, there is still a probabilistic hang. Despite _terminate_request for timed-out requests and it being removed from self.ctx_in_transmission_requests, we may hang in self.check_context_transfer_status(0) inside _send_disagg_ctx_cache much later.

This is because the future for the request still exists, and it will block on a future future.get(). If we never create the future, we never hang.

To test, checkout the first commit, use export FAIL_ONLY=2049 (or some other request id(s)) to fail a request on context side. I have added a path to skip creating a future for request 2049 in order to verify that this prevents the hang. I recommend export TLLM_LOG_LEVEL=debug in order to see the detailed logs for the behavior.

In order to further implement this feature to completion, it should integrate the cancelRequest changes in PR 6587 with the addition of failing the promise through i.e. something like mPromise.set_exception.

This PR is largely based on changes from #6801, please see this PR for earlier discussion.

Test Coverage

Test coverage needs to be added to this PR. Looking for feedback here.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@raayandhar
Copy link
Contributor Author

I will be trying to work on this since TRTLLM is open-source. If another engineer picks it up instead due to it being a higher priority, please let me know here so we don't duplicate efforts!

@raayandhar
Copy link
Contributor Author

Once PR6587 lands I will pick this back up.

@svc-trtllm-gh-bot svc-trtllm-gh-bot added the Community want to contribute PRs initiated from Community label Sep 7, 2025
@raayandhar
Copy link
Contributor Author

I see that #8114 has been merged. @pcastonguay do we still want this feature? If so, I will pick this back up and target taking this out of draft next week.

@pcastonguay
Copy link
Collaborator

I see that #8114 has been merged. @pcastonguay do we still want this feature? If so, I will pick this back up and target taking this out of draft next week.

Yes we still need this. If you have cycles to look into it early next week, please do so. If not I will pick up on Monday.

Copy link
Collaborator

@pcastonguay pcastonguay left a comment

Choose a reason for hiding this comment

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

Is there a way we could test this in a unit test? I.e. send a context-only request to a server, get the response but never send a request to the gen server. Then we could query the KV cache stats to make sure blocks have been freed.

requests_to_terminate.append(request)
continue

# Check if generation request needs cleanup due to KV cache transfer timeout
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible for a ctx request to ever enter this code path here? If not, should we move this inside the if request.is_generation_only_requests to make it clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't think a ctx request should be able to enter this code path since it loops over the generation requests in self.active_requests. But my understanding was that is_generation_only_request was for gen-only server requests? And if we had the ctx-gen disagg servers separate, we would never go down that code path in that case? I may be misunderstanding the is_generation_only_request case. Either way, I will test it.

@raayandhar
Copy link
Contributor Author

Is there a way we could test this in a unit test? I.e. send a context-only request to a server, get the response but never send a request to the gen server. Then we could query the KV cache stats to make sure blocks have been freed.

I can certainly try and look into it. I agree there needs to be some way to test this feature.

@raayandhar
Copy link
Contributor Author

I see that #8114 has been merged. @pcastonguay do we still want this feature? If so, I will pick this back up and target taking this out of draft next week.

Yes we still need this. If you have cycles to look into it early next week, please do so. If not I will pick up on Monday.

I should have cycles so I will work on it and keep you updated in this PR thread.

@raayandhar raayandhar force-pushed the kv_transfer_timeout branch from 814c810 to 0574624 Compare October 7, 2025 08:27
@raayandhar
Copy link
Contributor Author

A few notes:

  • I forced pushed a new version of the code that's untested from my branch kv_cache_transfer_new. I cannot make new PRs because I am prompted to sign into my NVIDIA login... This issue does not seem to be present on mobile. I also can't comment, etc unless on mobile...
  • The new stuff is untested. The machines I access through university have limited privileges and are quite slow, so after some wrangling I managed to build TRTLLM. But I think that there may some limitations in the testing. I should hope I can at least make sure it compiles and functions correctly. But the scope of the testing may be limited and I may need help here.
  • I need to read and understand the cancelRequest code carefully. I'm not sure if it matters that we cancel requests when they are expected to be terminated (simplifying some code). We also need to make sure that we don't run into the intermittent future blocking issue I was facing before. Also, when cancelling a generation request, we no longer send a message to the server is my understanding (previously we had done _handle_errors which terminated and handled this nicely). This is also something to look at.
  • Need to add unit testing for this feature. Also note to self is to test with both pybind and nanobind.

@pcastonguay
Copy link
Collaborator

A few notes:

  • I forced pushed a new version of the code that's untested from my branch kv_cache_transfer_new. I cannot make new PRs because I am prompted to sign into my NVIDIA login... This issue does not seem to be present on mobile. I also can't comment, etc unless on mobile...
  • The new stuff is untested. The machines I access through university have limited privileges and are quite slow, so after some wrangling I managed to build TRTLLM. But I think that there may some limitations in the testing. I should hope I can at least make sure it compiles and functions correctly. But the scope of the testing may be limited and I may need help here.
  • I need to read and understand the cancelRequest code carefully. I'm not sure if it matters that we cancel requests when they are expected to be terminated (simplifying some code). We also need to make sure that we don't run into the intermittent future blocking issue I was facing before. Also, when cancelling a generation request, we no longer send a message to the server is my understanding (previously we had done _handle_errors which terminated and handled this nicely). This is also something to look at.
  • Need to add unit testing for this feature. Also note to self is to test with both pybind and nanobind.

Thanks Raayan, I will pick it up from here and will let you know if I have any questions.

@raayandhar
Copy link
Contributor Author

A few notes:

  • I forced pushed a new version of the code that's untested from my branch kv_cache_transfer_new. I cannot make new PRs because I am prompted to sign into my NVIDIA login... This issue does not seem to be present on mobile. I also can't comment, etc unless on mobile...
  • The new stuff is untested. The machines I access through university have limited privileges and are quite slow, so after some wrangling I managed to build TRTLLM. But I think that there may some limitations in the testing. I should hope I can at least make sure it compiles and functions correctly. But the scope of the testing may be limited and I may need help here.
  • I need to read and understand the cancelRequest code carefully. I'm not sure if it matters that we cancel requests when they are expected to be terminated (simplifying some code). We also need to make sure that we don't run into the intermittent future blocking issue I was facing before. Also, when cancelling a generation request, we no longer send a message to the server is my understanding (previously we had done _handle_errors which terminated and handled this nicely). This is also something to look at.
  • Need to add unit testing for this feature. Also note to self is to test with both pybind and nanobind.

Thanks Raayan, I will pick it up from here and will let you know if I have any questions.

If you're busy I can still make headway. In fact I can certainly try to make some progress today. Just that certain testing may be difficult on my side is all.

@pcastonguay
Copy link
Collaborator

A few notes:

  • I forced pushed a new version of the code that's untested from my branch kv_cache_transfer_new. I cannot make new PRs because I am prompted to sign into my NVIDIA login... This issue does not seem to be present on mobile. I also can't comment, etc unless on mobile...
  • The new stuff is untested. The machines I access through university have limited privileges and are quite slow, so after some wrangling I managed to build TRTLLM. But I think that there may some limitations in the testing. I should hope I can at least make sure it compiles and functions correctly. But the scope of the testing may be limited and I may need help here.
  • I need to read and understand the cancelRequest code carefully. I'm not sure if it matters that we cancel requests when they are expected to be terminated (simplifying some code). We also need to make sure that we don't run into the intermittent future blocking issue I was facing before. Also, when cancelling a generation request, we no longer send a message to the server is my understanding (previously we had done _handle_errors which terminated and handled this nicely). This is also something to look at.
  • Need to add unit testing for this feature. Also note to self is to test with both pybind and nanobind.

Thanks Raayan, I will pick it up from here and will let you know if I have any questions.

If you're busy I can still make headway. In fact I can certainly try to make some progress today. Just that certain testing may be difficult on my side is all.

Yeah, I have a lot on my plate, so feel free to continue making headway. I also realize that you're limited in what you can test.

@raayandhar
Copy link
Contributor Author

Also been busy but will make some progress Fri. and through the weekend. Ideally you can pick it up for whatever remains of testing early next week.

@raayandhar
Copy link
Contributor Author

It now compiles with pybind and nanobind. I am working on testing. There are some permission issues with the machines I use, so I e.g. can't update CUDA etc so PyTorch won't work. I can let you know by tomorrow if this is the farthest I can go.

@raayandhar
Copy link
Contributor Author

@pcastonguay unfortunately I can't really test these changes. I'm not able to update the NVIDIA drivers on the machines I use. I know it compiles with both pybind and nanobind now after some fixes. So hopefully the changes, if any, are minimal. For testing I described how I tested in the PR description, I would apply some of the changes in 814c810 to test.

@pcastonguay
Copy link
Collaborator

@pcastonguay unfortunately I can't really test these changes. I'm not able to update the NVIDIA drivers on the machines I use. I know it compiles with both pybind and nanobind now after some fixes. So hopefully the changes, if any, are minimal. For testing I described how I tested in the PR description, I would apply some of the changes in 814c810 to test.

Thanks Raayan, I will pick this up tomorrow.

@pcastonguay
Copy link
Collaborator

@raayandhar could you take a look at recent commit from #8459.

I will close this PR and take over.

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

Labels

Community want to contribute PRs initiated from Community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants