Skip to content

[Refactor] Rename NSA → DSA: user-facing aliases, file/class/import rename#25821

Merged
ch-wan merged 37 commits into
mainfrom
cheng/refactor/step01-nsa-dsa-rename
May 20, 2026
Merged

[Refactor] Rename NSA → DSA: user-facing aliases, file/class/import rename#25821
ch-wan merged 37 commits into
mainfrom
cheng/refactor/step01-nsa-dsa-rename

Conversation

@ch-wan
Copy link
Copy Markdown
Collaborator

@ch-wan ch-wan commented May 19, 2026

Motivation

NSA (Native Sparse Attention) is a misnomer — this attention variant is specific to DeepSeek and should be called DSA (DeepSeek Sparse Attention). This PR performs a full rename from nsa to dsa across user-facing CLI/env/registry surfaces and internal files, while preserving backward-compatible aliases for the user-facing layer.

Modifications

User-facing (with deprecated backward-compat aliases):

  • ServerArgs fields: nsa_prefill_backenddsa_prefill_backend, nsa_decode_backenddsa_decode_backend, enable_nsa_prefill_context_parallelenable_dsa_prefill_context_parallel, nsa_prefill_cp_modedsa_prefill_cp_mode
  • CLI flags: --dsa-* as canonical; --nsa-* kept as deprecated aliases (emit logger warning via DeprecatedAliasStoreAction)
  • Attention backend key: "dsa" as canonical; "nsa" kept with DeprecationWarning
  • Env vars: SGLANG_DSA_* canonical; SGLANG_NSA_* as deprecated fallbacks via _DeprecatedEnvFallback mixin

Internal renames (no compat layer needed):

  • layers/attention/nsa/dsa/; nsa_backend.pydsa_backend.py; nsa_indexer.pydsa_indexer.py
  • NativeSparseAttnBackendDeepseekSparseAttnBackend (one-release alias kept); NSAMetadataDSAMetadata; NSAIndexerMetadataDSAIndexerMetadata; etc.
  • Env var reads updated to SGLANG_DSA_* inside DSA backend
  • All 33+ import sites updated; test files renamed: test_nsa_indexer.pytest_dsa_indexer.py, test_nsa_pool_host_unit.pytest_dsa_pool_host_unit.py
  • handle_attention_nsahandle_attention_dsa; _create_nsa_{decode,prefill}_backend_create_dsa_*
  • attach_hybrid_nsa_pool_to_hiradix_cacheattach_hybrid_dsa_pool_to_hiradix_cache
  • Backend lists (MLA_ATTENTION_BACKENDS, FORWARD_ABSORB_CORE_ATTENTION_BACKENDS, SEPARATE_ROPE_BACKENDS) updated to include "dsa" as canonical entry

Backward-compat shims (to be removed in N+1 release):

  • layers/attention/nsa_backend.py — thin re-export shim
  • layers/attention/nsa/__init__.py — thin re-export shim

Note: the directory mv (nsa/dsa/) may rebase-conflict with upstream PR #23906 (Cuda Graph Runner refactor). Coordination recommended before merge.

Accuracy Tests

Pure rename refactor — no model forward or kernel code changed. Verified with:

  • test_dsa_indexer.py: 9 passed
  • test_dsa_alias_cli_registry_env.py: 24 passed
  • test_dsa_pool_host_unit.py: 2 passed

Speed Tests and Profiling

N/A — no computation path changes.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): 🚫 Run #26137426290
Latest PR Test (Extra): ❌ Run #26137426228

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

