[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-LeapLabTHU--Agent-Attention":3,"tool-LeapLabTHU--Agent-Attention":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},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,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},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 真正成长为懂上",140436,2,"2026-04-05T23:32:43",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":70,"readme_en":71,"readme_zh":72,"quickstart_zh":73,"use_case_zh":74,"hero_image_url":75,"owner_login":76,"owner_name":77,"owner_avatar_url":78,"owner_bio":79,"owner_company":80,"owner_location":80,"owner_email":80,"owner_twitter":80,"owner_website":81,"owner_url":82,"languages":83,"stars":92,"forks":93,"last_commit_at":94,"license":80,"difficulty_score":10,"env_os":95,"env_gpu":96,"env_ram":95,"env_deps":97,"category_tags":104,"github_topics":80,"view_count":23,"oss_zip_url":80,"oss_zip_packed_at":80,"status":16,"created_at":105,"updated_at":106,"faqs":107,"releases":148},3223,"LeapLabTHU\u002FAgent-Attention","Agent-Attention","[ECCV 2024] Official repository of Agent Attention","Agent-Attention 是一种专为 Transformer 架构设计的新型注意力机制，旨在解决传统 Softmax 注意力计算成本过高、难以在长序列或高分辨率场景中高效应用的难题。它通过引入一组数量远少于查询令牌（Query）的“代理令牌”（Agent Tokens），让代理先聚合全局信息再分发给各个查询，从而在保持强大全局建模能力的同时，显著降低了计算复杂度。\n\n这项技术的核心亮点在于巧妙融合了 Softmax 注意力的强表达能力与线性注意力的高效特性。理论证明，Agent-Attention 实际上是线性注意力的一种广义形式，实现了两者的无缝集成。实验数据显示，它在图像分类、目标检测、语义分割等下游任务中表现优异，甚至在无需额外训练的情况下，直接应用于 Stable Diffusion（即 AgentSD）也能加速生成过程并提升图像质量。\n\nAgent-Attention 非常适合 AI 研究人员、深度学习开发者以及需要优化模型推理速度的工程师使用。如果你正在探索更高效的视觉骨干网络，或希望在资源受限的设备上部署高性能 Transformer 模型，Agent-Attent","Agent-Attention 是一种专为 Transformer 架构设计的新型注意力机制，旨在解决传统 Softmax 注意力计算成本过高、难以在长序列或高分辨率场景中高效应用的难题。它通过引入一组数量远少于查询令牌（Query）的“代理令牌”（Agent Tokens），让代理先聚合全局信息再分发给各个查询，从而在保持强大全局建模能力的同时，显著降低了计算复杂度。\n\n这项技术的核心亮点在于巧妙融合了 Softmax 注意力的强表达能力与线性注意力的高效特性。理论证明，Agent-Attention 实际上是线性注意力的一种广义形式，实现了两者的无缝集成。实验数据显示，它在图像分类、目标检测、语义分割等下游任务中表现优异，甚至在无需额外训练的情况下，直接应用于 Stable Diffusion（即 AgentSD）也能加速生成过程并提升图像质量。\n\nAgent-Attention 非常适合 AI 研究人员、深度学习开发者以及需要优化模型推理速度的工程师使用。如果你正在探索更高效的视觉骨干网络，或希望在资源受限的设备上部署高性能 Transformer 模型，Agent-Attention 提供了一个兼具速度与精度的优秀解决方案。","# Agent Attention\n\nThis repo contains the official PyTorch code and pre-trained models for **Agent Attention**.\n\n+ [Agent Attention: On the Integration of Softmax and Linear Attention](https:\u002F\u002Farxiv.org\u002Fabs\u002F2312.08874)\n\n## Introduction\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_784e2f1c3bb8.png\" width= \"400\">\n\u003C\u002Fp>\n\nThe attention module is the key component in Transformers. While the global attention mechanism offers robust expressiveness, its excessive computational cost constrains its applicability in various scenarios. In this paper, we propose a novel attention paradigm, **Agent Attention**, to strike a favorable balance between computational efficiency and representation power. Specifically, the Agent Attention, denoted as a quadruple $(Q, A, K, V)$, introduces an additional set of agent tokens $A$ into the conventional attention module.  The agent tokens first act as the agent for the query tokens $Q$ to aggregate information from $K$ and $V$, and then broadcast the information back to $Q$. Given the number of agent tokens can be designed to be much smaller than the number of query tokens, the agent attention is significantly more efficient than the widely adopted Softmax attention, while preserving global context modelling capability. Interestingly, we show that the proposed agent attention is equivalent to a generalized form of linear attention. Therefore, agent attention seamlessly integrates the powerful Softmax attention and the highly efficient linear attention.\n\n\n## Motivation\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_0c0b134af113.jpg\" width= \"500\">\n\u003C\u002Fp>\n\n(a) In Softmax attention, each query aggregates information from all features, incurring quadratic complexity. (b) Leveraging the redundancy between attention weights, agent attention uses a small number of agent tokens to act as the \"agent'' for queries, capturing diverse semantic information from all features, and then presenting it to each query.\n\n\n## Method\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_5930e23ce8fe.png\" width= \"1000\">\n\u003C\u002Fp>\n\n**An illustration of our agent attention and agent attention module.** (a) Agent attention uses agent tokens to aggregate global information and distribute it to individual image tokens, resulting in a practical integration of Softmax and linear attention. $\\rm{\\sigma}(\\cdot)$ represents Softmax function. In (b), we depict the information flow of agent attention module. As a showcase, we acquire agent tokens through pooling. Subsequently, agent tokens are utilized to aggregate information from $V$, and $Q$ queries features from the agent features. In addition, agent bias and DWC are adopted to add positional information and maintain feature diversity.\n\n## Results\n\n### Classification\n\nPlease go to the folder [agent_transformer](.\u002Fagent_transformer) for specific document.\n\n- Comparison of different models on ImageNet-1K.\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_67a114b45d80.png\" width= \"500\">\n\u003C\u002Fp>\n\n- Accuracy-Runtime curve on ImageNet.\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_4427bba56af2.png\" width= \"900\">\n\u003C\u002Fp>\n\n- Increasing resolution to $\\{256^2, 288^2, 320^2, 352^2, 384^2\\}$.\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_b339cca5ae0e.png\" width= \"300\">\n\u003C\u002Fp>\n\n### Downstream tasks\n\nPlease go to the folder [detection](.\u002Fdownstream\u002Fdetection), [segmentation](.\u002Fdownstream\u002Fsegmentation) for specific documents.\n\n\u003Cdiv style=\"display: flex; justify-content: center;\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_44b6dfdf8cf7.jpg\" width=\"360\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_8fba6f1cf58f.jpg\" width=\"315\" height=\"315\">\n\u003C\u002Fdiv>\n\n### AgentSD\n\nWhen applied to Stable Diffusion, our agent attention accelerates generation and substantially enhances image generation quality **without any additional training**. Please go to the folder [agentsd](.\u002Fagentsd) for specific document.\n\n- Quantitative Results of Stable Diffusion, ToMeSD and our AgentSD.\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_af9013bfabde.png\" width= \"300\">\n\u003C\u002Fp>\n\n- Samples generated by Stable Diffusion, ToMeSD ($r=0.4$) and AgentSD ($r=0.4$).\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_80775937c971.png\" width= \"450\">\n\u003C\u002Fp>\n\n## TODO\n\n - [x] Classification\n - [x] Segmentation\n - [x] Detection\n - [x] Agent Attention for Stable Diffusion\n\n\n## Acknowledgements\n\nOur code is developed on the top of [PVT](https:\u002F\u002Fgithub.com\u002Fwhai362\u002FPVT), [Swin Transformer](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FSwin-Transformer), [CSwin Transformer](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FCSWin-Transformer) and [ToMeSD](https:\u002F\u002Fgithub.com\u002Fdbolya\u002Ftomesd).\n\n## Citation\n\nIf you find this repo helpful, please consider citing us.\n\n```latex\n@inproceedings{han2024agent,\n  title={Agent attention: On the integration of softmax and linear attention},\n  author={Han, Dongchen and Ye, Tianzhu and Han, Yizeng and Xia, Zhuofan and Pan, Siyuan and Wan, Pengfei and Song, Shiji and Huang, Gao},\n  booktitle={European Conference on Computer Vision},\n  year={2024},\n}\n```\n\n## Contact\n\nIf you have any questions, please feel free to contact the authors. \n\nDongchen Han: [hdc23@mails.tsinghua.edu.cn](mailto:hdc23@mails.tsinghua.edu.cn)\n\nTianzhu Ye:  [ytz20@mails.tsinghua.edu.cn](mailto:ytz20@mails.tsinghua.edu.cn)\n","# Agent Attention\n\n此仓库包含 **Agent Attention** 的官方 PyTorch 代码及预训练模型。\n\n+ [Agent Attention：关于 Softmax 注意力与线性注意力的融合](https:\u002F\u002Farxiv.org\u002Fabs\u002F2312.08874)\n\n## 简介\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_784e2f1c3bb8.png\" width= \"400\">\n\u003C\u002Fp>\n\n注意力模块是 Transformer 中的核心组件。尽管全局注意力机制具有强大的表达能力，但其过高的计算成本限制了它在多种场景中的应用。本文提出了一种全新的注意力范式——**Agent Attention**，旨在在计算效率与表征能力之间取得良好平衡。具体而言，Agent Attention 以四元组 $(Q, A, K, V)$ 表示，在传统注意力模块中引入了一组额外的代理 token $A$。这些代理 token 首先作为 query token $Q$ 的“代理人”，从 $K$ 和 $V$ 中聚合信息，然后再将这些信息广播回 $Q$。由于代理 token 的数量可以远小于 query token 的数量，因此 Agent Attention 在保持全局上下文建模能力的同时，相比广泛使用的 Softmax 注意力显著提升了效率。有趣的是，我们证明了所提出的 Agent Attention 等价于一种广义的线性注意力形式。因此，Agent Attention 无缝地整合了功能强大的 Softmax 注意力和高效稳定的线性注意力。\n\n## 动机\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_0c0b134af113.jpg\" width= \"500\">\n\u003C\u002Fp>\n\n(a) 在 Softmax 注意力中，每个 query 都会从所有特征中聚合信息，导致复杂度呈二次方增长。(b) 利用注意力权重之间的冗余性，Agent Attention 使用少量的代理 token 作为 query 的“代理人”，从所有特征中捕捉多样化的语义信息，再将其传递给每个 query。\n\n## 方法\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_5930e23ce8fe.png\" width= \"1000\">\n\u003C\u002Fp>\n\n**我们提出的 Agent Attention 及其模块示意图。** (a) Agent Attention 使用代理 token 聚合全局信息，并将其分发到各个图像 token，从而实现了 Softmax 注意力与线性注意力的实际融合。$\\rm{\\sigma}(\\cdot)$ 表示 Softmax 函数。在 (b) 中，我们展示了 Agent Attention 模块的信息流。作为示例，我们通过池化操作获取代理 token。随后，代理 token 用于从 $V$ 中聚合信息，而 $Q$ 则从代理特征中查询信息。此外，还采用了代理偏置和 DWC 来加入位置信息并保持特征多样性。\n\n## 结果\n\n### 分类\n\n请前往 [agent_transformer](.\u002Fagent_transformer) 文件夹查看具体文档。\n\n- 不同模型在 ImageNet-1K 数据集上的对比结果。\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_67a114b45d80.png\" width= \"500\">\n\u003C\u002Fp>\n\n- ImageNet 上的准确率-运行时间曲线。\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_4427bba56af2.png\" width= \"900\">\n\u003C\u002Fp>\n\n- 分辨率提升至 $\\{256^2, 288^2, 320^2, 352^2, 384^2\\}$。\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_b339cca5ae0e.png\" width= \"300\">\n\u003C\u002Fp>\n\n### 下游任务\n\n请前往 [detection](.\u002Fdownstream\u002Fdetection) 和 [segmentation](.\u002Fdownstream\u002Fsegmentation) 文件夹查看具体文档。\n\n\u003Cdiv style=\"display: flex; justify-content: center;\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_44b6dfdf8cf7.jpg\" width=\"360\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_8fba6f1cf58f.jpg\" width=\"315\" height=\"315\">\n\u003C\u002Fdiv>\n\n### AgentSD\n\n当应用于 Stable Diffusion 时，我们的 Agent Attention 在无需任何额外训练的情况下，能够加速生成过程并显著提升图像质量。请前往 [agentsd](.\u002Fagentsd) 文件夹查看具体文档。\n\n- Stable Diffusion、ToMeSD 和我们提出的 AgentSD 的定量结果。\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_af9013bfabde.png\" width= \"300\">\n\u003C\u002Fp>\n\n- Stable Diffusion、ToMeSD ($r=0.4$) 和 AgentSD ($r=0.4$) 生成的样本。\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_readme_80775937c971.png\" width= \"450\">\n\u003C\u002Fp>\n\n## 待办事项\n\n - [x] 分类\n - [x] 分割\n - [x] 检测\n - [x] 将 Agent Attention 应用于 Stable Diffusion\n\n\n## 致谢\n\n我们的代码基于 [PVT](https:\u002F\u002Fgithub.com\u002Fwhai362\u002FPVT)、[Swin Transformer](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FSwin-Transformer)、[CSwin Transformer](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FCSWin-Transformer) 和 [ToMeSD](https:\u002F\u002Fgithub.com\u002Fdbolya\u002Ftomesd) 开发而成。\n\n## 引用\n\n如果您觉得本仓库对您有所帮助，请考虑引用我们的工作。\n\n```latex\n@inproceedings{han2024agent,\n  title={Agent attention: On the integration of softmax and linear attention},\n  author={Han, Dongchen and Ye, Tianzhu and Han, Yizeng and Xia, Zhuofan and Pan, Siyuan and Wan, Pengfei and Song, Shiji and Huang, Gao},\n  booktitle={欧洲计算机视觉会议},\n  year={2024},\n}\n```\n\n## 联系方式\n\n如有任何问题，请随时联系作者。\n\nDongchen Han：[hdc23@mails.tsinghua.edu.cn](mailto:hdc23@mails.tsinghua.edu.cn)\n\nTianzhu Ye：[ytz20@mails.tsinghua.edu.cn](mailto:ytz20@mails.tsinghua.edu.cn)","# Agent Attention 快速上手指南\n\nAgent Attention 是一种新型注意力机制，旨在平衡 Softmax 注意力强大的表达能力与线性注意力的高效计算成本。通过引入少量的“代理令牌（Agent Tokens）”来聚合全局信息并分发给查询令牌，该模型在保持全局上下文建模能力的同时，显著降低了计算复杂度。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: Linux (推荐 Ubuntu 18.04+) 或 macOS\n*   **Python**: 3.8 或更高版本\n*   **GPU**: 支持 CUDA 的 NVIDIA GPU (推荐显存 8GB+)\n*   **核心依赖**:\n    *   PyTorch >= 1.8.0\n    *   torchvision\n    *   timm\n    *   mmcv \u002F mmdetection \u002F mmsegmentation (如需运行下游任务)\n\n**国内加速建议**：\n推荐使用清华源或阿里源安装 Python 依赖，以加快下载速度。\n```bash\npip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple torch torchvision torchaudio\n```\n\n## 安装步骤\n\n1.  **克隆仓库**\n    从 GitHub 克隆官方代码库：\n    ```bash\n    git clone https:\u002F\u002Fgithub.com\u002Fhanc00l\u002FAgent-Attention.git\n    cd Agent-Attention\n    ```\n\n2.  **安装依赖**\n    安装项目所需的 Python 包。如果网络较慢，可结合国内镜像源使用：\n    ```bash\n    pip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n    ```\n    *注：若 `requirements.txt` 未包含所有下游任务依赖，请根据具体任务文件夹（如 `downstream\u002Fdetection`）中的说明额外安装 `mmdet` 或 `mmseg`。*\n\n3.  **验证安装**\n    确保能够导入核心模块（以分类任务为例）：\n    ```python\n    python -c \"from agent_transformer import create_model; print('Installation successful')\"\n    ```\n\n## 基本使用\n\n以下是最简单的使用示例，展示如何加载预训练的 Agent Attention 模型并进行推理。\n\n### 1. 图像分类推理\n\n假设您已下载 ImageNet 预训练权重（位于 `agent_transformer` 目录下的检查点文件），可以使用以下代码加载模型并处理一张图片：\n\n```python\nimport torch\nfrom PIL import Image\nfrom torchvision import transforms\nfrom agent_transformer import create_model\n\n# 配置设备\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n\n# 创建模型 (以 agent_tiny 为例，可根据需要更换为 agent_small, agent_base 等)\n# num_classes 需与预训练权重匹配，ImageNet 通常为 1000\nmodel = create_model('agent_tiny', pretrained=True, num_classes=1000)\nmodel.to(device)\nmodel.eval()\n\n# 预处理图像\ntransform = transforms.Compose([\n    transforms.Resize(256),\n    transforms.CenterCrop(224),\n    transforms.ToTensor(),\n    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),\n])\n\n# 加载图像\nimage = Image.open(\"your_image.jpg\").convert(\"RGB\")\ninput_tensor = transform(image).unsqueeze(0).to(device)\n\n# 推理\nwith torch.no_grad():\n    output = model(input_tensor)\n    probabilities = torch.nn.functional.softmax(output[0], dim=0)\n\nprint(f\"Prediction shape: {probabilities.shape}\")\n```\n\n### 2. 应用于 Stable Diffusion (AgentSD)\n\nAgent Attention 可直接加速 Stable Diffusion 的生成过程并提升质量，无需额外训练。具体用法请参考 `agentsd` 文件夹中的脚本。基本调用逻辑如下：\n\n```python\n# 伪代码示例，详细参数请参阅 agentsd 目录下的文档\nfrom agentsd import AgentSDPipeline\n\npipe = AgentSDPipeline.from_pretrained(\n    \"runwayml\u002Fstable-diffusion-v1-5\", \n    use_agent_attn=True, \n    ratio=0.4  # 代理令牌压缩率\n)\npipe.to(\"cuda\")\n\nprompt = \"a photo of an astronaut riding a horse on mars\"\nimage = pipe(prompt).images[0]\nimage.save(\"generated_image.png\")\n```\n\n> **提示**：更多关于检测（Detection）、分割（Segmentation）及高分辨率训练的详细配置，请分别查阅仓库中 `downstream\u002Fdetection`、`downstream\u002Fsegmentation` 及 `agent_transformer` 目录下的具体文档。","某计算机视觉团队正在开发一款基于 Stable Diffusion 的高分辨率工业缺陷检测图像生成系统，需要在有限算力下快速产出大量高质量样本以扩充训练集。\n\n### 没有 Agent-Attention 时\n- **推理速度缓慢**：处理高分辨率图像时，传统 Softmax 注意力机制的计算量呈平方级增长，导致单张图像生成耗时过长，无法满足实时或批量生产需求。\n- **显存占用过高**：全局注意力矩阵需要消耗巨大显存，迫使团队不得不降低图像分辨率或使用昂贵的多卡集群，增加了硬件成本。\n- **细节与效率难两全**：若改用线性注意力加速，往往会导致图像纹理模糊、缺陷特征丢失，严重影响生成数据对下游检测模型的训练价值。\n- **改造成本高昂**：为了平衡速度与质量，通常需要重新设计网络结构或对模型进行漫长的额外微调训练。\n\n### 使用 Agent-Attention 后\n- **生成效率显著提升**：Agent-Attention 引入少量“代理令牌”聚合全局信息，将计算复杂度大幅降低，在同等硬件下图像生成速度提升数倍。\n- **高分辨率轻松支持**：得益于高效的线性注意力特性，系统可直接处理更高分辨率的输入而不爆显存，清晰呈现微小的工业缺陷细节。\n- **画质无损甚至增强**：该机制无缝融合了 Softmax 的强表达能力，无需任何额外训练即可在加速的同时提升生成图像的 FID 分数，确保缺陷特征逼真。\n- **零成本平滑迁移**：团队可直接替换现有 Stable Diffusion 模型中的注意力模块，无需重新训练即可立即获得性能与质量的双重收益。\n\nAgent-Attention 通过独特的代理令牌机制，打破了高分辨率图像生成中速度与质量的互斥魔咒，让低成本硬件也能跑出顶级生成效果。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FLeapLabTHU_Agent-Attention_2852bfbc.png","LeapLabTHU","LeapLab","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FLeapLabTHU_e9baff07.png","The Learning And Perception (LEAP) Lab is a research group at Tsinghua University working in the area of machine learning, multi-modal learning and embodied int",null,"https:\u002F\u002Fwww.leaplab.ai\u002F","https:\u002F\u002Fgithub.com\u002FLeapLabTHU",[84,88],{"name":85,"color":86,"percentage":87},"Python","#3572A5",98.8,{"name":89,"color":90,"percentage":91},"Shell","#89e051",1.2,667,46,"2026-03-30T18:14:46","未说明","需要支持 CUDA 的 NVIDIA GPU（基于 PyTorch 实现，具体显存和 CUDA 版本未在文中明确，通常建议 8GB+ 以运行 Transformer 模型）",{"notes":98,"python":95,"dependencies":99},"README 未提供具体的安装指令、Python 版本或依赖库版本号。该项目是基于 PVT、Swin Transformer 和 ToMeSD 等现有代码库开发的。包含图像分类、分割、检测以及 Stable Diffusion (AgentSD) 的应用场景，其中 AgentSD 声称无需额外训练即可加速生成并提升质量。具体文档需参考 repo 中的子文件夹（agent_transformer, downstream, agentsd）。",[100,101,102,103],"PyTorch","PVT (代码基础)","Swin Transformer (代码基础)","ToMeSD (AgentSD 部分基础)",[14,13],"2026-03-27T02:49:30.150509","2026-04-06T11:30:59.380889",[108,113,118,123,128,133,138,143],{"id":109,"question_zh":110,"answer_zh":111,"source_url":112},14846,"论文中提到的 'A' (Agent Token) 在代码的哪个位置？","是的，`agent_transformer\u002Fmodels\u002Fagent_swin.py` 中的 `class AgentAttention` 就是相关代码。对于目标检测任务，可以使用该模块。预训练权重可在以下地址找到：\n1. ImageNet 通用下游任务预训练权重：https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Ftree\u002Fmaster\u002Fagent_transformer#pretrained-models\n2. 目标检测模型专用预训练权重：https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Ftree\u002Fmaster\u002Fdownstream\u002Fdetection#results-and-models","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F3",{"id":114,"question_zh":115,"answer_zh":116,"source_url":117},14847,"如何将 Agent Attention 扩展到 3D 数据（如深度 'd'）或更高维度？","如果 'd' 代表深度（depth），可以考虑扩展 agent bias 的维度，并将其处理方式类比于高度（height）和宽度（width）。如果 'd' 代表通道维度（dimension），则应将其处理方式类比于注意力头数（num_heads）。核心思路是根据新维度的特性调整 agent bias 的形状和处理逻辑。","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F13",{"id":119,"question_zh":120,"answer_zh":121,"source_url":122},14848,"如何在单张 GPU 上进行调试或训练，遇到 local_rank 和 world_size 报错怎么办？","这是分布式训练的常见配置问题。在单卡调试时，可以使用 `torch.distributed.launch` 并设置 `--nproc_per_node=1`。完整的启动命令示例如下：\n`torch.distributed.launch --nproc_per_node=1 \u003Cyour_script.py> --cfg \u003Cpath-to-config-file> --data-path \u003Cimagenet-path> --output \u003Coutput-path>`\n请确保将必要的参数（如配置文件路径、数据路径等）添加到命令列表中。更多通用设置可参考相关 PyTorch 分布式教程。","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F2",{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},14849,"是否有基于 ViT 或 DeiT 架构的 Agent Attention 实现代码？","有的。项目已经实现了基于 DeiT 的 Agent Attention，其模型结构与 ViT 相同。您可以直接查看 `agent_transformer\u002Fmodels\u002Fagent_deit.py` 文件获取详细代码实现，作为在 ViT 模块中应用 Agent Attention 的参考。","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F9",{"id":129,"question_zh":130,"answer_zh":131,"source_url":132},14850,"为什么 Agent-Swin 的窗口大小（window size）设置为 56，而原始 Swin-T 是 7？","根据论文第 5.5 节，Agent 模块具有线性复杂度，因此增大窗口大小不会显著增加计算量。我们将窗口大小设为 56 是为了获得全局感受野。相比之下，如果在原始 Swin-T 中将窗口从 7 扩大到 56，FLOPs 会从 4.5G 激增至 8.8G。\n设计原则是：在特征图分辨率较高的早期阶段使用 Agent Attention，以充分利用大感受野的优势。计算 FLOPs 可使用 `fvcore` 库。","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F27",{"id":134,"question_zh":135,"answer_zh":136,"source_url":137},14851,"如何将 Agent Attention 应用于自回归模型（如 GPT），以避免信息泄露？","Agent Attention 可以被视为一种广义的线性注意力机制。在自回归模型中应用时，应遵循线性注意力（Linear Attention）的训练方法，避免直接使用导致信息泄露的池化操作。建议参考以下两篇论文了解具体的训练策略：\n1. https:\u002F\u002Fproceedings.mlr.press\u002Fv119\u002Fkatharopoulos20a\u002Fkatharopoulos20a.pdf\n2. https:\u002F\u002Farxiv.org\u002Fpdf\u002F2312.11135.pdf","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F8",{"id":139,"question_zh":140,"answer_zh":141,"source_url":142},14852,"如果输入序列长度不是完全平方数（例如 320），无法通过开方得到 h 和 w，该如何处理？","代码中通过 2D 池化（2D-Pooling）对查询 $Q$ 进行下采样以获取 Agent Tokens 只是核心思想的一种实现方式。如果您的序列长度（如 320）不适合直接开方或使用 2D 池化，您可以采用其他合适的下采样方法来生成 Agent Tokens，只要能从 $Q$ 中提取出代表性的 Agent 即可。","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F39",{"id":144,"question_zh":145,"answer_zh":146,"source_url":147},14853,"测试时的图像分辨率与训练时不同（通常更高），导致报错，如何支持动态分辨率输入？","模型可以通过插值（interpolation）来适应动态分辨率。具体做法是：对 `agent bias` 进行插值操作，使其尺寸匹配当前输入图像的大小。此外，对于位置编码（`pos_embed`）等模型参数，也需要在推理时动态插值以适应新的图像尺寸，从而解决因 `num_patches` 不匹配导致的错误。","https:\u002F\u002Fgithub.com\u002FLeapLabTHU\u002FAgent-Attention\u002Fissues\u002F38",[]]