From 148c9a2e168a357878a13260893ac740b6648943 Mon Sep 17 00:00:00 2001 From: sufubao Date: Tue, 4 Aug 2026 16:39:01 +0800 Subject: [PATCH] fix(qwen3next): keep big-page state cache pinned across shm serialization write_to_shm serializes this object with ForkingPickler so other processes can share it. During that dump, torch migrates each CPU tensor's storage in-place into shared memory, which degrades the pinned (cudaHostAlloc) big-page state cache to unpinned shm in the local process; the linear attention small-page copy Triton kernel then rejects the pointer with: ValueError: Pointer argument cannot be accessed from Triton (cpu tensor?) Temporarily drop linear_att_big_page_buffers around the super() call so the dumper never sees it. The local pinned allocation is preserved, and cross-process consumers (pd trans / dp prompt cache fetch), which do not use the CPU-side big-page state cache, are unaffected. --- .../kv_cache_mem_manager/qwen3next_mem_manager.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lightllm/common/kv_cache_mem_manager/qwen3next_mem_manager.py b/lightllm/common/kv_cache_mem_manager/qwen3next_mem_manager.py index f65a849df..c8f69dac8 100644 --- a/lightllm/common/kv_cache_mem_manager/qwen3next_mem_manager.py +++ b/lightllm/common/kv_cache_mem_manager/qwen3next_mem_manager.py @@ -71,7 +71,17 @@ def _free_linear_att_buffers(self): def write_to_shm(self, req_manager): self.req_to_conv_state = req_manager.req_to_conv_state self.req_to_ssm_state = req_manager.req_to_ssm_state - return super().write_to_shm(req_manager) + # super().write_to_shm() 会用 ForkingPickler 序列化本对象,torch 在 dump 时会把 + # CPU tensor 的 storage 原地迁到共享内存,使本进程大页 state cache 原本 + # pinned(cudaHostAlloc) 的内存退化为普通 shm mmap,之后 Triton kernel 携带该指针 + # 启动会报 "Pointer argument cannot be accessed from Triton (cpu tensor?)"。 + # 跨进程消费方并不使用 cpu 侧大页 state cache,序列化期间临时剔除以保住 pinned。 + big_page_buffers = self.linear_att_big_page_buffers + self.linear_att_big_page_buffers = None + try: + return super().write_to_shm(req_manager) + finally: + self.linear_att_big_page_buffers = big_page_buffers def alloc_paged_kv_move_buffer(self, page_num, page_size) -> torch.Tensor: kv_move_buffer = super().alloc_paged_kv_move_buffer(page_num, page_size)