[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-116535":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":15,"stars7d":17,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":18,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":10,"pushedAt":37,"updatedAt":38,"readmeContent":39,"aiSummary":40,"trendingCount":16,"starSnapshotCount":16,"syncStatus":15,"lastSyncTime":41,"discoverSource":42},116535,"FlashTopK","Tencent-Hunyuan\u002FFlashTopK","Tencent-Hunyuan","Fast, exact fused top-k selection for learned sparse attention training and inference, from HyScale (Tencent Hy & University of Edinburgh).","https:\u002F\u002Farxiv.org\u002Fabs\u002F2610.32057",null,"Python",60,12,55,2,0,5,7,50.34,"Apache License 2.0",false,"main",true,[25,26,27,28,29,30,31,32,33,34,35,36],"cuda","cute-dsl","deepseek-sparse-attention","hyscale","lightning-indexer","llm-inference","llm-training","long-context","pytorch","sparse-attention","tencent-hunyuan","top-k","2026-11-09 10:12:33","2026-11-23 06:34:02","![FlashTopK, Tencent Hy](assets\u002Fbanner.png)\n\n# FlashTopK: Fast Fused Top-k Selection for Sparse Attention Training and Inference\n\n\u003Cp align=\"center\">\n  \u003Ca href=\"LICENSE\">\u003Cimg alt=\"License\" src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-Apache%202.0-blue\">\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2610.32057\">\u003Cimg alt=\"arXiv\" src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FarXiv-2610.32057-b31b1b\">\u003C\u002Fa>\n\u003C\u002Fp>\n\nFlashTopK is a fast, exact and deterministic fused top-k selection kernel for learned sparse attention, in both training and inference.\n\nOn a full prefill, FlashTopK is 1.7-3.3x faster than dense scoring + FlashInfer top-k (DeepGEMM \u002F cuDNN scoring) on trained indexers, and 1.2-2.0x faster on untrained indexers.\n\n## News\n\n[2026\u002F10] We have released **[HyScale: Scaling Long-Context Training for Learned Sparse Attention](https:\u002F\u002Farxiv.org\u002Fabs\u002F2610.32057)**.\n\n## Highlights\n\n- **Fast:** the fastest open-source implementation.\n- **Robust:** stays fast on trained and untrained indexers. Adaptive key pruning decides per call whether to skip keys by a score bound.\n- **Exact:** the true top-k. Rows the sampled threshold misses are rescored on the GPU.\n- **Deterministic:** the same bits on every run. Ties at the k-th score keep the smallest key indices.\n- **CP-compatible:** each row's threshold comes from a strided sample of its own window, so [context parallelism](docs\u002Fapi.md#training-and-context-parallelism) needs no selection from another rank.\n\n## Support\n\n| Sparse attention | Models | GPUs | Operands |\n|---|---|---|---|\n| Token-level selection, as in [DeepSeek Sparse Attention (DSA)](https:\u002F\u002Farxiv.org\u002Fabs\u002F2512.02556) | [GLM-5.1](https:\u002F\u002Fhuggingface.co\u002Fzai-org\u002FGLM-5.1), [GLM-5.2](https:\u002F\u002Fhuggingface.co\u002Fzai-org\u002FGLM-5.2), [GLM-5.3](https:\u002F\u002Fhuggingface.co\u002Fzai-org\u002FGLM-5.3), [GLM-5.3-Flash](https:\u002F\u002Fhuggingface.co\u002Fzai-org\u002FGLM-5.3-Flash), [Hy4-preview](https:\u002F\u002Fhuggingface.co\u002Ftencent\u002FHy4-preview): indexers of 32 heads × 128 | NVIDIA Hopper (SM90): H800, H20, H100, H200; NVIDIA SM100 and SM103 | FP8 or BF16, `topk` up to 4096 |\n\n[Hardware and model support](docs\u002Fhardware.md) lists which GPUs are tuned.\n\n## Getting started\n\n### Install\n\nFlashTopK needs Python 3.10+, PyTorch 2.6+, Triton 3.3+ and CuTe DSL (`nvidia-cutlass-dsl`) 4.5+. SM100 GPUs also need a CUDA 12.8+ driver.\n\n```bash\npip install -e .            # torch >= 2.6, triton >= 3.3, nvidia-cutlass-dsl >= 4.5, apache-tvm-ffi\npip install -e .[test]      # pytest for the test suite\n```\n\n### Quick start\n\nFor each query `t`, FlashTopK selects the `topk` keys `s` of its window `[ks[t], ke[t])` with the largest indexer score:\n\n```math\nI_{t,s} = \\sigma_s \\sum_{h=1}^{H_I} w_{t,h}\\,\\mathrm{ReLU}\\big(\\mathbf{q}_{t,h}^{\\top}\\mathbf{k}_s\\big)\n```\n\nHere **q**\u003Csub>t,h\u003C\u002Fsub> is head h of `q[t]`, **k**\u003Csub>s\u003C\u002Fsub> is `kv[s]`, w\u003Csub>t,h\u003C\u002Fsub> is head h's weight in `weights[t]`, σ\u003Csub>s\u003C\u002Fsub> is `kv_scales[s]` (1 for BF16 keys) and H\u003Csub>I\u003C\u002Fsub> = 32 is the number of heads. A causal prefill chunk of 4096 queries over 128K FP8 keys:\n\n```python\nimport torch\nimport flashtopk\n\nnum_q, seq_len_kv = 4096, 128 * 1024\nq = torch.randn(num_q, 32, 128, device=\"cuda\").to(torch.float8_e4m3fn)        # 32 heads of dimension 128\nkv = torch.randn(seq_len_kv, 128, device=\"cuda\").to(torch.float8_e4m3fn)       # one key per token\nkv_scales = torch.rand(seq_len_kv, device=\"cuda\") * 0.02 + 0.01                # FP8 keys need per-key scales\nweights = torch.randn(num_q, 32, device=\"cuda\") * 0.1                          # per-head weights, float32\n\n# The queries are the last num_q tokens: query i sees keys [0, seq_len_kv - num_q + i + 1).\nke = torch.arange(seq_len_kv - num_q + 1, seq_len_kv + 1, device=\"cuda\", dtype=torch.int32)\nks = torch.zeros_like(ke)\n\nindices = flashtopk.select(q, kv, weights, ks, ke, kv_scales, topk=2048)  # [4096, 2048] int32\n```\n\nThe first call in a process compiles the kernels it needs, about 15 seconds in all. `Selector.plan()` compiles them up front.\n\n### Usage\n\n```python\nflashtopk.select(q, kv, weights, ks, ke, kv_scales=None, topk=2048, ...)  # indices; return_scores=True adds scores\nselector = flashtopk.Selector(topk=2048, dtype=...).plan(max_rows, max_kv)  # owns the workspace, compiles up front\nselector.run(q, kv, weights, ks, ke, kv_scales)                             # select's arguments and outputs\ntorch.ops.flashtopk.select(...)                                             # select as a custom op, for torch.compile\nflashtopk.windows_from_cu_seqlens(cu_seqlens_q, cu_seqlens_k)               # causal windows of packed sequences\n```\n\nThe [API reference](docs\u002Fapi.md) covers every argument, the workspace, `last_info`, configuration and training with context parallelism.\n\n## Performance\n\nSpeedup of one full prefill (query rows = keys = the sequence length) over dense scoring + FlashInfer top-k on H800, with FP8 or BF16 operands. The [performance report](docs\u002Fperformance.md) has H20 and SM100 as well.\n\n### Trained indexer\n\n\u003Cp align=\"center\">\u003Cimg src=\"assets\u002Fperformance_trained_h800.png\" alt=\"FlashTopK against public top-k selectors on a trained indexer, H800\" width=\"100%\">\u003C\u002Fp>\n\nFlashTopK is the fastest at every length, and its lead grows with the length.\n\n### Untrained indexer\n\n\u003Cp align=\"center\">\u003Cimg src=\"assets\u002Fperformance_untrained_h800.png\" alt=\"FlashTopK against public top-k selectors on an untrained indexer, H800\" width=\"100%\">\u003C\u002Fp>\n\nThe score bound skips few keys, so FlashTopK mostly scans; it still leads at every length.\n\nThe [performance report](docs\u002Fperformance.md) describes the setup and the methods compared. It also has the results on random indexer weights and keys. [`reproduce\u002F`](reproduce\u002FREADME.md) provides pinned setup, inputs, comparison benchmarks and scripts to regenerate the figures.\n\n## Roadmap\n\n- Block-level learned sparse attention, such as CSA in [DeepSeek-V4](https:\u002F\u002Farxiv.org\u002Fabs\u002F2606.19348) and QSA in [Qwen3.8-Flash-Next](https:\u002F\u002Farxiv.org\u002Fabs\u002F2608.30320).\n- Paged KV cache; today the keys must be contiguous, with one contiguous window per query row.\n- Indexers with other head counts, such as the 64 heads of DeepSeek-V3.2.\n\n## License\n\nFlashTopK is released under the Apache License 2.0. See [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE) for details.\n\n## Acknowledgments\n\nFlashTopK builds on [FlashInfer](https:\u002F\u002Fgithub.com\u002Fflashinfer-ai\u002Fflashinfer) and [TensorRT-LLM](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FTensorRT-LLM) (the SM100 scan pipeline, which the pruning and refine kernels share), [LiteTopK](https:\u002F\u002Fgithub.com\u002FHeisenberg-Yin\u002FLiteTopK) (gate calibration and candidate selection) and [DoSA](https:\u002F\u002Farxiv.org\u002Fabs\u002F2610.13990) (the score bound of key pruning). [`NOTICE`](NOTICE) lists the files each part derives from.\n\n## Citation\n\n```bibtex\n@misc{deng2026hyscale,\n  title         = {HyScale: Scaling Long-Context Training for Learned Sparse Attention},\n  author        = {Yangshen Deng and Xinjing Huang and Yulong Wang and Yunzhuo Liu and Jun Hu and Shuyong Tan and Chun-Chih Tseng and Mingji Han and Ray Ying and Key Zhang and Luo Mai},\n  year          = {2026},\n  eprint        = {2610.32057},\n  archivePrefix = {arXiv},\n  primaryClass  = {cs.AI},\n  url           = {https:\u002F\u002Farxiv.org\u002Fabs\u002F2610.32057},\n}\n```\n","FlashTopK 是一个面向学习型稀疏注意力机制的快速、精确且确定性的融合 Top-k 选择内核，专为大语言模型训练与推理中的长上下文场景优化。它通过 CUDA 层面的算子融合（基于 CuTe DSL）实现高效 key 筛选，在预填充阶段显著优于传统密集打分+FlashInfer 方案；支持自适应键剪枝、FP8\u002FBF16 混合精度、上下文并行兼容，并保证结果严格精确与跨运行一致性。适用于基于 DeepSeek Sparse Attention 等架构的稀疏 LLM 训练与长文本推理任务。","2026-11-24 04:53:46","CREATED_QUERY"]