[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-107623":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":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":26,"updatedAt":27,"readmeContent":28,"aiSummary":29,"trendingCount":16,"starSnapshotCount":16,"syncStatus":19,"lastSyncTime":30,"discoverSource":31},107623,"latent-sparse-attention","Prefrontal-AI\u002Flatent-sparse-attention","Prefrontal-AI","Code for Latent Sparse Attention: Towards Subquadratic Ultra-Long Context Attention","",null,"Python",474,64,1,3,0,7,281,2,58.92,"Apache License 2.0",false,"main",true,[],"2026-11-16 16:04:58","2026-11-21 02:43:01","# Latent Sparse Attention\n\n**Towards Subquadratic Ultra-Long Context Attention**\n\n[![Paper](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FarXiv-2610.42147-b31b1b?logo=arxiv&logoColor=white)](https:\u002F\u002Farxiv.org\u002Fabs\u002F2610.42147)\n[![SGLang fork](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSGLang%20fork-lsa--v0.1.0-24292f?logo=github)](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Fsglang\u002Ftree\u002Flsa-v0.1.0)\n[![Docker image](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fghcr.io-sglang%3Alsa--v0.1.0-2496ed?logo=docker&logoColor=white)](https:\u002F\u002Fgithub.com\u002Forgs\u002FPrefrontal-AI\u002Fpackages\u002Fcontainer\u002Fpackage\u002Fsglang)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-Apache%202.0-blue)](LICENSE)\n\n![D-LSA and N-LSA overview](assets\u002Foverview.png)\n\n*One global attention layer under D-LSA and N-LSA. Keys are pooled and clustered into buckets, and a query scores the bucket centroids, then attends only to the selected long-range keys plus the sink and window.*\n\n## TL;DR\n\nLatent Sparse Attention (LSA) clusters keys hierarchically in a learned latent space, and each query scores the clusters instead of every key.\nPrefill, decode and training get faster at long context, while accuracy stays close to the original model's.\n\n- **D-LSA** (Distilled) is applied to a pre-trained model by distilling its indexer.\n  On GLM-5.3-Flash at 10M tokens it speeds up one attention layer by 22.7x in prefill and 4.6x in decode over the model's own sparse attention.\n  On Qwen3.8-27B it is 72.4x and 42.5x faster than full attention.\n- **N-LSA** (Native) is trained from scratch on the next-token loss alone.\n  It matches the accuracy of full attention, and its training is 1.6x faster per layer at 128k tokens.\n\nThe attention kernel is unchanged.\nLSA only decides which keys it reads.\n\n## Contents\n\n| Method | Paper name | Where |\n|---|---|---|\n| Distilled LSA, flat search | D-LSA (Flat) | `src\u002Flsa\u002Fcore`, served by `src\u002Flsa\u002Fsglang` |\n| Distilled LSA, tree search | D-LSA (Tree) | same |\n| Training-free LSA, a PCA map | D-LSA (Training-Free) | same |\n| Distillation of the index space | - | `src\u002Flsa\u002Ftraining\u002Fdistillation` |\n| Native LSA and the native baselines (Full Attention, SWA, NSA, PISA) | N-LSA | `src\u002Flsa\u002Ftraining\u002Fnative` |\n| Served baselines | Block Sparse Attention (Flat, Tree) | `src\u002Flsa\u002Fbaselines` |\n| Accuracy, kernel and end-to-end evaluations | - | `src\u002Flsa\u002Fevaluation` |\n\nEverything runs through one command, `lsa`.\n\n## Installation\n\nPython 3.12 and [uv](https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002F) 0.10 or later are needed.\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention.git\ncd latent-sparse-attention\nuv sync --locked --extra evaluation --extra training\nuv run lsa --help\n```\n\nFor evaluation alone, use `uv sync --locked --extra evaluation`.\n\nThe `training` extra builds `causal-conv1d` from source against the locked torch (CUDA 12.9), which needs a 12.x `nvcc` on `PATH`, 12.8 or later for B300 (sm_100) kernels.\ntorch's extension builder raises on an `nvcc` of another CUDA major version, so CUDA 13 does not work, and a 12.4 to 12.7 `nvcc` still builds for H200.\nWithout one, skip it:\n\n```bash\nuv sync --locked --extra evaluation --extra training --no-install-package causal-conv1d\n```\n\nOnly GLM-5.3-Flash's delta-attention layers use the package, and without it `transformers` runs a slower PyTorch kernel for them.\n\nA failed sync does not fail loudly later.\n`uv run lsa --help` works on the base dependencies alone, so it proves nothing about the extras.\nTo check them, run this - `hf` is the Hugging Face CLI that `transformers` installs, so it lands in `.venv\u002Fbin` only with an extra:\n\n```bash\n.venv\u002Fbin\u002Fhf version && uv run --no-sync python -c \"import transformers, lm_eval\"\n```\n\nThe results in the paper were measured on NVIDIA H200 GPUs.\n\n## Quick start: serve a model with LSA\n\nLSA is an SGLang plugin.\nIt runs in the serving image of our [SGLang fork](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Fsglang\u002Ftree\u002Flsa-v0.1.0), which adds the context-parallel and long-context support the 10M-token runs need.\nLSA itself is not in the image - you install this repository into it.\n\nPull the image and start a container with this repository, a distilled map and the Hugging Face cache mounted.\nThe image is built with CUDA 13.0.3, and B300 (Blackwell) nodes take their own image, tagged `lsa-v0.1.0-b300`.\nTo build it from source, run the fork's `docker\u002Fenroot\u002Fbuild.sh` at the tag, from a checkout of it - it needs Docker with buildx and enroot, no GPU, and writes `sglang-lsa-\u003Csha10>.sqsh`, where `\u003Csha10>` is the first 10 characters of the commit (`042d955ba3` for `lsa-v0.1.0`).\n`--cuda \u003Cversion>` builds against another CUDA version, `--ref \u003Ccommit>` another commit and `--out-dir \u003Cdir>` writes elsewhere.\n\nWith Docker, which needs the NVIDIA container runtime:\n\n```bash\ndocker pull ghcr.io\u002Fprefrontal-ai\u002Fsglang:lsa-v0.1.0\ndocker run -it --rm --gpus '\"device=0\"' --shm-size 32g --network host -e HF_HOME=\u002Fhf \\\n  -v $PWD:\u002Fworkspace\u002Flatent-sparse-attention:ro -v \u003Cmaps directory>:\u002Fmaps:ro -v $HF_HOME:\u002Fhf \\\n  ghcr.io\u002Fprefrontal-ai\u002Fsglang:lsa-v0.1.0 bash\n```\n\nDocker refuses a symlink as a mount source, so pass real directories.\n\nWith enroot on Slurm, which needs no GPU to import:\n\n```bash\nenroot import -o sglang-lsa-042d955ba3.sqsh 'docker:\u002F\u002Fghcr.io#prefrontal-ai\u002Fsglang:lsa-v0.1.0'\nenroot create --name lsa sglang-lsa-042d955ba3.sqsh\nenroot start --rw -e HF_HOME=\u002Fhf -m $PWD:\u002Fworkspace\u002Flatent-sparse-attention:none:x-create=dir,rbind,ro \\\n  -m \u003Cmaps directory>:\u002Fmaps:none:x-create=dir,rbind,ro -m $HF_HOME:\u002Fhf lsa bash\n```\n\nThe import takes about 10 minutes and `enroot create` about 20 for the 26 GB image, and both print little while they run, so create the container once and reuse it.\nThe checkout and the maps are read-only as in Docker, and a bare `-m` is read-write.\nEnroot spells that `:none:rbind,ro` plus `x-create=dir`: naming any option drops enroot's default `x-create=auto`, so without it the mount fails with `No such file or directory` when the mount point is not in the image (use `x-create=file` for a file).\n\nInside the container, install this repository and pass an `lsa` block in the model config:\n\n```bash\npip install --no-deps \u002Fworkspace\u002Flatent-sparse-attention\npython -m sglang.launch_server --model-path Qwen\u002FQwen3.8-27b --tp 1 \\\n  --attention-backend fa3 --page-size 1 --disable-prefill-cuda-graph \\\n  --json-model-override-args '{\"lsa\": {\"projections\": \"\u002Fmaps\u002Fqwen38_27b.pt\", \"query_heads\": \"all\"}}'\n```\n\n`--disable-prefill-cuda-graph` is required.\nLSA selects keys for a prefill on the host, which a CUDA graph cannot capture, so without the flag the server crashes during startup.\nDecode is still captured.\n\nThe plugin registers through SGLang's `sglang.srt.plugins` entry point and arms itself from the `lsa` block.\nThe server log prints `armed` when it does.\nWithout that line, the server is running the checkpoint's own attention.\nThe line appears before startup finishes, so wait for `\u002Fhealth` and send a request:\n\n```bash\ncurl -s localhost:30000\u002Fv1\u002Fcompletions -H 'Content-Type: application\u002Fjson' \\\n  -d '{\"model\": \"Qwen\u002FQwen3.8-27b\", \"prompt\": \"The capital of France is\", \"max_tokens\": 32}'\n```\n\nEvery key of the block defaults to the paper's flat design, and `docs\u002Freference\u002Fnotation.md` names each one.\n`projections` is a distilled map: train one (see [Distillation](#distillation)), or use the maps of the `d-lsa-weights-v1` release, see [Weights](#weights).\nOn a machine without internet access, download the model first and add `-e HF_HUB_OFFLINE=1` to `docker run` or `enroot start`.\n\nFor GLM-5.3-Flash, the full server settings are in `configs\u002Fevaluation\u002Faccuracy\u002Fglm53_flash\u002Flsa_flat_early_budget_tp8.yaml`.\n\n## Reproducing the paper\n\nThe evaluation harness starts the server, runs a suite against it and writes a record.\nEach command below submits a Slurm job through a *site* (see [Running on a cluster](#running-on-a-cluster)).\nAdd `--dry-run` to print what would be submitted.\n\nConfigs are named `\u003Cmethod>_\u003Cmesh>[_\u003Cslice>].yaml` under one directory per model, `qwen38_27b` or `glm53_flash`:\n\n| Paper method | Config stem |\n|---|---|\n| Full Attention | `full` (Qwen3.8-27B) |\n| Block Sparse Attention (Flat) | `qsa` on Qwen3.8-27B, `native` on GLM-5.3-Flash - each model's own indexer |\n| Block Sparse Attention (Tree) | `pisa_c8` |\n| D-LSA (Flat) | `lsa_flat`, and `lsa_flat_early_budget` on GLM-5.3-Flash |\n| D-LSA (Tree) | `lsa_tree` |\n| D-LSA (Training-Free) | `lsa_flat_pca` |\n\n### Accuracy (Section 4.2)\n\nPrepare RULER once for the model's tokenizer, then score a config.\nPreparation is deterministic - every haystack source is pinned by checksum, so the sets match the paper's byte for byte.\n\nThe accuracy config reads the sets from `data\u002Fbenchmarks-qwen38` under the site's root, so `--root` is that exact directory.\n`eval \"$(lsa --site mycluster env)\"` sets `LSA_ROOT` to the site's `root` if it is not set already.\nIt also sets the Hugging Face cache variables and turns on offline mode (`HF_HUB_OFFLINE=1`, `TRANSFORMERS_OFFLINE=1`), so in a shell you keep open, run `hf download` with `HF_HUB_OFFLINE=0` in front, or download first.\n\n```bash\neval \"$(lsa --site mycluster env)\"\nlsa --site mycluster data prepare ruler --tokenizer Qwen\u002FQwen3.8-27b \\\n  --root \"$LSA_ROOT\u002Fdata\u002Fbenchmarks-qwen38\" --lengths 4096 32768 --cpus 16 --mem-gb 64 --hours 2\nlsa --site mycluster evaluate accuracy configs\u002Fevaluation\u002Faccuracy\u002Fqwen38_27b\u002Flsa_flat_tp1.yaml \\\n  data.suite=ruler \"data.tasks=[ruler]\" \"data.lengths=[4096,32768]\" \\\n  run.output=\u003Cdir> --gpus 1 --hours 4\n```\n\n`data.tasks=[ruler]` selects every RULER task, and `data.lengths` narrows the cells.\nFor GLM-5.3-Flash, drop `--tokenizer` and `--root`, since its tokenizer is the default.\nAdd `--fetch-in-job` to `data prepare` when the machine you submit from has no network access but the compute nodes do.\n\nExpected results, RULER mean over 13 tasks of 100 rows each, from a clean checkout:\n\n| Run | 4k | 32k | Paper 4k | Paper 32k | Wall time |\n|---|---|---|---|---|---|\n| Qwen3.8-27B, D-LSA (Flat), 1 H200 | 0.974 | 0.968 | 0.975 | 0.966 | 1 h 52 min |\n| GLM-5.3-Flash, D-LSA (Flat) with early budget, 8 H200 | 0.973 | 0.968 | 0.973 | 0.968 | about 40 min |\n\n`data.suite` also takes `papertrail`, `full` and `smoke` (four rows per task, for a quick check).\n`full_tp1.yaml` scores the dense baseline, which needs no map.\n\n### Performance (Section 4.3)\n\n```bash\n# One attention layer on one GPU, prefill and decode, 128k to 10M tokens\nlsa --site mycluster evaluate kernels configs\u002Fevaluation\u002Fkernels\u002Fglm53_flash\u002Flsa_flat.yaml\n# Complete served requests end to end\nlsa --site mycluster evaluate production configs\u002Fevaluation\u002Fproduction\u002Fglm53_flash\u002Flsa_flat_cp8.yaml\n```\n\nSwap the stem for each method, and `glm53_flash` for `qwen38_27b`.\nThe configs prefixed `b300_` measure on B300.\n\n### Native training (Section 4.4)\n\nThe native arms pre-train a 24-layer hybrid model on 100B tokens of FineWeb-Edu at 4k, then decay at 128k on 12B tokens of LongDocs, each arm from its own checkpoint.\nEach sparse arm reads about 2,560 keys per query in the decay.\n\n| Arm | Pre-train | 128k decay |\n|---|---|---|\n| Full Attention | `pretrain_fineweb.yaml` | `decay_fineweb128k.yaml` |\n| SWA | `pretrain_fineweb_window.yaml` | `decay_fineweb128k_window.yaml` |\n| NSA | `nsam8.yaml` | `decay_fineweb128k_nsa.yaml` |\n| PISA | `pisam8.yaml` | `decay_fineweb128k_pisa.yaml` |\n| N-LSA | `pretrain_fineweb_lsa.yaml` | `decay_fineweb128k_lsa.yaml` |\n\n```bash\nlsa --site mycluster native train configs\u002Ftraining\u002Fnative\u002Fqwen35_0_8b_gpt2\u002Fpretrain_fineweb_lsa.yaml --gpus 8\nlsa --site mycluster native train configs\u002Ftraining\u002Fnative\u002Fqwen35_0_8b_gpt2\u002Fdecay_fineweb128k_lsa.yaml --gpus 8\nlsa --site mycluster native evaluate configs\u002Ftraining\u002Fnative\u002Fqwen35_0_8b_gpt2\u002Fdecay_fineweb128k_lsa.yaml \\\n  --checkpoint \u003Ccheckpoint> --suite benchmark\n```\n\nThe configs live in `configs\u002Ftraining\u002Fnative\u002Fqwen35_0_8b_gpt2\u002F`, and its README lists the other presets.\nAdd `--dry-run` to print each resolved run before submitting it.\n\n### Distillation\n\nD-LSA learns its index space from a frozen model on documents drawn from LongDocs, then exports the map the server reads:\n\n```bash\nlsa --site mycluster distill targets configs\u002Fdata\u002Ftargets\u002Fqwen38_27b\u002Flong_16k_1m_heavy.yaml\nlsa --site mycluster distill train configs\u002Ftraining\u002Fdistillation\u002Fqwen38_27b\u002Flong_16k_1m_heavy_key_and_query_d2048.yaml\nlsa distill export \u003Crun's maps.pt> \u003Cout.pt>\n```\n\n`long_16k_1m_heavy_key_and_query_d2048_smoke.yaml` runs a single step.\n\n## Released artifacts\n\n| Artifact | Needed for | Status |\n|---|---|---|\n| SGLang fork, tag `lsa-v0.1.0` | every served run | [available](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Fsglang\u002Ftree\u002Flsa-v0.1.0) |\n| LongDocs, the long-document corpus | distillation and the native 128k decay | assembled from the hub with `lsa data prepare \u003Csource>`, see [data\u002Flongdocs](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Ftree\u002Fmain\u002Fdata\u002Flongdocs) - the lock files are in [release `longdocs-locks-v1`](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Freleases\u002Ftag\u002Flongdocs-locks-v1) |\n| Agent traces `games` and `edgebench`, scrubbed | the distillation mix | [release `traces-v1`](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Freleases\u002Ftag\u002Ftraces-v1), see [the data guide](docs\u002Fguide\u002Fdata.md#sources) |\n| Distilled maps for Qwen3.8-27B and GLM-5.3-Flash | every `lsa_*` served config | [release `d-lsa-weights-v1`](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Freleases\u002Ftag\u002Fd-lsa-weights-v1) |\n| Checkpoints of the ten 128k decays of the native comparison, N-LSA and its baselines | `lsa native evaluate` | [release `n-lsa-weights-v1`](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Freleases\u002Ftag\u002Fn-lsa-weights-v1) |\n| PaperTrail | the `papertrail` suite | rebuilt from its kit, which is in the repository, with `lsa data prepare papertrail` - see [data\u002Fpapertrail](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Ftree\u002Fmain\u002Fdata\u002Fpapertrail) |\n| RULER haystack sources | `lsa data prepare ruler`, which rebuilds the paper's RULER sets byte for byte | [release `ruler-sources-v1`](https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Freleases\u002Ftag\u002Fruler-sources-v1) |\n\n### Weights\n\nThe distilled maps of D-LSA are assets of the release `d-lsa-weights-v1`, and the checkpoints of the native comparison, N-LSA included, of the release `n-lsa-weights-v1`.\nBoth unpack into the layout the configs read, under the site's `root` (`LSA_ROOT` overrides it).\nThe commands below use `gh`, which must be installed and needs no login for a public repository.\nWithout it, `curl -fL --create-dirs -o \"\u003Cdest>\u002F\u003Casset>\" https:\u002F\u002Fgithub.com\u002FPrefrontal-AI\u002Flatent-sparse-attention\u002Freleases\u002Fdownload\u002F\u003Ctag>\u002F\u003Casset>` fetches one asset, with no login either.\nRepeat the command for each asset, with the `\u003Cdest>` of the `gh` command that follows for that kind of asset: `$LSA_ROOT\u002Fmodels\u002Fmaps` for the distilled maps and `$LSA_ROOT\u002Fdownloads` for the parts of a native checkpoint and `SHA256SUMS`.\nThe distilled maps are single files that go in `models\u002Fmaps\u002F`, where the `lsa_*` configs name them as `${root:models\u002Fmaps\u002F\u003Cname>.pt}`:\n\n```bash\ngh release download d-lsa-weights-v1 -R Prefrontal-AI\u002Flatent-sparse-attention --pattern '*.pt' --dir \"$LSA_ROOT\u002Fmodels\u002Fmaps\"\n```\n\nA native checkpoint is a torchtitan step folder of 2.3 GB, split in two parts below the 2 GiB limit of a release asset.\nThere is one for each of the ten 128k decays of the comparison:\n\n| Arm | Checkpoints | Configs under `configs\u002Ftraining\u002Fnative\u002Fqwen35_0_8b_gpt2\u002F` |\n|---|---|---|\n| Full Attention | `decay128k-dense` | `evaluate_released_dense.yaml` |\n| SWA, window 2,560 and 4,608 | `decay128k-swa-2560`, `decay128k-swa-4608` | `evaluate_released_swa_2560.yaml`, `evaluate_released_swa_4608.yaml` |\n| NSA, 2,048 and 4,096 selected keys | `decay128k-nsa-2048`, `decay128k-nsa-4096` | `evaluate_released_nsa_2048.yaml`, `evaluate_released_nsa_4096.yaml` |\n| PISA, 2,368 and 4,416 keys | `decay128k-pisa-2368`, `decay128k-pisa-4416` | `evaluate_released_pisa_2368.yaml`, `evaluate_released_pisa_4416.yaml` |\n| N-LSA, 1,024, 2,048 and 4,096 long-range keys | `decay128k-lsa-1024`, `decay128k-lsa-2048`, `decay128k-lsa-4096` | `evaluate_released_lsa_k1024.yaml`, `evaluate_released_lsa_k2048.yaml`, `evaluate_released_lsa_k4096.yaml` |\n\nJoin the parts of the ones you want and unpack them at the root, which creates `training\u002Fnative\u002Freleased\u002F\u003Ccheckpoint>\u002Fcheckpoint\u002Fstep-5866`:\n\n```bash\ngh release download n-lsa-weights-v1 -R Prefrontal-AI\u002Flatent-sparse-attention --pattern 'decay128k-lsa-2048.tar.part-*' --pattern SHA256SUMS --dir \"$LSA_ROOT\u002Fdownloads\"\n(cd \"$LSA_ROOT\u002Fdownloads\" && sha256sum --check --ignore-missing SHA256SUMS && cat decay128k-lsa-2048.tar.part-* | tar -x -C \"$LSA_ROOT\")\nlsa native evaluate configs\u002Ftraining\u002Fnative\u002Fqwen35_0_8b_gpt2\u002Fevaluate_released_lsa_k2048.yaml --suite benchmark\n```\n\nEach config names its checkpoint, so no `--checkpoint` is needed.\nThe archive holds the step folder only.\nThe weights were trained with a different trainer, which is not released, and the tensors are mapped to the names of this one, which a reload checks exactly.\n\n## Running on a cluster\n\nA site holds everything specific to one machine, and no run spells it.\nIt is `configs\u002Fsite\u002F\u003Cname>.yaml`, chosen with `lsa --site \u003Cname>`.\nThe default, `local`, is an example to copy.\n\n\u003Cdetails>\n\u003Csummary>A Slurm site\u003C\u002Fsummary>\n\n```yaml\n# configs\u002Fsite\u002Fmycluster.yaml\nlauncher: slurm\nslurm:\n  partition: \u003Cpartition>\n  account: \u003Caccount>\nroot: \u002Fpath\u002Fto\u002Fshared\u002Fstorage\u002Flsa\ndatasets: \u002Fpath\u002Fto\u002Fshared\u002Fdatasets\nhf_home: \u002Fpath\u002Fto\u002Fhub\u002Fcache\nmounts: []\nimages:\n  h200: \u002Fpath\u002Fto\u002Fsglang-lsa-\u003Csha10>.sqsh\n  b300: \"\"\n```\n\nEvery `slurm` key is optional, and an unset key adds no sbatch flag.\nLarge artifacts - targets, maps, records and logs - live under `root`.\n`LSA_ROOT` and `HF_HOME` override `root` and `hf_home`, and `LSA_EXTRA_MOUNTS` adds directories to the serving container.\nJobs read the Hugging Face cache offline, so download a model first, for example `hf download Qwen\u002FQwen3.8-27b`.\nThat download is about 52 GB and a job log shows no progress for it, so run it in a terminal where the progress bar prints.\n`images` names the image built above, or a docker tag your runner can pull, and `run.image=\u003Cfile or tag>` overrides it for one run.\n\n\u003C\u002Fdetails>\n\n## Documentation\n\n| Document | Covers |\n|---|---|\n| `docs\u002Fguide\u002Fevaluation.md` | Accuracy, kernel and end-to-end evaluations |\n| `docs\u002Fguide\u002Ftraining.md` | Distillation and native training |\n| `docs\u002Fguide\u002Fdata.md` | Preparing benchmarks, targets and corpora |\n| `docs\u002Fguide\u002Fmodels.md` | Running LSA on another checkpoint, and the `lsa` block |\n| `docs\u002Fguide\u002Fadapters.md` | Writing an adapter for a new model |\n| `docs\u002Fguide\u002Fdevelopment.md` | Checks, tests and conventions |\n| `docs\u002Freference\u002Fnotation.md` | Every symbol and config key, mapped to its name in the code |\n\n## Development\n\n```bash\nmake sync     # uv sync --locked\nmake format   # apply every fix a tool can make\nmake check    # lint, types and the tests the installed environment can run\n```\n\nThe `gpu` and `cluster` test markers need a GPU and are deselected in CI.\n\n## Citation\n\n```bibtex\n@misc{kubicek2026latentsparseattentionsubquadratic,\n      title={Latent Sparse Attention: Towards Subquadratic Ultra-Long Context Attention}, \n      author={Ales Kubicek and Andrea Caciolai and Liangzu Peng and Sukrit Sumant and Benjamin Hoover and Fraser Greenlee and Ruairidh M. Battleday and Radim Urban and Torsten Hoefler and James C. R. Whittington},\n      year={2026},\n      eprint={2610.42147},\n      archivePrefix={arXiv},\n      primaryClass={cs.AI},\n      url={https:\u002F\u002Farxiv.org\u002Fabs\u002F2610.42147}, \n}\n```\n\n## License\n\nApache-2.0, see `LICENSE`.\nThird-party code keeps its own license, see `THIRD_PARTY_NOTICES.md`.\nThe PaperTrail kit in `data\u002Fpapertrail` is CC BY 4.0, by Sukrit Sumant, and the text of every dataset assembled from the hub keeps the license its source gave it, also in `THIRD_PARTY_NOTICES.md`.\n\n## Acknowledgements\n\nServing builds on [SGLang](https:\u002F\u002Fgithub.com\u002Fsgl-project\u002Fsglang).\nThe NSA training kernels are adapted from [flash-linear-attention](https:\u002F\u002Fgithub.com\u002Ffla-org\u002Fflash-linear-attention).\nLong-context accuracy uses [RULER](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FRULER) and [LongBench v2](https:\u002F\u002Fgithub.com\u002FTHUDM\u002FLongBench).\n\n## Contributors\n\n- [Ales Kubicek](https:\u002F\u002Fgithub.com\u002Faleskubicek)\n- [Andrea Caciolai](https:\u002F\u002Fgithub.com\u002Fcaciolai)\n- [Liangzu Peng](https:\u002F\u002Fgithub.com\u002Fliangzu)\n- [Sukrit Sumant](https:\u002F\u002Fgithub.com\u002FSukritSumant)\n","Latent Sparse Attention（LSA）是一种面向超长上下文的亚二次复杂度稀疏注意力机制，通过在隐空间中对键（keys）进行分层聚类，使查询仅与高相关性簇中心及选定的关键键交互，从而大幅降低计算开销。其包含Distilled LSA（D-LSA）和Native LSA（N-LSA）两种实现：前者可即插即用地加速已有大模型（如Qwen、GLM），后者支持端到端训练并保持与全注意力相当的精度。项目提供统一命令行工具lsa，兼容SGLang推理框架，并已集成Docker镜像。适用于需要处理数十万乃至百万级token上下文的大语言模型推理与训练场景，如长文档理解、代码补全与多轮对话记忆建模。","2026-11-24 04:32:26","CREATED_QUERY"]