[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-abertsch72--unlimiformer":3,"tool-abertsch72--unlimiformer":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",159636,2,"2026-04-17T23:33:34",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":67,"readme_en":68,"readme_zh":69,"quickstart_zh":70,"use_case_zh":71,"hero_image_url":72,"owner_login":73,"owner_name":74,"owner_avatar_url":75,"owner_bio":76,"owner_company":77,"owner_location":78,"owner_email":77,"owner_twitter":77,"owner_website":79,"owner_url":80,"languages":81,"stars":86,"forks":87,"last_commit_at":88,"license":89,"difficulty_score":90,"env_os":91,"env_gpu":92,"env_ram":93,"env_deps":94,"category_tags":100,"github_topics":77,"view_count":32,"oss_zip_url":77,"oss_zip_packed_at":77,"status":17,"created_at":101,"updated_at":102,"faqs":103,"releases":133},8959,"abertsch72\u002Funlimiformer","unlimiformer","Public repo for the NeurIPS 2023 paper \"Unlimiformer: Long-Range Transformers with Unlimited Length Input\"","Unlimiformer 是一款专为突破大模型输入长度限制而设计的开源工具，源自 NeurIPS 2023 的研究成果。它巧妙地为预训练的编码器 - 解码器模型（如 Llama-2 及其衍生版本）引入了基于检索的注意力机制，让模型能够处理无限长度的输入文本，例如整本书籍或超长文档，而无需修改原有的注意力数学定义或重新训练整个架构。\n\n传统 Transformer 模型受限于固定的上下文窗口，难以处理长序列数据，往往导致信息丢失或需要复杂的截断策略。Unlimiformer 通过动态检索机制解决了这一痛点，允许模型在推理阶段直接关注完整的历史输入。其独特之处在于支持“即插即用”，既能直接提升已有模型的性能，也支持结合特定训练策略以获得最佳效果。此外，它还提供了灵活的层级控制参数，让用户可以指定从哪一层开始启用长程注意力，从而在计算效率与生成质量之间找到平衡。\n\n这款工具非常适合 AI 研究人员、大模型开发者以及需要处理长文本任务的技术团队使用。无论是希望探索长上下文应用场景的研究者，还是试图让现有模型胜任长篇摘要、法律文档分析等任务的工程师，Unlimiformer 都提供了一个高效且低","Unlimiformer 是一款专为突破大模型输入长度限制而设计的开源工具，源自 NeurIPS 2023 的研究成果。它巧妙地为预训练的编码器 - 解码器模型（如 Llama-2 及其衍生版本）引入了基于检索的注意力机制，让模型能够处理无限长度的输入文本，例如整本书籍或超长文档，而无需修改原有的注意力数学定义或重新训练整个架构。\n\n传统 Transformer 模型受限于固定的上下文窗口，难以处理长序列数据，往往导致信息丢失或需要复杂的截断策略。Unlimiformer 通过动态检索机制解决了这一痛点，允许模型在推理阶段直接关注完整的历史输入。其独特之处在于支持“即插即用”，既能直接提升已有模型的性能，也支持结合特定训练策略以获得最佳效果。此外，它还提供了灵活的层级控制参数，让用户可以指定从哪一层开始启用长程注意力，从而在计算效率与生成质量之间找到平衡。\n\n这款工具非常适合 AI 研究人员、大模型开发者以及需要处理长文本任务的技术团队使用。无论是希望探索长上下文应用场景的研究者，还是试图让现有模型胜任长篇摘要、法律文档分析等任务的工程师，Unlimiformer 都提供了一个高效且低成本的解决方案。","# Unlimiformer: Long-Range Transformers with Unlimited Length Input (NeurIPS 2023)\n![unlimiformer_diagram3_with_overlaps](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_1434ef2c14b3.png)\n\nThis is the official implementation of the paper:\n\n[Amanda Bertsch](https:\u002F\u002Fwww.cs.cmu.edu\u002F~abertsch\u002F), [Uri Alon](https:\u002F\u002Furialon.ml\u002F), [Graham Neubig](http:\u002F\u002Fwww.phontron.com\u002F), and [Matthew R. Gormley](http:\u002F\u002Fwww.cs.cmu.edu\u002F~mgormley\u002F):   \n[Unlimiformer: Long-Range Transformers with Unlimited Length Input](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2305.01625) (to appear in **NeurIPS 2023**)\n\nUnlimiformer is a method for augmenting pretrained encoder-decoder models with retrieval-based attention, without changing the mathematical definition of attention. \nThis allows the use of unlimited length inputs with any pretrained encoder-decoder!  \nSee also our [**Tweet**](https:\u002F\u002Ftwitter.com\u002Fabertsch72\u002Fstatus\u002F1654110919977324545?s=20).\n\nUnlimiformer can be used to improve the performance of an already-trained model. For best results, the model can be trained with Unlimiformer training. \n\nIf you have any questions on this work, please open a [GitHub issue](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fissues) or email the authors at ```abertsch@cs.cmu.edu, ualon@cs.cmu.edu```\n\n## **_October 2023_** - Unlimiformer will appear at NeurIPS 2023!\n\n## **_August 2023_** - Unlimiformer now supports **Llama-2** (and all its derivatives)! \nTo prompt Llama-2 with extremely long inputs, for example, the content of an *entire book*, use:\n```bash\npython src\u002Frun_generation.py --model_type llama --model_name_or_path meta-llama\u002FLlama-2-13b-chat-hf \\\n    --prefix \"\u003Cs>[INST] \u003C\u003CSYS>>\\n You are a helpful assistant. Answer with detailed responses according to the entire instruction or question. \\n\u003C\u003C\u002FSYS>>\\n\\n Summarize the following book: \" \\\n    --prompt example_inputs\u002Fharry_potter_full.txt \\\n    --suffix \" [\u002FINST]\" --test_unlimiformer --fp16 --length 200 --layer_begin 16 \\\n    --index_devices 1 --datastore_device 1 \n```\n* The final prompt will be a concatenation of the content of the flags: `--prefix`, `--prompt`, `--suffix`.\n* The flag `--prompt` may contain either a path to a text file (e.g., `example_inputs\u002Fharry_potter_full.txt`) or the concrete prompt string.\n* The flag `--test_unlimiformer` is required to enable Unlimiformer.\n* The flag `--length` determines the desired output length.\n* The flag `--layer_begin` determines the layer from which Unlimiformer will start to be applied. For example, if we set `--layer_begin 20`, the first 20 layers of the model will perform the standard attention over the last `context_window_size` tokens of the prompt as usual, and the 21st layer and above will attend to the _entire long input_. From our initial experiments, the value of `--layer_begin` should be more than half of the total number of layers in the model, and tuning it dramatically changes the quality of the output.\n* The flags: `--datastore_device N` and `--index_devices N1 N2 N3 ...` specify on which GPUs to store Unlimiformer's datastore and index (the base model will be stored on GPU #0).\n* Add the flag `--stream_output` to make the generated tokens appear one by one as they are generated.\n\n\n## Getting Started\n\n### General Instructions\nCopy the files from `src` into your source code folder.\n\nYou'll need to set values for the Unlimiformer-specific arguments outlined in [`usage.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Fusage.py) - you can add these arguments wherever you usually process hyperparameters. To use the model, you must set `test_unlimiformer=True`. For datastore usage, the model must be in evaluation model (e.g. call ```model.eval()``` before inference). \n\n[`inference-example.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Finference-example.py) outlines a minimal example for running a sequence through an Unlimiformer model, using the default arguments. \n\n[`run.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Frun.py) is an example of a full training setup that integrates Unlimiformer, adopted from [SLED](https:\u002F\u002Fgithub.com\u002FMivg\u002FSLED). See full command lines below.\n\n### Reproducing the Experiments from the Paper - Command Lines\n\nTo run a standard finetuning + evaluation of BART-base on the GovReport dataset (as examples), use:\n```python\npython src\u002Frun.py \\\n    src\u002Fconfigs\u002Ftraining\u002Fbase_training_args.json \\\n    src\u002Fconfigs\u002Fdata\u002Fgov_report.json \\\n    --output_dir output_train_bart_base_local\u002F \\\n    --learning_rate 1e-5 \\\n    --model_name_or_path facebook\u002Fbart-base \\\n    --max_source_length 1024 \\\n    --eval_max_source_length 1024 --do_eval=True \\\n    --eval_steps 1000 --save_steps 1000 \\\n    --per_device_eval_batch_size 1 --per_device_train_batch_size 2 \\\n    --extra_metrics bertscore\n```\n\n* To use Unlimiformer at **training** time (called \"Retrieval training\" in the paper), use: `--unlimiformer_training --max_source_length 16384`\n    * In this case, you might want to use Unlimiformer also at **test**\u002Fvalidation time, and use also: `--test_unlimiformer --eval_max_source_length 999999`\n* Alternatively, to use the computationally cheaper \"Random-encoded\" at **training** time, use `--random_unlimiformer_training --max_source_length 16384`\n* To alternate between \"retrieval training\" and \"random-encoded training\", use both flags: `--unlimiformer_training --random_unlimiformer_training --max_source_length 16384`\n\nFor additional flags and options, see [`usage.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Fusage.py)\n\n\n## Recommended settings\n\n### To evaluate with Unlimiformer\nAt evaluation time, we recommend the default value for each setting. \n\n### To train with Unlimiformer\nFor an inexpensive method, we recommend training as usual and using Unlimiformer during early stopping. To do so, set ```knn=True``` and leave all other values at default.\n\n\nFor best performance, there are 3 expensive settings for training. The best one varies by dataset.\n1. Set ```random_unlimiformer_training=True```: this is the *random-encoded training* setting from the paper\n2. Set ```unlimiformer_training=True```: this is the *retrieval training* setting from the paper\n3. Set ```random_unlimiformer_training=True``` AND ```unlimiformer_training=True```: this is the *alternating training* setting from the paper\n\nSee Table 5 in the paper for a more detailed breakdown of relative training costs. \n\n## Tips for very large inputs\n### For training\n* you may need to truncate your inputs at training time, e.g. to 8k or 16k tokens. You can use the full inputs at evaluation time\n* you can also try splitting your inputs into 16k-token-chunks and training on each one as its own example\n### For evaluation (including early stopping)\n* if you're consistently running out of CUDA memory, set ```use_datastore=True``` to use a Faiss datastore to store hidden states.\n* if you're still having issues, set ```gpu_datastore=False``` or ```gpu_index=False```, but note that this will degrade performance\n\n## Trained models\nThe following models from the paper are available on Hugging Face. Please note that you must add the Unlimiformer-specific files to your repository, and load these models with ```test_unlimiformer=True```. *If you download these models from Hugging Face, they may not use Unlimiformer by default!* \n\n### Table 3: low-cost training methods\n| Dataset  |  Method | Hugging Face link |\n| ------------- | ------------- | ------------- |\n| GovReport | Baseline: BART-base  | [abertsch\u002Fbart-base-govreport](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Fbart-base-govreport)  |\n| GovReport  | BART-base + Unlimiformer early stopping  | [abertsch\u002Funlimiformer-bart-govreport-earlyk](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-govreport-earlyk) |\n| SummScreen | Baseline: BART-base  | [abertsch\u002Fbart-base-summscreen](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Fbart-base-summscreen) |\n| SummScreen  | BART-base + Unlimiformer early stopping  | [abertsch\u002Funlimiformer-bart-summscreen-earlyk](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-summscreen-earlyk)  |\n\n\n### Table 4: Long-range training methods\n| Dataset  |  Method | Hugging Face link |\n| ------------- | ------------- | ------------- |\n| GovReport | BART + Unlimiformer (alternating training)  | [abertsch\u002Funlimiformer-bart-govreport-alternating](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-govreport-alternating)  |\n| SummScreen | BART + Unlimiformer (retrieval training)  | [abertsch\u002Funlimiformer-bart-summscreen-retrieval](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-summscreen-retrieval) |\n\n## Table 5: BookSum\n| Dataset  |  Method | Hugging Face link |\n| ------------- | ------------- | ------------- |\n| BookSum | Baseline: BART-base  | [abertsch\u002Fbart-base-booksum](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Fbart-base-booksum)  |\n| BookSum  | BART-base + Unlimiformer early stopping  | [abertsch\u002Funlimiformer-bart-booksum-earlyk](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-booksum-earlyk) |\n| Booksum  | BART-base + Unlimiformer (random-encoding training)  | [abertsch\u002Funlimiformer-bart-booksum-random-encoding](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-booksum-random-encoding)  |\n| Booksum  | BART-base + Unlimiformer (alternating training)  | [abertsch\u002Funlimiformer-bart-booksum-alternating](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-booksum-alternating)  |\n\n## Results\n\n\u003Cimg width=\"50%\" alt=\"image\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_b0dba5216a91.png\">\n\u003Cimg width=\"50%\" alt=\"image\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_16dd79738927.png\">\n\u003Cimg width=\"50%\" alt=\"image\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_b3c15ec1cb49.png\">\n\n\n## Citation\nIf you use our method or models, please cite [our paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F2305.01625):\n```\n@article{bertsch2023unlimiformer,\n  title={Unlimiformer: Long-Range Transformers with Unlimited Length Input},\n  author={Bertsch, Amanda and Alon, Uri and Neubig, Graham and Gormley, Matthew R},\n  journal={arXiv preprint arXiv:2305.01625},\n  year={2023}\n}\n```\n\n\n\n","# Unlimiformer：支持无限长度输入的长距离Transformer（NeurIPS 2023）\n![unlimiformer_diagram3_with_overlaps](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_1434ef2c14b3.png)\n\n这是论文的官方实现：\n\n[Amanda Bertsch](https:\u002F\u002Fwww.cs.cmu.edu\u002F~abertsch\u002F)、[Uri Alon](https:\u002F\u002Furialon.ml\u002F)、[Graham Neubig](http:\u002F\u002Fwww.phontron.com\u002F) 和 [Matthew R. Gormley](http:\u002F\u002Fwww.cs.cmu.edu\u002F~mgormley\u002F)：\n[Unlimiformer：支持无限长度输入的长距离Transformer](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2305.01625)（即将发表于 **NeurIPS 2023**）\n\nUnlimiformer 是一种在不改变注意力机制数学定义的情况下，通过检索式注意力增强预训练编码器-解码器模型的方法。\n这使得任何预训练的编码器-解码器模型都能处理无限长度的输入！\n另请参阅我们的 [**推文**](https:\u002F\u002Ftwitter.com\u002Fabertsch72\u002Fstatus\u002F1654110919977324545?s=20)。\n\nUnlimiformer 可用于提升已训练模型的性能。为了获得最佳效果，可以使用 Unlimiformer 训练方法对模型进行训练。\n\n如果您对这项工作有任何疑问，请在 [GitHub 问题](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fissues) 中提出，或发送邮件至 ```abertsch@cs.cmu.edu, ualon@cs.cmu.edu```。\n\n## **_2023年10月_** - Unlimiformer 将在 NeurIPS 2023 上亮相！\n\n## **_2023年8月_** - Unlimiformer 现在支持 **Llama-2**（及其所有衍生模型）！\n例如，要使用 Llama-2 处理极长的输入，比如一本 *整本书* 的内容，可以使用以下命令：\n```bash\npython src\u002Frun_generation.py --model_type llama --model_name_or_path meta-llama\u002FLlama-2-13b-chat-hf \\\n    --prefix \"\u003Cs>[INST] \u003C\u003CSYS>>\\n 您是一位乐于助人的助手。请根据完整的指令或问题提供详细的回答。\\n\u003C\u003C\u002FSYS>>\\n\\n 请总结以下书籍：\" \\\n    --prompt example_inputs\u002Fharry_potter_full.txt \\\n    --suffix \" [\u002FINST]\" --test_unlimiformer --fp16 --length 200 --layer_begin 16 \\\n    --index_devices 1 --datastore_device 1 \n```\n* 最终的提示将是 `--prefix`、`--prompt` 和 `--suffix` 这三个标志内容的拼接。\n* `--prompt` 标志既可以是文本文件的路径（如 `example_inputs\u002Fharry_potter_full.txt`），也可以直接指定提示字符串。\n* 必须使用 `--test_unlimiformer` 标志才能启用 Unlimiformer。\n* `--length` 标志决定了期望的输出长度。\n* `--layer_begin` 标志决定了从哪一层开始应用 Unlimiformer。例如，如果设置为 `--layer_begin 20`，模型的前 20 层将像往常一样仅对提示中的最后 `context_window_size` 个标记执行标准注意力操作，而第 21 层及以后的层则会关注整个长输入。根据我们的初步实验，`--layer_begin` 的值应超过模型总层数的一半，且调整该值会显著影响输出质量。\n* `--datastore_device N` 和 `--index_devices N1 N2 N3 ...` 标志指定了在哪些 GPU 上存储 Unlimiformer 的数据存储和索引（基础模型将存储在 GPU #0 上）。\n* 添加 `--stream_output` 标志可以使生成的标记在生成时逐个显示。\n\n## 开始使用\n\n### 一般说明\n将 `src` 目录下的文件复制到您的源代码文件夹中。\n\n您需要为 [`usage.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Fusage.py) 中列出的 Unlimiformer 特定参数设置值——您可以将这些参数添加到平时处理超参数的地方。要使用该模型，必须设置 `test_unlimiformer=True`。对于数据存储的使用，模型必须处于评估模式（例如，在推理之前调用 ```model.eval()```）。\n\n[`inference-example.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Finference-example.py) 提供了一个使用默认参数运行序列到 Unlimiformer 模型的最小示例。\n\n[`run.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Frun.py) 是一个整合了 Unlimiformer 的完整训练设置示例，改编自 [SLED](https:\u002F\u002Fgithub.com\u002FMivg\u002FSLED)。完整的命令行如下所示。\n\n### 复现论文中的实验——命令行\n\n要对 GovReport 数据集上的 BART-base 模型进行标准微调和评估（作为示例），可以使用以下命令：\n```python\npython src\u002Frun.py \\\n    src\u002Fconfigs\u002Ftraining\u002Fbase_training_args.json \\\n    src\u002Fconfigs\u002Fdata\u002Fgov_report.json \\\n    --output_dir output_train_bart_base_local\u002F \\\n    --learning_rate 1e-5 \\\n    --model_name_or_path facebook\u002Fbart-base \\\n    --max_source_length 1024 \\\n    --eval_max_source_length 1024 --do_eval=True \\\n    --eval_steps 1000 --save_steps 1000 \\\n    --per_device_eval_batch_size 1 --per_device_train_batch_size 2 \\\n    --extra_metrics bertscore\n```\n\n* 要在 **训练** 时使用 Unlimiformer（论文中称为“检索训练”），请使用：`--unlimiformer_training --max_source_length 16384`\n    * 在这种情况下，您可能还希望在 **测试**\u002F验证时使用 Unlimiformer，并同时使用：`--test_unlimiformer --eval_max_source_length 999999`\n* 或者，要在 **训练** 时使用计算成本更低的“随机编码”方法，可以使用 `--random_unlimiformer_training --max_source_length 16384`\n* 若要在“检索训练”和“随机编码训练”之间交替使用，可以同时使用两个标志：`--unlimiformer_training --random_unlimiformer_training --max_source_length 16384`\n\n有关其他标志和选项，请参阅 [`usage.py`](https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fblob\u002Fmain\u002Fsrc\u002Fusage.py)。\n\n## 推荐设置\n\n### 使用 Unlimiformer 进行评估\n在评估时，我们建议使用每个设置的默认值。\n\n### 使用 Unlimiformer 进行训练\n对于低成本的方法，我们建议按常规方式训练，并在早停时使用 Unlimiformer。为此，设置 ```knn=True``` 并将其他所有值保持默认。\n\n为了获得最佳性能，有三种高成本的训练设置。哪种设置最好取决于具体的数据集。\n1. 设置 ```random_unlimiformer_training=True```：这是论文中的“随机编码训练”设置。\n2. 设置 ```unlimiformer_training=True```：这是论文中的“检索训练”设置。\n3. 同时设置 ```random_unlimiformer_training=True``` 和 ```unlimiformer_training=True```：这是论文中的“交替训练”设置。\n\n有关相对训练成本的更详细分解，请参阅论文中的表 5。\n\n## 处理超大输入的技巧\n### 对于训练\n* 您可能需要在训练时截断输入，例如将其限制为 8k 或 16k 个标记。而在评估时则可以使用完整的输入。\n* 您还可以尝试将输入分割成 16k 标记的块，并将每一块作为单独的示例进行训练。\n\n### 用于评估（包括早停）\n* 如果您经常遇到 CUDA 显存不足的问题，请设置 ```use_datastore=True```，以使用 Faiss 数据存储来保存隐藏状态。\n* 如果问题仍然存在，请将 ```gpu_datastore=False``` 或 ```gpu_index=False```，但请注意，这会降低性能。\n\n## 训练好的模型\n论文中提到的以下模型已在 Hugging Face 上发布。请注意，您必须将 Unlimiformer 特有的文件添加到您的仓库，并通过 ```test_unlimiformer=True``` 来加载这些模型。*如果您从 Hugging Face 下载这些模型，默认情况下它们可能不会使用 Unlimiformer！*\n\n### 表3：低成本训练方法\n| 数据集      | 方法                           | Hugging Face 链接                                   |\n| ----------- | ------------------------------ | -------------------------------------------------- |\n| GovReport   | 基线：BART-base                | [abertsch\u002Fbart-base-govreport](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Fbart-base-govreport) |\n| GovReport   | BART-base + Unlimiformer 早停  | [abertsch\u002Funlimiformer-bart-govreport-earlyk](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-govreport-earlyk) |\n| SummScreen  | 基线：BART-base                | [abertsch\u002Fbart-base-summscreen](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Fbart-base-summscreen) |\n| SummScreen  | BART-base + Unlimiformer 早停  | [abertsch\u002Funlimiformer-bart-summscreen-earlyk](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-summscreen-earlyk) |\n\n### 表4：长距离训练方法\n| 数据集      | 方法                           | Hugging Face 链接                                   |\n| ----------- | ------------------------------ | -------------------------------------------------- |\n| GovReport   | BART + Unlimiformer（交替训练） | [abertsch\u002Funlimiformer-bart-govreport-alternating](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-govreport-alternating) |\n| SummScreen  | BART + Unlimiformer（检索训练） | [abertsch\u002Funlimiformer-bart-summscreen-retrieval](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-summscreen-retrieval) |\n\n## 表5：BookSum\n| 数据集      | 方法                           | Hugging Face 链接                                   |\n| ----------- | ------------------------------ | -------------------------------------------------- |\n| BookSum     | 基线：BART-base                | [abertsch\u002Fbart-base-booksum](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Fbart-base-booksum) |\n| BookSum     | BART-base + Unlimiformer 早停  | [abertsch\u002Funlimiformer-bart-booksum-earlyk](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-booksum-earlyk) |\n| BookSum     | BART-base + Unlimiformer（随机编码训练） | [abertsch\u002Funlimiformer-bart-booksum-random-encoding](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-booksum-random-encoding) |\n| BookSum     | BART-base + Unlimiformer（交替训练） | [abertsch\u002Funlimiformer-bart-booksum-alternating](https:\u002F\u002Fhuggingface.co\u002Fabertsch\u002Funlimiformer-bart-booksum-alternating) |\n\n## 结果\n\n\u003Cimg width=\"50%\" alt=\"image\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_b0dba5216a91.png\">\n\u003Cimg width=\"50%\" alt=\"image\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_16dd79738927.png\">\n\u003Cimg width=\"50%\" alt=\"image\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_readme_b3c15ec1cb49.png\">\n\n\n## 引用\n如果您使用了我们的方法或模型，请引用[我们的论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F2305.01625)：\n```\n@article{bertsch2023unlimiformer,\n  title={Unlimiformer: Long-Range Transformers with Unlimited Length Input},\n  author={Bertsch, Amanda and Alon, Uri and Neubig, Graham and Gormley, Matthew R},\n  journal={arXiv preprint arXiv:2305.01625},\n  year={2023}\n}\n```","# Unlimiformer 快速上手指南\n\nUnlimiformer 是一种无需改变注意力机制数学定义，即可通过检索增强预训练编码器 - 解码器模型的方法。它允许任何预训练的 Encoder-Decoder 模型处理**无限长度**的输入（如整本书），特别适用于长文本摘要和生成任务。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Linux (推荐) 或 macOS\n- **GPU**: 支持 CUDA 的 NVIDIA GPU（建议显存充足，或使用多卡分布存储索引）\n- **Python**: 3.8+\n\n### 前置依赖\n确保已安装 PyTorch 和 Transformers 库。建议使用 `pip` 安装基础依赖：\n\n```bash\npip install torch transformers faiss-gpu sentencepiece protobuf\n```\n\n> **注意**：本项目依赖 Faiss 进行高效检索。如果无法访问官方源，可尝试使用国内镜像加速安装：\n> ```bash\n> pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple torch transformers faiss-gpu sentencepiece protobuf\n> ```\n\n## 安装步骤\n\nUnlimiformer 没有独立的 PyPI 包，需直接克隆源码并使用其中的模块。\n\n1. **克隆仓库**\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer.git\n   cd unlimiformer\n   ```\n\n2. **配置代码**\n   将 `src` 目录下的文件复制到你的项目源代码文件夹中，或者直接在当前目录下运行脚本。\n   \n   核心逻辑在于需要在你的推理或训练代码中引入 `usage.py` 定义的参数，并设置 `test_unlimiformer=True`。\n\n## 基本使用\n\n### 场景一：推理（处理超长输入）\n\n以下示例展示如何使用 Unlimiformer 让 Llama-2 模型处理整本书的内容进行摘要。\n\n**关键参数说明：**\n- `--test_unlimiformer`: **必须添加**，用于启用 Unlimiformer。\n- `--layer_begin`: 指定从哪一层开始应用检索注意力。通常设为总层数的一半以上（例如 16 或 20）。\n- `--prompt`: 可以是文本文件路径（如整本书），也可以是字符串。\n- `--datastore_device` \u002F `--index_devices`: 指定存储 datastore 和索引的 GPU 设备 ID，避免显存溢出。\n\n**运行命令：**\n\n```bash\npython src\u002Frun_generation.py --model_type llama --model_name_or_path meta-llama\u002FLlama-2-13b-chat-hf \\\n    --prefix \"\u003Cs>[INST] \u003C\u003CSYS>>\\n You are a helpful assistant. Answer with detailed responses according to the entire instruction or question. \\n\u003C\u003C\u002FSYS>>\\n\\n Summarize the following book: \" \\\n    --prompt example_inputs\u002Fharry_potter_full.txt \\\n    --suffix \" [\u002FINST]\" --test_unlimiformer --fp16 --length 200 --layer_begin 16 \\\n    --index_devices 1 --datastore_device 1 \n```\n\n*若希望实时看到生成结果，可添加 `--stream_output` 标志。*\n\n### 场景二：最小化代码集成示例\n\n如果你想在自定义 Python 脚本中集成，请参考 `src\u002Finference-example.py` 的逻辑。核心步骤如下：\n\n1. 加载预训练模型。\n2. 调用 `model.eval()` 进入评估模式（使用 datastore 必须此步骤）。\n3. 在生成参数中设置 `test_unlimiformer=True` 及相关 Unlimiformer 参数。\n\n```python\n# 伪代码示例，具体实现请参考 src\u002Finference-example.py\nfrom transformers import AutoModelForSeq2SeqLM, AutoTokenizer\n# 引入 unlimiformer 相关逻辑 (需将 src 文件加入路径)\nfrom usage import add_unlimiformer_args, setup_unlimiformer \n\n# 1. 加载模型\nmodel = AutoModelForSeq2SeqLM.from_pretrained(\"facebook\u002Fbart-base\")\ntokenizer = AutoTokenizer.from_pretrained(\"facebook\u002Fbart-base\")\n\n# 2. 设置为评估模式 (必须)\nmodel.eval()\n\n# 3. 准备输入 (超长文本)\ninput_text = \"...\" # 你的长文本\n\n# 4. 执行生成 (需在内部逻辑中开启 test_unlimiformer=True)\n# 具体调用方式取决于你如何整合 src\u002Frun.py 或 inference-example.py 的逻辑\n# 关键在于传递 unlimiformer 特定的 args\n```\n\n### 场景三：微调训练（可选）\n\n若需获得最佳效果，建议使用 Unlimiformer 进行训练（Retrieval training）。\n\n**基础微调命令（BART-base on GovReport）：**\n```bash\npython src\u002Frun.py \\\n    src\u002Fconfigs\u002Ftraining\u002Fbase_training_args.json \\\n    src\u002Fconfigs\u002Fdata\u002Fgov_report.json \\\n    --output_dir output_train_bart_base_local\u002F \\\n    --learning_rate 1e-5 \\\n    --model_name_or_path facebook\u002Fbart-base \\\n    --max_source_length 1024 \\\n    --eval_max_source_length 1024 --do_eval=True \\\n    --eval_steps 1000 --save_steps 1000 \\\n    --per_device_eval_batch_size 1 --per_device_train_batch_size 2 \\\n    --extra_metrics bertscore\n```\n\n**启用 Unlimiformer 训练：**\n添加 `--unlimiformer_training` 并增大 `--max_source_length`（如 16384）。\n```bash\npython src\u002Frun.py ... \\\n    --unlimiformer_training --max_source_length 16384 \\\n    --test_unlimiformer --eval_max_source_length 999999\n```\n\n> **提示**：对于显存受限的情况，训练时可截断输入（如 8k 或 16k），仅在评估时使用完整长输入。若评估时显存不足，可设置 `use_datastore=True` 使用 Faiss 存储隐藏状态。","某法律科技团队需要让大模型基于数百页的完整案件卷宗（如《哈利·波特》全书量级的文本）生成精准的法律摘要，但受限于显存和架构瓶颈。\n\n### 没有 unlimiformer 时\n- **输入长度被强制截断**：模型只能读取卷宗的前几千字，导致关键证据或后续判决依据丢失，分析结果片面甚至错误。\n- **硬件成本高昂**：为了强行容纳长文本，必须使用多卡并行或昂贵的超大显存 GPU，推理门槛极高。\n- **上下文连贯性差**：采用滑动窗口或分段处理会切断段落间的逻辑联系，模型无法理解跨章节的复杂因果关系。\n- **需重新训练模型**：若要支持长文本，通常需要对预训练模型进行耗时耗力的微调或架构修改。\n\n### 使用 unlimiformer 后\n- **实现无限长度输入**：直接加载整本卷宗文件，unlimiformer 通过检索机制让模型关注全文任意位置，不再遗漏任何细节。\n- **复用现有预训练模型**：无需改变注意力数学定义或重新训练，即可为 Llama-2 等现有模型赋予长文本处理能力。\n- **显著降低显存占用**：将索引和数据存储卸载到指定设备，基础模型仅需常规显存即可运行超长序列推理。\n- **灵活控制计算层级**：通过调整 `layer_begin` 参数，让模型底层处理局部语境、高层关注全局信息，大幅提升摘要质量。\n\nunlimiformer 的核心价值在于打破了 Transformer 的长度枷锁，让开发者能以低成本直接利用现有模型处理“全书级”的超长上下文任务。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fabertsch72_unlimiformer_364cba59.png","abertsch72","Amanda Bertsch","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fabertsch72_8a5bccd1.jpg","PhD student @ CMU LTI",null,"Pittsburgh, PA","https:\u002F\u002Fwww.cs.cmu.edu\u002F~abertsch\u002F","https:\u002F\u002Fgithub.com\u002Fabertsch72",[82],{"name":83,"color":84,"percentage":85},"Python","#3572A5",100,1064,77,"2026-04-07T10:36:39","MIT",4,"未说明","必需 NVIDIA GPU。支持多卡配置：基础模型存储在 GPU #0，Unlimiformer 的数据存储 (datastore) 和索引 (index) 可通过 `--datastore_device` 和 `--index_devices` 参数指定在其他 GPU 上。显存需求取决于输入长度，处理超长输入（如整本书）或遇到 CUDA 内存不足时，建议启用 `use_datastore=True` 使用 Faiss 存储隐藏状态，或将其卸载到 CPU (`gpu_datastore=False`)。","未说明（但在 GPU 显存不足时可将索引\u002F数据存储卸载至系统内存，暗示对系统 RAM 有潜在高需求）",{"notes":95,"python":91,"dependencies":96},"1. 该工具主要用于增强预训练的 Encoder-Decoder 模型（如 BART, Llama-2），使其支持无限长度输入。\n2. 推理时必须设置 `test_unlimiformer=True` 并将模型置于评估模式 (`model.eval()`)。\n3. 支持 Llama-2 及其衍生模型，处理整书等超长文本时需调整 `--layer_begin` 参数（通常设为总层数的一半以上）以平衡性能和质量。\n4. 训练时可选多种策略：标准微调后早停、随机编码训练、检索训练或交替训练，不同策略计算成本差异较大。\n5. 若直接从 Hugging Face 下载作者提供的模型，默认可能未启用 Unlimiformer，需手动集成源码并开启相关标志。",[97,98,99],"transformers","faiss","torch",[35,14],"2026-03-27T02:49:30.150509","2026-04-18T14:32:13.351413",[104,109,114,119,124,129],{"id":105,"question_zh":106,"answer_zh":107,"source_url":108},40208,"导入 Unlimiformer 时出现 'ImportError: cannot import name'Unlimiformer'' 错误怎么办？","这通常是由于环境路径或运行时状态问题导致的。建议尝试以下步骤：\n1. 重启 Google Colab 的运行时（Runtime -> Restart runtime）。\n2. 删除并重新创建运行时实例。\n3. 确保当前工作目录正确，使用 `%cd \u002Fcontent\u002Funlimiformer\u002Fsrc` 切换到源代码目录。\n4. 如果是在 Jupyter Notebook 中运行，尝试将相关文件移动到当前工作目录。\n维护者测试表明，在最小化的 Colab 环境中通常可以正常导入，因此请检查是否遗漏了依赖安装或路径配置。","https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fissues\u002F24",{"id":110,"question_zh":111,"answer_zh":112,"source_url":113},40209,"如何在仅解码器模型（如 LLaMA\u002FLLaMA-2）上使用 Unlimiformer？","Unlimiformer 现已正式支持 LLaMA、LLaMA-2 及其所有衍生模型。您无需手动修改代码中的注意力机制（如将 encoder_attn 替换为 self_attn）或处理缺失的 encoder_hidden_states。请直接拉取最新版本的代码库，按照官方文档中的示例进行配置即可直接使用。","https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fissues\u002F15",{"id":115,"question_zh":116,"answer_zh":117,"source_url":118},40210,"如何复现论文中 '+test Unlimiformer' 的设置（仅推理，不训练）？","您可以加载现有的检查点（如 HuggingFace 上的 bart-base-govreport）并直接运行推理。关键步骤如下：\n1. 确保拉取了最新版本的代码（tokenizer 现已自动包含在模型中，无需单独设置 tokenizer_name，但旧版本需添加 `--tokenizer_name facebook\u002Fbart-base`）。\n2. 使用以下命令运行（仅测试，不训练）：\n```bash\npython src\u002Frun.py \\\n    src\u002Fconfigs\u002Fmodel\u002Fbart_base_sled.json \\\n    src\u002Fconfigs\u002Ftraining\u002Fbase_training_args.json \\\n    src\u002Fconfigs\u002Fdata\u002Fgov_report.json \\\n    --output_dir output_train_bart_base_local\u002F \\\n    --learning_rate 1e-5 \\\n    --model_name_or_path facebook\u002Fbart-base \\\n    --max_source_length 1024 \\\n    --eval_max_source_length 999999 --do_eval=True --do_train=False \\\n    --eval_steps 1000 --save_steps 1000 \\\n    --per_device_eval_batch_size 1 --per_device_train_batch_size 2 \\\n    --extra_metrics bertscore --test_unlimiformer\n```\n注意：`--use_datastore` 仅在输入极长时有用，常规情况下可不加。","https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fissues\u002F17",{"id":120,"question_zh":121,"answer_zh":122,"source_url":123},40211,"如何在多张 GPU 上运行 Unlimiformer 进行长文本推理（例如超过 130k token）？","可以通过指定不同的设备 ID 来分配索引构建和数据存储任务。以下是一个在 4 张 GPU 上运行 LLaMA-2-13b 处理 130k+ token 输入的示例命令：\n```bash\nCUDA_VISIBLE_DEVICES=0,1,2,3 python src\u002Frun_generation.py \\\n    --model_type llama \\\n    --model_name_or_path meta-llama\u002FLlama-2-13b-chat-hf \\\n    --prefix \"\u003C\u003CSYS>>\\n You are a helpful assistant... \\n\u003C\u003C\u002FSYS>>\\n\\n [INST] Summarize the following book: \" \\\n    --prompt example_inputs\u002Fharry_potter_full.txt \\\n    --suffix \" [\u002FINST]\" \\\n    --test_unlimiformer \\\n    --fp16 \\\n    --length 200 \\\n    --layer_begin 20 \\\n    --index_devices 2 \\\n    --datastore_device 3 \\\n    --stream_output\n```\n其中 `--index_devices` 和 `--datastore_device` 用于指定具体的 GPU 编号，以平衡负载并避免显存溢出。","https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fissues\u002F29",{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},40212,"在使用 LLaMA 运行 `test_datastore` 时，为什么保留的注意力质量（attention mass）远低于预期的 99%？","这通常是对代码中断言（assertion）的误解。代码中关于注意力质量的检查是用于内部调试的，并不直接代表最终保留的概率质量。\n理论上，如果您有 20,000 个 key，保留前 1,000 个最高分，即使分布均匀也能保留 5% 的质量。在实际应用中，注意力分布非常集中，保留前 1,000 个通常能保留 99% 以上的质量。\n如果您观察到只有 1% 左右，请检查是否正确配置了 datastore 相关参数，或者是否误读了内部调试变量的值。该属性在 BART 模型和摘要数据集上已得到验证，对于 LLaMA 也应表现类似，除非数据分布极度特殊。","https:\u002F\u002Fgithub.com\u002Fabertsch72\u002Funlimiformer\u002Fissues\u002F41",{"id":130,"question_zh":131,"answer_zh":132,"source_url":128},40213,"运行 LLaMA 模型时使用 `test_datastore` 报错，提示 `process_key_value` 函数中的捕获器（capturer）注入错误，如何解决？","该问题源于 `UnlimiformerLLaMa` 类中 `process_key_value` 函数使用了错误的捕获器注入方式（使用了 `activation_to_capture` 而非 `get_kv_projections`）。\n虽然用户曾尝试通过添加新的捕获器来解决，但维护者指出这可能与对内部机制的理解偏差有关。建议首先更新到最新版本代码，因为官方已针对 LLaMA 架构进行了适配。如果问题依旧，请确认您没有手动修改核心逻辑，而是直接使用官方提供的 `UnlimiformerLlama` 实现，该实现已正确处理了 Decoder-only 模型的 Key\u002FValue 投影获取方式。",[]]