Publish defnoteatin/PseudoBrain-Qwen3-Coder-Next-FP8 (40 base shards + PB27 GDN)
Browse filesFiles changed (2)
29 unmodified lines30313233343536378 unmodified lines4647484950515227 unmodified lines808182838485868788899091929394959642 unmodified lines1391401411421431441451461474 unmodified lines15215315415515615715815916016116216328 unmodified lines1921931941951961971982 unmodified lines201202203204205206101 unmodified lines30830931031131231365 unmodified lines3793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144158 unmodified lines42442542642742842945 unmodified lines47547647747847948078 unmodified lines55956056156256356454 unmodified lines619620621622623624119 unmodified lines74474574674774874975075165 unmodified lines8178188198208218221 unmodified line82482582682782882983083110 unmodified lines84284384484584684784842 unmodified lines89189289389489589689762 unmodified lines96096196296396496596631 unmodified lines9989991000100110021003100412 unmodified lines10171018101910201021102210231024102510261027102810291030103110321033103424 unmodified lines1059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108481 unmodified lines11661167116811691170117188 unmodified lines1260126112621263126412654 unmodified lines127012711272127312741275127661 unmodified lines1338133913401341134213431344134513461347134813491350135113521353135413551356135729 unmodified lineslog = logging.getLogger("vllm")MEMORY: dict = {"enabled": True, "blocks": 256, "block_size": 64, "decode_blocks": 256, "neighbors": 0, "rerank": 512,"chunk": 64, "window": int(os.environ.get("PB27_WINDOW", "16384"))}DEBUG = os.environ.get("PB27_MEMORY_DEBUG", "") == "1"NORETRIEVE = os.environ.get("PB27_MEMORY_NORETRIEVE", "") == "1" # diagnostic: recompute pieces from the archive without retrievalSINKS = int(os.environ.get("PB27_MEMORY_SINKS", "4") or 0) # PB-27 was trained with 4 always-visible sink positions; vLLM8 unmodified linesORIGIN = SINKS if FAITHFUL else 0 # after the sinks (blocks at 4+64j) and keeps tailQWIN = os.environ.get("PB27_MEMORY_QWIN", "") == "1" # decode retrieval uses trailing verified query windowDSTEP = os.environ.get("PB27_MEMORY_DSTEP", "") == "1" # step-1 decode uses `blocks`; step-2+ decode uses `decode_blocks`SCALE = [int(x) for x in os.environ.get("PB27_MEMORY_SCALE", "2048:384:4096:512:8192:1536").split(":") if x.strip()]OFFLOAD = os.environ.get("PB27_MEMORY_OFFLOAD", "nvme").strip().lower() # "", "cpu", "fp8", "cpu_fp8", or "nvme"# "nvme": fp8/bf16 K/V live in an unlinked sparse file mapped into memory (page cache is evictable, so resident memory# stays flat while disk holds the history); block bounds stay resident. NVME_CAP is the max tokens per request.27 unmodified linesGPU_WIN_CAP = 32768LSE = os.environ.get("PB27_MEMORY_LSE", "1") != "0" # FlashAttention-2 LSE-merge fast path for piece_attentionRERANK_ALL = os.environ.get("PB27_MEMORY_RERANK_ALL", "1") != "0" # exact rescoring for every piece, not only decodeBATCH: dict = {"ib": None, "pos_list": None} # the runner's current InputBatch (req_ids, query_start_loc, ...)PROMPT_LENS: dict[str, int] = {} # req_id -> initial prompt_len from RequestState.add_requestARCHIVES: dict[tuple[str, str], "Archive"] = {} # (req_id, layer_name) -> ArchiveSTATS: dict = {"calls": 0, "fallback": 0, "retrievals": 0, "pieces": 0, "tokens_archived": 0,"adopt_full": 0, "adopt_partial": 0, "adopt_none": 0, "hole_skips": 0,"pertoken": 0, "pertoken_capped": 0}# Prefix caching: vLLM skips computing the cached prefix of a new request, so the archive of the request that# produced that prefix is retained after it finishes and adopted by the next request whose tokens match it.RETAIN = int(os.environ.get("PB27_MEMORY_RETAIN", "0") or 0) # max retired archive sets kept (0 = off)RETIRED: list[dict] = [] # [{"tokens": int32 tensor of the finished request, "archives": {layer: Archive}}]ADOPTED: dict[str, tuple] = {} # req_id -> (archives by layer, hole_lo, hole_hi, num_computed)def configure_from_env() -> None:42 unmodified linescached_ns: int = -1 # cached sink count in cached_pre_k / cached_pre_vcached_pre_k: torch.Tensor | None = None # [ns + k*B, KV, D] FA2-ready pre_k cached on GPUcached_pre_v: torch.Tensor | None = None # [ns + k*B, KV, D] FA2-ready pre_v cached on GPUcached_cu: tuple | None = None # (t, w_len, p_len, cu_q, cu_w, cu_p) cached int32 cu_seqlens on GPUsmax: torch.Tensor | None = None # [KV, (cap // block + SBLK - 1) // SBLK, D] coarse bf16 super-block maxsmin: torch.Tensor | None = None # [KV, (cap // block + SBLK - 1) // SBLK, D] coarse bf16 super-block min@staticmethoddef new(kv: int, d: int, cap: int, block: int, dtype, device, max_hint: int = 0) -> "Archive":4 unmodified linesarc_dtype = torch.float8_e4m3fn if NVME_DTYPE == "fp8" else dtypen_blk = cap // blockn_sb = (n_blk + SBLK - 1) // SBLKreturn Archive(_mapped(kv, big, d, arc_dtype), _mapped(kv, big, d, arc_dtype),torch.empty(kv, n_blk, d, dtype=b_dtype, device=device),torch.empty(kv, n_blk, d, dtype=b_dtype, device=device),mapped=True,smax=torch.empty(kv, n_sb, d, dtype=b_dtype, device=device),smin=torch.empty(kv, n_sb, d, dtype=b_dtype, device=device))if OFFLOAD == "nvme":cap = min(max(cap, -(-max_hint // block) * block), gpu_cap)n_blk = cap // block28 unmodified linesif OFFLOAD == "nvme" and not self.mapped and need > gpu_cap:big = max(new_cap, -(-NVME_CAP // block) * block)arc_dtype = torch.float8_e4m3fn if NVME_DTYPE == "fp8" else self.keys.dtypemk, mv = _mapped(kv, big, d, arc_dtype), _mapped(kv, big, d, arc_dtype)if self.size > 0:mk[:, :self.size] = self.keys[:, :self.size].to(device=mk.device, dtype=arc_dtype)mv[:, :self.size] = self.values[:, :self.size].to(device=mv.device, dtype=arc_dtype)2 unmodified linesself.sink_k = self.keys[:, :s_end].transpose(0, 1).contiguous()self.sink_v = self.values[:, :s_end].transpose(0, 1).contiguous()self.keys, self.values, self.mapped = mk, mv, Truenew_cap = min(new_cap, self.keys.shape[1] // block * block)elif self.mapped:if need > self.keys.shape[1]:101 unmodified linesself.keys[:, p_idx] = kt.to(device=self.keys.device, dtype=self.keys.dtype)self.values[:, p_idx] = vt.to(device=self.values.device, dtype=self.values.dtype)self.size = max(self.size, hi)if hi - 1 < ORIGIN:returnlo_b, hi_b = max(0, p0 - ORIGIN) // block, (hi - 1 - ORIGIN) // block65 unmodified linesdst_v.copy_(sv)def _mapped(kv: int, cap: int, d: int, dtype) -> torch.Tensor:"""[kv, cap, d] demand-paged tensor (anonymous mmap by default, or unlinked sparse file when NVME_DIR is set)."""pool_key = (kv, cap, d, dtype)bucket = _MMAP_POOL.get(pool_key)if bucket:return bucket.pop()nbytes = kv * cap * d * torch.empty(0, dtype=dtype).element_size()if NVME_DIR:fd, path = tempfile.mkstemp(dir=NVME_DIR, prefix="pb27_arc_")try:os.unlink(path)os.ftruncate(fd, nbytes)mm = mmap.mmap(fd, nbytes)finally:os.close(fd)else:mm = mmap.mmap(-1, nbytes)return torch.frombuffer(mm, dtype=torch.uint8).view(dtype).view(kv, cap, d)def _free(archives) -> None:for arc in archives.values():if getattr(arc, "mapped", False):for t in (arc.keys, arc.values):if t is not None and t.device.type == "cpu":pool_key = (t.shape[0], t.shape[1], t.shape[2], t.dtype)bucket = _MMAP_POOL.setdefault(pool_key, [])if len(bucket) < _MMAP_POOL_MAX:bucket.append(t)archives.clear()if torch.cuda.is_available() and (torch.cuda.memory_reserved() - torch.cuda.memory_allocated()) > (8 << 30):torch.cuda.empty_cache()8 unmodified linesif RETAIN <= 0 or tokens is None or len(tokens) < 2 or any(a.hole_hi > a.hole_lo for a in archives.values()):_free(archives)returnRETIRED.append({"tokens": tokens, "archives": archives})while len(RETIRED) > RETAIN:_free(RETIRED.pop(0)["archives"])45 unmodified linesreturn t.gather(1, idx.unsqueeze(-1).expand(-1, -1, t.shape[2]))def _gather_blocks(t: torch.Tensor, blk_idx: torch.Tensor, block: int) -> torch.Tensor:"""Gather contiguous blocks `blk_idx` [KV, B] starting at ORIGIN from `t` [KV, cap, D] -> [KV, B * block, D]."""kv, cap, d = t.shape78 unmodified lineselse:s_dtype = q.dtype if (q.is_cuda and q.dtype in (torch.bfloat16, torch.float16)) else torch.float32qg_s = q.to(s_dtype).permute(1, 0, 2).reshape(kv, groups * t, d)pos, neg = qg_s.clamp(min=0), qg_s.clamp(max=0)if not rerank and SBLK > 1 and arc.smax is not None and arc.smin is not None and full > SBLK * 16:n_sb = (full + SBLK - 1) // SBLK54 unmodified linescand = score.topk(c, dim=-1).indices # [KV, c]ck_raw = _gather_blocks(arc.keys, cand, block).to(device=q.device)ck = ck_raw.float()exact = torch.einsum("gqd,gnd->gqn", qg, ck).amax(1).view(kv, c, block).amax(-1)keep = exact.topk(k, dim=-1).indicestop = cand.gather(-1, keep)119 unmodified linesif (q_hist is not None and lead == 0 and q_hist.shape[0] > 1) else q_step)t_ev, h, d = q_eval.shapekv = h // groupss_dtype = q_eval.dtype if (q_eval.is_cuda and q_eval.dtype in (torch.bfloat16, torch.float16)) else torch.float32qg_s = q_eval.to(s_dtype).permute(1, 0, 2).reshape(kv, groups * t_ev, d)pos, neg = qg_s.clamp(min=0), qg_s.clamp(max=0)n_valid = fullhole_b0 = hole_b1 = 065 unmodified linesd_merged = torch.cat((d_inter, blk_ord[:, k_d:]), dim=-1) if k_d < blk_ord.shape[1] else d_interblk_ord = _dedup_priority(d_merged, k_sel)arc.decode_top = blk_orddec_prio, dec_sorted = _expand_successors_dedup(blk_ord, full, k_sel, m_succ=k_sel)if arc.prompt_top is not None:p_prev = arc.prompt_top.clamp(max=full - 1)1 unmodified linen_pin = max(0, k_out - dec_prio.shape[1])merged = torch.cat((p_prev[:, :n_pin], dec_prio, p_prev[:, n_pin:]), dim=-1)top_prio = _dedup_priority(merged, k_out)blk = top_prio.sort(-1).valueselse:blk = dec_sortedSTATS["retrievals"] += 1STATS["pertoken"] += 110 unmodified linesfor s_thresh, s_blocks in zip(SCALE[0::2], SCALE[1::2]):if n_arch > s_thresh:budget = max(budget, s_blocks)k = min(max(budget, 1536 if n_arch > 8192 else (512 if n_arch > 4096 else (384 if n_arch > 2048 else budget))), n_valid)rerank_pool = max(MEMORY["rerank"], 2 * k) if MEMORY["rerank"] > 0 else 0c0 = min(max(rerank_pool, k), n_valid)cand_mult = max(PERTOKEN_CAND, 2) if (lead is not None or t_ev > 1) else max(PERTOKEN_CAND, 1)42 unmodified linesexact_parts = []for c_s in range(0, c, 1024):c_e = min(c, c_s + 1024)ck_part = _gather_blocks(arc.keys, cand[:, c_s:c_e], block).to(device=q.device, dtype=torch.float32)ex_part = torch.bmm(qg, ck_part.transpose(-1, -2)).view(kv, groups, t_ev, c_e - c_s, block).amax(-1).amax(1)exact_parts.append(ex_part)exact = torch.cat(exact_parts, dim=-1) if len(exact_parts) > 1 else exact_parts[0]62 unmodified lineselse:merged_ord = blk_ordm_succ = min(640, k) if k > 1024 else ktop_prio, blk = _expand_successors_dedup(merged_ord, full, k, m_succ=m_succ)if lead is not None and lead < 0:arc.prompt_top = top_prioSTATS["retrievals"] += 131 unmodified linescontig_q = (t == 1 or (q_max - q_min == t - 1))lo = max(0, q_min - window + 1)hi = q_max + 1use_lse = (own is None and LSE and HAS_FA2 and q.is_cuda and q.dtype in (torch.bfloat16, torch.float16) and contig_q)tail0 = ORIGIN + ((lo - ORIGIN) // block) * blockfold_tail = bool(use_lse and t <= MEMORY["chunk"] and FAITHFUL and top is not None and lo > tail0)w_lo = tail0 if fold_tail else lo12 unmodified linespre_k = arc.cached_pre_k.to(dtype=q.dtype)pre_v = arc.cached_pre_v.to(dtype=q.dtype)else:rk, rv = _gather_cached_delta(arc, top, block, q.dtype, q.device)arc.last_top = arc.last_rk = Nonearc.cached_top = toparc.cached_rk = rkarc.cached_rv = rvif ns > 0:if arc.sink_k is not None and ns <= arc.sink_k.shape[0]:sk_t = arc.sink_k[:ns].to(dtype=q.dtype)sv_t = arc.sink_v[:ns].to(dtype=q.dtype)else:sk_t = arc.keys[:, :ns].to(device=q.device, dtype=q.dtype).transpose(0, 1)sv_t = arc.values[:, :ns].to(device=q.device, dtype=q.dtype).transpose(0, 1)pre_k = torch.cat((sk_t, rk.transpose(0, 1)), dim=0)pre_v = torch.cat((sv_t, rv.transpose(0, 1)), dim=0)else:24 unmodified linesunmasked = (t == 1 and own is None)need_mask = not (use_lse or unmasked)parts_k, parts_v, parts_allow = [], [], []if ns > 0:if arc.sink_k is not None and ns <= arc.sink_k.shape[0]:parts_k.append(arc.sink_k[:ns].transpose(0, 1).to(dtype=q.dtype))parts_v.append(arc.sink_v[:ns].transpose(0, 1).to(dtype=q.dtype))else:parts_k.append(arc.keys[:, :ns].to(device=q.device).to(dtype=q.dtype))parts_v.append(arc.values[:, :ns].to(device=q.device).to(dtype=q.dtype))if need_mask:parts_allow.append(torch.ones(t, ns, dtype=torch.bool, device=q.device))if top is not None:if arc.last_top is top and arc.last_rk is not None:rk = arc.last_rk.to(dtype=q.dtype)else:rk = _gather_blocks(arc.keys, top, block).to(device=q.device).to(dtype=q.dtype) # [KV, R, D]arc.last_top = arc.last_rk = Nonerv = _gather_blocks(arc.values, top, block).to(device=q.device).to(dtype=q.dtype)parts_k.append(rk); parts_v.append(rv)if own is None and arc.prompt_top is not None:arc.cached_top = toparc.cached_rk = rkarc.cached_rv = rvarc.cached_ns = nsarc.cached_pre_k = (parts_k[0] if len(parts_k) == 1 else torch.cat(parts_k, dim=1)).transpose(0, 1).contiguous()81 unmodified linesnum_computed = kwargs.get("num_computed_tokens", args[1] if len(args) > 1 else 0)if all_token_ids is not None and num_computed:adopt_for_request(req_id, all_token_ids, int(num_computed))return orig_add(self, req_id, prompt_len, *args, **kwargs)def remove_request(self, req_id, *args, **kwargs):88 unmodified linesreq_bounds[i] = (int(next(p_it)), int(next(p_it)))BATCH["req_bounds"] = req_boundsBATCH["req_bounds_T"] = Tpos_list = BATCH.get("pos_list")skip_base = not NORETRIEVE and not ORACLEif skip_base:4 unmodified linesp_first, p_last = req_bounds[i]arc_existing = ARCHIVES.get((req_id, layer))has_hole = req_id in ADOPTED or (arc_existing is not None and arc_existing.hole_hi > arc_existing.hole_lo)full_cov = (e - s) <= piece or PREFILL in ("pt", "1")if has_hole or not full_cov or (p_last - p_first != e - s - 1) or (p_first - window + 1 < ORIGIN + block):skip_base = Falsebreak61 unmodified linesbounds = [(max(s, p1 - piece), p1) for p1 in range(e, s, -piece)]q_piece = max(piece, 160)if is_prefill and PREFILL == "pt":# the PyTorch tier's decode-faithful semantics: the prefill chunk retrieves ONE block set shared by all its# queries (bound only), and the final piece (the question) gets its own retrieval with exact rescoringat_prompt_end = p_last + 1 >= arc.prompt_lencut = (e - q_piece if e - s > q_piece else s) if at_prompt_end else ebounds = []if cut > s: # split at the same absolute 2048-token boundaries the PyTorchp_s = p_first # stream uses (vLLM's prefill chunks can be ~8k tokens)b0 = sfor p in range((p_s // PT_CHUNK + 1) * PT_CHUNK, p_s + (cut - s), PT_CHUNK):b = s + (p - p_s) # positions are contiguous within a request's prefill chunkbounds.append((b0, b)); b0 = bbounds.append((b0, cut))if cut < e:bounds.append((cut, e))elif is_prefill and PREFILL not in ("0", "1"):bounds = bounds[:TAIL] # retrieval during prefill only in the last TAIL pieces of the chunkfor p0, p1 in bounds:29 unmodified lines30313233343536378 unmodified lines4647484950515253545527 unmodified lines838485868788899091929394959697989910042 unmodified lines1431441451461471481491501511521531541551561571581591601611621634 unmodified lines16816917017117217317417517617717817918018118228 unmodified lines2112122132142152162172182 unmodified lines221222223224225226227101 unmodified lines32933033133233333433533633765 unmodified lines4034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384398 unmodified lines44844945045145245345445545645745845946045 unmodified lines50650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661778 unmodified lines69669769869970070170270370454 unmodified lines759760761762763764765766119 unmodified lines88688788888989089189289389489589689765 unmodified lines9639649659669679689699701 unmodified line97297397497597697797897998010 unmodified lines99199299399499599699742 unmodified lines104010411042104310441045104610471048104962 unmodified lines1112111311141115111611171118111931 unmodified lines115111521153115411551156115712 unmodified lines11701171117211731174117511761177117811791180118111821183118411851186118711881189119024 unmodified lines1215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124381 unmodified lines13251326132713281329133013311332133388 unmodified lines14221423142414251426142714281429143014311432143314341435143614374 unmodified lines144214431444144514461447144861 unmodified lines1510151115121513151415151516151715181519152029 unmodified lineslog = logging.getLogger("vllm")MEMORY: dict = globals().get("MEMORY", {"enabled": True, "blocks": 256, "block_size": 64, "decode_blocks": 256, "neighbors": 0, "rerank": 512,"chunk": 64, "window": int(os.environ.get("PB27_WINDOW", "16384"))})DEBUG = os.environ.get("PB27_MEMORY_DEBUG", "") == "1"NORETRIEVE = os.environ.get("PB27_MEMORY_NORETRIEVE", "") == "1" # diagnostic: recompute pieces from the archive without retrievalSINKS = int(os.environ.get("PB27_MEMORY_SINKS", "4") or 0) # PB-27 was trained with 4 always-visible sink positions; vLLM8 unmodified linesORIGIN = SINKS if FAITHFUL else 0 # after the sinks (blocks at 4+64j) and keeps tailQWIN = os.environ.get("PB27_MEMORY_QWIN", "") == "1" # decode retrieval uses trailing verified query windowDSTEP = os.environ.get("PB27_MEMORY_DSTEP", "") == "1" # step-1 decode uses `blocks`; step-2+ decode uses `decode_blocks`SCALE = [2048, 384, 4096, 512, 8192, 1024]ROPE_HORIZON = 262144ROPE_ARC_SPAN = 98304ROPE_THETA = float(os.environ.get("PB27_MEMORY_ROPE_THETA", "10000000.0") or 10000000.0)OFFLOAD = os.environ.get("PB27_MEMORY_OFFLOAD", "nvme").strip().lower() # "", "cpu", "fp8", "cpu_fp8", or "nvme"# "nvme": fp8/bf16 K/V live in an unlinked sparse file mapped into memory (page cache is evictable, so resident memory# stays flat while disk holds the history); block bounds stay resident. NVME_CAP is the max tokens per request.27 unmodified linesGPU_WIN_CAP = 32768LSE = os.environ.get("PB27_MEMORY_LSE", "1") != "0" # FlashAttention-2 LSE-merge fast path for piece_attentionRERANK_ALL = os.environ.get("PB27_MEMORY_RERANK_ALL", "1") != "0" # exact rescoring for every piece, not only decodeBATCH: dict = globals().get("BATCH", {"ib": None, "pos_list": None}) # the runner's current InputBatch (req_ids, query_start_loc, ...)PROMPT_LENS: dict[str, int] = globals().get("PROMPT_LENS", {}) # req_id -> initial prompt_len from RequestState.add_requestARCHIVES: dict[tuple[str, str], "Archive"] = globals().get("ARCHIVES", {}) # (req_id, layer_name) -> ArchiveSTATS: dict = globals().get("STATS", {"calls": 0, "fallback": 0, "retrievals": 0, "pieces": 0, "tokens_archived": 0,"adopt_full": 0, "adopt_partial": 0, "adopt_none": 0, "hole_skips": 0,"pertoken": 0, "pertoken_capped": 0})# Prefix caching: vLLM skips computing the cached prefix of a new request, so the archive of the request that# produced that prefix is retained after it finishes and adopted by the next request whose tokens match it.RETAIN = int(os.environ.get("PB27_MEMORY_RETAIN", "0") or 0) # max retired archive sets kept (0 = off)RETIRED: list[dict] = globals().get("RETIRED", []) # [{"tokens": int32 tensor of the finished request, "archives": {layer: Archive}}]ADOPTED: dict[str, tuple] = globals().get("ADOPTED", {}) # req_id -> (archives by layer, hole_lo, hole_hi, num_computed)_MTIME: float = os.path.getmtime(__file__) if os.path.exists(__file__) else 0.0def configure_from_env() -> None:42 unmodified linescached_ns: int = -1 # cached sink count in cached_pre_k / cached_pre_vcached_pre_k: torch.Tensor | None = None # [ns + k*B, KV, D] FA2-ready pre_k cached on GPUcached_pre_v: torch.Tensor | None = None # [ns + k*B, KV, D] FA2-ready pre_v cached on GPUlast_prio_rank: torch.Tensor | None = None # [KV, k] priority rank of each block in sorted `top`cached_cu: tuple | None = None # (t, w_len, p_len, cu_q, cu_w, cu_p) cached int32 cu_seqlens on GPUsmax: torch.Tensor | None = None # [KV, (cap // block + SBLK - 1) // SBLK, D] coarse bf16 super-block maxsmin: torch.Tensor | None = None # [KV, (cap // block + SBLK - 1) // SBLK, D] coarse bf16 super-block minmapped_files: list[tuple[int, mmap.mmap, int]] = field(default_factory=list)last_evict_pos: int = 0def evict_page_cache(self) -> None:for fd, mm, nbytes in self.mapped_files:try:os.fdatasync(fd)mm.madvise(mmap.MADV_DONTNEED)os.posix_fadvise(fd, 0, nbytes, os.POSIX_FADV_DONTNEED)except OSError:pass@staticmethoddef new(kv: int, d: int, cap: int, block: int, dtype, device, max_hint: int = 0) -> "Archive":4 unmodified linesarc_dtype = torch.float8_e4m3fn if NVME_DTYPE == "fp8" else dtypen_blk = cap // blockn_sb = (n_blk + SBLK - 1) // SBLKmk, mf_k = _mapped(kv, big, d, arc_dtype)mv, mf_v = _mapped(kv, big, d, arc_dtype)return Archive(mk, mv,torch.empty(kv, n_blk, d, dtype=b_dtype, device=device),torch.empty(kv, n_blk, d, dtype=b_dtype, device=device),mapped=True,smax=torch.empty(kv, n_sb, d, dtype=b_dtype, device=device),smin=torch.empty(kv, n_sb, d, dtype=b_dtype, device=device),mapped_files=[mf_k, mf_v])if OFFLOAD == "nvme":cap = min(max(cap, -(-max_hint // block) * block), gpu_cap)n_blk = cap // block28 unmodified linesif OFFLOAD == "nvme" and not self.mapped and need > gpu_cap:big = max(new_cap, -(-NVME_CAP // block) * block)arc_dtype = torch.float8_e4m3fn if NVME_DTYPE == "fp8" else self.keys.dtypemk, mf_k = _mapped(kv, big, d, arc_dtype)mv, mf_v = _mapped(kv, big, d, arc_dtype)if self.size > 0:mk[:, :self.size] = self.keys[:, :self.size].to(device=mk.device, dtype=arc_dtype)mv[:, :self.size] = self.values[:, :self.size].to(device=mv.device, dtype=arc_dtype)2 unmodified linesself.sink_k = self.keys[:, :s_end].transpose(0, 1).contiguous()self.sink_v = self.values[:, :s_end].transpose(0, 1).contiguous()self.keys, self.values, self.mapped = mk, mv, Trueself.mapped_files = [mf_k, mf_v]new_cap = min(new_cap, self.keys.shape[1] // block * block)elif self.mapped:if need > self.keys.shape[1]:101 unmodified linesself.keys[:, p_idx] = kt.to(device=self.keys.device, dtype=self.keys.dtype)self.values[:, p_idx] = vt.to(device=self.values.device, dtype=self.values.dtype)self.size = max(self.size, hi)if self.mapped and self.size - self.last_evict_pos >= 65536:self.evict_page_cache()self.last_evict_pos = self.sizeif hi - 1 < ORIGIN:returnlo_b, hi_b = max(0, p0 - ORIGIN) // block, (hi - 1 - ORIGIN) // block65 unmodified linesdst_v.copy_(sv)def _mapped(kv: int, cap: int, d: int, dtype) -> tuple[torch.Tensor, tuple[int, mmap.mmap, int]]:"""[kv, cap, d] tensor backed by an unlinked sparse file; only touched pages use disk or evictable page cache."""nbytes = kv * cap * d * torch.empty(0, dtype=dtype).element_size()target_dir = NVME_DIR if (NVME_DIR and os.path.isdir(NVME_DIR)) else Nonefd, path = tempfile.mkstemp(dir=target_dir, prefix="pb27_arc_")try:os.unlink(path)os.ftruncate(fd, nbytes)mm = mmap.mmap(fd, nbytes)except Exception:os.close(fd)raisereturn torch.frombuffer(mm, dtype=torch.uint8).view(dtype).view(kv, cap, d), (fd, mm, nbytes)def _free(archives) -> None:for arc in archives.values():for fd, mm, nbytes in getattr(arc, "mapped_files", ()):try:mm.madvise(mmap.MADV_DONTNEED)os.posix_fadvise(fd, 0, nbytes, os.POSIX_FADV_DONTNEED)except OSError:passtry:os.close(fd)except OSError:passif hasattr(arc, "mapped_files"):arc.mapped_files.clear()archives.clear()if torch.cuda.is_available() and (torch.cuda.memory_reserved() - torch.cuda.memory_allocated()) > (2 << 30):torch.cuda.empty_cache()8 unmodified linesif RETAIN <= 0 or tokens is None or len(tokens) < 2 or any(a.hole_hi > a.hole_lo for a in archives.values()):_free(archives)returnfor arc in archives.values():arc.prompt_top = arc.decode_top = arc.last_top = arc.last_rk = Nonearc.cached_top = arc.cached_rk = arc.cached_rv = Nonearc.cached_pre_k = arc.cached_pre_v = arc.cached_cu = Nonearc.cached_ns = -1if arc.mapped:arc.evict_page_cache()RETIRED.append({"tokens": tokens, "archives": archives})while len(RETIRED) > RETAIN:_free(RETIRED.pop(0)["archives"])45 unmodified linesreturn t.gather(1, idx.unsqueeze(-1).expand(-1, -1, t.shape[2]))_ROPE_INV_FREQ: dict[tuple[torch.device, int], torch.Tensor] = {}def _get_rope_inv_freq(device: torch.device, d_rot: int) -> torch.Tensor:key = (device, d_rot)inv_freq = _ROPE_INV_FREQ.get(key)if inv_freq is None:inv_freq = 1.0 / (ROPE_THETA ** (torch.arange(0, d_rot, 2, device=device, dtype=torch.float32) / float(d_rot)))_ROPE_INV_FREQ[key] = inv_freqreturn inv_freqdef _reposition_rope_sinks(sk: torch.Tensor, ref_pos: int, span: int | None = None) -> torch.Tensor:"""Reposition the sink keys `sk` [KV, ns, D] from original positions `0..ns-1` to sit immediately before therepositioned archive span `[ref_pos - ROPE_ARC_SPAN, ref_pos)` when `ref_pos > ROPE_HORIZON`."""if ROPE_HORIZON <= 0 or ref_pos <= ROPE_HORIZON or sk.numel() == 0:return skkv, ns, d = sk.shaped_rot = d // 4half = d_rot // 2if half <= 0:return skarc_span = ROPE_ARC_SPAN if span is None else spandelta_val = float(max(0, ref_pos - arc_span - ORIGIN))if delta_val <= 0.0:return skinv_freq = _get_rope_inv_freq(sk.device, d_rot)angles = delta_val * inv_freqcos = angles.cos().view(1, 1, half)sin = angles.sin().view(1, 1, half)x1 = sk[..., :half].float()x2 = sk[..., half:d_rot].float()r1 = (x1 * cos - x2 * sin).to(sk.dtype)r2 = (x2 * cos + x1 * sin).to(sk.dtype)out = sk.clone()out[..., :half] = r1out[..., half:d_rot] = r2return outdef _reposition_rope_blocks(rk: torch.Tensor,blk_idx: torch.Tensor,block: int,ref_pos: int,contiguous_runs: bool = True,span: int | None = None,prio_rank: torch.Tensor | None = None,) -> torch.Tensor:"""Compress archived-block rotary positions into `[ref_pos - ROPE_ARC_SPAN, ref_pos)` when `ref_pos > ROPE_HORIZON`.Because 2D Neox-style RoPE is an abelian group (`RoPE(RoPE(k, p), delta) = RoPE(k, p + delta)`), rotating all`block` tokens of block `b` by the same shift `delta_b` preserves exact `+1` relative token offsets inside eachblock, and assigning the same `delta_b` across contiguous block runs `[b, b + 1, ...]` preserves exact `+1`relative token offsets across block boundaries without cross-head rotary drift."""if ROPE_HORIZON <= 0 or ref_pos <= ROPE_HORIZON or rk.numel() == 0:return rkkv, total_t, d = rk.shapen_blk = blk_idx.shape[1]if n_blk == 0 or total_t != n_blk * block:return rkd_rot = d // 4half = d_rot // 2if half <= 0:return rkidx = blk_idx.to(device=rk.device, dtype=torch.long)arc_span = ROPE_ARC_SPAN if span is None else spanif contiguous_runs and arc_span > 0 and n_blk > 1:is_succ = torch.zeros_like(idx, dtype=torch.bool)is_succ[:, 1:] = idx[:, 1:] == (idx[:, :-1] + 1)if prio_rank is not None and prio_rank.shape == idx.shape:pr = prio_rank.to(device=idx.device)is_succ[:, 1:] = is_succ[:, 1:] & ((pr[:, 1:] > pr[:, :-1]) | (pr[:, :-1] < 128))step = 1while step < n_blk:prev_idx = torch.cat((idx[:, :step], idx[:, :-step]), dim=1)prev_succ = torch.cat((torch.zeros_like(is_succ[:, :step]), is_succ[:, :-step]), dim=1)idx = torch.where(is_succ, prev_idx, idx)is_succ = is_succ & prev_succstep <<= 1orig_pos = (ORIGIN + idx * block).to(torch.float32)if arc_span == 0 or not contiguous_runs:end_pos = float(max(0, ref_pos - 2 * block))delta = (end_pos - orig_pos).clamp(min=0.0)else:scale = 1.0 - min(1.0, float(arc_span) / float(max(1, ref_pos)))target_pos = orig_pos + torch.round((float(ref_pos) - orig_pos).clamp(min=0.0) * scale)delta = (target_pos - orig_pos).clamp(min=0.0)inv_freq = _get_rope_inv_freq(rk.device, d_rot)angles = delta.unsqueeze(-1) * inv_freqcos = angles.cos().unsqueeze(2)sin = angles.sin().unsqueeze(2)rk_v = rk.view(kv, n_blk, block, d)x1 = rk_v[..., :half].float()x2 = rk_v[..., half:d_rot].float()r1 = (x1 * cos - x2 * sin).to(rk.dtype)r2 = (x2 * cos + x1 * sin).to(rk.dtype)out = rk.clone().view(kv, n_blk, block, d)out[..., :half] = r1out[..., half:d_rot] = r2return out.view(kv, total_t, d)def _gather_blocks(t: torch.Tensor, blk_idx: torch.Tensor, block: int) -> torch.Tensor:"""Gather contiguous blocks `blk_idx` [KV, B] starting at ORIGIN from `t` [KV, cap, D] -> [KV, B * block, D]."""kv, cap, d = t.shape78 unmodified lineselse:s_dtype = q.dtype if (q.is_cuda and q.dtype in (torch.bfloat16, torch.float16)) else torch.float32qg_s = q.to(s_dtype).permute(1, 0, 2).reshape(kv, groups * t, d)if ROPE_HORIZON > 0 and limit > ROPE_HORIZON:qg_s = qg_s.clone()qg_s[..., : d // 4] = 0pos, neg = qg_s.clamp(min=0), qg_s.clamp(max=0)if not rerank and SBLK > 1 and arc.smax is not None and arc.smin is not None and full > SBLK * 16:n_sb = (full + SBLK - 1) // SBLK54 unmodified linescand = score.topk(c, dim=-1).indices # [KV, c]ck_raw = _gather_blocks(arc.keys, cand, block).to(device=q.device)ck = ck_raw.float()if ROPE_HORIZON > 0 and limit > ROPE_HORIZON:ck = _reposition_rope_blocks(ck, cand, block, limit, contiguous_runs=False, span=0)exact = torch.einsum("gqd,gnd->gqn", qg, ck).amax(1).view(kv, c, block).amax(-1)keep = exact.topk(k, dim=-1).indicestop = cand.gather(-1, keep)119 unmodified linesif (q_hist is not None and lead == 0 and q_hist.shape[0] > 1) else q_step)t_ev, h, d = q_eval.shapekv = h // groupsref_pos = limits_dtype = q_eval.dtype if (q_eval.is_cuda and q_eval.dtype in (torch.bfloat16, torch.float16)) else torch.float32qg_s = q_eval.to(s_dtype).permute(1, 0, 2).reshape(kv, groups * t_ev, d)if ROPE_HORIZON > 0 and ref_pos > ROPE_HORIZON:qg_s = qg_s.clone()qg_s[..., : d // 4] = 0pos, neg = qg_s.clamp(min=0), qg_s.clamp(max=0)n_valid = fullhole_b0 = hole_b1 = 065 unmodified linesd_merged = torch.cat((d_inter, blk_ord[:, k_d:]), dim=-1) if k_d < blk_ord.shape[1] else d_interblk_ord = _dedup_priority(d_merged, k_sel)arc.decode_top = blk_ordif kv > 1:blk_ord = _dedup_priority(blk_ord.transpose(0, 1).reshape(1, -1), k_sel).expand(kv, -1).contiguous()dec_prio, dec_sorted = _expand_successors_dedup(blk_ord, full, k_sel, m_succ=k_sel)if arc.prompt_top is not None:p_prev = arc.prompt_top.clamp(max=full - 1)1 unmodified linen_pin = max(0, k_out - dec_prio.shape[1])merged = torch.cat((p_prev[:, :n_pin], dec_prio, p_prev[:, n_pin:]), dim=-1)top_prio = _dedup_priority(merged, k_out)blk, arc.last_prio_rank = top_prio.sort(-1)else:_, arc.last_prio_rank = dec_prio.sort(-1)blk = dec_sortedSTATS["retrievals"] += 1STATS["pertoken"] += 110 unmodified linesfor s_thresh, s_blocks in zip(SCALE[0::2], SCALE[1::2]):if n_arch > s_thresh:budget = max(budget, s_blocks)k = min(max(budget, 1024 if n_arch > 8192 else (512 if n_arch > 4096 else (384 if n_arch > 2048 else budget))), n_valid)rerank_pool = max(MEMORY["rerank"], 2 * k) if MEMORY["rerank"] > 0 else 0c0 = min(max(rerank_pool, k), n_valid)cand_mult = max(PERTOKEN_CAND, 2) if (lead is not None or t_ev > 1) else max(PERTOKEN_CAND, 1)42 unmodified linesexact_parts = []for c_s in range(0, c, 1024):c_e = min(c, c_s + 1024)cand_part = cand[:, c_s:c_e]ck_part = _gather_blocks(arc.keys, cand_part, block).to(device=q.device, dtype=torch.float32)if ROPE_HORIZON > 0 and ref_pos > ROPE_HORIZON:ck_part = _reposition_rope_blocks(ck_part, cand_part, block, ref_pos, contiguous_runs=False, span=0)ex_part = torch.bmm(qg, ck_part.transpose(-1, -2)).view(kv, groups, t_ev, c_e - c_s, block).amax(-1).amax(1)exact_parts.append(ex_part)exact = torch.cat(exact_parts, dim=-1) if len(exact_parts) > 1 else exact_parts[0]62 unmodified lineselse:merged_ord = blk_ordm_succ = min(640, k) if k > 1024 else ktop_prio, _ = _expand_successors_dedup(merged_ord, full, k, m_succ=m_succ)blk, arc.last_prio_rank = top_prio.sort(-1)if lead is not None and lead < 0:arc.prompt_top = top_prioSTATS["retrievals"] += 131 unmodified linescontig_q = (t == 1 or (q_max - q_min == t - 1))lo = max(0, q_min - window + 1)hi = q_max + 1use_lse = (own is None and LSE and HAS_FA2 and d <= 256 and q.is_cuda and q.dtype in (torch.bfloat16, torch.float16) and contig_q)tail0 = ORIGIN + ((lo - ORIGIN) // block) * blockfold_tail = bool(use_lse and t <= MEMORY["chunk"] and FAITHFUL and top is not None and lo > tail0)w_lo = tail0 if fold_tail else lo12 unmodified linespre_k = arc.cached_pre_k.to(dtype=q.dtype)pre_v = arc.cached_pre_v.to(dtype=q.dtype)else:rk_raw, rv = _gather_cached_delta(arc, top, block, q.dtype, q.device)arc.last_top = arc.last_rk = Nonearc.cached_top = toparc.cached_rk = rk_rawarc.cached_rv = rvref_pos = lork = _reposition_rope_blocks(rk_raw, top, block, ref_pos, contiguous_runs=True, prio_rank=arc.last_prio_rank)if ns > 0:if arc.sink_k is not None and ns <= arc.sink_k.shape[0]:sk_kv = arc.sink_k[:ns].transpose(0, 1).to(dtype=q.dtype)sv_t = arc.sink_v[:ns].to(dtype=q.dtype)else:sk_kv = arc.keys[:, :ns].to(device=q.device, dtype=q.dtype)sv_t = arc.values[:, :ns].to(device=q.device, dtype=q.dtype).transpose(0, 1)sk_t = _reposition_rope_sinks(sk_kv, ref_pos).transpose(0, 1)pre_k = torch.cat((sk_t, rk.transpose(0, 1)), dim=0)pre_v = torch.cat((sv_t, rv.transpose(0, 1)), dim=0)else:24 unmodified linesunmasked = (t == 1 and own is None)need_mask = not (use_lse or unmasked)parts_k, parts_v, parts_allow = [], [], []ref_pos = loif ns > 0:if arc.sink_k is not None and ns <= arc.sink_k.shape[0]:sk_kv = arc.sink_k[:ns].transpose(0, 1).to(dtype=q.dtype)parts_v.append(arc.sink_v[:ns].transpose(0, 1).to(dtype=q.dtype))else:sk_kv = arc.keys[:, :ns].to(device=q.device).to(dtype=q.dtype)parts_v.append(arc.values[:, :ns].to(device=q.device).to(dtype=q.dtype))parts_k.append(_reposition_rope_sinks(sk_kv, ref_pos))if need_mask:parts_allow.append(torch.ones(t, ns, dtype=torch.bool, device=q.device))if top is not None:if arc.last_top is top and arc.last_rk is not None:rk_raw = arc.last_rk.to(dtype=q.dtype)else:rk_raw = _gather_blocks(arc.keys, top, block).to(device=q.device).to(dtype=q.dtype) # [KV, R, D]arc.last_top = arc.last_rk = Nonerv = _gather_blocks(arc.values, top, block).to(device=q.device).to(dtype=q.dtype)rk = _reposition_rope_blocks(rk_raw, top, block, ref_pos, contiguous_runs=True, prio_rank=arc.last_prio_rank)parts_k.append(rk); parts_v.append(rv)if own is None and arc.prompt_top is not None:arc.cached_top = toparc.cached_rk = rk_rawarc.cached_rv = rvarc.cached_ns = nsarc.cached_pre_k = (parts_k[0] if len(parts_k) == 1 else torch.cat(parts_k, dim=1)).transpose(0, 1).contiguous()81 unmodified linesnum_computed = kwargs.get("num_computed_tokens", args[1] if len(args) > 1 else 0)if all_token_ids is not None and num_computed:adopt_for_request(req_id, all_token_ids, int(num_computed))if int(prompt_len) > 262144 and not ADOPTED.get(req_id, ({},))[0] and len(RETIRED) >= max(1, RETAIN):while RETIRED:_free(RETIRED.pop(0)["archives"])return orig_add(self, req_id, prompt_len, *args, **kwargs)def remove_request(self, req_id, *args, **kwargs):88 unmodified linesreq_bounds[i] = (int(next(p_it)), int(next(p_it)))BATCH["req_bounds"] = req_boundsBATCH["req_bounds_T"] = Tif any(p0 == 0 for p0, _ in req_bounds.values()):try:mt = os.path.getmtime(__file__)if mt > _MTIME:import importlibimport sysimportlib.reload(sys.modules[__name__])return sys.modules[__name__].windowed_attention_with_memory(attn_module, q, k, v, positions)except Exception:passpos_list = BATCH.get("pos_list")skip_base = not NORETRIEVE and not ORACLEif skip_base:4 unmodified linesp_first, p_last = req_bounds[i]arc_existing = ARCHIVES.get((req_id, layer))has_hole = req_id in ADOPTED or (arc_existing is not None and arc_existing.hole_hi > arc_existing.hole_lo)full_cov = (e - s) <= piece or PREFILL == "1"if has_hole or not full_cov or (p_last - p_first != e - s - 1) or (p_first - window + 1 < ORIGIN + block):skip_base = Falsebreak61 unmodified linesbounds = [(max(s, p1 - piece), p1) for p1 in range(e, s, -piece)]q_piece = max(piece, 160)if is_prefill and PREFILL == "pt":# Keep vLLM's clean shift-invariant sliding-window output for haystack chunks and run exact rescoring# retrieval + piece_attention only on the final question piece `(cut, e)` at the end of the prompt.at_prompt_end = p_last + 1 >= arc.prompt_lencut = (e - q_piece if e - s > q_piece else s) if at_prompt_end else ebounds = [(cut, e)] if cut < e else []elif is_prefill and PREFILL not in ("0", "1"):bounds = bounds[:TAIL] # retrieval during prefill only in the last TAIL pieces of the chunkfor p0, p1 in bounds:
114 unmodified lines11511611711811912011 unmodified lines132133134135136137138205 unmodified lines344345346347348349350351352353354185 unmodified lines540541542543544545177 unmodified lines723724725726727728303 unmodified lines103210331034103510361037221 unmodified lines125912601261126212631264126512661267126812691270114 unmodified lines)class _PB27MambaStateMixin(HasInnerState, IsHybrid):"""Shared Mamba/GDN state shape, dtype, and copy calculators."""11 unmodified linesdef get_mamba_state_shape_from_config(cls, vllm_config: VllmConfig) -> tuple[tuple[int, int], tuple[int, int, int]]:hf_config = vllm_config.model_config.hf_text_configtp_size = vllm_config.parallel_config.tensor_parallel_sizenum_spec = (vllm_config.speculative_config.num_speculative_tokens205 unmodified linesattention_window,)def get_layer(layer_prefix: str):return PB27Qwen3NextDecoderLayer(vllm_config,layer_type=config.layer_types[extract_layer_index(layer_prefix)],prefix=layer_prefix,hybrid_layers=hybrid_layers,attention_window=attention_window,)185 unmodified linesper_layer_sliding_window=window,)if self.is_hybrid:self.gdn = QwenGatedDeltaNetAttention(config=config,vllm_config=vllm_config,177 unmodified linessa.forward = _forward_with_memoryif self.is_hybrid:self.gdn = QwenGatedDeltaNetAttention(config=config,vllm_config=vllm_config,303 unmodified linespb_sliding_window=window if self.is_hybrid else None,)if self.is_hybrid:self.gdn = QwenGatedDeltaNetAttention(config=config,vllm_config=vllm_config,221 unmodified linesself.start_layer, self.end_layer, self.layers = make_layers(config.num_hidden_layers,lambda layer_prefix: PB27Gemma4DecoderLayer(vllm_config=vllm_config,config=config,cache_config=cache_config,quant_config=quant_config,prefix=layer_prefix,),prefix=f"{prefix}.layers",)114 unmodified lines11511611711811912012112212312412512612712812913013113213313413511 unmodified lines147148149150151152153205 unmodified lines359360361362363364365366367368369185 unmodified lines555556557558559560561177 unmodified lines739740741742743744745303 unmodified lines1049105010511052105310541055221 unmodified lines127712781279128012811282128312841285128612871288114 unmodified lines)def _ensure_linear_gdn_config(config: Any) -> Any:"""Ensure non-Qwen3.5/Qwen3Next HF configs have linear_* GDN attributes set."""for attr, default in (("linear_num_key_heads", 16),("linear_key_head_dim", 128),("linear_num_value_heads", 16),("linear_value_head_dim", 128),("linear_conv_kernel_dim", 4),("hidden_act", "silu"),):if getattr(config, attr, None) is None:setattr(config, attr, default)return configclass _PB27MambaStateMixin(HasInnerState, IsHybrid):"""Shared Mamba/GDN state shape, dtype, and copy calculators."""11 unmodified linesdef get_mamba_state_shape_from_config(cls, vllm_config: VllmConfig) -> tuple[tuple[int, int], tuple[int, int, int]]:hf_config = _ensure_linear_gdn_config(vllm_config.model_config.hf_text_config)tp_size = vllm_config.parallel_config.tensor_parallel_sizenum_spec = (vllm_config.speculative_config.num_speculative_tokens205 unmodified linesattention_window,)def get_layer(prefix: str):return PB27Qwen3NextDecoderLayer(vllm_config,layer_type=config.layer_types[extract_layer_index(prefix)],prefix=prefix,hybrid_layers=hybrid_layers,attention_window=attention_window,)185 unmodified linesper_layer_sliding_window=window,)if self.is_hybrid:_ensure_linear_gdn_config(config)self.gdn = QwenGatedDeltaNetAttention(config=config,vllm_config=vllm_config,177 unmodified linessa.forward = _forward_with_memoryif self.is_hybrid:_ensure_linear_gdn_config(config)self.gdn = QwenGatedDeltaNetAttention(config=config,vllm_config=vllm_config,303 unmodified linespb_sliding_window=window if self.is_hybrid else None,)if self.is_hybrid:_ensure_linear_gdn_config(config)self.gdn = QwenGatedDeltaNetAttention(config=config,vllm_config=vllm_config,221 unmodified linesself.start_layer, self.end_layer, self.layers = make_layers(config.num_hidden_layers,lambda prefix: PB27Gemma4DecoderLayer(vllm_config=vllm_config,config=config,cache_config=cache_config,quant_config=quant_config,prefix=prefix,),prefix=f"{prefix}.layers",)
pb27_vllm_plugin/pb27_vllm/memory.py+228-65
pb27_vllm_plugin/pb27_vllm/universal_models.py+24-6