- Rename C++ struct fields nsa_cache_seqlens → dsa_cache_seqlens in fused_metadata_copy.cuh
- Update Python wrapper fused_metadata_copy.py param names (nsa_* → dsa_*)
- Rename get_nsa_kv_pool_cls → get_dsa_kv_pool_cls in platforms/interface.py and callers
- Update comments/docstrings: NSA → DSA across 20 files (jit_kernel, mem_cache, srt layers, disaggregation, server_args)
- Rename DeepSeekNSAAlgorithm → DeepSeekDSAAlgorithm and update imports
- Update .claude/skills references (overlap-catalog, fuse-overlap-catalog, triage_kernel_helpers)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@ch-wan ch-wan requested review from ByronHsu and YAMY1234 as code owners May 20, 2026 01:20
ch-wan and others added 2 commits May 19, 2026 18:23
Update ~25 stray NSA references in comments and docstrings across
dsa_indexer.py, cp_utils.py, pool_configurator.py, model_runner*.py,
deepseek_v4.py, forward_mha.py, forward_mla.py, model_config.py,
hisparse_hook.py, and deepseek_v2_attention_mla_npu.py.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- plugin.md: get_nsa_kv_pool_cls → get_dsa_kv_pool_cls (matches code rename)
- attention_backend.md: remove (NSA) from section header, fix anchor link

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@ch-wan ch-wan removed the run-ci label May 20, 2026
ch-wan and others added 2 commits May 19, 2026 18:30
- NSATokenToKVPool → DSATokenToKVPool (memory_pool.py + all callers)
- HiSparseNSATokenToKVPool → HiSparseDSATokenToKVPool
- NSAIndexerPoolHost → DSAIndexerPoolHost
- nsa_kv_cache_store_fp8 → dsa_kv_cache_store_fp8
- nsa_impl / nsa_impl_for_batch → dsa_impl / dsa_impl_for_batch (dsa_backend.py)
- _nsa_payload → _dsa_payload (disaggregation/prefill.py, decode.py)
- _send_swa_nsa_state → _send_swa_dsa_state (mori/conn.py)
- MockNSATokenToKVPool → MockDSATokenToKVPool (test file)
- _jit_nsa_fused_store_module → _jit_dsa_fused_store_module

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
… names

- docs_new/docs/: attention_backend.mdx, server_arguments.mdx,
  deepseek_v32.mdx, hisparse_guide.mdx, ascend docs, plugin.mdx,
  environment_variables.mdx — all --nsa-* → --dsa-*
- docs_new/cookbook/: GLM-5, GLM-5.1, DeepSeek-V3.2 mdx files
- docs_new/src/snippets/: 4 JSX deployment snippet files
- .github/workflows/: nightly AMD test job names NSA → DSA
- environ.py: comment update

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
ch-wan and others added 8 commits May 19, 2026 18:44
- StateType.NSA = "nsa" → StateType.DSA = "dsa" (symbol + wire value)
- Update all callers: disaggregation/utils.py, prefill.py, decode.py,
  nixl/conn.py, mooncake/conn.py, mori/conn.py ("nsa" string literal)
- attention_registry.py: create_nsa_backend → _create_nsa_compat
  (keeps @register_attention_backend("nsa") user-facing key + DeprecationWarning)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…OPK, get_nsa_kv_pool_cls

- test_fused_metadata_copy.py: nsa_cache_seqlens_*/nsa_cu_seqlens_k_* → dsa_* (dict keys + vars)
- environ.py: remove stale SGLANG_NSA_* EnvBool definitions (now covered by DSA canonical + alias)
- test_platform_interface.py: get_nsa_kv_pool_cls → get_dsa_kv_pool_cls
- skills/: fused_nsa_cache_seqlens → fused_dsa_cache_seqlens in profiler catalog
- docs/references/environment_variables.md: SGLANG_NSA_* → SGLANG_DSA_* as canonical + deprecated alias note
- docs_new/docs/references/environment_variables.mdx: same

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…eepseek_v4.py

- AttnTPContext.is_nsa → is_dsa (attr + init_context param)
- _nsa_needs_bf16 local var → _dsa_needs_bf16 (×2 in communicator.py)
- deepseek_v4.py: init_context(is_nsa=True) → init_context(is_dsa=True)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- test_fused_metadata_copy.py: nsa_seqlens_expanded → dsa_seqlens_expanded
- dsa_indexer.py: get_nsa_extend_len_cpu → get_dsa_extend_len_cpu
- test_dsa_indexer.py: mock get_nsa_extend_len_cpu → get_dsa_extend_len_cpu
- dequant_k_cache.py: comment nsa_backend → dsa_backend
- dsa_backend.py: comment nsa_prefill_impl → dsa_prefill_impl
- factory.py: "deepseek_nsa" dict key → "deepseek_dsa"
- model_runner_kv_cache_mixin.py: is_nsa_model → is_dsa_model (×9)
- forward_mha.py: _get_mla_kv_buffer_from_fp8_for_nsa → _for_dsa
- forward_mla.py: _skip_rope_for_nsa_tilelang_fused → _for_dsa (def + 3 calls)
- communicator.py: is_nsa/init_context param already fixed in prior commit

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ning SGLANG_NSA_* as canonical

