[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-openai--blocksparse":3,"tool-openai--blocksparse":61},[4,18,26,36,44,52],{"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 真正成长为懂上",141543,2,"2026-04-06T11:32:54",[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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107888,"2026-04-06T11:32:50",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":10,"last_commit_at":50,"category_tags":51,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":53,"name":54,"github_repo":55,"description_zh":56,"stars":57,"difficulty_score":10,"last_commit_at":58,"category_tags":59,"status":17},4292,"Deep-Live-Cam","hacksider\u002FDeep-Live-Cam","Deep-Live-Cam 是一款专注于实时换脸与视频生成的开源工具，用户仅需一张静态照片，即可通过“一键操作”实现摄像头画面的即时变脸或制作深度伪造视频。它有效解决了传统换脸技术流程繁琐、对硬件配置要求极高以及难以实时预览的痛点，让高质量的数字内容创作变得触手可及。\n\n这款工具不仅适合开发者和技术研究人员探索算法边界，更因其极简的操作逻辑（仅需三步：选脸、选摄像头、启动），广泛适用于普通用户、内容创作者、设计师及直播主播。无论是为了动画角色定制、服装展示模特替换，还是制作趣味短视频和直播互动，Deep-Live-Cam 都能提供流畅的支持。\n\n其核心技术亮点在于强大的实时处理能力，支持口型遮罩（Mouth Mask）以保留使用者原始的嘴部动作，确保表情自然精准；同时具备“人脸映射”功能，可同时对画面中的多个主体应用不同面孔。此外，项目内置了严格的内容安全过滤机制，自动拦截涉及裸露、暴力等不当素材，并倡导用户在获得授权及明确标注的前提下合规使用，体现了技术发展与伦理责任的平衡。",88924,"2026-04-06T03:28:53",[14,15,13,60],"视频",{"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":77,"owner_email":77,"owner_twitter":77,"owner_website":78,"owner_url":79,"languages":80,"stars":109,"forks":110,"last_commit_at":111,"license":112,"difficulty_score":113,"env_os":114,"env_gpu":115,"env_ram":116,"env_deps":117,"category_tags":123,"github_topics":77,"view_count":32,"oss_zip_url":77,"oss_zip_packed_at":77,"status":17,"created_at":124,"updated_at":125,"faqs":126,"releases":157},4464,"openai\u002Fblocksparse","blocksparse","Efficient GPU kernels for block-sparse matrix multiplication and convolution","blocksparse 是一个专为深度学习设计的高性能开源库，核心功能是提供针对“块稀疏”矩阵乘法和卷积运算的高效 GPU 内核。在训练大型神经网络时，模型参数往往存在大量冗余，传统稠密计算浪费了宝贵的算力资源。blocksparse 通过引入块稀疏结构，允许开发者定义特定的稀疏模式，仅对非零数据块进行计算，从而在显著减少内存占用和计算量的同时，充分利用 GPU 并行加速能力，大幅提升模型训练与推理效率。\n\n该工具主要面向 AI 研究人员和深度学习工程师，特别是那些致力于优化大模型架构、探索稀疏化算法或需要在有限硬件资源下提升性能的用户。其技术亮点在于提供了高度定制的 TensorFlow 算子，支持多种 NVIDIA GPU 架构（如 Maxwell、Pascal 和 Volta），并针对不同硬件特性自动选择最优的底层实现（ASM 或 CUDA C）。此外，它还集成了边缘偏置、稀疏权重归一化等辅助操作，为构建复杂的稀疏神经网络提供了完整的基础设施。虽然目前处于活跃开发阶段，API 可能存在变动，但对于追求极致计算效率的技术团队而言，blocksparse 是一个极具价值的底层加速工具","blocksparse 是一个专为深度学习设计的高性能开源库，核心功能是提供针对“块稀疏”矩阵乘法和卷积运算的高效 GPU 内核。在训练大型神经网络时，模型参数往往存在大量冗余，传统稠密计算浪费了宝贵的算力资源。blocksparse 通过引入块稀疏结构，允许开发者定义特定的稀疏模式，仅对非零数据块进行计算，从而在显著减少内存占用和计算量的同时，充分利用 GPU 并行加速能力，大幅提升模型训练与推理效率。\n\n该工具主要面向 AI 研究人员和深度学习工程师，特别是那些致力于优化大模型架构、探索稀疏化算法或需要在有限硬件资源下提升性能的用户。其技术亮点在于提供了高度定制的 TensorFlow 算子，支持多种 NVIDIA GPU 架构（如 Maxwell、Pascal 和 Volta），并针对不同硬件特性自动选择最优的底层实现（ASM 或 CUDA C）。此外，它还集成了边缘偏置、稀疏权重归一化等辅助操作，为构建复杂的稀疏神经网络提供了完整的基础设施。虽然目前处于活跃开发阶段，API 可能存在变动，但对于追求极致计算效率的技术团队而言，blocksparse 是一个极具价值的底层加速工具。","**Status:** Active (under active development, breaking changes may occur)\n\n# Blocksparse\n\nThe `blocksparse` package contains TensorFlow Ops and corresponding GPU kernels for block-sparse matrix multiplication.  Also included are related ops like edge bias, sparse weight norm and layer norm.\n\nTo learn more, see [the launch post on the OpenAI blog](https:\u002F\u002Fblog.openai.com\u002Fblock-sparse-gpu-kernels\u002F).\n\n## Prerequisites\n\nFirst, you need at least one Nvidia GPU. For best performance, we recommend using a Pascal or Maxwell generation GPU -- this is the full list of features by GPU type:\n\n| GPU Family | BSMatMul-ASM | BSMatMul-CudaC | BSConv |\n|------------|------------------------|----------------|--------|\n| Kepler | - | X | - |\n| Maxwell | X (fastest) | X | X |\n| Pascal | X (fastest) | X | X |\n| Volta | - | X (fastest) | - |\n\nNote that BSMatMul-CudaC **only supports `feature_axis=0`**, while BSMatMul-ASM only supports `feature_axis=1`.\n\nAdditionally, you need:\n\n- A working Linux installation (we run Ubuntu 16.04) with the Nvidia drivers for your GPU.\n- CUDA 8 (in `\u002Fusr\u002Flocal\u002Fcuda`)\n- Python 3.5 or newer, or 2.7 or newer\n- TensorFlow 1.4.0 or newer, [with GPU support](https:\u002F\u002Fwww.tensorflow.org\u002Finstall\u002Finstall_linux#install_tensorflow) (e.g. `pip install tensorflow-gpu`)\n- CUDA 9 and Volta will work if you update the build targets (-gencode=arch=compute_70,code=sm_70) and also build tenorflow from source.\n\n## Installation\n\n```\npip install blocksparse\n```\n\n## Usage\n\nThis example performs a block-sparse matrix multiplication:\n```\nfrom blocksparse.matmul import BlocksparseMatMul\nimport tensorflow as tf\nimport numpy as np\n\nhidden_size = 4096\nblock_size = 32\nminibatch_size = 64\n\n# Create a (random) sparsity pattern\nsparsity = np.random.randint(2, size=(hidden_size\u002F\u002Fblock_size,hidden_size\u002F\u002Fblock_size))\n\n# Initialize the sparse matrix multiplication object\nbsmm = BlocksparseMatMul(sparsity, block_size=block_size)\n\n# Input to graph\nx = tf.placeholder(tf.float32, shape=[None, hidden_size])\n\n# Initialize block-sparse weights\nw = tf.get_variable(\"w\", bsmm.w_shape, dtype=tf.float32)\n\n# Block-sparse matrix multiplication\ny = bsmm(x, w)\n\n# Run\nsess = tf.InteractiveSession()\nsess.run(tf.global_variables_initializer())\nresult = sess.run([y], feed_dict = {x: np.ones((minibatch_size,hidden_size), dtype='float32')})\nprint(result)\n```\n\nFor a more involved example using block-sparse ops to train a language model, see [`examples\u002F`](.\u002Fexamples\u002F).\n\n## Development\n\nIf you're interested in hacking on the ops and kernels, go ahead and build from source:\n\n    git clone git@github.com:openai\u002Fblocksparse.git\n    cd blocksparse\n\n    make compile\n    pip install dist\u002F*.whl\n\n    # test it if you like\n    test\u002Fblocksparse_matmul_test.py\n    test\u002Fblocksparse_conv_test.py\n\nIf your CUDA is not in `\u002Fusr\u002Flocal\u002Fcuda` or you have several versions, e.g. both `\u002Fusr\u002Flocal\u002Fcuda-8.0` and `\u002Fusr\u002Flocal\u002Fcuda-9.0`, set `CUDA_HOME` to the base path to use when compiling `make compile`.\n\n\n## API Documentation:\n\n\n### blocksparse.matmul\n\n    class BlocksparseMatMul(object)\n\n        def __init__(self, layout, block_size=32, feature_axis=1)\n        \"\"\"\n        layout: a 2d array of ones and zeros specifying the block layout\n        block_size: values 32, 16, 8 supported\n        feature_axis: when block_size is less than 32 memory access becomes far more efficient\n                      with a (C,N) activation layout\n        \"\"\"\n\n        # shape helpers for generating tensors (N=minibatch)\n        self.w_shape\n        def i_shape(self, N)\n        def o_shape(self, N)\n\n        # return the coordinates (c,k) in the layout that corresponds to a given block id\n        def block_coord(self, block)\n\n        # experimental ortho init\n        def ortho_init(self)\n\n        # in practice, identity_init + layernorm is all you need for initialization\n        # with gpu=True the init is performed by kernel on the device\n        def identity_init(self, gpu=False)\n\n        # To implement weight normalization.  In practice, layernorm works much better.\n        def l2_normalize(self, W, gain=None, epsilon=1e-6, dtype=np.float32)\n\n        def __call__(self, I, W, dw_dtype=tf.float32)\n        \"\"\"\n        Execute the op.  Note that the weight variable is independant from the bsmm object.\n        This allows multiple weights to be tied to the same bsmm layout.\n\n        dw_dtype: allows control over dw precision format.\n        \"\"\"\n\n\n    def group_param_grads(param_grad, group_size=8, cast32=True)\n    \"\"\"\n    param_grad: the tensorflow parameter gradient for a give bsmm weight variable (returned from tf.gradients)\n    group_size: desired group size, up to 8 supported\n\n    This causes the tf graph to be rewritten so that weight grad matmuls from different time steps\n    (and shared weights across time) are combined into a more efficient single matmul.\n    \"\"\"\n\n\n    class SparseProj(object):\n        def __init__(self, nhidden, nproj=None, proj_stride=None, block_size=32, gather_lut=None)\n        \"\"\"\n        Experimental class to support dense-to-sparse and sparse-to-dense projections.\n        Basically the same as the tensorflow ops but faster and support alternate precision formats.\n        They assume a unique 1 to 1 mapping so atomics need not be used on backward ops.\n        \"\"\"\n\n        def gather(self, x)\n        def scatter(self, x)\n        def scatter_add(self, x, y)\n        def scatter_mul(self, x, y)\n\n\n\n### blocksparse.conv\n\n    class BlocksparseConv(object):\n        def __init__(self, BCK, TRS, DHW, MPQ=None, strides=(1,1,1), dilates=(1,1,1), padding=\"SAME\", edge_bias=False)\n        \"\"\"\n        BCK: (                                             # block(B)\u002Finput(C)\u002Foutput(K) feature dims\n                 ( (c0, c1, c2, ...), (k0, k1, k2, ...) ), # block 0 c,k are indeces into C,K dims\n                 ( (c0, c1, c2, ...), (k0, k1, k2, ...) ), # block 1\n                 ( (c0, c1, c2, ...), (k0, k1, k2, ...) ), # block 2 ...\n             )\n        TRS: (T,R,S) or (R,S) or (S,)         - filter spatial size dims\n        DHW: (D,H,W) or (H,W) or (W,)         - input image spatial size dims\n        MPQ: (M,P,Q) or (P,Q) or (Q,) or None - output image spatial size dims (used for ambiguous dims in strided transpose conv)\n        strides: (1,1,1) or (1,1) or (1,)\n        dilates: (1,1,1) or (1,1) or (1,)\n        padding: (1,1,1) or (1,1) or (1,) or \"SAME\" or \"VALID\"\n        edge_bias: True\u002FFalse\n        \"\"\"\n\n        # shape helpers for setting up variables or test tensors\n        def edge_bias_shape(self)\n        def f_shape(self, block=None)\n        def i_shape(self, N)\n        def o_shape(self, N)\n\n        # execute op passing in param variables and input\n        def __call__(self, F, I, edge_bias=None):\n\n        # for implementing weight norm\n        def l2_normalize(self, F, gain=None, epsilon=1e-6, dtype=np.float32):\n\n    class BlocksparseDeconv(BlocksparseConv)\n        def __init__(self, BCK, TRS, DHW, MPQ=None, strides=(1,1,1), dilates=(1,1,1), padding=\"SAME\", edge_bias=False)\n        \"\"\"\n        Deconvolution.  Same params as above.\n        \"\"\"\n\n    def cwise_linear(x, a=None, b=None)\n    \"\"\"\n    In the NCHW tensor format, tensorflow is extremely slow at implementing simple broadcasting ops on the middle C dim.\n    This lets you do:\n        y = a*x + b\n        y = a*x\n        y = x + b\n\n    Where a and b are of shape (1,C,1,1)\n    This is useful for ops like weight norm.\n\n### blocksparse.ew\n\n    # same as tf ops but generally more efficient and allow custom precision formats\n    def        add(x, y, name=None)\n    def   multiply(x, y, name=None)\n    def   subtract(x, y, name=None)\n    def     divide(x, y, name=None)\n    def    maximum(x, y, name=None)\n    def    minimum(x, y, name=None)\n\n    def   negative(x,    name=None)\n    def reciprocal(x,    name=None)\n    def     square(x,    name=None)\n    def       sqrt(x,    name=None)\n    def        exp(x,    name=None)\n    def        log(x,    name=None)\n    def    sigmoid(x,    name=None)\n    def       tanh(x,    name=None)\n    def       relu(x,    name=None)\n    def       elu (x, alpha=1.0, name=None)\n\n    # here args can be the 4 independant gate tensors or\n    # a single merged gate tensor (which gets split in 4 internally)\n    def fused_lstm_gates(c, *args, name=None)\n\n    def split4(x)\n    def concat4(x0, x1, x2, x3)\n\n    # A custom cast op to help explore novel precision formats\n    def float_cast(x, dtype, dx_dtype=None)\n\n    # a much faster (and non-deterministic) dropout op\n    # also supports novel precision formats\n    def dropout(x, keep_prob=0.8, mask=None)\n\n    # an op to be used in tf.gradients when adding together multiple contributions of a gradient.\n    # note that only 8 inputs are supported as you'd never want a single op to consume all possible inputs\n    # before it starts executing in the graph (and hence reducing the memory footprint)\n    def add_n8(xs, name=None)\n\n\n\n### blocksparse.norms\n\n    def layer_norm(x, g, b, axis=1, epsilon=1e-6, relu=False)\n    \"\"\"\n    Very fast layernorm to support both bsmm feature_axis activation layouts.\n    Also inlcludes optional integrated relu (applied to end)\n    \"\"\"\n\n    # basic batch norm ops for the NCHW layout\n    def batch_norm(x, g, b, epsilon=1e-6)\n    def batch_norm_inference(x, g, b, m, v, epsilon=1e-6)\n\n\n","**状态:** 活跃（处于积极开发中，可能会有破坏性变更）\n\n# Blocksparse\n\n`blocksparse` 包含用于块稀疏矩阵乘法的 TensorFlow 操作及相应的 GPU 内核。此外，还包含与之相关的操作，如边偏置、稀疏权重归一化和层归一化。\n\n欲了解更多信息，请参阅 [OpenAI 博客上的发布文章](https:\u002F\u002Fblog.openai.com\u002Fblock-sparse-gpu-kernels\u002F)。\n\n## 前提条件\n\n首先，您需要至少一块 Nvidia GPU。为获得最佳性能，我们建议使用 Pascal 或 Maxwell 架构的 GPU——以下是按 GPU 类型划分的功能列表：\n\n| GPU 系列 | BSMatMul-ASM | BSMatMul-CudaC | BSConv |\n|------------|------------------------|----------------|--------|\n| Kepler | - | X | - |\n| Maxwell | X（最快） | X | X |\n| Pascal | X（最快） | X | X |\n| Volta | - | X（最快） | - |\n\n请注意，BSMatMul-CudaC **仅支持 `feature_axis=0`**，而 BSMatMul-ASM 仅支持 `feature_axis=1`。\n\n此外，您还需要：\n\n- 一个可用的 Linux 系统（我们使用 Ubuntu 16.04），并安装适用于您的 GPU 的 Nvidia 驱动程序。\n- CUDA 8（位于 `\u002Fusr\u002Flocal\u002Fcuda`）。\n- Python 3.5 或更高版本，或 2.7 或更高版本。\n- TensorFlow 1.4.0 或更高版本，并具备 [GPU 支持](https:\u002F\u002Fwww.tensorflow.org\u002Finstall\u002Finstall_linux#install_tensorflow)（例如：`pip install tensorflow-gpu`）。\n- 如果您使用 CUDA 9 和 Volta 架构的 GPU，需更新构建目标（`-gencode=arch=compute_70,code=sm_70`），并从源码编译 TensorFlow。\n\n## 安装\n\n```\npip install blocksparse\n```\n\n## 使用方法\n\n以下示例执行了一个块稀疏矩阵乘法：\n```\nfrom blocksparse.matmul import BlocksparseMatMul\nimport tensorflow as tf\nimport numpy as np\n\nhidden_size = 4096\nblock_size = 32\nminibatch_size = 64\n\n# 创建一个（随机）稀疏模式\nsparsity = np.random.randint(2, size=(hidden_size\u002F\u002Fblock_size,hidden_size\u002F\u002Fblock_size))\n\n# 初始化稀疏矩阵乘法对象\nbsmm = BlocksparseMatMul(sparsity, block_size=block_size)\n\n# 图中的输入\nx = tf.placeholder(tf.float32, shape=[None, hidden_size])\n\n# 初始化块稀疏权重\nw = tf.get_variable(\"w\", bsmm.w_shape, dtype=tf.float32)\n\n# 执行块稀疏矩阵乘法\ny = bsmm(x, w)\n\n# 运行\nsess = tf.InteractiveSession()\nsess.run(tf.global_variables_initializer())\nresult = sess.run([y], feed_dict = {x: np.ones((minibatch_size,hidden_size), dtype='float32')})\nprint(result)\n```\n\n有关使用块稀疏操作训练语言模型的更复杂示例，请参阅 [`examples\u002F`](.\u002Fexamples\u002F)。\n\n## 开发\n\n如果您有兴趣对这些操作和内核进行修改，可以直接从源码构建：\n\n    git clone git@github.com:openai\u002Fblocksparse.git\n    cd blocksparse\n\n    make compile\n    pip install dist\u002F*.whl\n\n    # 如果需要，可以运行测试\n    test\u002Fblocksparse_matmul_test.py\n    test\u002Fblocksparse_conv_test.py\n\n如果您的 CUDA 不在 `\u002Fusr\u002Flocal\u002Fcuda` 目录下，或者同时安装了多个版本，例如 `\u002Fusr\u002Flocal\u002Fcuda-8.0` 和 `\u002Fusr\u002Flocal\u002Fcuda-9.0`，请将 `CUDA_HOME` 设置为编译时使用的基础路径，以便在执行 `make compile` 时正确引用。\n\n## API 文档：\n\n### blocksparse.matmul\n\n    class BlocksparseMatMul(object)\n\n        def __init__(self, layout, block_size=32, feature_axis=1)\n        \"\"\"\n        layout：一个由 1 和 0 组成的二维数组，用于指定块布局。\n        block_size：支持 32、16 和 8。\n        feature_axis：当 block_size 小于 32 时，采用 (C,N) 激活布局会使内存访问效率显著提高。\n        \"\"\"\n\n        # 用于生成张量的形状辅助函数（N 表示小批量大小）\n        self.w_shape\n        def i_shape(self, N)\n        def o_shape(self, N)\n\n        # 根据给定的块 ID 返回布局中对应的 (c,k) 坐标\n        def block_coord(self, block)\n\n        # 实验性正交初始化\n        def ortho_init(self)\n\n        # 在实践中，只需使用 identity_init 加上层归一化即可完成初始化。\n        # 当 gpu=True 时，初始化操作由设备上的内核直接执行。\n        def identity_init(self, gpu=False)\n\n        # 用于实现权重归一化。但在实际应用中，层归一化效果更好。\n        def l2_normalize(self, W，gain=None，epsilon=1e-6，dtype=np.float32)\n\n        def __call__(self, I，W，dw_dtype=tf.float32)\n        \"\"\"\n        执行该操作。请注意，权重变量与 bsmm 对象是独立的，这允许多个权重绑定到同一个 bsmm 布局。\n\n        dw_dtype：用于控制 dw 的精度格式。\n        \"\"\"\n\n\n    def group_param_grads(param_grad, group_size=8, cast32=True)\n    \"\"\"\n    param_grad：给定 bsmm 权重变量的 TensorFlow 参数梯度（由 tf.gradients 返回）。\n    group_size：期望的分组大小，最多支持 8 组。\n\n    此函数会重写 TensorFlow 图，将来自不同时间步的权重梯度矩阵乘法（以及跨时间共享的权重）合并为一个更高效的单次矩阵乘法。\n    \"\"\"\n\n\n    class SparseProj(object):\n        def __init__(self, nhidden, nproj=None，proj_stride=None，block_size=32，gather_lut=None)\n        \"\"\"\n        实验性类，用于支持稠密到稀疏以及稀疏到稠密的投影操作。其功能与 TensorFlow 操作基本相同，但速度更快，并支持其他精度格式。此类假设存在唯一的 1 对 1 映射，因此在反向传播操作中无需使用原子操作。\n        \"\"\"\n\n        def gather(self, x)\n        def scatter(self, x)\n        def scatter_add(self, x，y)\n        def scatter_mul(self, x，y)\n\n### blocksparse.conv\n\n    class BlocksparseConv(object):\n        def __init__(self, BCK, TRS, DHW, MPQ=None, strides=(1,1,1), dilates=(1,1,1), padding=\"SAME\", edge_bias=False)\n        \"\"\"\n        BCK: (                                             # 块(B)\u002F输入(C)\u002F输出(K)特征维度\n                 ( (c0, c1, c2, ...), (k0, k1, k2, ...) ), # 块 0 的 c,k 是 C,K 维度的索引\n                 ( (c0, c1, c2, ...), (k0, k1, k2, ...) ), # 块 1\n                 ( (c0, c1, c2, ...), (k0, k1, k2, ...) ), # 块 2 ...\n             )\n        TRS: (T,R,S) 或 (R,S) 或 (S,)         - 卷积核的空间尺寸维度\n        DHW: (D,H,W) 或 (H,W) 或 (W,)         - 输入图像的空间尺寸维度\n        MPQ: (M,P,Q) 或 (P,Q) 或 (Q,) 或 None - 输出图像的空间尺寸维度（用于步幅转置卷积中存在歧义的情况）\n        strides: (1,1,1) 或 (1,1) 或 (1,)\n        dilates: (1,1,1) 或 (1,1) 或 (1,)\n        padding: (1,1,1) 或 (1,1) 或 (1,) 或 \"SAME\" 或 \"VALID\"\n        edge_bias: True\u002FFalse\n        \"\"\"\n\n        # 用于设置变量或测试张量的形状辅助函数\n        def edge_bias_shape(self)\n        def f_shape(self, block=None)\n        def i_shape(self, N)\n        def o_shape(self, N)\n\n        # 执行操作，传入参数变量和输入\n        def __call__(vs, F, I, edge_bias=None):\n\n        # 用于实现权重归一化\n        def l2_normalize(self, F, gain=None, epsilon=1e-6, dtype=np.float32):\n\n    class BlocksparseDeconv(BlocksparseConv)\n        def __init__(self, BCK, TRS, DHW, MPQ=None, strides=(1,1,1), dilates=(1,1,1), padding=\"SAME\", edge_bias=False)\n        \"\"\"\n        反卷积。参数与上述相同。\n        \"\"\"\n\n    def cwise_linear(x, a=None, b=None)\n    \"\"\"\n    在 NCHW 张量格式下，TensorFlow 对中间 C 维度上的简单广播操作实现得非常缓慢。\n    这个函数可以用来执行：\n        y = a*x + b\n        y = a*x\n        y = x + b\n\n    其中 a 和 b 的形状为 (1,C,1,1)。\n    这对于权重归一化等操作非常有用。\n\n### blocksparse.ew\n\n    # 与 tf 操作相同，但通常更高效，并支持自定义精度格式\n    def        add(x, y, name=None)\n    def   multiply(x, y, name=None)\n    def   subtract(x, y, name=None)\n    def     divide(x, y, name=None)\n    def    maximum(x, y, name=None)\n    def    minimum(x, y, name=None)\n\n    def   negative(x,    name=None)\n    def reciprocal(x,    name=None)\n    def     square(x,    name=None)\n    def       sqrt(x,    name=None)\n    def        exp(x,    name=None)\n    def        log(x,    name=None)\n    def    sigmoid(x,    name=None)\n    def       tanh(x,    name=None)\n    def       relu(x,    name=None)\n    def       elu (x, alpha=1.0, name=None)\n\n    # 这里参数可以是 4 个独立的门控张量，或者\n    # 一个合并后的门控张量（内部会拆分成 4 个）\n    def fused_lstm_gates(c, *args, name=None)\n\n    def split4(x)\n    def concat4(x0, x1, x2, x3)\n\n    # 一个自定义的类型转换操作，用于探索新的精度格式\n    def float_cast(x, dtype, dx_dtype=None)\n\n    # 一个更快（且非确定性）的 dropout 操作\n    # 同时也支持新的精度格式\n    def dropout(x, keep_prob=0.8, mask=None)\n\n    # 一个在 tf.gradients 中使用，用于将多个梯度贡献相加的操作。\n    # 注意，只支持最多 8 个输入，因为不希望单个操作在图中开始执行之前就消耗掉所有可能的输入，\n    # 从而减少内存占用。\n    def add_n8(xs, name=None)\n\n\n\n### blocksparse.norms\n\n    def layer_norm(x, g, b, axis=1, epsilon=1e-6, relu=False)\n    \"\"\"\n    非常快速的层归一化，支持两种 bsmm 特征轴激活布局。\n    同时还包括可选的集成 ReLU（在最后应用）。\n    \"\"\"\n\n    # NCHW 布局下的基本批归一化操作\n    def batch_norm(x, g, b, epsilon=1e-6)\n    def batch_norm_inference(x, g, b, m, v, epsilon=1e-6)","# Blocksparse 快速上手指南\n\n`blocksparse` 是 OpenAI 开源的 TensorFlow 扩展包，提供了针对块稀疏矩阵乘法（Block-Sparse Matrix Multiplication）优化的 GPU 算子及内核。它旨在显著提升稀疏神经网络在 GPU 上的训练和推理速度。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**：Linux（推荐 Ubuntu 16.04 或更高版本）。\n*   **硬件要求**：至少一张 NVIDIA GPU。\n    *   **推荐架构**：Maxwell 或 Pascal 系列（性能最佳，支持所有特性）。\n    *   **其他支持**：Kepler（部分支持）、Volta（需特殊编译配置）。\n*   **软件依赖**：\n    *   NVIDIA 显卡驱动（已正确安装）。\n    *   CUDA Toolkit 8.0（默认路径 `\u002Fusr\u002Flocal\u002Fcuda`）。\n        *   *注：若使用 Volta 架构及 CUDA 9.0+，需从源码编译 TensorFlow 并修改构建目标。*\n    *   Python 3.5+ 或 2.7+。\n    *   TensorFlow 1.4.0+（必须包含 GPU 支持，即 `tensorflow-gpu`）。\n\n## 安装步骤\n\n### 1. 安装 TensorFlow GPU 版\n如果您尚未安装支持 GPU 的 TensorFlow，请使用以下命令（推荐使用国内镜像源加速）：\n\n```bash\npip install tensorflow-gpu -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n### 2. 安装 Blocksparse\n直接通过 pip 安装官方发布的 wheel 包：\n\n```bash\npip install blocksparse -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n> **注意**：如果您的 CUDA 不在默认路径 `\u002Fusr\u002Flocal\u002Fcuda`，或者需要自定义编译选项，请参考原文档 \"Development\" 部分进行源码编译。\n\n## 基本使用\n\n以下是一个最简单的示例，演示如何创建一个块稀疏矩阵乘法对象并执行计算。\n\n```python\nfrom blocksparse.matmul import BlocksparseMatMul\nimport tensorflow as tf\nimport numpy as np\n\n# 定义超参数\nhidden_size = 4096\nblock_size = 32\nminibatch_size = 64\n\n# 1. 创建随机稀疏模式 (0 和 1 组成的二维数组)\nsparsity = np.random.randint(2, size=(hidden_size\u002F\u002Fblock_size, hidden_size\u002F\u002Fblock_size))\n\n# 2. 初始化块稀疏矩阵乘法对象\nbsmm = BlocksparseMatMul(sparsity, block_size=block_size)\n\n# 3. 定义输入占位符\nx = tf.placeholder(tf.float32, shape=[None, hidden_size])\n\n# 4. 初始化块稀疏权重变量\nw = tf.get_variable(\"w\", bsmm.w_shape, dtype=tf.float32)\n\n# 5. 执行块稀疏矩阵乘法\ny = bsmm(x, w)\n\n# 6. 运行会话\nsess = tf.InteractiveSession()\nsess.run(tf.global_variables_initializer())\n\n# 构造测试数据并运行\nresult = sess.run([y], feed_dict={x: np.ones((minibatch_size, hidden_size), dtype='float32')})\n\nprint(result)\n```\n\n### 核心 API 简述\n*   **`BlocksparseMatMul(layout, block_size, feature_axis)`**: 核心类。`layout` 定义稀疏结构，`block_size` 支持 32\u002F16\u002F8。\n*   **`__call__(I, W)`**: 执行乘法操作，其中 `I` 为输入激活，`W` 为权重。\n*   **辅助功能**: 包内还包含优化的 `layer_norm`、`conv`（卷积）、`ew`（逐元素运算）等算子，可直接替换标准 TensorFlow 算子以提升性能。\n\n更多复杂示例（如语言模型训练）可参考项目源码中的 `examples\u002F` 目录。","某 AI 实验室团队正在基于 TensorFlow 训练一个超大规模的语言模型，旨在提升长文本生成的准确性与响应速度。\n\n### 没有 blocksparse 时\n- **显存浪费严重**：传统稠密矩阵乘法强制存储和计算大量零值参数，导致高端 GPU 显存迅速耗尽，无法加载更大规模的模型。\n- **训练效率低下**：GPU 算力被无效的零值运算占用，每个训练步耗时过长，迭代一次完整数据集需要数天时间。\n- **硬件适配困难**：团队难以针对不同代际的 Nvidia GPU（如 Maxwell 或 Pascal）手动优化底层内核，性能发挥受限。\n- **开发成本高昂**：若要实现稀疏加速，工程师需从头编写复杂的 CUDA 内核代码，极易出错且维护困难。\n\n### 使用 blocksparse 后\n- **显存利用率倍增**：blocksparse 通过块稀疏矩阵乘法仅处理非零数据块，在相同显存下可支撑参数量翻倍的网络结构。\n- **推理与训练提速**：利用专为 GPU 优化的高效内核，消除了冗余计算，模型训练速度显著提升，大幅缩短研发周期。\n- **自动硬件优化**：工具内置针对 Kepler 到 Volta 等不同架构的优化策略（如 ASM 或 CUDA C 实现），自动匹配最佳执行路径。\n- **集成便捷高效**：只需几行代码即可替换标准矩阵乘法操作，无缝融入现有 TensorFlow 工作流，无需深入底层驱动开发。\n\nblocksparse 让研究团队在不增加硬件投入的前提下，突破了大模型训练的显存与算力瓶颈，实现了效率与规模的双重飞跃。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fopenai_blocksparse_e66f77ef.png","openai","OpenAI","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fopenai_1960bbf4.png","",null,"https:\u002F\u002Fopenai.com\u002F","https:\u002F\u002Fgithub.com\u002Fopenai",[81,85,89,93,97,101,105],{"name":82,"color":83,"percentage":84},"Cuda","#3A4E3A",40.9,{"name":86,"color":87,"percentage":88},"Python","#3572A5",23,{"name":90,"color":91,"percentage":92},"C++","#f34b7d",21.2,{"name":94,"color":95,"percentage":96},"CSS","#663399",11.3,{"name":98,"color":99,"percentage":100},"C","#555555",3.3,{"name":102,"color":103,"percentage":104},"Makefile","#427819",0.3,{"name":106,"color":107,"percentage":108},"Shell","#89e051",0,1064,198,"2026-03-05T06:49:33","MIT",4,"Linux","必需 NVIDIA GPU。推荐 Pascal 或 Maxwell 架构（性能最佳），支持 Kepler、Volta（需重新编译）。未明确说明显存大小要求。默认支持 CUDA 8；若使用 CUDA 9 和 Volta 架构，需更新构建目标并从源码编译 TensorFlow。","未说明",{"notes":118,"python":119,"dependencies":120},"该工具处于活跃开发中，可能会发生破坏性变更。BSMatMul-CudaC 仅支持 feature_axis=0，而 BSMatMul-ASM 仅支持 feature_axis=1。如果 CUDA 不在默认路径 (\u002Fusr\u002Flocal\u002Fcuda) 或有多个版本，编译时需设置 CUDA_HOME 环境变量。对于 Volta 架构和 CUDA 9，需要从源码编译 TensorFlow 并修改构建参数。","3.5+ 或 2.7+",[121,122],"tensorflow-gpu>=1.4.0","numpy",[14],"2026-03-27T02:49:30.150509","2026-04-06T22:51:28.524358",[127,132,137,142,147,152],{"id":128,"question_zh":129,"answer_zh":130,"source_url":131},20292,"更新后 BlocksparseMatMul 的输出维度发生了变化，如何正确使用？","这是因为默认的特征轴（feature_axis）从 1 更改为了 0。您可以尝试在初始化时显式设置该参数来修复问题。例如：\n```python\nfrom blocksparse.matmul import BlocksparseMatMul\nimport tensorflow as tf\nimport numpy as np\n\nhidden_size = 4096\nblock_size = 32\nminibatch_size = 64\n\n# 创建稀疏模式\nsparsity = np.ones((hidden_size\u002F\u002Fblock_size, hidden_size\u002F\u002Fblock_size))\n\n# 初始化块稀疏矩阵乘法对象，注意检查是否需要指定 axis 或 feature_axis\nbsmm = BlocksparseMatMul(sparsity, block_size=block_size)\n\nx = tf.placeholder(tf.float32, shape=[None, hidden_size])\nw = tf.ones(bsmm.w_shape, dtype=tf.float32)\ny = bsmm(x, w)\n\nsess = tf.InteractiveSession()\nsess.run(tf.global_variables_initializer())\nresult = sess.run([y], feed_dict={x: np.ones((minibatch_size, hidden_size), dtype='float32')})\nprint(result[0].shape)\n```\n如果维度仍不对，请确认输入 x 的形状是否符合新的轴定义。","https:\u002F\u002Fgithub.com\u002Fopenai\u002Fblocksparse\u002Fissues\u002F25",{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},20293,"运行多 GPU 示例时报错 'has no attribute allreduce_nccl' 怎么办？","官方 pip 包默认未编译 NCCL 和 MPI 库，相关代码在 Makefile 中被注释掉了。解决方法是从源码重新构建：\n1. 克隆仓库并找到 Makefile。\n2. 取消注释涉及 NCCL 和 MPI 编译的行。\n3. 运行 `make` 重新编译生成 `blocksparse_ops.so`。\n如果仍然遇到问题，建议直接使用 Horovod 替代 mpi4py 进行多 GPU 训练，这通常更稳定且易于配置。","https:\u002F\u002Fgithub.com\u002Fopenai\u002Fblocksparse\u002Fissues\u002F24",{"id":138,"question_zh":139,"answer_zh":140,"source_url":141},20294,"运行 LSTM 示例时出现内存溢出（OOM），对硬件有什么要求？","LSTM 示例对显存要求较高。根据社区反馈，使用默认设置和 `--ngpu=1` 参数时，至少需要一张拥有 24GB 显存的显卡（如 Quadro M6000）才能正常运行。如果您使用的是较小显存的显卡，可能需要减小隐藏层单元数（hidden units）或批次大小（batch size）。此外，确保您使用的 TensorFlow 版本没有已知的形状推断 bug（某些 1.5 版本存在此问题），必要时可降级到 TensorFlow 1.4.1 配合 CUDA 8 尝试。","https:\u002F\u002Fgithub.com\u002Fopenai\u002Fblocksparse\u002Fissues\u002F10",{"id":143,"question_zh":144,"answer_zh":145,"source_url":146},20295,"导入库时报错 'undefined symbol: _ZN10tensorflow7strings6StrCat...' 如何解决？","这通常是由于编译时的 C++ ABI 设置与当前安装的 TensorFlow 不匹配导致的。维护者已更新 Makefile 以自动检测正确的 `_GLIBCXX_USE_CXX11_ABI` 值。\n如果您手动编译，请确保：\n1. 拉取最新的代码以获取更新后的 Makefile。\n2. 清理之前的构建文件（`make clean`）。\n3. 重新运行 `make compile` 进行编译。\n这将确保生成的 `.so` 文件与您系统中的 TensorFlow 二进制文件兼容。","https:\u002F\u002Fgithub.com\u002Fopenai\u002Fblocksparse\u002Fissues\u002F7",{"id":148,"question_zh":149,"answer_zh":150,"source_url":151},20296,"在计算能力为 5.0 的旧显卡（如 GTX 960M）上运行报错 'invalid resource handle' 怎么办？","默认编译配置仅针对计算能力 5.2 (sm_52) 及以上的显卡（如 Maxwell 架构的某些型号），而 GTX 960M 的计算能力是 5.0。您需要修改源码以支持 sm_50：\n1. 打开 `generate_kernels.py` 文件，找到第 241 行左右，将 `major, minor = 5, 2` 修改为 `major, minor = 5, 0`。\n2. 打开 `Makefile` 文件，找到第 28 行左右的编译器标志，将 `arch=compute_52,code=sm_52` 修改为 `arch=compute_50,code=sm_50`。\n3. 重新运行 `make` 进行编译。\n完成后即可在 GTX 960M 等 sm_50 架构的显卡上正常运行。","https:\u002F\u002Fgithub.com\u002Fopenai\u002Fblocksparse\u002Fissues\u002F1",{"id":153,"question_zh":154,"answer_zh":155,"source_url":156},20297,"enwik8.py 示例中的位置编码实现是否正确？","根据用户反馈和相关论文描述，enwik8.py 中的位置编码实现可能存在偏差。论文中提到对于文本和音频使用了二维注意力嵌入（two-dimensional attention embeddings），其中 dattn=2。如果发现模型收敛困难或结果不符合预期，建议检查 `enwik8.py` 中关于位置嵌入（positional embedding）的代码部分，确保其索引对应关系与论文描述的二维结构一致。具体修复可能需要参考原始论文公式调整代码中的嵌入维度或索引逻辑。","https:\u002F\u002Fgithub.com\u002Fopenai\u002Fblocksparse\u002Fissues\u002F34",[]]