Skip to content

Deepseek v2 support - #693

Merged
hnyls2002 merged 6 commits into
mainfrom
deepseek
Jul 27, 2024
Merged

hnyls2002 merged 6 commits into
mainfrom
deepseek

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Jul 21, 2024 •

Copy link
Copy Markdown
Collaborator

To use deepseek v2, please sepcify the --context-length or --max-num-reqs to avoid oom. The context length for deepseek is quite large, for the current static req_to_token layout, we cannot support large requests num and large context length at the same time.

@hnyls2002
hnyls2002 marked this pull request as draft July 21, 2024 22:44
@m0g1cian

Copy link
Copy Markdown

Looking forward to see Deepseek v2 gets supported! I was trying to do the same thing two weeks ago but found the exact same issue of

RuntimeError: shape mismatch: value tensor of shape [7, 16, 256] cannot be broadcast to indexing result of shape [7, 16, 40]

@hnyls2002
hnyls2002 marked this pull request as ready for review July 26, 2024 23:31
@hnyls2002
hnyls2002 merged commit 679ebcb into main Jul 27, 2024
@hnyls2002
hnyls2002 deleted the deepseek branch July 27, 2024 00:10
@Xu-Chen

Xu-Chen commented Jul 27, 2024

Copy link
Copy Markdown
Contributor

Thank you for your excellent work. Will you support MLA in the future? Reduce KV cache to support larger context length.

@Ying1123 Ying1123 mentioned this pull request Aug 2, 2024
15 of 29 tasks
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
cen121212 pushed a commit to cen121212/sglang that referenced this pull request Nov 10, 2025
* Update test_utils.py

* Update test_utils.py

* Update test_utils.py

* Update run_suite.py

* Update run_suite.py

* Uncomment test_original_logprobs.py in test suite

* Update pr-test-npu-debug.yml

* Fix variable name from exit_code to ret_code

* Update run_suite.py

* Update run_suite.py

* Update daily-build-test-npu-innersource.yml
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…ad only STAGED

VERIFIED INDEPENDENTLY FROM SOURCE, then against F4-r4's chain -- both arrive
at the same place, which is why this ships rather than another hypothesis.

