[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-feifeibear--long-context-attention":3,"tool-feifeibear--long-context-attention":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 真正成长为懂上",150037,2,"2026-04-10T23:33:47",[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":79,"owner_twitter":80,"owner_website":81,"owner_url":82,"languages":83,"stars":92,"forks":93,"last_commit_at":94,"license":95,"difficulty_score":96,"env_os":97,"env_gpu":98,"env_ram":99,"env_deps":100,"category_tags":108,"github_topics":109,"view_count":32,"oss_zip_url":80,"oss_zip_packed_at":80,"status":17,"created_at":116,"updated_at":117,"faqs":118,"releases":149},6430,"feifeibear\u002Flong-context-attention","long-context-attention","USP: Unified (a.k.a. Hybrid, 2D) Sequence Parallel Attention for Long Context Transformers Model Training and Inference","long-context-attention（又名 YunChang）是一款专为长上下文大语言模型训练与推理设计的开源加速工具。它提出了一种“统一序列并行”（USP）机制，巧妙融合了 DeepSpeed-Ulysses 和 Ring-Attention 两种主流分布式注意力算法的优势，旨在突破现有技术在处理超长文本时的性能瓶颈。\n\n传统方案往往面临两难：Ulysses 虽计算高效，但受限于注意力头数量，难以适配 GQA 或 MQA 等现代架构；Ring-Attention 虽通用性强，但在计算效率和通信带宽利用率上略显不足。long-context-attention 通过混合并行策略，既保留了对各种注意力机制的广泛兼容性，又显著提升了大规模集群下的训练速度与稳定性，有效避免了通信死锁风险。\n\n该工具特别适合从事大模型研发的工程师、算法研究人员以及需要优化长文本处理性能的 AI 开发者。其技术亮点在于灵活适配多种硬件环境：不仅支持 NVIDIA H100\u002FA100 等 GPU 上的 FlashAttention V2\u002FV3 加速，还能为不支持 FlashAttention 的 NPU ","long-context-attention（又名 YunChang）是一款专为长上下文大语言模型训练与推理设计的开源加速工具。它提出了一种“统一序列并行”（USP）机制，巧妙融合了 DeepSpeed-Ulysses 和 Ring-Attention 两种主流分布式注意力算法的优势，旨在突破现有技术在处理超长文本时的性能瓶颈。\n\n传统方案往往面临两难：Ulysses 虽计算高效，但受限于注意力头数量，难以适配 GQA 或 MQA 等现代架构；Ring-Attention 虽通用性强，但在计算效率和通信带宽利用率上略显不足。long-context-attention 通过混合并行策略，既保留了对各种注意力机制的广泛兼容性，又显著提升了大规模集群下的训练速度与稳定性，有效避免了通信死锁风险。\n\n该工具特别适合从事大模型研发的工程师、算法研究人员以及需要优化长文本处理性能的 AI 开发者。其技术亮点在于灵活适配多种硬件环境：不仅支持 NVIDIA H100\u002FA100 等 GPU 上的 FlashAttention V2\u002FV3 加速，还能为不支持 FlashAttention 的 NPU 提供基于 PyTorch 的基础实现。作为已被 NVIDIA TransformerEngine 集成的成熟方案，long-context-attention 为构建高效、可扩展的长上下文模型提供了坚实的技术底座。","#  YunChang: A Unified Sequence Parallel (USP) Attention for Long Context LLM Model Training and Inference.\n\n[\\[Tech Report\\] USP: A Unified Sequence Parallelism Approach for Long Context Generative AI](https:\u002F\u002Farxiv.org\u002Fabs\u002F2405.07719)\n\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_3c2d6b12d5ee.jpg\" width=\"200\" \u002F>\n\u003C\u002Fp>\n\nThis repo provides a sequence parallel approach that synergizes the strengths of two popular distributed attentions, i.e. DeepSpeed-Ulysses-Attention and Ring-Attention, delivering a more general and stronger versatility and better performance. \nThe project is built on [zhuzilin\u002Fring-flash-attention](https:\u002F\u002Fgithub.com\u002Fzhuzilin\u002Fring-flash-attention) and refers to the [DeepSpeed-Ulysses](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FDeepSpeed\u002Fblob\u002Fmaster\u002Fblogs\u002Fdeepspeed-ulysses\u002FREADME.md).\n\nUSP has been applied in [NVIDIA\u002FTransformerEngine](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FTransformerEngine\u002Fblob\u002F54aa12a9a1f166c53a20f17f309adeab5698f5f6\u002Ftransformer_engine\u002Fpytorch\u002Fattention.py#L1542) `AttnFuncWithCPAndKVP2P`. You can use it in API `attn_forward_func_with_cp`.\n\n\n## Why not apply Ulysses and Ring Attention Individually?\n\n- Ulysses is sensitive to the number of attention heads. \nThe parallelism degree in Ulysses cannot exceed the number of heads. \nConsequently, it is not suitable for GQA (Grouped Query Attention) and MQA (Multi-Query Attention) scenarios. For instance, Ulysses does not operate effectively with a single head. \nIn addition, since Tensor Parallelism also requires division across the head number dimension, achieving compatibility between Ulysses and TP can be challenging.\n\n- Ring-Attention is ineffient than Ulysses in computation and communication.\nRing-Attention segments the Query, Key, and Value (QKV) into smaller blocks, which can lead to a decrease in efficiency when using FlashAttention.\nEven with the communication and computation processes fully overlapped, the total execution time lags behind that of Ulysses. \nFurthermore, Ring-Attention utilizes asynchronous peer-to-peer communication, which not only has a lower bandwidth utilization compared to collective communication methods but also poses the risk of potential communication deadlocks in large-scale deployments.\n\n\n## LongContextAttention, also known as Unified Sequence Parallelism and Hybrid Sequence Parallelism\n\n`LongContextAttention` is a **unified sequence parallel** , also known as **hybrid sequence parallel** ,that hybrid DeepSpeed-Ulysses-Attention and Ring-Attention therefore addressing the limitations of both methods.\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_869c1905c224.png\">\n\u003C\u002Fp>\n\n\n### 1. Installation\n\nFlashAttention is the most important external dependency and is often the cause of errors when installing and using yunchang. \nYunchang supports flash_attn 2.6.x and 2.7.x, both v3 and v2 versions. Additionally, yunchang supports runs without flash_attn, which is suitable for NPUs.\n\nAs shown in the figure below, there are three usage methods based on the flash_attn situation:\n\n1. For H100, B100, hardware that supports FA v3, ring_flash_attn uses FA v3.\n\n2. For A100, L40, hardware that supports FA v2, ring_flash_attn uses FA v2.\n\n3. For hardware such as NPUs that does not support FA, use torch to implement attention computation. In this case, there is no need to install `flash_attn`, and you should apply `LongContextAttention(ring_impl_type=\"basic\", attn_type=AttnType.TORCH_EFFICIENT)`. *Note: the backward pass is not supported for AttnType.TORCH_EFFICIENT.*\n\nOption 1: pip install\n\n`pip install flash-attn`\n\n`pip install yunchang`\n\n#### Apply FlashAttention V3: Since FA V3 is beta-released, you need to install FlashAttention V3 from source code.\n\nFollow the [FlashAttention beta-release](https:\u002F\u002Fgithub.com\u002FDao-AILab\u002Fflash-attention?tab=readme-ov-file#flashattention-3-beta-release) to install V3 for NVIDIA Hopper GPUs.\n\nWe applied the Nov 10 2024 commit `b443207c1fc4c98e4532aad4e88cfee1d590d996`.\n\n\nOption 2: build from local.\n\n`pip install .`\n\nInstall for AMD GPU: [install_amd.md](.\u002Fdocs\u002Finstall_amd.md)\n\n\n### 2. Usage\n\nPlease refer to [test\u002Ftest_hybrid_qkvpacked_attn.py](.\u002Ftest\u002Ftest_hybrid_qkvpacked_attn.py) and [test\u002Ftest_hybrid_attn.py](.\u002Ftest\u002Ftest_hybrid_attn.py) for usage.\n\nIn short, we take the `zigzag` ring attention implementation as an example:\n\n1. apply `set_seq_parallel_pg` to set the process group\n2. extract local tensors with `zigzag_extract_local`. We need reorder the input tokens or input tensors for load balance ring attention.\n3. then apply `LongContextAttention(ring_impl_type=\"zigzag\")` as a drop-in replacement for Attention implementation.\n\n```python\nfrom yunchang import (\n    AsyncLongContextAttention,\n    LongContextAttention,\n    set_seq_parallel_pg,\n    EXTRACT_FUNC_DICT\n)\nfrom yunchang.kernels import AttnType\n\nsp_ulysses_degree = 2\nsp_ring_degree = 4\n\n# support world_size = 8\nset_seq_parallel_pg(sp_ulysses_degree, sp_ring_degree, rank, world_size)\n\n# attn_type could be FA, FA3, TORCH_EFFICIENT.\nlongctx_attn = LongContextAttention(ring_impl_type=\"zigzag\", attn_type=AttnType.FA)\n\n# if you use NPUs, where no flash_attn is supported, you can use the following code.\n# LongContextAttention(ring_impl_type=\"zigzag\", attn_type=AttnType.TORCH_EFFICIENT)\n\n# extract a local shard for the global Q, K, V.\nlocal_q = EXTRACT_FUNC_DICT[\"zigzag\"](\n        Q, rank, world_size=world_size, rd=sp_ring_degree, ud=sp_ulysses_degree\n    ).detach().clone()\n...\n\nlocal_out = usp_attn(\n        local_q,\n        local_k,\n        local_v,\n        dropout_p=dropout_p,\n        causal=True, # zigzag and stripe is load balance strategy for causal=True\n        window_size=window_size,\n        softcap=0.0,\n        alibi_slopes=alibi_slopes,\n        deterministic=deterministic,\n        return_attn_probs=True,\n    )\n\n```\n\n### 3.Test\n\nif you do not install yuanchang, add the project root directory to the PYTHONPATH:\n```\nexport PYTHONPATH=$PWD:$PYTHONPATH\n````\n\n- FlashAttn\u002FTorch Test\n```bash\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type \"zigzag\" --causal --attn_impl fa --use_bwd\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type \"zigzag\" --causal --attn_impl torch\ntorchrun --nproc_per_node 8 test\u002Ftest_hybrid_qkvpacked_attn.py\n```\n\n- Sage\u002FSpargeAttention Test (fwd only, Non causal)\n\nyou need install [SpargeAttn](https:\u002F\u002Fgithub.com\u002Fthu-ml\u002FSpargeAttn) and [SageAttention](https:\u002F\u002Fgithub.com\u002Fthu-ml\u002FSageAttention) from source.\n\n```bash\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --attn_impl sage_fp8\n```\n\n```bash\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 4 --attn_impl sparse_sage --sparse_sage_tune_mode\n```\n\n- FlashInfer Test (fwd only)\n\nInstall FlashInfer from [here](https:\u002F\u002Fdocs.flashinfer.ai\u002Finstallation.html#quick-start).\n\n```bash\ntorchrun --nproc_per_node=4 --master_port=1234 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type 'basic_flashinfer' --attn_impl flashinfer\n```\n\n### 4. Verified in Megatron-LM\nThe loss curves for Data Parallel (DP) and Unified Sequence Parallel (ulysses=2+ring=2) are closely aligned, as illustrated in the figure. This alignment confirms the accuracy of the unified sequence parallel.\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_f0fc6bb3fe64.png\">\n\u003C\u002Fp>\n\nWhen utilizing load-balance Ring Attention with a causal mask, it is essential to reorder the Query tensors using the [EXTRACT_FUNC_DICT](.\u002Fyunchang\u002Fcomm\u002Fextract_local.py) function.\n\nIn Megatron-LM, you can reorder the input tokens before feeding them into the model and apply the same reordering to the RoPE parameters. For detailed instructions, please refer to our paper.\n\nFor an example implementation, you can check out this [PR](https:\u002F\u002Fgithub.com\u002FFlagOpen\u002FFlagScale\u002Fcommit\u002Ff98ee1e293bd906cc77f512f7a884b2030c10a12), which integrates USP into a BAAI's Megatron-LM framework.\n\n### 6. Benchmark\n\n\n```bash\nbash .\u002Fscripts\u002Frun_qkvpack_compare.sh\n```\n\nOn an 8xA100 NVLink machine, the benchmark results are as follows:\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_b6c0d0899b6a.png\">\n\u003C\u002Fp>\n\nOn an 8xL20 PCIe machine and a 4xA100 PCIe machine, the benchmark results are as follows:\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_165f09b53d25.jpg\">\n\u003C\u002Fp>\n\nSome Conclusions:\n\n1. If the head number is enough, Ulysses outperforms Ring-Attention. The All-to-All communication of Ulysses is highly efficient within a single machine, with a very low overhead ratio. In contrast, Ring splits computation and communication, which increases the overall of computation time, and even with complete overlap, it is slower than Ulysses.\n\n2. QKV packed (`LongContextAttentionQKVPacked`) is better than the QKV no packed (`LongContextAttention`) version, with the difference becoming more pronounced as the sequence length decreases. MAQ and GQA can only use the no packed version.\n\n3. Among the variants of the Ring-Attention implementation, `zigzag` and `stripe` perform better than `basic`. Typically, zigzag is slightly better than stripe, but as the sequence length increases, the difference between zigzag and stripe becomes less noticeable. It is worth noting that both zigzag and stripe have specific layout requirements for the sequence dimension.\n\n4. Hybrid parallelism works well to heterogeneous network devices. For example, on an 8-GPU L20 setup, the optimal performance is achieved when ulysess_degree is set to 2 and ring_degree is set to 4.\n\n### 7. Best Practice for 4D Parallelism\n\nWe analyze the impact of introducing Sequnce Parallelism to Data\u002FZeRO\u002FTensor\u002FPipeline Parallelism in a technique report, which can be found at [here](https:\u002F\u002Farxiv.org\u002Fabs\u002F2405.07719).\n\nSome best practices are listed here:\n\n1. We suggest using Unified-SP in place of SP-Ring and SP-Ulysses, as it encompasses the capabilities of both while offering additional benefits.\n\n2. DP (data parallelism) vs SP: We suggest prioritizing the use of DP over SP if possible. \nOnly when the batch size (bs) is insufficient for partitioning should one consider whether to employ SP\n\n3. Utilizing SP, it should always be used in conjunction wit ZeRO-1\u002F2.\n\n4. Unified-SP has lower communication cost than Tensor Parallel with megatron-lm sequence parallelism (TP-sp)! You can use Unified-SP to replace TP for better speed. However, now switching TP (tensor parallelism) to SP+ZeRO2 cannot increase the sequence length in training. SP+ZeRO3 can train a similar sequence length as TP-sp. We suggest that SP may have an advantage over TP when employing GQA in terms of communication cost, as GQA can reduce the communication cost of SP without affecting TP.\n\n5. Setting a higher parallel degree of SP parallelism is possible, which may need to set a large ring degree when the head number is limited, to train a long sequence across a greater number of computational devices. But TP could not be set a high parallel.\n\n\n\n### 8. Projects apply USP\nI am honored that this repository has contributed to the following projects:\n\n1. [xdit-project\u002FxDiT](https:\u002F\u002Fgithub.com\u002Fxdit-project\u002FxDiT)\n2. [NVlabs\u002FVILA](https:\u002F\u002Fgithub.com\u002FNVlabs\u002FVILA\u002Fblob\u002Fmain\u002FLongVILA.md)\n3. [feifeibear\u002FOdysseus-Transformer](https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002FOdysseus-Transformer)\n4. [Ascend\u002FAscendSpeed](https:\u002F\u002Fgitee.com\u002Fascend\u002FAscendSpeed\u002Fblob\u002Fmaster\u002Fdocs\u002Ffeatures\u002Fhybrid-context-parallel.md)\n5. [jzhang38\u002FEasyContext](https:\u002F\u002Fgithub.com\u002Fjzhang38\u002FEasyContext)\n6. [FlagOpen\u002FFlagScale](https:\u002F\u002Fgithub.com\u002FFlagOpen\u002FFlagScale\u002Fcommit\u002Ff98ee1e293bd906cc77f512f7a884b2030c10a12)\n7. [zhiyuanhubj\u002FLongRecipe](https:\u002F\u002Fgithub.com\u002Fzhiyuanhubj\u002FLongRecipe)\n8. [NVIDIA\u002FTransformerEngine](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FTransformerEngine\u002Fblob\u002F54aa12a9a1f166c53a20f17f309adeab5698f5f6\u002Ftransformer_engine\u002Fpytorch\u002Fattention.py#L1542)\n9. [xdit-project\u002Fmochi-xdit](https:\u002F\u002Fgithub.com\u002Fxdit-project\u002Fmochi-xdit)\n \n### 9. Cite Us\n\n[USP: A Unified Sequence Parallelism Approach for Long Context Generative AI](https:\u002F\u002Farxiv.org\u002Fabs\u002F2405.07719)\n\n```\n@article{fang2024unified,\n  title={A Unified Sequence Parallelism Approach for Long Context Generative AI},\n  author={Fang, Jiarui and Zhao, Shangchun},\n  journal={arXiv preprint arXiv:2405.07719},\n  year={2024}\n}\n\n```\n","#  YunChang：一种统一的序列并行（USP）注意力机制，用于长上下文大模型的训练和推理。\n\n[\\[技术报告\\] USP：一种适用于长上下文生成式 AI 的统一序列并行方法](https:\u002F\u002Farxiv.org\u002Fabs\u002F2405.07719)\n\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_3c2d6b12d5ee.jpg\" width=\"200\" \u002F>\n\u003C\u002Fp>\n\n本仓库提供了一种序列并行方法，它融合了两种流行的分布式注意力机制——DeepSpeed-Ulysses-Attention 和 Ring-Attention 的优势，从而具备更通用、更强的适应性以及更好的性能。该项目基于 [zhuzilin\u002Fring-flash-attention](https:\u002F\u002Fgithub.com\u002Fzhuzilin\u002Fring-flash-attention) 构建，并参考了 [DeepSpeed-Ulysses](https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002FDeepSpeed\u002Fblob\u002Fmaster\u002Fblogs\u002Fdeepspeed-ulysses\u002FREADME.md) 的实现。\n\nUSP 已被应用于 [NVIDIA\u002FTransformerEngine](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FTransformerEngine\u002Fblob\u002F54aa12a9a1f166c53a20f17f309adeab5698f5f6\u002Ftransformer_engine\u002Fpytorch\u002Fattention.py#L1542) 的 `AttnFuncWithCPAndKVP2P` 中。您可以在 API `attn_forward_func_with_cp` 中使用它。\n\n\n## 为什么不能单独使用 Ulysses 和 Ring Attention？\n\n- Ulysses 对注意力头的数量较为敏感。其并行度不能超过头数，因此不适用于 GQA（分组查询注意力）和 MQA（多查询注意力）场景。例如，当只有一个注意力头时，Ulysses 无法有效工作。此外，由于张量并行也需要在头数维度上进行划分，因此要实现 Ulysses 与张量并行的兼容性较为困难。\n\n- 在计算和通信效率方面，Ring-Attention 低于 Ulysses。Ring-Attention 将 Query、Key 和 Value（QKV）分割成较小的块，这可能导致在使用 FlashAttention 时效率下降。即使通信和计算过程完全重叠，总执行时间仍会落后于 Ulysses。此外，Ring-Attention 使用异步点对点通信，不仅带宽利用率低于集体通信方式，而且在大规模部署中还存在潜在的通信死锁风险。\n\n\n## LongContextAttention，又称统一序列并行和混合序列并行\n\n`LongContextAttention` 是一种 **统一的序列并行**，也称为 **混合序列并行**，它结合了 DeepSpeed-Ulysses-Attention 和 Ring-Attention 的优点，从而克服了这两种方法各自的局限性。\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_869c1905c224.png\">\n\u003C\u002Fp>\n\n\n### 1. 安装\n\nFlashAttention 是最重要的外部依赖项，也是安装和使用 yunchang 时经常出错的原因。Yunchang 支持 flash_attn 2.6.x 和 2.7.x 版本，包括 v3 和 v2 版本。此外，yunchang 还支持在没有 flash_attn 的情况下运行，这非常适合 NPU 设备。\n\n如下图所示，根据是否使用 flash_attn，有三种使用方法：\n\n1. 对于 H100、B100 等支持 FA v3 的硬件，ring_flash_attn 使用 FA v3。\n\n2. 对于 A100、L40 等支持 FA v2 的硬件，ring_flash_attn 使用 FA v2。\n\n3. 对于 NPU 等不支持 FA 的硬件，可以使用 PyTorch 实现注意力计算。在这种情况下，无需安装 `flash_attn`，应使用 `LongContextAttention(ring_impl_type=\"basic\", attn_type=AttnType.TORCH_EFFICIENT)`。*注意：AttnType.TORCH_EFFICIENT 不支持反向传播。*\n\n选项 1：通过 pip 安装\n\n`pip install flash-attn`\n\n`pip install yunchang`\n\n#### 应用 FlashAttention V3：由于 FA V3 处于测试版发布阶段，您需要从源代码安装 FlashAttention V3。\n\n请按照 [FlashAttention 测试版发布](https:\u002F\u002Fgithub.com\u002FDao-AILab\u002Fflash-attention?tab=readme-ov-file#flashattention-3-beta-release) 的说明，为 NVIDIA Hopper GPU 安装 V3 版本。我们采用了 2024 年 11 月 10 日的提交 `b443207c1fc4c98e4532aad4e88cfee1d590d996`。\n\n\n选项 2：本地构建\n\n`pip install .`\n\nAMD GPU 的安装：[install_amd.md](.\u002Fdocs\u002Finstall_amd.md)\n\n\n### 2. 使用\n\n请参阅 [test\u002Ftest_hybrid_qkvpacked_attn.py](.\u002Ftest\u002Ftest_hybrid_qkvpacked_attn.py) 和 [test\u002Ftest_hybrid_attn.py](.\u002Ftest\u002Ftest_hybrid_attn.py) 了解具体用法。\n\n简而言之，我们以 `zigzag` 式的环形注意力实现为例：\n\n1. 调用 `set_seq_parallel_pg` 设置进程组。\n2. 使用 `zigzag_extract_local` 提取局部张量。为了使环形注意力负载均衡，我们需要对输入 token 或输入张量进行重新排序。\n3. 然后将 `LongContextAttention(ring_impl_type=\"zigzag\")` 作为注意力实现的直接替代品使用。\n\n```python\nfrom yunchang import (\n    AsyncLongContextAttention,\n    LongContextAttention,\n    set_seq_parallel_pg,\n    EXTRACT_FUNC_DICT\n)\nfrom yunchang.kernels import AttnType\n\nsp_ulysses_degree = 2\nsp_ring_degree = 4\n\n# 支持 world_size = 8\nset_seq_parallel_pg(sp_ulysses_degree, sp_ring_degree, rank, world_size)\n\n# attn_type 可以是 FA、FA3 或 TORCH_EFFICIENT。\nlongctx_attn = LongContextAttention(ring_impl_type=\"zigzag\", attn_type=AttnType.FA)\n\n# 如果您使用的是不支持 flash_attn 的 NPU，可以使用以下代码。\n# LongContextAttention(ring_impl_type=\"zigzag\", attn_type=AttnType.TORCH_EFFICIENT)\n\n# 提取全局 Q、K、V 的局部片断。\nlocal_q = EXTRACT_FUNC_DICT[\"zigzag\"](\n        Q, rank, world_size=world_size, rd=sp_ring_degree, ud=sp_ulysses_degree\n    ).detach().clone()\n...\n\nlocal_out = usp_attn(\n        local_q,\n        local_k,\n        local_v,\n        dropout_p=dropout_p,\n        causal=True, # zigzag 和 stripe 是针对 causal=True 的负载均衡策略\n        window_size=window_size,\n        softcap=0.0,\n        alibi_slopes=alibi_slopes,\n        deterministic=deterministic,\n        return_attn_probs=True,\n    )\n\n```\n\n### 3. 测试\n\n如果您尚未安装 yuanchang，请将项目根目录添加到 PYTHONPATH：\n```\nexport PYTHONPATH=$PWD:$PYTHONPATH\n```\n\n- FlashAttn\u002FTorch 测试\n```bash\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type \"zigzag\" --causal --attn_impl fa --use_bwd\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type \"zigzag\" --causal --attn_impl torch\ntorchrun --nproc_per_node 8 test\u002Ftest_hybrid_qkvpacked_attn.py\n```\n\n- Sage\u002FSpargeAttention 测试（仅前向传播，非因果）\n\n您需要从源码安装 [SpargeAttn](https:\u002F\u002Fgithub.com\u002Fthu-ml\u002FSpargeAttn) 和 [SageAttention](https:\u002F\u002Fgithub.com\u002Fthu-ml\u002FSageAttention)。\n\n```bash\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --attn_impl sage_fp8\n```\n\n```bash\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 4 --attn_impl sparse_sage --sparse_sage_tune_mode\n```\n\n- FlashInfer 测试（仅前向传播）\n\n请从 [这里](https:\u002F\u002Fdocs.flashinfer.ai\u002Finstallation.html#quick-start) 安装 FlashInfer。\n\n```bash\ntorchrun --nproc_per_node=4 --master_port=1234 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type 'basic_flashinfer' --attn_impl flashinfer\n```\n\n### 4. 在 Megatron-LM 中验证\n数据并行（DP）和统一序列并行（ulysses=2+ring=2）的损失曲线非常接近，如图所示。这一对齐结果证实了统一序列并行的准确性。\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_f0fc6bb3fe64.png\">\n\u003C\u002Fp>\n\n当使用负载均衡环形注意力机制并施加因果掩码时，必须使用 [EXTRACT_FUNC_DICT](.\u002Fyunchang\u002Fcomm\u002Fextract_local.py) 函数对 Query 张量进行重新排序。\n\n在 Megatron-LM 中，您可以在将输入标记送入模型之前对其进行重新排序，并对 RoPE 参数应用相同的重新排序。有关详细说明，请参阅我们的论文。\n\n有关示例实现，您可以查看此 [PR](https:\u002F\u002Fgithub.com\u002FFlagOpen\u002FFlagScale\u002Fcommit\u002Ff98ee1e293bd906cc77f512f7a884b2030c10a12)，其中将 USP 集成到了 BAAI 的 Megatron-LM 框架中。\n\n### 6. 基准测试\n\n\n```bash\nbash .\u002Fscripts\u002Frun_qkvpack_compare.sh\n```\n\n在一台 8xA100 NVLink 机器上，基准测试结果如下：\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_b6c0d0899b6a.png\">\n\u003C\u002Fp>\n\n在一台 8xL20 PCIe 机器和一台 4xA100 PCIe 机器上，基准测试结果如下：\n\n\u003Cp align=\"center\">\n    \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_readme_165f09b53d25.jpg\">\n\u003C\u002Fp>\n\n一些结论：\n\n1. 如果头数足够多，Ulysses 的性能优于 Ring-Attention。Ulysses 的 All-to-All 通信在单机内非常高效，开销比例极低。相比之下，Ring 将计算和通信分开，这增加了总的计算时间，即使完全重叠，其速度也仍慢于 Ulysses。\n\n2. QKV 打包版本（`LongContextAttentionQKVPacked`）比 QKV 非打包版本（`LongContextAttention`）更好，且随着序列长度的缩短，这种差异更加明显。MAQ 和 GQA 只能使用非打包版本。\n\n3. 在 Ring-Attention 的不同实现变体中，`zigzag` 和 `stripe` 的性能优于 `basic`。通常情况下，zigzag 略好于 stripe，但随着序列长度的增加，zigzag 和 stripe 之间的差异变得不那么明显。值得注意的是，zigzag 和 stripe 对序列维度都有特定的布局要求。\n\n4. 混合并行性在异构网络设备上表现良好。例如，在 8-GPU L20 配置中，当 ulysess_degree 设置为 2、ring_degree 设置为 4 时，可达到最佳性能。\n\n### 7. 4D 并行的最佳实践\n\n我们在一篇技术报告中分析了将序列并行引入数据并行\u002FZeRO 并行\u002F张量并行\u002F流水线并行的影响，该报告可在 [这里](https:\u002F\u002Farxiv.org\u002Fabs\u002F2405.07719) 查阅。\n\n以下列出了一些最佳实践：\n\n1. 我们建议使用统一序列并行（Unified-SP）代替 SP-Ring 和 SP-Ulysses，因为它兼具两者的功能，并提供更多优势。\n\n2. 数据并行（DP）与序列并行（SP）：我们建议尽可能优先使用 DP，只有在批量大小（bs）不足以进行划分时，才考虑是否采用 SP。\n\n3. 使用 SP 时，应始终与 ZeRO-1\u002F2 结合使用。\n\n4. 统一序列并行的通信成本低于 Megatron-LM 序列并行下的张量并行！您可以使用统一序列并行来替代张量并行，以获得更好的速度。然而，目前将张量并行切换为 SP+ZeRO2 并不能增加训练中的序列长度。而 SP+ZeRO3 则可以训练与 TP-sp 相似的序列长度。我们建议，在采用 GQA 时，SP 在通信成本方面可能比 TP 更具优势，因为 GQA 可以降低 SP 的通信成本，同时不影响 TP。\n\n5. 可以设置更高的 SP 并行度，这可能需要在头数有限的情况下设置较大的 ring degree，以便在更多计算设备上训练长序列。但 TP 却无法设置较高的并行度。\n\n\n\n### 8. 应用 USP 的项目\n我很荣幸本仓库已为以下项目做出了贡献：\n\n1. [xdit-project\u002FxDiT](https:\u002F\u002Fgithub.com\u002Fxdit-project\u002FxDiT)\n2. [NVlabs\u002FVILA](https:\u002F\u002Fgithub.com\u002FNVlabs\u002FVILA\u002Fblob\u002Fmain\u002FLongVILA.md)\n3. [feifeibear\u002FOdysseus-Transformer](https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002FOdysseus-Transformer)\n4. [Ascend\u002FAscendSpeed](https:\u002F\u002Fgitee.com\u002Fascend\u002FAscendSpeed\u002Fblob\u002Fmaster\u002Fdocs\u002Ffeatures\u002Fhybrid-context-parallel.md)\n5. [jzhang38\u002FEasyContext](https:\u002F\u002Fgithub.com\u002Fjzhang38\u002FEasyContext)\n6. [FlagOpen\u002FFlagScale](https:\u002F\u002Fgithub.com\u002FFlagOpen\u002FFlagScale\u002Fcommit\u002Ff98ee1e293bd906cc77f512f7a884b2030c10a12)\n7. [zhiyuanhubj\u002FLongRecipe](https:\u002F\u002Fgithub.com\u002Fzhiyuanhubj\u002FLongRecipe)\n8. [NVIDIA\u002FTransformerEngine](https:\u002F\u002Fgithub.com\u002FNVIDIA\u002FTransformerEngine\u002Fblob\u002F54aa12a9a1f166c53a20f17f309adeab5698f5f6\u002Ftransformer_engine\u002Fpytorch\u002Fattention.py#L1542)\n9. [xdit-project\u002Fmochi-xdit](https:\u002F\u002Fgithub.com\u002Fxdit-project\u002Fmochi-xdit)\n \n### 9. 引用我们\n\n[USP：一种用于长上下文生成式 AI 的统一序列并行方法](https:\u002F\u002Farxiv.org\u002Fabs\u002F2405.07719)\n\n```\n@article{fang2024unified,\n  title={A Unified Sequence Parallelism Approach for Long Context Generative AI},\n  author={Fang, Jiarui and Zhao, Shangchun},\n  journal={arXiv preprint arXiv:2405.07719},\n  year={2024}\n}\n\n```","# YunChang (Long-Context-Attention) 快速上手指南\n\nYunChang 是一个统一的序列并行（Unified Sequence Parallelism, USP）注意力机制库，旨在优化长上下文大语言模型（LLM）的训练与推理。它结合了 DeepSpeed-Ulysses 和 Ring-Attention 的优势，解决了两者单独使用时的局限性（如 Ulysses 对头数的限制、Ring-Attention 的计算通信效率问题），特别适用于 GQA\u002FMQA 架构及大规模分布式训练。\n\n## 1. 环境准备\n\n### 系统要求\n*   **硬件**：NVIDIA GPU (推荐 A100, H100, L20, L40 等) 或 国产 NPU (如 Ascend)。\n*   **软件**：PyTorch, CUDA (针对 NVIDIA)。\n\n### 前置依赖\n核心依赖为 `flash-attn`。根据硬件型号选择版本：\n*   **H100\u002FB100 (支持 FA v3)**：需从源码安装 FlashAttention v3 (Beta 版)。\n*   **A100\u002FL40 (支持 FA v2)**：可直接通过 pip 安装 FlashAttention v2。\n*   **NPU\u002F无 FA 支持硬件**：无需安装 `flash_attn`，将使用 PyTorch 原生实现（注意：原生实现目前不支持反向传播）。\n\n> **国内加速建议**：安装 Python 包时，推荐使用清华或阿里镜像源以提升下载速度。\n> ```bash\n> export PIP_INDEX_URL=https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n> ```\n\n## 2. 安装步骤\n\n### 方案 A：标准安装 (适用于大多数 NVIDIA GPU)\n直接通过 pip 安装 `flash-attn` 和 `yunchang`。\n\n```bash\n# 安装 flash-attn (自动匹配适合当前硬件的版本，通常为 v2)\npip install flash-attn\n\n# 安装 yunchang\npip install yunchang\n```\n\n### 方案 B：安装 FlashAttention v3 (仅适用于 H100\u002FB100 等新一代显卡)\n由于 FA v3 处于 Beta 阶段，需从源码编译安装。\n\n```bash\n# 克隆 flash-attention 仓库并切换到指定 commit (2024-11-10)\ngit clone https:\u002F\u002Fgithub.com\u002FDao-AILab\u002Fflash-attention.git\ncd flash-attention\ngit checkout b443207c1fc4c98e4532aad4e88cfee1d590d996\n\n# 从源码安装\npip install .\n\n# 返回上级目录并安装 yunchang\ncd ..\npip install yunchang\n```\n\n### 方案 C：本地源码安装 (开发模式)\n如果你克隆了本仓库进行二次开发：\n\n```bash\npip install .\n```\n\n### 方案 D：AMD GPU 支持\n请参考项目文档 `docs\u002Finstall_amd.md` 进行特定安装。\n\n## 3. 基本使用\n\n以下示例展示了如何使用 `zigzag` 模式的混合序列并行注意力机制。主要流程包括：设置并行组、提取局部张量、调用注意力计算。\n\n### 代码示例\n\n```python\nimport torch\nfrom yunchang import (\n    LongContextAttention,\n    set_seq_parallel_pg,\n    EXTRACT_FUNC_DICT\n)\nfrom yunchang.kernels import AttnType\n\n# 1. 配置并行度\n# sp_ulysses_degree: Ulysses 并行度\n# sp_ring_degree: Ring 并行度\n# 确保 rank 和 world_size 与实际运行环境一致 (例如 torchrun 启动的参数)\nsp_ulysses_degree = 2\nsp_ring_degree = 4\nrank = int(os.environ.get(\"RANK\", 0))\nworld_size = int(os.environ.get(\"WORLD_SIZE\", 8))\n\n# 初始化序列并行进程组\nset_seq_parallel_pg(sp_ulysses_degree, sp_ring_degree, rank, world_size)\n\n# 2. 初始化注意力模块\n# ring_impl_type: 可选 \"zigzag\", \"stripe\", \"basic\" 等\n# attn_type: 可选 AttnType.FA (FlashAttn v2), AttnType.FA3 (FlashAttn v3), AttnType.TORCH_EFFICIENT (无 FA 时)\nlongctx_attn = LongContextAttention(ring_impl_type=\"zigzag\", attn_type=AttnType.FA)\n\n# 如果是 NPU 或不支持 FlashAttn 的环境，请使用:\n# longctx_attn = LongContextAttention(ring_impl_type=\"zigzag\", attn_type=AttnType.TORCH_EFFICIENT)\n\n# 3. 准备数据 (假设 Q, K, V 已定义且形状正确)\n# Q, K, V shape: [batch, seq_len, num_heads, head_dim]\n\n# 提取局部切片 (Load Balance 关键步骤)\n# 对于 causal mask，必须使用 extract_func 重排输入以平衡负载\nlocal_q = EXTRACT_FUNC_DICT[\"zigzag\"](\n    Q, rank, world_size=world_size, rd=sp_ring_degree, ud=sp_ulysses_degree\n).detach().clone()\n\nlocal_k = EXTRACT_FUNC_DICT[\"zigzag\"](\n    K, rank, world_size=world_size, rd=sp_ring_degree, ud=sp_ulysses_degree\n).detach().clone()\n\nlocal_v = EXTRACT_FUNC_DICT[\"zigzag\"](\n    V, rank, world_size=world_size, rd=sp_ring_degree, ud=sp_ulysses_degree\n).detach().clone()\n\n# 4. 执行注意力计算\nlocal_out = longctx_attn(\n    local_q,\n    local_k,\n    local_v,\n    dropout_p=0.0,\n    causal=True,  # zigzag 和 stripe 策略专为 causal=True 设计以实现负载均衡\n    window_size=-1, # -1 表示无滑动窗口限制\n    softcap=0.0,\n    alibi_slopes=None,\n    deterministic=False,\n    return_attn_probs=False,\n)\n\n# local_out 即为计算结果，后续可根据需要聚合或继续使用\n```\n\n### 运行测试\n安装完成后，可通过以下命令验证安装是否成功（以 4 卡为例）：\n\n```bash\n# 测试 FlashAttn 实现 (含反向传播)\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type \"zigzag\" --causal --attn_impl fa --use_bwd\n\n# 测试 PyTorch 原生实现 (适用于无 FA 环境，仅前向)\ntorchrun --nproc_per_node=4 .\u002Ftest\u002Ftest_hybrid_attn.py --sp_ulysses_degree 2 --ring_impl_type \"zigzag\" --causal --attn_impl torch\n```\n\n### 最佳实践提示\n*   **并行策略选择**：优先使用统一序列并行 (Unified-SP) 替代单独的 Ring-SP 或 Ulysses-SP。\n*   **与 DP\u002FZeRO 配合**：建议在使用 SP 时同时开启 ZeRO-1 或 ZeRO-2。当显存不足以支撑大 Batch Size 时，再考虑引入 SP。\n*   **GQA\u002FMQA 支持**：USP 完美支持 GQA 和 MQA，这是传统 Ulysses 难以做到的。\n*   **异构网络**：在异构网络环境下（如 PCIe 互联），调整 `ulysses_degree` 和 `ring_degree` 的比例（例如 2:4）往往能获得更佳性能。","某大型金融科技公司正在训练一款需要处理百页法律合同与长周期市场报告的生成式 AI 模型，团队试图在有限的 GPU 集群上扩展上下文窗口至 128k。\n\n### 没有 long-context-attention 时\n- **架构兼容性差**：由于模型采用了高效的 GQA（分组查询注意力）架构，传统的 DeepSpeed-Ulysses 因并行度受限于头数而无法启用，导致无法利用序列并行加速。\n- **训练效率低下**：若强行使用 Ring-Attention 替代，其分块计算机制导致 FlashAttention 利用率下降，即使重叠通信与计算，总耗时仍显著高于理论最优值。\n- **大规模部署风险高**：Ring-Attention 依赖的异步点对点通信在跨节点大规模扩展时带宽利用率低，且极易引发通信死锁，导致训练任务频繁中断。\n- **资源扩展受限**：为了规避上述问题，团队不得不减少单卡显存占用或缩小模型规模，牺牲了模型对长文档的理解能力。\n\n### 使用 long-context-attention 后\n- **完美支持先进架构**：long-context-attention 通过混合并行策略，打破了对注意力头数的限制，使 GQA 和 MQA 模型也能顺畅运行序列并行。\n- **性能显著提升**：该工具融合了 Ulysses 的计算高效性与 Ring 的显存优势，在保持 FlashAttention 满血运行的同时，大幅缩短了每步训练时间。\n- **通信稳定可靠**：采用更优化的集体通信模式替代异步点对点传输，不仅提升了带宽利用率，还彻底消除了大规模集群下的死锁隐患。\n- **硬件适配灵活**：无论是支持 FA v3 的 H100 集群，还是仅支持 FA v2 的 A100 甚至部分 NPU 设备，都能通过配置参数获得最佳的注意力计算方案。\n\nlong-context-attention 通过统一序列并行技术，让团队在不改变模型架构的前提下，实现了超长上下文训练的高效、稳定与低成本落地。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ffeifeibear_long-context-attention_9d3cfd47.png","feifeibear","Jiarui Fang（方佳瑞）","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Ffeifeibear_8e536dfd.jpg","Democratizing AGI","ByteDance","Shanghai, China","fangjiarui123@gmail.com",null,"https:\u002F\u002Ffangjiarui.github.io\u002F","https:\u002F\u002Fgithub.com\u002Ffeifeibear",[84,88],{"name":85,"color":86,"percentage":87},"Python","#3572A5",97.8,{"name":89,"color":90,"percentage":91},"Shell","#89e051",2.2,660,79,"2026-04-08T08:59:22","Apache-2.0",4,"Linux","必需。支持 NVIDIA GPU (A100, H100, B100, L40, L20) 和 AMD GPU。H100\u002FB100 需支持 FlashAttention v3；A100\u002FL40 需支持 FlashAttention v2。也支持不支持 FA 的 NPU (使用 Torch 后端，但不支持反向传播)。未明确具体显存大小，但针对长上下文训练通常需大显存。","未说明",{"notes":101,"python":99,"dependencies":102},"1. FlashAttention 是最关键的外部依赖，安装错误常源于此。根据硬件不同需选择 FA v2、v3 或不安装 (NPU 场景)。\n2. 若使用 NPU 且无 FlashAttention 支持，需设置 attn_type=AttnType.TORCH_EFFICIENT，但注意该模式不支持反向传播 (backward pass)。\n3. 在 Megatron-LM 中使用因果掩码 (causal mask) 的负载均衡 Ring Attention 时，必须预先对输入 Token 和 RoPE 参数进行重排序。\n4. 支持混合序列并行 (Unified Sequence Parallelism)，结合了 Ulysses 和 Ring-Attention 的优势，适用于长上下文 LLM 训练和推理。",[103,104,105,106,107],"torch","flash-attn (2.6.x, 2.7.x, 或 v3 beta)","SpargeAttn (可选)","SageAttention (可选)","FlashInfer (可选)",[14,35],[110,111,112,113,114,115],"attention-is-all-you-need","llm-inference","llm-training","pytorch","ring-attention","deepspeed-ulysses","2026-03-27T02:49:30.150509","2026-04-11T08:11:52.411903",[119,124,129,134,139,144],{"id":120,"question_zh":121,"answer_zh":122,"source_url":123},29086,"在分布式训练（如 Ulysses 或 Ring Attention）中，数据是如何分割和合并的？每个 GPU 的输出形状是什么？","在并行训练时，输入数据会被分割，每个 GPU 处理 N\u002FP 长度的数据（其中 N 是总序列长度，P 是 GPU 数量）。对于 Ulysses 或 Ring Attention，每个 GPU 的前向传播输出形状也是 (N\u002FP, d)，而不是汇总后的 (N, d)。虽然前向计算是分布式的，但在反向传播（backward）之前，梯度通常会在优化步骤前通过 reduce 操作在各个进程间同步。框架如 Accelerate 或 DeepSpeed 默认支持这种梯度聚合，无需手动 Gather 输出后再进行 backward，具体的实现逻辑可参考项目中的 Megatron-DeepSpeed patch。","https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fissues\u002F37",{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},29087,"如果没有 A100\u002FH100 显卡无法使用 Flash Attention，如何正确配置以使用 PyTorch 原生实现？","当设置 `attn_type=AttnType.TORCH` 时，库内部会调用 `pytorch_attn_forward`。由于 PyTorch SDPA 支持多种后端（如 MATH, FLASH_ATTENTION, EFFICIENT_ATTENTION, CUDNN_ATTENTION），如果默认参数不符合预期可能会报错。建议根据具体需求细化配置，或者确保在未安装 Flash Attention 的环境下，库能自动回退到 `efficient` 或其他可用模式。如果遇到问题，可以检查 `select_flash_attn_impl` 的逻辑，确认其是否正确选择了非 Flash 的实现路径。","https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fissues\u002F161",{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},29088,"这些长上下文注意力方法（如 Sequence Parallelism）能与 DeepSpeed Zero 一起使用吗？","可以结合使用，但 DeepSpeed 原生可能未直接暴露自定义 Sequence Parallel process group 的接口。通常需要参考 `yunchang\u002Fglobals.py` 文件，在 DeepSpeed 初始化阶段手动定义全局的 sequence parallel process group。如果使用纯 DeepSpeed 而不结合 Megatron 风格的结构，可能需要修改源码以解决 group 初始化冲突问题（例如 `torch.distributed.new_group` 与 Zero 默认 group 的冲突）。推荐参考项目中提供的 DeepSpeed-Megatron 融合方案或相关 patch。","https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fissues\u002F29",{"id":135,"question_zh":136,"answer_zh":137,"source_url":138},29089,"Ulysses 和 Ring Attention 在性能上有什么区别？哪种更高效？","在单机多卡（如 8 卡 NVLink）环境下，Ulysses 通常比 Ring Attention 更高效。基准测试显示，Ring Attention 由于将完整的 Attention 计算切分，导致整体计算时间变长；而 Ulysses 虽然增加了额外的 All-to-All 通信，但其通信时间占比很小，且计算密度更高。特别是在长上下文场景中，计算复杂度为 O(N^2) 而通信为 O(N)，Ulysses 的优势更明显。测试数据显示，在相同迭代次数下，Ring Attention 的耗时可能显著高于 Ulysses（例如 100ms vs 60ms）。","https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fissues\u002F40",{"id":140,"question_zh":141,"answer_zh":142,"source_url":143},29090,"Data Parallel (DP) 和 Sequence Parallel (SP) 在通信和切分策略上有什么本质区别？","DP（数据并行）是在批次（Batch）维度上进行切分，每个 GPU 处理不同的样本，通信主要发生在反向传播时的梯度聚合（All-Reduce）。而 SP（序列并行）是在序列长度维度上进行切分，多个 GPU 共同处理同一个长序列样本。SP 需要在 Attention 计算过程中进行在线的通信和切分（如 All-to-All 或 Ring 通信），因此其通信量通常比 DP 更大，且随着节点数量增加，SP 相对于 DP 的效率可能会降低。选择哪种策略取决于显存限制和序列长度需求。","https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fissues\u002F68",{"id":145,"question_zh":146,"answer_zh":147,"source_url":148},29091,"导入库时遇到 'TypeError: Attempted to reuse key' 错误怎么办？","这是一个已知的代码重复定义问题（例如 `SAGE_FP16_TRITON` 键被定义了两次）。该问题已在版本 `0.6.3.post1` 中修复。如果遇到此错误，请将库升级到最新版本：`pip install --upgrade yunchang` 或指定版本 `pip install yunchang==0.6.3.post1`。","https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fissues\u002F145",[150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235],{"id":151,"version":152,"summary_zh":153,"released_at":154},197912,"0.6.4","## 变更内容\n* 修复 sage_fp16_triton 重复问题，由 @ITerydh 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F146 中完成\n* 版本升级至 0.6.3.post1，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F147 中完成\n* 修复：移除冗余代码以避免在特定环境下出现错误，由 @ZDJeffrey 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F150 中完成\n* 修复：flashattention3 调用问题，由 @yuyu5333 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F151 中完成\n* 【功能】适配 Moore Threads 图形处理器，由 @houchen-li 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F152 中完成\n* 【修复】修正 attention.py 中的算子别名，由 @houchen-li 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F153 中完成\n* 修复反向梯度计数不匹配问题，由 @MartinPernus 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F156 中完成\n* 添加 AttnType.AITER 枚举值，由 @kTorp 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F159 中完成\n* 适配华为 Ascend NPU，由 @endymion-ni 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F162 中完成\n* 基于 torch_npu.npu_fusion_attention_v2 和 npu_fusion_attention_grad_v2，为 LongContextAttention、UlyssesAttention 和 RingAttention 的计算适配 Ascend NPU，支持训练与推理场景，由 @L4-1024 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F167 中完成\n* 优化 AttnType.TORCH 枚举值，由 @genghisun 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F165 中完成\n* 版本升级至 0.6.4，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F168 中完成\n\n## 新贡献者\n* @ITerydh 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F146 中完成了首次贡献\n* @yuyu5333 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F151 中完成了首次贡献\n* @houchen-li 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F152 中完成了首次贡献\n* @MartinPernus 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F156 中完成了首次贡献\n* @kTorp 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F159 中完成了首次贡献\n* @endymion-ni 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F162 中完成了首次贡献\n* @L4-1024 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F167 中完成了首次贡献\n* @genghisun 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F165 中完成了首次贡献\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.6.3...0.6.4","2026-01-13T08:13:49",{"id":156,"version":157,"summary_zh":158,"released_at":159},197913,"0.6.3.post1","## 变更内容\n* 修复 sage_fp16_triton 重复问题，由 @ITerydh 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F146 中完成\n* 版本升级至 0.6.3.post1，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F147 中完成\n\n## 新贡献者\n* @ITerydh 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F146 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.6.3...0.6.3.post1","2025-04-21T01:52:35",{"id":161,"version":162,"summary_zh":163,"released_at":164},197914,"0.6.3","## 变更内容\n* @intervitens 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F141 中添加了使用 Triton Kernel 实现 SageAttention 的选项\n* @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F143 中增加了更多 Sage Attention 的实现\n* @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F144 中将版本升级至 0.6.3\n\n## 新贡献者\n* @intervitens 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F141 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.6.2...0.6.3","2025-04-18T05:39:59",{"id":166,"version":167,"summary_zh":168,"released_at":169},197915,"0.6.2","## 变更内容\n* （开发中）特性：支持 sparse_sage_attn，由 @Eigensystem 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F132 中实现\n* 移除无用的测试和基准测试，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F134 中完成\n* 特性：支持 sparse sage attn，并通过单元测试，由 @Eigensystem 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F136 中实现\n* 重命名 sparse sage 的测试参数，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F138 中完成\n* 特性：支持 flashinfer 用于环形注意力机制，由 @ZDJeffrey 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F139 中实现\n* 将版本号升级至 0.6.2，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F140 中完成\n\n## 新贡献者\n* @ZDJeffrey 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F139 中完成了首次贡献\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.6.1...0.6.2","2025-04-08T09:14:15",{"id":171,"version":172,"summary_zh":173,"released_at":174},197916,"0.6.1","## 变更内容\n* 修复 qkvpacked_attn 的反向传播错误，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F121 中完成\n* 【修复】移除不必要的打印语句，由 @xibosun 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F123 中完成\n* 将 PyTorch 的注意力机制更新为 Flash Attention，由 @FrankLeeeee 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F124 中完成\n* 新特性：支持 Sage Attention，由 @Eigensystem 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F126 中实现\n* 修复 SageAttention 的相关 bug，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F127 中完成\n* 修复 SageAttention 的 lse 返回形状错误，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F128 中完成\n* （Sage Attention）修复布局问题，由 @Eigensystem 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F129 中完成\n* 版本升级至 0.6.1，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F130 中完成\n\n## 新贡献者\n* @FrankLeeeee 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F124 中完成了首次贡献\n\n**完整变更日志**：https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.6.0...0.6.1","2025-03-20T01:32:21",{"id":176,"version":177,"summary_zh":178,"released_at":179},197917,"0.6.0","## 变更内容\n* FlashAttentionImpl -> AttnType，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F117 中完成\n* 版本升级至 0.6.0，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F118 中完成\n* 修复许可证分类器错误，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F119 中完成\n\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.5.1...0.6.0","2024-12-26T07:36:18",{"id":181,"version":182,"summary_zh":183,"released_at":184},197918,"0.5.1","## 变更内容\n* 由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F111 中更新了 README 图片\n* 由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F113 中使用 flash_attn 2.6.3 进行测试，并增加了测试的灵活性\n* 由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F115 中实现了 PyTorch 的环形注意力机制\n* 由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F116 中将版本号提升至 0.5.1\n\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.5.0...0.5.1","2024-12-26T06:30:00",{"id":186,"version":187,"summary_zh":188,"released_at":189},197919,"0.5.0","## 变更内容\n* 支持 fa 2.7.0，并仅支持 torch 的 ulysses，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F108 中完成\n* 更新 README，加入 fav3 并移除 fa 的使用说明，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F109 中完成\n* 版本升级至 0.5.0，由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F110 中完成\n\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.4.3...0.5.0","2024-12-11T10:03:18",{"id":191,"version":192,"summary_zh":193,"released_at":194},197920,"0.4.3","## 变更内容\n* 由 @xibosun 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F107 中添加对 flash_attn 2.7.0 的支持\n\n## 新贡献者\n* @xibosun 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F107 中完成了首次贡献\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.4.2...0.4.3","2024-12-05T07:40:09",{"id":196,"version":197,"summary_zh":198,"released_at":199},197921,"0.4.2","## 变更内容\n* 由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F104 中将 ulysses 加入基准测试\n* 由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F105 中不再直接导入 flash_attn3\n* 由 @feifeibear 在 https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F106 中将版本升级至 0.4.2\n\n\n**完整变更日志**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.4.1...0.4.2","2024-11-19T02:12:52",{"id":201,"version":202,"summary_zh":203,"released_at":204},197922,"0.4.1","## What's Changed\r\n* feat: add use_sync switch to ulysses by @Eigensystem in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F103\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.4.0...0.4.1","2024-11-15T08:34:54",{"id":206,"version":207,"summary_zh":208,"released_at":209},197923,"0.4.0","The 0.4.0 version starts to support FlashAttention V3 on Hopper GPUs. This version also has been tested on low-memory (24GB) GPUs.\r\n\r\n## What's Changed\r\n* update all_to_all by @Lay2000 in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F87\r\n* upgrade version to 0.3.6 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F89\r\n* prevent dispatch issues in SequenceParallel to improve performance by @uclalch in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F92\r\n* sync after all2all for device memory saving by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F93\r\n* version 0.3.7 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F94\r\n* flash attention 3 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F95\r\n* FA3: update to the latest FA3 API. by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F96\r\n* add dit benchmark script by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F97\r\n* 1114v2 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F98\r\n* update readme for FA3 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F99\r\n* version to 0.4.0 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F100\r\n* dump version to 0.4.1 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F101\r\n* dump to 0.4.0 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F102\r\n\r\n## New Contributors\r\n* @Lay2000 made their first contribution in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F87\r\n* @uclalch made their first contribution in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F92\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.3.5...0.4.0","2024-11-15T08:16:22",{"id":211,"version":212,"summary_zh":213,"released_at":214},197924,"0.3.5","## What's Changed\r\n* revert version 0.3.2 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F83\r\n* version 0.3.5 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F84\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002F0.3.3...0.3.5","2024-09-19T15:22:55",{"id":216,"version":217,"summary_zh":218,"released_at":219},197925,"0.3.2","## What's Changed\r\n* remove amd installation to an individual doc by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F76\r\n* auto publish python package when release on github by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F77\r\n* version 0.3.2 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F78\r\n* remove useless workflow by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F79\r\n* version to 0.3.2 by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F80\r\n* polish publish workflow by @feifeibear in https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fpull\u002F81\r\n\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Ffeifeibear\u002Flong-context-attention\u002Fcompare\u002Fv0.3.1...0.3.2","2024-09-19T14:57:22",{"id":221,"version":222,"summary_zh":223,"released_at":224},197926,"v0.3.1","stripe_extract_local, basic_extract_local, zigzag_extract_local works for tensors dimension >=2.","2024-09-14T03:32:35",{"id":226,"version":227,"summary_zh":228,"released_at":229},197927,"v0.3","upgrade flash_attn >= 2.6.0","2024-08-27T08:13:45",{"id":231,"version":232,"summary_zh":233,"released_at":234},197928,"v0.2","1. Ulysses supports T4 and V100.\r\n2. Updates some directory structures.","2024-06-25T03:07:41",{"id":236,"version":237,"summary_zh":238,"released_at":239},197929,"v0.1","Sequence parallel attention adopting a hybrid ulysses and ring attention approach.\r\nSupport GQA\r\nSupport QKV packed.","2024-04-11T08:32:21"]