[None][chore] Route MHC fused-HC workspace through global Buffers pool - #14305
[None][chore] Route MHC fused-HC workspace through global Buffers pool#14305lancelly wants to merge 2 commits into
Conversation
…s pool Add an opt-in path in _FusedHcWorkspaceCache.get that routes the four output buffers (residual_cur, post_mix_cur, comb_mix_cur, layer_input_cur) and the three internal scratch buffers (y_acc_ws, r_acc_ws, done_counter_ws) through get_memory_buffers() so MHC scratch can share backing memory with other layer-transient buffers (e.g., the attention workspace). The env switch TRTLLM_DSV4_MEM_OPTS is read once at class definition (cached as _USE_POOL) so the lookup doesn't run on every workspace request. Pool routing is gated to decode-sized B (B <= _CACHE_MAX_B). For B > _CACHE_MAX_B (prefill), the code falls through to fresh torch.empty per call, matching the upstream uncached path; this preserves prefill's no-aliasing semantics where layer N's *_prev inputs and layer N+1's *_cur outputs live in distinct tensors. At decode, upstream's existing per-runner LRU already returns the same tensor across layers, so the kernel is already in-place safe; pool routing inherits that aliasing without widening it. With TRTLLM_DSV4_MEM_OPTS off (default), behavior is byte-identical to current source. Split out from PR NVIDIA#14053 (DSv4 mem-opts master switch) and from PR NVIDIA#14241 (RoPE cap + MHC pool): this PR contains only the MHC pool routing piece, still gated on TRTLLM_DSV4_MEM_OPTS so it can be validated in isolation. Signed-off-by: Lanyu Liao <lancelly@users.noreply.github.com>
|
/bot run --disable-fail-fast |
|
PR_Github #49180 [ run ] triggered by Bot. Commit: |
|
PR_Github #49180 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #49312 [ run ] triggered by Bot. Commit: |
|
PR_Github #49312 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #49396 [ run ] triggered by Bot. Commit: |
|
PR_Github #49396 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #49531 [ run ] triggered by Bot. Commit: |
|
PR_Github #49531 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #49608 [ run ] triggered by Bot. Commit: |
|
PR_Github #49608 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #49665 [ run ] triggered by Bot. Commit: |
|
Concern: with TRTLLM_DSV4_MEM_OPTS=1, this may break CUDA graph address stability. The old cache is keyed by (B, ws_ks, m_batches, device). The new pool path uses fixed Suggested fix:
Also add a regression test with TRTLLM_DSV4_MEM_OPTS=1: There is also a device-keying issue: old cache includes device; the new pool path does |
|
PR_Github #49665 [ run ] completed with state
|
|
We no longer use the ds v4 side branch. Closing this PR. Please prepare PR against main. |
Summary
Split out the MHC fused-HC workspace pool routing from PR #14053 / #14241 as an independent, opt-in memory optimization.
Activated via the env switch
TRTLLM_DSV4_MEM_OPTS=1; default off → behavior is byte-identical to current source.Change
_FusedHcWorkspaceCache.get(tensorrt_llm/_torch/modules/mhc/mhc_cuda.py) gains an opt-in path that routes the four output buffers (residual_cur,post_mix_cur,comb_mix_cur,layer_input_cur) and the three internal scratch buffers (y_acc_ws,r_acc_ws,done_counter_ws) throughget_memory_buffers()so MHC scratch can share backing memory with other layer-transient buffers (e.g., the attention workspace).The env switch is read once at class definition (cached on
_FusedHcWorkspaceCache._USE_POOL) so the lookup doesn't run on every workspace request.Aliasing invariant
Pool routing only applies for
B <= _CACHE_MAX_B(decode-sized shapes). ForB > _CACHE_MAX_B(prefill), the code falls through to freshtorch.emptyper call, matching the upstream uncached path; this preserves prefill's no-aliasing semantics where layer N's*_previnputs and layer N+1's*_curoutputs live in distinct tensors.At decode, upstream's existing per-runner LRU already returns the same tensor across layers, so the kernel is already in-place safe; pool routing inherits that aliasing without widening it.
Files touched
Required env
export TRTLLM_DSV4_MEM_OPTS=1Optional (recommended for parallel-job stability, orthogonal to this PR):
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True