Skip to content

[Cherry-Pick][BugFix] Fix clear_parameters hang issue in MTP during weight cleanup in RL (#7522)#7523

Merged
Deleter-D merged 2 commits into
PaddlePaddle:release/2.6from
Deleter-D:2.6_fix_mtp_clear_graph
Apr 22, 2026
Merged

[Cherry-Pick][BugFix] Fix clear_parameters hang issue in MTP during weight cleanup in RL (#7522)#7523
Deleter-D merged 2 commits into
PaddlePaddle:release/2.6from
Deleter-D:2.6_fix_mtp_clear_graph

Conversation

@Deleter-D
Copy link
Copy Markdown
Collaborator

Motivation

Cleaning CUDA Graphs after releasing weights may lead to a hang issue.

Modifications

This PR resolves the problem by moving the CUDA Graph cleanup logic in MTP to occur before weight cleanup, preventing hangs observed in RL scenarios.

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
Copy Markdown

paddle-bot Bot commented Apr 20, 2026

Thanks for your contribution!

PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.6@be2fd17). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/worker/gpu_model_runner.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.6    #7523   +/-   ##
==============================================
  Coverage               ?   73.55%           
==============================================
  Files                  ?      376           
  Lines                  ?    53033           
  Branches               ?     8288           
==============================================
  Hits                   ?    39011           
  Misses                 ?    11274           
  Partials               ?     2748           
Flag Coverage Δ
GPU 73.55% <0.00%> (?)

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.

Copy link
Copy Markdown
Collaborator

@gongshaotian gongshaotian left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

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

🤖 AI Code Review | 2026-04-21 21:05:12

📋 Review 摘要

PR 概述:将 MTP Speculative Decoding 场景中 CUDA Graph 的清理操作移至权重释放之前,修复 RL 场景下的 hang 问题。
变更范围fastdeploy/worker/gpu_model_runner.pyclear_parameters 方法
影响面 Tag[Speculative Decoding] [RL]

问题

级别 文件 概述
❓ 疑问 gpu_model_runner.py:2700 proposer.model.clear_graph_opt_backend() 嵌套在 if self.use_cudagraph: 内,当主模型未使用 cudagraph 但 draft model 启用了 cudagraph 时,可能存在资源未释放风险
🟡 建议 该 hang 问题缺乏回归测试,建议补充测试用例防止未来回退

总体评价

修复思路正确,将 proposer.model.clear_graph_opt_backend() 前移至 clear_parameters() 之前以避免 hang,同时新增 speculative_decodingdraft_model_use_cudagraph 条件守卫使逻辑更严谨。建议确认 use_cudagraphdraft_model_use_cudagraph 的配置约束关系,以及考虑补充回归测试。

# Clear CUDAGraph
if self.use_cudagraph:
self.model.clear_graph_opt_backend()
if (
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❓ 疑问 proposer.model.clear_graph_opt_backend() 现在嵌套在 if self.use_cudagraph: 块内

原始代码中,MTP 的 proposer.model.clear_graph_opt_backend() 是在 if self.spec_method == SpecMethod.MTP: 条件下单独调用的,与主模型的 use_cudagraph 开关无关。

新代码将其嵌套在 if self.use_cudagraph: 内,意味着当主模型禁用 cudagraph(use_cudagraph=False),但 draft model 独立启用了 cudagraph(draft_model_use_cudagraph=True)时,proposer.model.clear_graph_opt_backend()永远不会被调用,可能导致 draft model 的 CUDA graph 资源泄漏。

请确认:draft_model_use_cudagraph=True 是否在设计上一定需要 use_cudagraph=True 才能生效?如果是,建议在配置层面添加约束或断言,使假设显式化。

Copy link
Copy Markdown
Collaborator

@EmmonsCurse EmmonsCurse left a comment

Choose a reason for hiding this comment

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

LGTM~ Skip coverage check as it mainly relies on tests with RL.

@Deleter-D Deleter-D merged commit 2961400 into PaddlePaddle:release/2.6 Apr 22, 2026
51 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants