[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:
Cheng Wan
2026-05-20 00:18:04 -07:00
committed by GitHub
co-authored by Claude Sonnet 4.6
parent da6d549ab2
commit 8131641bc6
162 changed files with 11298 additions and 10740 deletions
+2 -2
View File
@@ -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",
+2 -2
View File
@@ -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",
+2 -2
View File
@@ -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",
+2 -2
View File
@@ -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 -1
View File
@@ -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`."""
+2 -2
View File
@@ -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",
+2 -2
View File
@@ -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",
+2 -2
View File
@@ -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",
@@ -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,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,
)
@@ -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)