- environ.py: add SGLANG_DSA_HIP_DISABLE_PRESHUFFLE with deprecated_name fallback
- dsa/utils.py: use envs.SGLANG_DSA_HIP_DISABLE_PRESHUFFLE; update docstring
- server_args.py: update comment to SGLANG_DSA_HIP_DISABLE_PRESHUFFLE
- docs/basic_usage/deepseek_v32.md: SGLANG_NSA_PREFILL_DENSE_ATTN_KV_LEN_THRESHOLD → DSA canonical
- docs_new/docs/basic_usage/deepseek_v32.mdx: same
- skills/fuse-overlap-catalog.md: SGLANG_NSA_FUSE_TOPK → SGLANG_DSA_FUSE_TOPK

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…iCacheTransfer → TestDSAHiCacheTransfer

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@ch-wan ch-wan added the run-ci label May 20, 2026
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@ch-wan ch-wan merged commit 8131641 into main May 20, 2026
226 of 254 checks passed
@ch-wan ch-wan deleted the cheng/refactor/step01-nsa-dsa-rename branch May 20, 2026 07:18
cursor Bot pushed a commit that referenced this pull request May 20, 2026
Conflicts: .github/workflows/nightly-test-amd.yml and
.github/workflows/nightly-test-amd-rocm720.yml.

The only main commit that touched these two files was PR #25821
"[Refactor] Rename NSA → DSA: user-facing aliases, file/class/import
rename" (8131641), which changed 4 step-name strings:

  "Accuracy Test (8-GPU GLM-5.1 NSA)"        -> "...DSA)"
  "Accuracy Test MI35x (8-GPU GLM-5.1 NSA)"  -> "...DSA)"
  "Accuracy Test ROCm 7.2 (8-GPU GLM-5.1 NSA)"      -> "...DSA)"
  "Accuracy Test MI35x ROCm 7.2 (8-GPU GLM-5.1 NSA)" -> "...DSA)"

(2 occurrences in nightly-test-amd.yml, 2 in nightly-test-amd-rocm720.yml.)

This PR's "Reorder nightly-test-amd*.yml jobs by model" commits moved
the surrounding GLM-5.1 job blocks to different physical line ranges
in the YAML. Git's 3-way merge could not reconcile "we moved a 500-line
range" with "they changed a single word in that range", so it dumped
both entire spans into one large conflict region per file.

Resolved by:
  1. taking this PR's reordered content for both nightly files
     (git checkout --ours), since the reorder is a core change of this
     PR and is content-equivalent to main's;
  2. then mechanically applying the 4 NSA -> DSA string renames on top
     so main's rename intent is preserved.

After resolution `rg "GLM-5.1 NSA" .github/workflows/nightly-test-amd*.yml`
returns 0 hits; the 4 expected "GLM-5.1 DSA" step names are present.

Verified post-merge:
  - yaml.safe_load passes on all 4 AMD workflows
  - per-workflow: jobs <-> dropdown <-> contains() gating <-> finish-needs
    sets are mutually consistent
  - no conflict markers anywhere

All other NSA -> DSA changes from #25821 are in files this PR does not
touch (docs, attention backend code, server args, etc.) and auto-merged
cleanly.

Co-authored-by: Bingxu Chen <Bingxu.Chen@amd.com>
AliceChenyy added a commit to AliceChenyy/sglang that referenced this pull request May 20, 2026
Resolve conflicts from NSA→DSA rename (sgl-project#25821):
- Migrate SM120 guards from nsa_indexer.py → dsa_indexer.py
- Migrate SM120 guards from nsa_backend.py → dsa_backend.py
- Move sm120_mqa_fallback.py, sm120_mqa_triton.py to dsa/ directory
- Update test import path to dsa.sm120_mqa_fallback
- Use is_sm120_supported() directly (no module-level _is_sm120 var)
AliceChenyy added a commit to AliceChenyy/sglang that referenced this pull request May 20, 2026
…ctor

The NSA→DSA rename (PR sgl-project#25821) changed all backend attributes from
nsa_prefill_backend/nsa_decode_backend to dsa_prefill_backend/dsa_decode_backend,
but the SM120 branches in _set_default_dsa_backends() still used the old names,
silently creating orphan attributes while leaving dsa_* as None.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shunkangz pushed a commit to Shunkangz/sglang that referenced this pull request May 27, 2026
…ename (sgl-project#25821)

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant