[Refactor] Rename NSA → DSA: user-facing aliases, file/class/import rename (#25821)
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
da6d549ab2
commit
8131641bc6
@@ -87,8 +87,8 @@ class TestB200FlashCP(DSV4FlashAime25TestBase):
|
||||
"4",
|
||||
"--moe-a2a-backend",
|
||||
"deepep",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--chunked-prefill-size",
|
||||
"16384",
|
||||
|
||||
@@ -101,8 +101,8 @@ class TestB200ProCP(DSV4ProAime25TestBase):
|
||||
"8",
|
||||
"--moe-a2a-backend",
|
||||
"deepep",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--chunked-prefill-size",
|
||||
"16384",
|
||||
|
||||
@@ -89,8 +89,8 @@ class TestB300FlashCP(DSV4FlashAime25TestBase):
|
||||
"4",
|
||||
"--moe-a2a-backend",
|
||||
"deepep",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--chunked-prefill-size",
|
||||
"16384",
|
||||
|
||||
@@ -103,8 +103,8 @@ class TestB300ProCP(DSV4ProAime25TestBase):
|
||||
"8",
|
||||
"--moe-a2a-backend",
|
||||
"deepep",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--chunked-prefill-size",
|
||||
"16384",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""DSV4 Flash PD-disagg with NIXL backend. Both sides run dp-attention
|
||||
+ deepep + EAGLE MTP so attn_tp_size and the V4 state pool layout are
|
||||
fully symmetric: same SWA item_len under matching attn_tp, and same
|
||||
NSA c4/c128 indexer ring buffer size under matching spec status. nixl
|
||||
DSA c4/c128 indexer ring buffer size under matching spec status. nixl
|
||||
`send_state` is page-by-index and has no V4 TP-slice / spec-asymmetric
|
||||
path, so any layout mismatch would trip the item_len assert in
|
||||
`nixl/conn.py`."""
|
||||
|
||||
@@ -87,8 +87,8 @@ class TestGB300FlashCP(DSV4FlashAime25TestBase):
|
||||
"4",
|
||||
"--moe-a2a-backend",
|
||||
"deepep",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--chunked-prefill-size",
|
||||
"16384",
|
||||
|
||||
@@ -103,8 +103,8 @@ class TestGB300ProCP(DSV4ProAime25TestBase):
|
||||
"4",
|
||||
"--moe-a2a-backend",
|
||||
"deepep",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--chunked-prefill-size",
|
||||
"16384",
|
||||
|
||||
@@ -98,8 +98,8 @@ class TestH200Fp8FlashCP(DSV4FlashAime25TestBase):
|
||||
"4",
|
||||
"--moe-a2a-backend",
|
||||
"deepep",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--chunked-prefill-size",
|
||||
"16384",
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ from typing import Tuple
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from sglang.srt.layers.attention.nsa.tilelang_kernel import act_quant
|
||||
from sglang.srt.layers.attention.nsa.triton_kernel import act_quant as act_quant_triton
|
||||
from sglang.srt.layers.attention.dsa.tilelang_kernel import act_quant
|
||||
from sglang.srt.layers.attention.dsa.triton_kernel import act_quant as act_quant_triton
|
||||
|
||||
|
||||
def benchmark_kernel(
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import torch
|
||||
|
||||
from sglang.srt.layers.attention.nsa.index_buf_accessor import (
|
||||
from sglang.srt.layers.attention.dsa.index_buf_accessor import (
|
||||
_get_k_and_s_triton_kernel,
|
||||
)
|
||||
|
||||
+18
-18
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Correctness tests for NSA Indexer K/S Buffer Access with Fused Triton Kernels.
|
||||
Correctness tests for DSA Indexer K/S Buffer Access with Fused Triton Kernels.
|
||||
|
||||
This test verifies that the optimized Triton implementations (GetK, GetS, GetKAndS)
|
||||
produce identical results to the torch_fast baseline implementations.
|
||||
@@ -13,11 +13,11 @@ Test coverage:
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from sglang.srt.layers.attention.nsa.index_buf_accessor import GetK, GetKAndS, GetS
|
||||
from sglang.srt.layers.attention.dsa.index_buf_accessor import GetK, GetKAndS, GetS
|
||||
|
||||
|
||||
class MockNSATokenToKVPool:
|
||||
"""Mock pool object that mimics NSATokenToKVPool for testing."""
|
||||
class MockDSATokenToKVPool:
|
||||
"""Mock pool object that mimics DSATokenToKVPool for testing."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -78,7 +78,7 @@ class TestGetK:
|
||||
seq_len = min(seq_len, max_seq_len)
|
||||
|
||||
# Create mock pool
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
|
||||
@@ -119,7 +119,7 @@ class TestGetK:
|
||||
num_pages = 10
|
||||
seq_len = 320 # 5 pages
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -140,7 +140,7 @@ class TestGetK:
|
||||
num_pages = 5
|
||||
seq_len = 192 # 3 pages
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -171,7 +171,7 @@ class TestGetS:
|
||||
seq_len = min(seq_len, max_seq_len)
|
||||
|
||||
# Create mock pool
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
|
||||
@@ -212,7 +212,7 @@ class TestGetS:
|
||||
num_pages = 10
|
||||
seq_len = 320 # 5 pages
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -233,7 +233,7 @@ class TestGetS:
|
||||
num_pages = 5
|
||||
seq_len = 192 # 3 pages
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -267,7 +267,7 @@ class TestGetKAndS:
|
||||
seq_len_tensor = torch.tensor([seq_len], dtype=torch.int64, device=device)
|
||||
|
||||
# Create mock pool
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
|
||||
@@ -326,7 +326,7 @@ class TestGetKAndS:
|
||||
seq_len = 320 # 5 pages
|
||||
seq_len_tensor = torch.tensor([seq_len], dtype=torch.int64, device=device)
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -356,7 +356,7 @@ class TestGetKAndS:
|
||||
seq_len = 192 # 3 pages
|
||||
seq_len_tensor = torch.tensor([seq_len], dtype=torch.int64, device=device)
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -386,7 +386,7 @@ class TestGetKAndS:
|
||||
seq_len = 100 # Not a multiple of 64
|
||||
seq_len_tensor = torch.tensor([seq_len], dtype=torch.int64, device=device)
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -422,7 +422,7 @@ class TestEdgeCases:
|
||||
seq_len = 1
|
||||
seq_len_tensor = torch.tensor([seq_len], dtype=torch.int64, device=device)
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -455,7 +455,7 @@ class TestEdgeCases:
|
||||
seq_len = 192 # Exactly 3 pages
|
||||
seq_len_tensor = torch.tensor([seq_len], dtype=torch.int64, device=device)
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -488,7 +488,7 @@ class TestEdgeCases:
|
||||
seq_len = 4096 # 64 pages
|
||||
seq_len_tensor = torch.tensor([seq_len], dtype=torch.int64, device=device)
|
||||
|
||||
pool = MockNSATokenToKVPool(
|
||||
pool = MockDSATokenToKVPool(
|
||||
page_size=page_size, index_head_dim=index_head_dim, device=device
|
||||
)
|
||||
buf = create_test_buffer(num_pages, page_size, index_head_dim, device)
|
||||
@@ -520,7 +520,7 @@ class TestEdgeCases:
|
||||
def print_test_summary():
|
||||
"""Print a summary message about the test suite."""
|
||||
print("\n" + "=" * 80)
|
||||
print("NSA Indexer K/S Buffer Accessor Correctness Tests")
|
||||
print("DSA Indexer K/S Buffer Accessor Correctness Tests")
|
||||
print("=" * 80)
|
||||
print("Testing Triton implementations against torch_fast baseline:")
|
||||
print(" - GetK.triton() vs GetK.torch_fast()")
|
||||
@@ -55,7 +55,7 @@ class TestNightlyDeepseekV32Performance(unittest.TestCase):
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "nsa",
|
||||
"name": "dsa",
|
||||
"other_args": [
|
||||
"--trust-remote-code",
|
||||
"--tp",
|
||||
@@ -64,10 +64,10 @@ class TestNightlyDeepseekV32Performance(unittest.TestCase):
|
||||
"8",
|
||||
"--enable-dp-attention",
|
||||
"--attention-backend",
|
||||
"nsa",
|
||||
"--nsa-prefill-backend",
|
||||
"dsa",
|
||||
"--dsa-prefill-backend",
|
||||
"flashmla_sparse",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"flashmla_kv",
|
||||
"--model-loader-extra-config",
|
||||
'{"enable_multithread_load": true}',
|
||||
@@ -80,10 +80,10 @@ class TestNightlyDeepseekV32Performance(unittest.TestCase):
|
||||
"--tp",
|
||||
"8",
|
||||
"--attention-backend",
|
||||
"nsa",
|
||||
"--nsa-prefill-backend",
|
||||
"dsa",
|
||||
"--dsa-prefill-backend",
|
||||
"flashmla_sparse",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"flashmla_kv",
|
||||
"--model-loader-extra-config",
|
||||
'{"enable_multithread_load": true}',
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
"""
|
||||
Manual test for step 01: NSA → DSA user-facing alias layer.
|
||||
|
||||
Tests:
|
||||
1. CLI: --dsa-* canonical flags write to dsa_* attrs
|
||||
2. CLI: --nsa-* deprecated flags write to dsa_* attrs + log deprecation warning
|
||||
3. Registry: "dsa" key creates the backend; "nsa" key triggers DeprecationWarning
|
||||
4. Env: SGLANG_DSA_* canonical vars work
|
||||
5. Env: SGLANG_NSA_* deprecated vars fall back to SGLANG_DSA_* with DeprecationWarning
|
||||
|
||||
Run:
|
||||
python test/manual/test_dsa_alias_cli_registry_env.py
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../python"))
|
||||
|
||||
|
||||
class TestDSAChoicesAndFields(unittest.TestCase):
|
||||
"""Verify DSA_CHOICES constant and ServerArgs field renaming."""
|
||||
|
||||
def setUp(self):
|
||||
from sglang.srt.server_args import (
|
||||
DSA_CHOICES,
|
||||
DSA_PREFILL_CP_SPLIT_CHOICES,
|
||||
NSA_CHOICES,
|
||||
NSA_PREFILL_CP_SPLIT_CHOICES,
|
||||
ServerArgs,
|
||||
)
|
||||
|
||||
self.ServerArgs = ServerArgs
|
||||
self.DSA_CHOICES = DSA_CHOICES
|
||||
self.NSA_CHOICES = NSA_CHOICES
|
||||
self.DSA_PREFILL_CP_SPLIT_CHOICES = DSA_PREFILL_CP_SPLIT_CHOICES
|
||||
self.NSA_PREFILL_CP_SPLIT_CHOICES = NSA_PREFILL_CP_SPLIT_CHOICES
|
||||
|
||||
def test_dsa_choices_is_canonical(self):
|
||||
self.assertIn("fa3", self.DSA_CHOICES)
|
||||
self.assertIn("tilelang", self.DSA_CHOICES)
|
||||
|
||||
def test_nsa_choices_is_alias(self):
|
||||
self.assertIs(
|
||||
self.NSA_CHOICES,
|
||||
self.DSA_CHOICES,
|
||||
"NSA_CHOICES must be the same object as DSA_CHOICES",
|
||||
)
|
||||
|
||||
def test_nsa_cp_split_choices_is_alias(self):
|
||||
self.assertIs(
|
||||
self.NSA_PREFILL_CP_SPLIT_CHOICES,
|
||||
self.DSA_PREFILL_CP_SPLIT_CHOICES,
|
||||
)
|
||||
|
||||
def test_serverargs_has_dsa_fields(self):
|
||||
sa = self.ServerArgs
|
||||
self.assertTrue(hasattr(sa, "dsa_prefill_backend"))
|
||||
self.assertTrue(hasattr(sa, "dsa_decode_backend"))
|
||||
self.assertTrue(hasattr(sa, "enable_dsa_prefill_context_parallel"))
|
||||
self.assertTrue(hasattr(sa, "dsa_prefill_cp_mode"))
|
||||
|
||||
def test_serverargs_no_nsa_fields(self):
|
||||
"""The nsa_* attributes should no longer exist on ServerArgs."""
|
||||
sa = self.ServerArgs
|
||||
self.assertFalse(
|
||||
hasattr(sa, "nsa_prefill_backend"),
|
||||
"nsa_prefill_backend should have been renamed",
|
||||
)
|
||||
self.assertFalse(
|
||||
hasattr(sa, "nsa_decode_backend"),
|
||||
"nsa_decode_backend should have been renamed",
|
||||
)
|
||||
self.assertFalse(hasattr(sa, "enable_nsa_prefill_context_parallel"))
|
||||
self.assertFalse(hasattr(sa, "nsa_prefill_cp_mode"))
|
||||
|
||||
|
||||
class TestCLICanonicalFlags(unittest.TestCase):
|
||||
"""--dsa-* canonical flags write to dsa_* attributes with no warning."""
|
||||
|
||||
def setUp(self):
|
||||
from sglang.srt.server_args import ServerArgs
|
||||
|
||||
self.parser = argparse.ArgumentParser()
|
||||
ServerArgs.add_cli_args(self.parser)
|
||||
|
||||
def _parse(self, extra_args):
|
||||
return self.parser.parse_args(["--model", "dummy"] + extra_args)
|
||||
|
||||
def test_dsa_prefill_backend_canonical(self):
|
||||
args = self._parse(["--dsa-prefill-backend", "fa3"])
|
||||
self.assertEqual(args.dsa_prefill_backend, "fa3")
|
||||
|
||||
def test_dsa_decode_backend_canonical(self):
|
||||
args = self._parse(["--dsa-decode-backend", "tilelang"])
|
||||
self.assertEqual(args.dsa_decode_backend, "tilelang")
|
||||
|
||||
def test_enable_dsa_prefill_cp_canonical(self):
|
||||
args = self._parse(["--enable-dsa-prefill-context-parallel"])
|
||||
self.assertTrue(args.enable_dsa_prefill_context_parallel)
|
||||
|
||||
def test_dsa_prefill_cp_mode_canonical(self):
|
||||
args = self._parse(["--dsa-prefill-cp-mode", "in-seq-split"])
|
||||
self.assertEqual(args.dsa_prefill_cp_mode, "in-seq-split")
|
||||
|
||||
def test_defaults_are_none_or_false(self):
|
||||
args = self._parse([])
|
||||
self.assertIsNone(args.dsa_prefill_backend)
|
||||
self.assertIsNone(args.dsa_decode_backend)
|
||||
self.assertFalse(args.enable_dsa_prefill_context_parallel)
|
||||
self.assertEqual(args.dsa_prefill_cp_mode, "round-robin-split")
|
||||
|
||||
def test_attention_backend_dsa_key_in_choices(self):
|
||||
args = self._parse(["--attention-backend", "dsa"])
|
||||
self.assertEqual(args.attention_backend, "dsa")
|
||||
|
||||
|
||||
class TestCLIDeprecatedFlags(unittest.TestCase):
|
||||
"""--nsa-* deprecated flags write to dsa_* attributes and emit logger warning."""
|
||||
|
||||
def setUp(self):
|
||||
import logging
|
||||
|
||||
from sglang.srt.server_args import ServerArgs
|
||||
|
||||
self.parser = argparse.ArgumentParser()
|
||||
ServerArgs.add_cli_args(self.parser)
|
||||
|
||||
# Capture log output to detect deprecation warnings
|
||||
self.log_records = []
|
||||
handler = (
|
||||
logging.handlers_collector(self.log_records)
|
||||
if hasattr(logging, "handlers_collector")
|
||||
else None
|
||||
)
|
||||
|
||||
def _parse(self, extra_args):
|
||||
return self.parser.parse_args(["--model", "dummy"] + extra_args)
|
||||
|
||||
def _parse_capture_warnings(self, extra_args):
|
||||
"""Parse and capture both warnings.warn and logger output."""
|
||||
import io
|
||||
import logging
|
||||
|
||||
log_stream = io.StringIO()
|
||||
handler = logging.StreamHandler(log_stream)
|
||||
handler.setLevel(logging.WARNING)
|
||||
root = logging.getLogger()
|
||||
root.addHandler(handler)
|
||||
try:
|
||||
args = self._parse(extra_args)
|
||||
finally:
|
||||
root.removeHandler(handler)
|
||||
return args, log_stream.getvalue()
|
||||
|
||||
def test_nsa_prefill_backend_deprecated_writes_to_dsa(self):
|
||||
args, log_output = self._parse_capture_warnings(
|
||||
["--nsa-prefill-backend", "fa3"]
|
||||
)
|
||||
self.assertEqual(args.dsa_prefill_backend, "fa3")
|
||||
self.assertIn(
|
||||
"deprecated",
|
||||
log_output.lower(),
|
||||
f"Expected deprecation warning in log; got: {log_output!r}",
|
||||
)
|
||||
|
||||
def test_nsa_decode_backend_deprecated_writes_to_dsa(self):
|
||||
args, log_output = self._parse_capture_warnings(
|
||||
["--nsa-decode-backend", "tilelang"]
|
||||
)
|
||||
self.assertEqual(args.dsa_decode_backend, "tilelang")
|
||||
self.assertIn("deprecated", log_output.lower())
|
||||
|
||||
def test_enable_nsa_prefill_cp_deprecated(self):
|
||||
args, log_output = self._parse_capture_warnings(
|
||||
["--enable-nsa-prefill-context-parallel"]
|
||||
)
|
||||
self.assertTrue(args.enable_dsa_prefill_context_parallel)
|
||||
self.assertIn("deprecated", log_output.lower())
|
||||
|
||||
def test_nsa_prefill_cp_mode_deprecated(self):
|
||||
args, log_output = self._parse_capture_warnings(
|
||||
["--nsa-prefill-cp-mode", "in-seq-split"]
|
||||
)
|
||||
self.assertEqual(args.dsa_prefill_cp_mode, "in-seq-split")
|
||||
self.assertIn("deprecated", log_output.lower())
|
||||
|
||||
def test_attention_backend_nsa_still_accepted(self):
|
||||
"""attention_backend='nsa' still parses without error (registry handles the deprecation)."""
|
||||
args = self._parse(["--attention-backend", "nsa"])
|
||||
self.assertEqual(args.attention_backend, "nsa")
|
||||
|
||||
|
||||
class TestAttentionRegistry(unittest.TestCase):
|
||||
"""Registry: 'dsa' key creates backend; 'nsa' key emits DeprecationWarning."""
|
||||
|
||||
def test_dsa_key_registered(self):
|
||||
from sglang.srt.layers.attention.attention_registry import ATTENTION_BACKENDS
|
||||
|
||||
self.assertIn("dsa", ATTENTION_BACKENDS)
|
||||
|
||||
def test_nsa_key_still_registered(self):
|
||||
from sglang.srt.layers.attention.attention_registry import ATTENTION_BACKENDS
|
||||
|
||||
self.assertIn("nsa", ATTENTION_BACKENDS, "nsa must remain as deprecated alias")
|
||||
|
||||
def test_nsa_key_emits_deprecation_warning(self):
|
||||
"""Calling the nsa factory should emit DeprecationWarning."""
|
||||
from sglang.srt.layers.attention.attention_registry import ATTENTION_BACKENDS
|
||||
|
||||
nsa_factory = ATTENTION_BACKENDS.get("nsa")
|
||||
self.assertIsNotNone(nsa_factory)
|
||||
|
||||
class _FakeRunner:
|
||||
server_args = type("S", (), {"attention_backend": "nsa"})()
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
try:
|
||||
nsa_factory(_FakeRunner())
|
||||
except Exception:
|
||||
pass # import errors OK; we only care about DeprecationWarning
|
||||
dep_warns = [x for x in w if issubclass(x.category, DeprecationWarning)]
|
||||
self.assertTrue(
|
||||
len(dep_warns) > 0,
|
||||
"Expected DeprecationWarning when using 'nsa' registry key",
|
||||
)
|
||||
self.assertIn("deprecated", str(dep_warns[0].message).lower())
|
||||
|
||||
|
||||
class TestEnvVarAliases(unittest.TestCase):
|
||||
"""SGLANG_DSA_* canonical; SGLANG_NSA_* fall back with DeprecationWarning."""
|
||||
|
||||
def setUp(self):
|
||||
# Clean state for every test
|
||||
for key in [
|
||||
"SGLANG_DSA_FUSE_TOPK",
|
||||
"SGLANG_NSA_FUSE_TOPK",
|
||||
"SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD",
|
||||
"SGLANG_NSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD",
|
||||
"SGLANG_DSA_ENABLE_MTP_PRECOMPUTE_METADATA",
|
||||
"SGLANG_NSA_ENABLE_MTP_PRECOMPUTE_METADATA",
|
||||
]:
|
||||
os.environ.pop(key, None)
|
||||
# Re-import to reset descriptor state
|
||||
from importlib import reload
|
||||
|
||||
import sglang.srt.environ as e
|
||||
|
||||
reload(e)
|
||||
from sglang.srt.environ import envs
|
||||
|
||||
self.envs = envs
|
||||
|
||||
def tearDown(self):
|
||||
for key in [
|
||||
"SGLANG_DSA_FUSE_TOPK",
|
||||
"SGLANG_NSA_FUSE_TOPK",
|
||||
"SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD",
|
||||
"SGLANG_NSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD",
|
||||
]:
|
||||
os.environ.pop(key, None)
|
||||
|
||||
def test_dsa_fuse_topk_default(self):
|
||||
self.assertTrue(self.envs.SGLANG_DSA_FUSE_TOPK.get())
|
||||
|
||||
def test_dsa_fuse_topk_canonical_set(self):
|
||||
os.environ["SGLANG_DSA_FUSE_TOPK"] = "0"
|
||||
self.assertFalse(self.envs.SGLANG_DSA_FUSE_TOPK.get())
|
||||
|
||||
def test_nsa_fuse_topk_deprecated_fallback(self):
|
||||
"""SGLANG_NSA_FUSE_TOPK=0 should be read by SGLANG_DSA_FUSE_TOPK with DeprecationWarning."""
|
||||
os.environ["SGLANG_NSA_FUSE_TOPK"] = "0"
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
val = self.envs.SGLANG_DSA_FUSE_TOPK.get()
|
||||
self.assertFalse(val)
|
||||
dep = [x for x in w if issubclass(x.category, DeprecationWarning)]
|
||||
self.assertTrue(
|
||||
len(dep) > 0, "Expected DeprecationWarning for SGLANG_NSA_FUSE_TOPK"
|
||||
)
|
||||
|
||||
def test_dsa_threshold_default(self):
|
||||
self.assertEqual(
|
||||
self.envs.SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD.get(), 2048
|
||||
)
|
||||
|
||||
def test_nsa_threshold_deprecated_fallback(self):
|
||||
os.environ["SGLANG_NSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD"] = "1024"
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
val = self.envs.SGLANG_DSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD.get()
|
||||
self.assertEqual(val, 1024)
|
||||
dep = [x for x in w if issubclass(x.category, DeprecationWarning)]
|
||||
self.assertTrue(len(dep) > 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
@@ -102,55 +102,55 @@ class TestDeepseekV32(unittest.TestCase):
|
||||
)
|
||||
|
||||
@unittest.skipIf(is_blackwell_system(), "Requires H200 system")
|
||||
def test_deepseek_v32_nsa_backends(self):
|
||||
"""Test NSA attention backend variants (H200 only).
|
||||
def test_deepseek_v32_dsa_backends(self):
|
||||
"""Test DSA attention backend variants (H200 only).
|
||||
|
||||
Tests three NSA backend configurations:
|
||||
Tests three DSA backend configurations:
|
||||
- flashmla: flashmla_sparse prefill + flashmla_kv decode
|
||||
- fa3: FA3 prefill + FA3 decode
|
||||
- fp8kvcache: default backends with FP8 KV cache
|
||||
"""
|
||||
NSA_FLASHMLA_ARGS = [
|
||||
"--attention-backend=nsa",
|
||||
"--nsa-prefill-backend=flashmla_sparse",
|
||||
"--nsa-decode-backend=flashmla_kv",
|
||||
DSA_FLASHMLA_ARGS = [
|
||||
"--attention-backend=dsa",
|
||||
"--dsa-prefill-backend=flashmla_sparse",
|
||||
"--dsa-decode-backend=flashmla_kv",
|
||||
]
|
||||
|
||||
NSA_FA3_ARGS = [
|
||||
"--attention-backend=nsa",
|
||||
"--nsa-prefill-backend=fa3",
|
||||
"--nsa-decode-backend=fa3",
|
||||
DSA_FA3_ARGS = [
|
||||
"--attention-backend=dsa",
|
||||
"--dsa-prefill-backend=fa3",
|
||||
"--dsa-decode-backend=fa3",
|
||||
]
|
||||
|
||||
NSA_FP8KV_ARGS = [
|
||||
"--attention-backend=nsa",
|
||||
DSA_FP8KV_ARGS = [
|
||||
"--attention-backend=dsa",
|
||||
"--kv-cache-dtype=fp8_e4m3",
|
||||
]
|
||||
|
||||
nsa_variants = [
|
||||
dsa_variants = [
|
||||
# flashmla backend
|
||||
ModelLaunchSettings(
|
||||
DEEPSEEK_V32_MODEL_PATH,
|
||||
tp_size=8,
|
||||
extra_args=BASE_ARGS + DP_ARGS + NSA_FLASHMLA_ARGS,
|
||||
extra_args=BASE_ARGS + DP_ARGS + DSA_FLASHMLA_ARGS,
|
||||
),
|
||||
# fa3 backend
|
||||
ModelLaunchSettings(
|
||||
DEEPSEEK_V32_MODEL_PATH,
|
||||
tp_size=8,
|
||||
extra_args=BASE_ARGS + DP_ARGS + NSA_FA3_ARGS,
|
||||
extra_args=BASE_ARGS + DP_ARGS + DSA_FA3_ARGS,
|
||||
),
|
||||
# fp8 kv cache
|
||||
ModelLaunchSettings(
|
||||
DEEPSEEK_V32_MODEL_PATH,
|
||||
tp_size=8,
|
||||
extra_args=BASE_ARGS + DP_ARGS + NSA_FP8KV_ARGS,
|
||||
extra_args=BASE_ARGS + DP_ARGS + DSA_FP8KV_ARGS,
|
||||
),
|
||||
]
|
||||
|
||||
run_combined_tests(
|
||||
models=nsa_variants,
|
||||
test_name="DeepSeek-V3.2 NSA Backends",
|
||||
models=dsa_variants,
|
||||
test_name="DeepSeek-V3.2 DSA Backends",
|
||||
accuracy_params=AccuracyTestParams(
|
||||
dataset="gsm8k", baseline_accuracy=GSM8K_BASELINE
|
||||
),
|
||||
|
||||
@@ -38,7 +38,7 @@ class TestGLM5DPHiSparse(CustomTestCase):
|
||||
"--disable-radix-cache",
|
||||
"--kv-cache-dtype",
|
||||
"bfloat16",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"flashmla_sparse",
|
||||
"--enable-hisparse",
|
||||
"--hisparse-config",
|
||||
|
||||
@@ -33,7 +33,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestReturnIndexerTopk(CustomTestCase):
|
||||
"""Indexer-topk capture e2e test for DSv3.2 (NSA).
|
||||
"""Indexer-topk capture e2e test for DSv3.2 (DSA).
|
||||
|
||||
Single server with `--enable-return-indexer-topk` and `index_topk_freq=2`.
|
||||
Validates the native `/generate` endpoint only — OpenAI-protocol surface
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""AMD GLM-5.1 GSM8K Completion Evaluation Test (8-GPU)
|
||||
|
||||
Tests GLM-5.1-FP8 with NSA attention backend using few-shot
|
||||
Tests GLM-5.1-FP8 with DSA attention backend using few-shot
|
||||
completion benchmark on MI325/MI300X.
|
||||
|
||||
Registry: nightly-amd-accuracy-8-gpu-glm51 suite
|
||||
@@ -58,16 +58,16 @@ GLM51_MODELS = [
|
||||
tp_size=8,
|
||||
accuracy_threshold=0.93,
|
||||
timeout=3600,
|
||||
variant="nsa",
|
||||
variant="dsa",
|
||||
other_args=[
|
||||
"--trust-remote-code",
|
||||
"--reasoning-parser",
|
||||
"glm45",
|
||||
"--tool-call-parser",
|
||||
"glm47",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--chunked-prefill-size",
|
||||
"131072",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""AMD GLM-5 GSM8K Completion Evaluation Test (8-GPU)
|
||||
|
||||
Tests GLM-5 with NSA attention backend using few-shot completion
|
||||
Tests GLM-5 with DSA attention backend using few-shot completion
|
||||
benchmark on MI325/MI300X.
|
||||
|
||||
Registry: nightly-amd-accuracy-8-gpu-glm5 suite
|
||||
@@ -55,24 +55,24 @@ class ModelConfig:
|
||||
return self.model_path
|
||||
|
||||
|
||||
# GLM-5 models for MI325/MI300X - NSA attention backend
|
||||
# GLM-5 models for MI325/MI300X - DSA attention backend
|
||||
GLM5_MODELS = [
|
||||
# GLM-5 with NSA attention (TP=8)
|
||||
# GLM-5 with DSA attention (TP=8)
|
||||
ModelConfig(
|
||||
model_path="zai-org/GLM-5-FP8",
|
||||
tp_size=8,
|
||||
accuracy_threshold=0.93,
|
||||
timeout=3600,
|
||||
variant="nsa",
|
||||
variant="dsa",
|
||||
other_args=[
|
||||
"--trust-remote-code",
|
||||
"--reasoning-parser",
|
||||
"glm45",
|
||||
"--tool-call-parser",
|
||||
"glm47",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--chunked-prefill-size",
|
||||
"131072",
|
||||
|
||||
@@ -60,9 +60,9 @@ class TestDeepseekV32DP(CustomTestCase):
|
||||
"--enable-dp-attention",
|
||||
"--model-loader-extra-config",
|
||||
'{"enable_multithread_load": true}',
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
]
|
||||
cls.process = popen_launch_server(
|
||||
|
||||
@@ -78,9 +78,9 @@ MI35X_DEEPSEEK_V32_MODELS = [
|
||||
variant="basic",
|
||||
other_args=[
|
||||
"--trust-remote-code",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--mem-fraction-static",
|
||||
"0.85",
|
||||
|
||||
@@ -59,9 +59,9 @@ class TestDeepseekV32TPMTP(CustomTestCase):
|
||||
"--trust-remote-code",
|
||||
"--tp",
|
||||
"8",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--speculative-algorithm",
|
||||
"EAGLE",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""MI35x GLM-5.1 GSM8K Completion Evaluation Test (8-GPU)
|
||||
|
||||
Tests GLM-5.1-FP8 with NSA attention backend using few-shot
|
||||
Tests GLM-5.1-FP8 with DSA attention backend using few-shot
|
||||
completion benchmark on MI35x.
|
||||
|
||||
Registry: nightly-amd-8-gpu-mi35x-glm51 suite
|
||||
@@ -62,16 +62,16 @@ MI35X_GLM51_MODELS = [
|
||||
tp_size=8,
|
||||
accuracy_threshold=0.93,
|
||||
timeout=5400,
|
||||
variant="nsa",
|
||||
variant="dsa",
|
||||
other_args=[
|
||||
"--trust-remote-code",
|
||||
"--reasoning-parser",
|
||||
"glm45",
|
||||
"--tool-call-parser",
|
||||
"glm47",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--chunked-prefill-size",
|
||||
"131072",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""MI35x GLM-5 GSM8K Completion Evaluation Test (8-GPU)
|
||||
|
||||
Tests GLM-5 with NSA attention backend using few-shot completion
|
||||
Tests GLM-5 with DSA attention backend using few-shot completion
|
||||
benchmark on MI35x.
|
||||
|
||||
Registry: nightly-amd-8-gpu-mi35x-glm5 suite
|
||||
@@ -60,24 +60,24 @@ class ModelConfig:
|
||||
return self.model_path
|
||||
|
||||
|
||||
# GLM-5 models for MI35x - NSA attention backend
|
||||
# GLM-5 models for MI35x - DSA attention backend
|
||||
MI35X_GLM5_MODELS = [
|
||||
# GLM-5 with NSA attention (TP=8)
|
||||
# GLM-5 with DSA attention (TP=8)
|
||||
ModelConfig(
|
||||
model_path="zai-org/GLM-5-FP8",
|
||||
tp_size=8,
|
||||
accuracy_threshold=0.93,
|
||||
timeout=5400,
|
||||
variant="nsa",
|
||||
variant="dsa",
|
||||
other_args=[
|
||||
"--trust-remote-code",
|
||||
"--reasoning-parser",
|
||||
"glm45",
|
||||
"--tool-call-parser",
|
||||
"glm47",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--chunked-prefill-size",
|
||||
"131072",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Nightly performance benchmark for GLM-5.1 on MI30x.
|
||||
|
||||
Tests GLM-5.1-FP8 with NSA attention backend using bench_one_batch
|
||||
Tests GLM-5.1-FP8 with DSA attention backend using bench_one_batch
|
||||
on 8 GPUs with TP=8, FP8 KV cache.
|
||||
|
||||
Model path can be configured via GLM51_MODEL_PATH environment variable.
|
||||
@@ -53,7 +53,7 @@ PROFILE_DIR = "performance_profiles_glm51"
|
||||
class TestNightlyGLM51Performance(unittest.TestCase):
|
||||
"""Nightly performance benchmark for GLM-5.1 on MI30x.
|
||||
|
||||
Tests GLM-5.1-FP8 with NSA attention backend on TP=8.
|
||||
Tests GLM-5.1-FP8 with DSA attention backend on TP=8.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@@ -74,9 +74,9 @@ class TestNightlyGLM51Performance(unittest.TestCase):
|
||||
"glm47",
|
||||
"--tp",
|
||||
"8",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--kv-cache-dtype",
|
||||
"fp8_e4m3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Nightly performance benchmark for GLM-5 on MI30x.
|
||||
|
||||
Tests GLM-5 with NSA attention backend using bench_one_batch on 8 GPUs.
|
||||
Tests GLM-5 with DSA attention backend using bench_one_batch on 8 GPUs.
|
||||
|
||||
Model paths can be configured via environment variables:
|
||||
- GLM5_MODEL_PATH: Path to GLM-5 model (default: zai-org/GLM-5-FP8)
|
||||
@@ -54,7 +54,7 @@ PROFILE_DIR = "performance_profiles_glm5"
|
||||
class TestNightlyGLM5Performance(unittest.TestCase):
|
||||
"""Nightly performance benchmark for GLM-5.
|
||||
|
||||
Tests GLM-5 with NSA attention backend on TP=8.
|
||||
Tests GLM-5 with DSA attention backend on TP=8.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@@ -75,9 +75,9 @@ class TestNightlyGLM5Performance(unittest.TestCase):
|
||||
"glm47",
|
||||
"--tp",
|
||||
"8",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--kv-cache-dtype",
|
||||
"fp8_e4m3",
|
||||
|
||||
@@ -78,16 +78,16 @@ class TestNightlyDeepseekV32BasicPerformance(unittest.TestCase):
|
||||
cls.output_lens = tuple(_parse_int_list_env("NIGHTLY_OUTPUT_LENS", "512"))
|
||||
|
||||
# Basic variant configuration for DeepSeek-V3.2
|
||||
# MI35x uses tilelang NSA backends
|
||||
# MI35x uses tilelang DSA backends
|
||||
cls.variant_config = {
|
||||
"name": "basic",
|
||||
"other_args": [
|
||||
"--trust-remote-code",
|
||||
"--tp",
|
||||
"8",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--mem-fraction-static",
|
||||
"0.85",
|
||||
|
||||
@@ -132,16 +132,16 @@ class TestNightlyDeepseekV32MTPPerformance(unittest.TestCase):
|
||||
cls.output_lens = tuple(_parse_int_list_env("NIGHTLY_OUTPUT_LENS", "512"))
|
||||
|
||||
# MTP variant configuration for DeepSeek-V3.2
|
||||
# MI35x uses tilelang NSA backends + EAGLE speculative decoding
|
||||
# MI35x uses tilelang DSA backends + EAGLE speculative decoding
|
||||
cls.variant_config = {
|
||||
"name": "mtp",
|
||||
"other_args": [
|
||||
"--trust-remote-code",
|
||||
"--tp",
|
||||
"8",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--speculative-algorithm",
|
||||
"EAGLE",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""MI35x Nightly performance benchmark for GLM-5.1.
|
||||
|
||||
Tests GLM-5.1-FP8 with NSA attention backend using bench_one_batch
|
||||
Tests GLM-5.1-FP8 with DSA attention backend using bench_one_batch
|
||||
on 8 GPUs with TP=8, FP8 KV cache.
|
||||
|
||||
Registry: nightly-perf-8-gpu-mi35x-glm51 suite
|
||||
@@ -55,7 +55,7 @@ PROFILE_DIR = "performance_profiles_glm51_mi35x"
|
||||
class TestGLM51PerfMI35x(unittest.TestCase):
|
||||
"""Nightly performance benchmark for GLM-5.1 on MI35x.
|
||||
|
||||
Tests GLM-5.1-FP8 with NSA attention backend on TP=8.
|
||||
Tests GLM-5.1-FP8 with DSA attention backend on TP=8.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@@ -76,9 +76,9 @@ class TestGLM51PerfMI35x(unittest.TestCase):
|
||||
"glm47",
|
||||
"--tp",
|
||||
"8",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--kv-cache-dtype",
|
||||
"fp8_e4m3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""MI35x Nightly performance benchmark for GLM-5.
|
||||
|
||||
Tests GLM-5 with NSA attention backend using bench_one_batch on 8 GPUs.
|
||||
Tests GLM-5 with DSA attention backend using bench_one_batch on 8 GPUs.
|
||||
|
||||
Registry: nightly-perf-8-gpu-mi35x-glm5 suite
|
||||
"""
|
||||
@@ -54,7 +54,7 @@ PROFILE_DIR = "performance_profiles_glm5_mi35x"
|
||||
class TestGLM5PerfMI35x(unittest.TestCase):
|
||||
"""Nightly performance benchmark for GLM-5 on MI35x.
|
||||
|
||||
Tests GLM-5 with NSA attention backend on TP=8.
|
||||
Tests GLM-5 with DSA attention backend on TP=8.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@@ -75,9 +75,9 @@ class TestGLM5PerfMI35x(unittest.TestCase):
|
||||
"glm47",
|
||||
"--tp",
|
||||
"8",
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
"--kv-cache-dtype",
|
||||
"fp8_e4m3",
|
||||
|
||||
@@ -38,9 +38,9 @@ class TestDeepseekV32DP(CustomTestCase):
|
||||
]
|
||||
if is_in_amd_ci():
|
||||
other_args += [
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
]
|
||||
|
||||
@@ -106,9 +106,9 @@ class TestDeepseekV32TP(CustomTestCase):
|
||||
]
|
||||
if is_in_amd_ci():
|
||||
other_args += [
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
]
|
||||
|
||||
|
||||
@@ -54,9 +54,9 @@ class TestDeepseekV32DPMTP(CustomTestCase):
|
||||
]
|
||||
if is_in_amd_ci():
|
||||
other_args += [
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
]
|
||||
cls.process = popen_launch_server(
|
||||
@@ -146,9 +146,9 @@ class TestDeepseekV32TPMTP(CustomTestCase):
|
||||
]
|
||||
if is_in_amd_ci():
|
||||
other_args += [
|
||||
"--nsa-prefill-backend",
|
||||
"--dsa-prefill-backend",
|
||||
"tilelang",
|
||||
"--nsa-decode-backend",
|
||||
"--dsa-decode-backend",
|
||||
"tilelang",
|
||||
]
|
||||
cls.process = popen_launch_server(
|
||||
|
||||
@@ -31,8 +31,8 @@ class TestDeepseekV32CPInSeqSplit(CustomTestCase):
|
||||
"2",
|
||||
"--attn-cp-size",
|
||||
"4",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"in-seq-split",
|
||||
"--speculative-algorithm",
|
||||
"EAGLE",
|
||||
@@ -97,8 +97,8 @@ class TestDeepseekV32CPRoundRobinSplit(CustomTestCase):
|
||||
"8",
|
||||
"--attn-cp-size",
|
||||
"8",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--speculative-algorithm",
|
||||
"EAGLE",
|
||||
|
||||
@@ -158,8 +158,8 @@ class TestDSV4FlashFP4B200Balanced_CP(ServerSanityMixin, CustomTestCase):
|
||||
"1",
|
||||
"--speculative-num-draft-tokens",
|
||||
"2",
|
||||
"--enable-nsa-prefill-context-parallel",
|
||||
"--nsa-prefill-cp-mode",
|
||||
"--enable-dsa-prefill-context-parallel",
|
||||
"--dsa-prefill-cp-mode",
|
||||
"round-robin-split",
|
||||
"--deepep-config",
|
||||
DEEPEP_CONFIG,
|
||||
|
||||
+22
-22
@@ -11,15 +11,15 @@ from sglang.test.ci.ci_register import register_cuda_ci
|
||||
_dp_attn.get_attention_tp_size = lambda: 1 # TP size = 1 for unit test
|
||||
|
||||
from sglang.srt.configs.model_config import AttentionArch
|
||||
from sglang.srt.layers.attention.nsa.nsa_indexer import (
|
||||
from sglang.srt.layers.attention.dsa.dsa_indexer import (
|
||||
BaseIndexerMetadata,
|
||||
Indexer,
|
||||
rotate_activation,
|
||||
)
|
||||
from sglang.srt.layers.attention.nsa_backend import NativeSparseAttnBackend
|
||||
from sglang.srt.layers.attention.dsa_backend import DeepseekSparseAttnBackend
|
||||
from sglang.srt.layers.layernorm import LayerNorm
|
||||
from sglang.srt.layers.linear import LinearBase
|
||||
from sglang.srt.mem_cache.memory_pool import NSATokenToKVPool
|
||||
from sglang.srt.mem_cache.memory_pool import DSATokenToKVPool
|
||||
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
|
||||
from sglang.srt.server_args import ServerArgs, set_global_server_args_for_scheduler
|
||||
from sglang.test.test_utils import CustomTestCase
|
||||
@@ -136,7 +136,7 @@ class MockIndexerMetadata(BaseIndexerMetadata):
|
||||
"""Return: seq lens for each batch."""
|
||||
return torch.tensor(self.seq_lens, dtype=torch.int32, device=self.device)
|
||||
|
||||
def get_nsa_extend_len_cpu(self) -> List[int]:
|
||||
def get_dsa_extend_len_cpu(self) -> List[int]:
|
||||
"""
|
||||
Return: extend seq lens for each batch.
|
||||
"""
|
||||
@@ -179,7 +179,7 @@ class MockModelRunner:
|
||||
max_context_len = self.config["context_len"]
|
||||
max_batch_size = self.config["max_bs"]
|
||||
|
||||
# Create mock hf_config for NSA - instantiate it as an object, not a type
|
||||
# Create mock hf_config for DSA - instantiate it as an object, not a type
|
||||
hf_config = type(
|
||||
"HfConfig",
|
||||
(),
|
||||
@@ -224,9 +224,9 @@ class MockModelRunner:
|
||||
},
|
||||
)()
|
||||
|
||||
# Create NSATokenToKVPool
|
||||
# Create DSATokenToKVPool
|
||||
max_total_num_tokens = max_batch_size * max_context_len
|
||||
self.token_to_kv_pool = NSATokenToKVPool(
|
||||
self.token_to_kv_pool = DSATokenToKVPool(
|
||||
size=max_total_num_tokens,
|
||||
page_size=self.config["page_size"],
|
||||
dtype=self.config["kv_cache_dtype"],
|
||||
@@ -239,7 +239,7 @@ class MockModelRunner:
|
||||
kv_cache_dim=self.config["kv_lora_rank"] + self.config["qk_rope_head_dim"],
|
||||
)
|
||||
|
||||
# Required by backend with NSA-specific attributes
|
||||
# Required by backend with DSA-specific attributes
|
||||
self.server_args = type(
|
||||
"ServerArgs",
|
||||
(),
|
||||
@@ -248,21 +248,21 @@ class MockModelRunner:
|
||||
"speculative_eagle_topk": None,
|
||||
"speculative_num_draft_tokens": 0,
|
||||
"enable_deterministic_inference": False,
|
||||
"nsa_prefill_backend": "flashmla_sparse",
|
||||
"nsa_decode_backend": "fa3",
|
||||
"dsa_prefill_backend": "flashmla_sparse",
|
||||
"dsa_decode_backend": "fa3",
|
||||
},
|
||||
)()
|
||||
|
||||
|
||||
@unittest.skipIf(not torch.cuda.is_available(), "Test requires CUDA")
|
||||
class TestNSAIndexer(CustomTestCase):
|
||||
class TestDSAIndexer(CustomTestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Set up global server args for testing."""
|
||||
server_args = ServerArgs(model_path="dummy")
|
||||
server_args.enable_dp_attention = False
|
||||
server_args.nsa_prefill_backend = "flashmla_sparse"
|
||||
server_args.nsa_decode_backend = "flashmla_sparse"
|
||||
server_args.dsa_prefill_backend = "flashmla_sparse"
|
||||
server_args.dsa_decode_backend = "flashmla_sparse"
|
||||
set_global_server_args_for_scheduler(server_args)
|
||||
|
||||
# Check GPU capability for FP8
|
||||
@@ -289,7 +289,7 @@ class TestNSAIndexer(CustomTestCase):
|
||||
if config_override:
|
||||
config.update(config_override)
|
||||
self.model_runner = MockModelRunner(config)
|
||||
self.backend = NativeSparseAttnBackend(self.model_runner)
|
||||
self.backend = DeepseekSparseAttnBackend(self.model_runner)
|
||||
|
||||
def _create_indexer(self, **kwargs):
|
||||
"""Create an Indexer instance with default parameters."""
|
||||
@@ -417,7 +417,7 @@ class TestNSAIndexer(CustomTestCase):
|
||||
"Output should have padding or exact topk size",
|
||||
)
|
||||
|
||||
@patch("sglang.srt.layers.attention.nsa.nsa_indexer.deep_gemm")
|
||||
@patch("sglang.srt.layers.attention.dsa.dsa_indexer.deep_gemm")
|
||||
def test_indexer_basic_creation(self, mock_deep_gemm):
|
||||
"""Test basic indexer creation and initialization."""
|
||||
mock_deep_gemm.get_num_sms.return_value = 132
|
||||
@@ -431,8 +431,8 @@ class TestNSAIndexer(CustomTestCase):
|
||||
self.assertEqual(indexer.index_topk, self.config["index_topk"])
|
||||
self.assertEqual(indexer.layer_id, self.config["layer_id"])
|
||||
|
||||
@patch("sglang.srt.layers.attention.nsa.nsa_indexer.deep_gemm")
|
||||
@patch("sglang.srt.layers.attention.nsa.triton_kernel.act_quant")
|
||||
@patch("sglang.srt.layers.attention.dsa.dsa_indexer.deep_gemm")
|
||||
@patch("sglang.srt.layers.attention.dsa.triton_kernel.act_quant")
|
||||
def test_forward_extend_mode(self, mock_act_quant, mock_deep_gemm):
|
||||
"""Test indexer forward pass in extend mode."""
|
||||
if not self.supports_fp8:
|
||||
@@ -513,8 +513,8 @@ class TestNSAIndexer(CustomTestCase):
|
||||
topk_indices, self.batch_size, self.seq_len, self.config["index_topk"]
|
||||
)
|
||||
|
||||
@patch("sglang.srt.layers.attention.nsa.nsa_indexer.deep_gemm")
|
||||
@patch("sglang.srt.layers.attention.nsa.triton_kernel.act_quant")
|
||||
@patch("sglang.srt.layers.attention.dsa.dsa_indexer.deep_gemm")
|
||||
@patch("sglang.srt.layers.attention.dsa.triton_kernel.act_quant")
|
||||
def test_forward_decode_mode(self, mock_act_quant, mock_deep_gemm):
|
||||
"""Test indexer forward pass in decode mode."""
|
||||
if not self.supports_fp8:
|
||||
@@ -627,7 +627,7 @@ class TestNSAIndexer(CustomTestCase):
|
||||
self.assertEqual(topk_indices.shape, (batch_size, topk))
|
||||
|
||||
# TODO: enable this test after indexer accuracy aligned
|
||||
# @patch("sglang.srt.layers.attention.nsa.nsa_indexer.deep_gemm")
|
||||
# @patch("sglang.srt.layers.attention.dsa.dsa_indexer.deep_gemm")
|
||||
# def test_indexer_with_different_topk(self, mock_deep_gemm):
|
||||
# """Test indexer with different topk values."""
|
||||
# mock_deep_gemm.get_num_sms.return_value = 132
|
||||
@@ -637,7 +637,7 @@ class TestNSAIndexer(CustomTestCase):
|
||||
# indexer = self._create_indexer(index_topk=topk)
|
||||
# self.assertEqual(indexer.index_topk, topk)
|
||||
|
||||
@patch("sglang.srt.layers.attention.nsa.nsa_indexer.deep_gemm")
|
||||
@patch("sglang.srt.layers.attention.dsa.dsa_indexer.deep_gemm")
|
||||
def test_indexer_with_fused_wk(self, mock_deep_gemm):
|
||||
"""Test indexer creation with fused wk and weights projection."""
|
||||
mock_deep_gemm.get_num_sms.return_value = 132
|
||||
@@ -647,7 +647,7 @@ class TestNSAIndexer(CustomTestCase):
|
||||
indexer = self._create_indexer()
|
||||
self.assertIsNotNone(indexer)
|
||||
|
||||
@patch("sglang.srt.layers.attention.nsa.nsa_indexer.deep_gemm")
|
||||
@patch("sglang.srt.layers.attention.dsa.dsa_indexer.deep_gemm")
|
||||
def test_indexer_with_alt_stream(self, mock_deep_gemm):
|
||||
"""Test indexer creation with alternative CUDA stream."""
|
||||
mock_deep_gemm.get_num_sms.return_value = 132
|
||||
@@ -37,7 +37,7 @@ class TestDeepseekV32FP4DPSpecV2(CustomTestCase):
|
||||
"4",
|
||||
"--enable-dp-attention",
|
||||
"--attention-backend",
|
||||
"nsa",
|
||||
"dsa",
|
||||
"--moe-runner-backend",
|
||||
"flashinfer_trtllm",
|
||||
"--quantization",
|
||||
@@ -127,7 +127,7 @@ class TestDeepseekV32FP4TPSpecV2(CustomTestCase):
|
||||
"--tp",
|
||||
"4",
|
||||
"--attention-backend",
|
||||
"nsa",
|
||||
"dsa",
|
||||
"--moe-runner-backend",
|
||||
"flashinfer_trtllm",
|
||||
"--quantization",
|
||||
|
||||
@@ -94,11 +94,11 @@ class TestHiSparseUnit(unittest.TestCase):
|
||||
global_page_size = 1 if is_hip() else PAGE_SIZE
|
||||
|
||||
from sglang.srt.mem_cache.hisparse_memory_pool import (
|
||||
HiSparseNSATokenToKVPool,
|
||||
HiSparseDSATokenToKVPool,
|
||||
HiSparseTokenToKVPoolAllocator,
|
||||
)
|
||||
|
||||
cls.device_pool = HiSparseNSATokenToKVPool(
|
||||
cls.device_pool = HiSparseDSATokenToKVPool(
|
||||
size=SIZE,
|
||||
page_size=global_page_size,
|
||||
kv_lora_rank=KV_LORA_RANK,
|
||||
|
||||
+7
-7
@@ -2,11 +2,11 @@ import unittest
|
||||
|
||||
import torch
|
||||
|
||||
from sglang.srt.mem_cache.memory_pool import NSATokenToKVPool
|
||||
from sglang.srt.mem_cache.memory_pool import DSATokenToKVPool
|
||||
from sglang.srt.mem_cache.memory_pool_host import (
|
||||
ALLOC_MEMORY_FUNCS,
|
||||
DSAIndexerPoolHost,
|
||||
MLATokenToKVPoolHost,
|
||||
NSAIndexerPoolHost,
|
||||
alloc_with_pin_memory,
|
||||
)
|
||||
from sglang.srt.utils import is_cuda, is_hip, is_npu, is_xpu
|
||||
@@ -15,12 +15,12 @@ from sglang.test.ci.ci_register import register_cuda_ci
|
||||
register_cuda_ci(est_time=9, stage="base-b", runner_config="1-gpu-small")
|
||||
|
||||
|
||||
class TestNSAHiCacheTransfer(unittest.TestCase):
|
||||
class TestDSAHiCacheTransfer(unittest.TestCase):
|
||||
def setUp(self):
|
||||
if not torch.cuda.is_available():
|
||||
self.skipTest("CUDA is required for NSA host transfer tests.")
|
||||
self.skipTest("CUDA is required for DSA host transfer tests.")
|
||||
if is_npu() or is_xpu():
|
||||
self.skipTest("NSA host transfer tests only support CUDA/ROCm.")
|
||||
self.skipTest("DSA host transfer tests only support CUDA/ROCm.")
|
||||
if not (is_cuda() or is_hip()):
|
||||
self.skipTest("CUDA/ROCm not available.")
|
||||
|
||||
@@ -42,7 +42,7 @@ class TestNSAHiCacheTransfer(unittest.TestCase):
|
||||
layer_num = 2
|
||||
size = page_size * 4
|
||||
|
||||
device_pool = NSATokenToKVPool(
|
||||
device_pool = DSATokenToKVPool(
|
||||
size=size,
|
||||
page_size=page_size,
|
||||
kv_lora_rank=128,
|
||||
@@ -70,7 +70,7 @@ class TestNSAHiCacheTransfer(unittest.TestCase):
|
||||
allocator_type="default",
|
||||
override_kv_cache_dim=device_pool.kv_cache_dim,
|
||||
)
|
||||
indexer_host = NSAIndexerPoolHost(
|
||||
indexer_host = DSAIndexerPoolHost(
|
||||
device_pool=device_pool,
|
||||
anchor_host=mla_host,
|
||||
layout="layer_first",
|
||||
@@ -71,7 +71,7 @@ class _StubPlatform(SRTPlatform):
|
||||
def get_mla_kv_pool_cls(self):
|
||||
return object
|
||||
|
||||
def get_nsa_kv_pool_cls(self):
|
||||
def get_dsa_kv_pool_cls(self):
|
||||
return object
|
||||
|
||||
def get_paged_allocator_cls(self):
|
||||
|
||||
Reference in New Issue
Block a user