THE SPECIMEN (2026-08-16 13:58:37, sgl-project#693, all three ranks byte-identically):

    RuntimeError: Out of memory. Try to allocate 512 tokens.
    Available full tokens: 167743 (full_available_size=392 + full_evictable_size=167351)

and NO `EVICTION UNDER-DELIVERED` line. That absence is the evidence, not a hole
in it: `_eviction_shortfall_note` returns "" only when `evicted >= asked`, so
eviction reported delivering its full 512 while the pool's free count stayed at
392.

THE CHAIN, every hop read:

  1. `_evict_leaf_node` (mamba_radix_cache.py:915-916) calls
     `token_to_kv_pool_allocator.free(x.value)` and counts `len(x.value)`.
     Same for the tombstone route `_free_tombstone_leaf` (:1705-1706).
  2. `TokenToKVPoolAllocator.free` (allocator/token.py:67-80) applies pages only
     `if self.is_not_in_free_group`; otherwise `self.free_group.append(idx)`.
  3. `available_size` (:52-54) is `len(free_pages) + len(release_pages)` -- the
     staged list is in NEITHER -- and `alloc` (:56-61) compares against
     `len(free_pages)` alone.
  4. `free_group_begin` is called from inside the event loop
     (batch_result_processor.py:92 and :741). An eviction landing in that
     window frees into the staging list.

So the receipt is TRUE about the tree and FALSE about the pool: the nodes are
gone and their tokens counted, and the pages sit in `allocator.free_group`
waiting for `free_group_end()`.

NOT A POOL-TIER MISMATCH, which was the other axis: `release_pages` IS counted
by `available_size`, so a tier split would still show the tokens. And not a
race -- the group opens at a fixed point in a replicated event loop, which is
exactly why three independent processes printed identical counters.

THE FIX, AND WHY THIS ONE OF THE THREE.

  (a) flush-and-close before an eviction-driven alloc -- rejected: it ends a
      batching window the caller still owns, silently unbatching its remaining
      frees and turning its own `free_group_end` into a no-op it never asked
      for.
  (b) make `num_tokens_evicted` count only non-deferred frees -- rejected as
      THE fix: it makes the counter honest and leaves the crash, since the
      caller's last word is still the sgl-project#679 hard raise. It repairs the message,
      not the state.
  (c) SHIPPED: `flush_free_group()` applies the staged frees WITHOUT closing
      the group.

Safety is the whole question and it is answerable from the source:
`free_group_end` is PURE BATCHING -- `self.free(torch.cat(self.free_group))`,
one concat and one `_notify_free` (allocator/base.py:203-206). It defers
nothing for correctness: no in-flight reference, no graph-replay barrier, and
the same iteration applies these very pages a few lines later regardless.
Flushing moves that application earlier; it makes nothing reachable that was
not already about to be. The flag is restored so the caller's window and its
later end-call are untouched, and the staged list is consumed so that end-call
cannot double-free.

Called from `alloc_token_slots` BEFORE the relief ladder, because it is not
relief: the rungs below spend host bandwidth or a victim's decode progress,
this spends nothing. Cold path only -- it runs after an allocation has already
failed, so a healthy alloc pays nothing at all. `backup_state` is re-taken
after a flush; no caller passes it on this path today, and re-taking keeps that
a fact about the callers rather than a dependency of this fix.

TESTS. Red-first: 5 of 8 fail, and the three that matter fail with the
specimen's own `RuntimeError: Out of memory` -- sgl-project#693 reproduced hermetically.
The stand-in allocator mirrors token.py's free/alloc/group semantics and binds
the PRODUCTION `flush_free_group` onto itself rather than reimplementing it, so
the method under test is the real one. Covered: the allocation succeeding once
the staged frees are applied; the group still OPEN afterwards; the caller's
`free_group_end` still safe (no double free); no group open and nothing staged
both byte-identical; a genuinely empty pool still raising (fail-loud preserved);
and the base class carrying the method so every subclass inherits it.

NO REGRESSIONS, measured both sides on the same subset: mem_cache 940 failed /
757 passed before, 940 failed / 765 passed after -- identical failures (all
CUDA-gated collection), +8 = exactly the new cases. managers 2084 passed, 0
failed. Hermetic (CUDA_VISIBLE_DEVICES=""). NO DEPLOY.

WHAT THIS DOES NOT CLAIM. It removes the counted-but-unpayable state. It does
not make the pool larger: a genuinely exhausted pool still raises, and the
admission-side fixes (sgl-project#679 park, sgl-project#681 group-uniform ceiling) remain the layer
that should prevent reaching here at all.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 16, 2026
…ad only STAGED

VERIFIED INDEPENDENTLY FROM SOURCE, then against F4-r4's chain -- both arrive
at the same place, which is why this ships rather than another hypothesis.

THE SPECIMEN (2026-08-16 13:58:37, sgl-project#693, all three ranks byte-identically):

    RuntimeError: Out of memory. Try to allocate 512 tokens.
    Available full tokens: 167743 (full_available_size=392 + full_evictable_size=167351)

and NO `EVICTION UNDER-DELIVERED` line. That absence is the evidence, not a hole
in it: `_eviction_shortfall_note` returns "" only when `evicted >= asked`, so
eviction reported delivering its full 512 while the pool's free count stayed at
392.

THE CHAIN, every hop read:

  1. `_evict_leaf_node` (mamba_radix_cache.py:915-916) calls
     `token_to_kv_pool_allocator.free(x.value)` and counts `len(x.value)`.
     Same for the tombstone route `_free_tombstone_leaf` (:1705-1706).
  2. `TokenToKVPoolAllocator.free` (allocator/token.py:67-80) applies pages only
     `if self.is_not_in_free_group`; otherwise `self.free_group.append(idx)`.
  3. `available_size` (:52-54) is `len(free_pages) + len(release_pages)` -- the
     staged list is in NEITHER -- and `alloc` (:56-61) compares against
     `len(free_pages)` alone.
  4. `free_group_begin` is called from inside the event loop
     (batch_result_processor.py:92 and :741). An eviction landing in that
     window frees into the staging list.

So the receipt is TRUE about the tree and FALSE about the pool: the nodes are
gone and their tokens counted, and the pages sit in `allocator.free_group`
waiting for `free_group_end()`.

NOT A POOL-TIER MISMATCH, which was the other axis: `release_pages` IS counted
by `available_size`, so a tier split would still show the tokens. And not a
race -- the group opens at a fixed point in a replicated event loop, which is
exactly why three independent processes printed identical counters.

THE FIX, AND WHY THIS ONE OF THE THREE.

  (a) flush-and-close before an eviction-driven alloc -- rejected: it ends a
      batching window the caller still owns, silently unbatching its remaining
      frees and turning its own `free_group_end` into a no-op it never asked
      for.
  (b) make `num_tokens_evicted` count only non-deferred frees -- rejected as
      THE fix: it makes the counter honest and leaves the crash, since the
      caller's last word is still the sgl-project#679 hard raise. It repairs the message,
      not the state.
  (c) SHIPPED: `flush_free_group()` applies the staged frees WITHOUT closing
      the group.

Safety is the whole question and it is answerable from the source:
`free_group_end` is PURE BATCHING -- `self.free(torch.cat(self.free_group))`,
one concat and one `_notify_free` (allocator/base.py:203-206). It defers
nothing for correctness: no in-flight reference, no graph-replay barrier, and
the same iteration applies these very pages a few lines later regardless.
Flushing moves that application earlier; it makes nothing reachable that was
not already about to be. The flag is restored so the caller's window and its
later end-call are untouched, and the staged list is consumed so that end-call
cannot double-free.

Called from `alloc_token_slots` BEFORE the relief ladder, because it is not
relief: the rungs below spend host bandwidth or a victim's decode progress,
this spends nothing. Cold path only -- it runs after an allocation has already
failed, so a healthy alloc pays nothing at all. `backup_state` is re-taken
after a flush; no caller passes it on this path today, and re-taking keeps that
a fact about the callers rather than a dependency of this fix.

TESTS. Red-first: 5 of 8 fail, and the three that matter fail with the
specimen's own `RuntimeError: Out of memory` -- sgl-project#693 reproduced hermetically.
The stand-in allocator mirrors token.py's free/alloc/group semantics and binds
the PRODUCTION `flush_free_group` onto itself rather than reimplementing it, so
the method under test is the real one. Covered: the allocation succeeding once
the staged frees are applied; the group still OPEN afterwards; the caller's
`free_group_end` still safe (no double free); no group open and nothing staged
both byte-identical; a genuinely empty pool still raising (fail-loud preserved);
and the base class carrying the method so every subclass inherits it.

NO REGRESSIONS, measured both sides on the same subset: mem_cache 940 failed /
757 passed before, 940 failed / 765 passed after -- identical failures (all
CUDA-gated collection), +8 = exactly the new cases. managers 2084 passed, 0
failed. Hermetic (CUDA_VISIBLE_DEVICES=""). NO DEPLOY.

WHAT THIS DOES NOT CLAIM. It removes the counted-but-unpayable state. It does
not make the pool larger: a genuinely exhausted pool still raises, and the
admission-side fixes (sgl-project#679 park, sgl-project#681 group-uniform ceiling) remain the layer
that should prevent reaching here at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants