[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-google-deepmind--penzai":3,"tool-google-deepmind--penzai":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":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":79,"owner_twitter":79,"owner_website":80,"owner_url":81,"languages":82,"stars":91,"forks":92,"last_commit_at":93,"license":94,"difficulty_score":23,"env_os":95,"env_gpu":95,"env_ram":95,"env_deps":96,"category_tags":101,"github_topics":102,"view_count":10,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":107,"updated_at":108,"faqs":109,"releases":138},593,"google-deepmind\u002Fpenzai","penzai","A JAX research toolkit for building, editing, and visualizing neural networks.","penzai 是一个基于 JAX 的开源研究工具包，致力于让神经网络的构建、编辑和可视化变得更加直观。它的名字源自“盆栽”艺术，寓意着像修剪盆景一样精细地塑造模型结构。\n\n不同于传统框架侧重训练流程，penzai 的核心优势在于模型训练后的操作。它解决了研究人员在进行逆向工程、组件消融、内部激活探测以及模型手术时，难以灵活修改和分析网络结构的痛点。因此，penzai 特别适合深度学习研究员、算法工程师以及对模型可解释性感兴趣的开发者使用。\n\n技术层面，penzai 将神经网络表示为易读的函数式树形数据结构，让用户能像操作普通数据一样直接干预模型逻辑。其独特亮点包括：内置的 Treescope 可视化工具，能清晰展示深层嵌套结构；灵活的选择器，支持复杂的重写与补丁；以及命名轴系统，简化了张量操作风格。此外，它还提供了 Gemma、Llama 等主流 Transformer 架构的模块化参考实现，极大便利了架构调试与训练动态分析。","# Penzai\n\n> **盆 (\"pen\", tray) 栽 (\"zai\", planting)** - *an ancient Chinese art of forming\n  trees and landscapes in miniature, also called penjing and an ancestor of the\n  Japanese art of bonsai.*\n\nPenzai is a JAX library for writing models as legible, functional pytree data\nstructures, along with tools for visualizing, modifying, and analyzing them.\nPenzai focuses on **making it easy to do stuff with models after they have been\ntrained**, making it a great choice for research involving reverse-engineering\nor ablating model components, inspecting and probing internal activations,\nperforming model surgery, debugging architectures, and more. (But if you just\nwant to build and train a model, you can do that too!)\n\nWith Penzai, your neural networks could look like this:\n\n![Screenshot of the Gemma model in Penzai](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fgoogle-deepmind_penzai_readme_28abb826bc33.png)\n\nPenzai is structured as a collection of modular tools, designed together but\neach useable independently:\n\n\n* A superpowered interactive Python pretty-printer:\n\n  * [Treescope](https:\u002F\u002Ftreescope.readthedocs.io\u002Fen\u002Fstable\u002F) (`pz.ts`):\n    A drop-in replacement for the ordinary IPython\u002FColab renderer, originally\n    a part of Penzai but now available as a standalone package. It's designed to\n    help understand Penzai models and other deeply-nested JAX pytrees, with\n    built-in support for visualizing arbitrary-dimensional NDArrays.\n\n* A set of JAX tree and array manipulation utilities:\n\n  * `penzai.core.selectors` (`pz.select`): A pytree swiss-army-knife,\n    generalizing JAX's `.at[...].set(...)` syntax to arbitrary type-driven\n    pytree traversals, and making it easy to do complex rewrites or\n    on-the-fly patching of Penzai models and other data structures.\n\n  * `penzai.core.named_axes` (`pz.nx`): A lightweight named axis system which\n    lifts ordinary JAX functions to vectorize over named axes, and allows you to\n    seamlessly switch between named and positional programming styles without\n    having to learn a new array API.\n\n* A declarative combinator-based neural network library, where models are\n  represented as easy-to-modify data structures:\n\n  * `penzai.nn` (`pz.nn`): An alternative to other neural network libraries like\n    Flax, Haiku, Keras, or Equinox, which exposes the full structure of your model's\n    forward pass using declarative combinators. Like Equinox, models are\n    represented as JAX PyTrees, which means you can see everything your model\n    does by pretty printing it, and inject new runtime logic with `jax.tree_util`.\n    However, `penzai.nn` models may also contain mutable variables at the leaves\n    of the tree, allowing them to keep track of mutable state and parameter\n    sharing.\n\n* A modular implementation of common Transformer architectures, to support\n  research into interpretability, model surgery, and training dynamics:\n\n  * `penzai.models.transformer`: A reference Transformer implementation that\n  can load the pre-trained weights for the Gemma, Llama, Mistral, and\n  GPT-NeoX \u002F Pythia architectures. Built using modular components and named\n  axes, to simplify complex model-manipulation workflows.\n\nDocumentation on Penzai can be found at\n[https:\u002F\u002Fpenzai.readthedocs.io](https:\u002F\u002Fpenzai.readthedocs.io).\n\n> [!IMPORTANT]\n> Penzai 0.2 includes a number of breaking changes to the neural network API.\n> These changes are intended to simplify common workflows\n> by introducing first-class support for mutable state and parameter sharing\n> and removing unnecessary boilerplate. You can read about the differences\n> between the old \"V1\" API and the current \"V2\" API in the\n> [\"Changes in the V2 API\"][v2_differences] overview.\n>\n> If you are currently using the V1 API and have not yet converted to the V2\n> system, you can instead keep the old behavior by importing from the\n> `penzai.deprecated.v1` submodule, e.g. ::\n>\n> ```python\n> from penzai.deprecated.v1 import pz\n> from penzai.deprecated.v1.example_models import simple_mlp\n> ```\n\n[v2_differences]: https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fstable\u002Fguides\u002Fv2_differences.html\n\n\n## Getting Started\n\nIf you haven't already installed JAX, you should do that first, since the\ninstallation process depends on your platform. You can find instructions in the\n[JAX documentation](https:\u002F\u002Fjax.readthedocs.io\u002Fen\u002Flatest\u002Finstallation.html).\nAfterward, you can install Penzai using\n\n```python\npip install penzai\n```\n\nand import it using\n\n```python\nimport penzai\nfrom penzai import pz\n```\n\n(`penzai.pz` is an *alias namespace*, which makes it easier to reference\ncommon Penzai objects.)\n\nWhen working in an Colab or IPython notebook, we recommend also configuring\nTreescope (Penzai's companion pretty-printer) as the default pretty printer, and\nenabling some utilities for interactive use:\n\n```python\nimport treescope\ntreescope.basic_interactive_setup(autovisualize_arrays=True)\n```\n\nHere's how you could initialize and visualize a simple neural network:\n\n```python\nfrom penzai.models import simple_mlp\nmlp = simple_mlp.MLP.from_config(\n    name=\"mlp\",\n    init_base_rng=jax.random.key(0),\n    feature_sizes=[8, 32, 32, 8]\n)\n\n# Models and arrays are visualized automatically when you output them from a\n# Colab\u002FIPython notebook cell:\nmlp\n```\n\nHere's how you could capture and extract the activations after the elementwise\nnonlinearities:\n\n```python\n@pz.pytree_dataclass\nclass AppendIntermediate(pz.nn.Layer):\n  saved: pz.StateVariable[list[Any]]\n  def __call__(self, x: Any, **unused_side_inputs) -> Any:\n    self.saved.value = self.saved.value + [x]\n    return x\n\nvar = pz.StateVariable(value=[], label=\"my_intermediates\")\n\n# Make a copy of the model that saves its activations:\nsaving_model = (\n    pz.select(mlp)\n    .at_instances_of(pz.nn.Elementwise)\n    .insert_after(AppendIntermediate(var))\n)\n\noutput = saving_model(pz.nx.ones({\"features\": 8}))\nintermediates = var.value\n```\n\nTo learn more about how to build and manipulate neural networks with Penzai,\nwe recommend starting with the [\"How to Think in Penzai\" tutorial][how_to_think]\nor one of the other tutorials in the [Penzai documentation][].\n\n[how_to_think]: https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fstable\u002Fnotebooks\u002Fhow_to_think_in_penzai.html\n[Penzai documentation]: https:\u002F\u002Fpenzai.readthedocs.io\n\n## Citation\n\nIf you have found Penzai to be useful for your research, please consider\nciting the following writeup (also avaliable on [arXiv](https:\u002F\u002Farxiv.org\u002Fabs\u002F2408.00211)):\n\n```\n@article{johnson2024penzai,\n    author={Daniel D. Johnson},\n    title={{Penzai} + {Treescope}: A Toolkit for Interpreting, Visualizing, and Editing Models As Data},\n    year={2024},\n    journal={ICML 2024 Workshop on Mechanistic Interpretability}\n}\n```\n\n---\n\n*This is not an officially supported Google product.*\n","# Penzai\n\n> **盆 (\"pen\", 托盘) 栽 (\"zai\", 种植)** - *一种将树木和景观微缩化的古老中国艺术，也称为盆景，是日本盆景艺术的祖先。*\n\nPenzai 是一个 JAX 库，用于将模型编写为可读的、函数式的 pytree 数据结构（一种树形数据结构），并提供可视化工具、修改和分析它们的工具。Penzai 专注于**在模型训练后轻松进行操作**，使其成为涉及逆向工程或消融模型组件、检查和探测内部激活、执行模型手术、调试架构等的绝佳选择。（但如果你只是想构建和训练一个模型，也可以这样做！）\n\n有了 Penzai，你的神经网络可能看起来像这样：\n\n![Screenshot of the Gemma model in Penzai](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fgoogle-deepmind_penzai_readme_28abb826bc33.png)\n\nPenzai 被结构化为一系列模块化工具的集合，它们共同设计但可独立使用：\n\n\n* 一个功能强大的交互式 Python 美化打印机：\n\n  * [Treescope](https:\u002F\u002Ftreescope.readthedocs.io\u002Fen\u002Fstable\u002F) (`pz.ts`)：\n    它是普通 IPython\u002FColab 渲染器的即插即用替代品，最初是 Penzai 的一部分，但现在作为独立包可用。它旨在帮助理解 Penzai 模型和其他深层嵌套的 JAX pytrees，内置支持可视化任意维度的 NDArrays（多维数组）。\n\n* 一组 JAX 树和数组操作实用工具：\n\n  * `penzai.core.selectors` (`pz.select`)：一个 pytree 瑞士军刀，将 JAX 的 `.at[...].set(...)` 语法推广到任意类型驱动的 pytree 遍历，使得对 Penzai 模型和其他数据结构进行复杂重写或即时修补变得容易。\n\n  * `penzai.core.named_axes` (`pz.nx`)：一个轻量级的命名轴系统（named axes），它将普通的 JAX 函数提升为按命名轴向量化，并允许你在命名和位置编程风格之间无缝切换，而无需学习新的数组 API。\n\n* 一个基于声明式组合器的神经网络库，其中模型表示为易于修改的数据结构：\n\n  * `penzai.nn` (`pz.nn`)：这是 Flax、Haiku、Keras 或 Equinox 等其他神经网络库的替代方案，它使用声明式组合器暴露模型前向传播的完整结构。与 Equinox 一样，模型表示为 JAX PyTrees，这意味着你可以通过美化打印看到模型所做的所有事情，并使用 `jax.tree_util` 注入新的运行时逻辑。然而，`penzai.nn` 模型也可以在树的叶子节点包含可变变量，使它们能够跟踪可变状态和参数共享。\n\n* 常见 Transformer 架构的模块化实现，以支持可解释性、模型手术和训练动态的研究：\n\n  * `penzai.models.transformer`：参考 Transformer 实现，可以加载 Gemma、Llama、Mistral 和 GPT-NeoX \u002F Pythia 架构的预训练权重。使用模块化组件和命名轴构建，以简化复杂的模型操作工作流。\n\nPenzai 的文档可在 [https:\u002F\u002Fpenzai.readthedocs.io](https:\u002F\u002Fpenzai.readthedocs.io) 找到。\n\n> [!IMPORTANT]\n> Penzai 0.2 包含神经网络的许多破坏性更改。这些更改旨在通过引入对可变状态和参数共享的一等支持并移除不必要的样板代码来简化常见工作流。你可以在 [\"Changes in the V2 API\"][v2_differences] 概述中阅读旧版 \"V1\" API 与当前 \"V2\" API 之间的差异。\n>\n> 如果你目前正在使用 V1 API 且尚未转换为 V2 系统，你可以通过从 `penzai.deprecated.v1` 子模块导入来保留旧行为，例如：::\n>\n> ```python\n> from penzai.deprecated.v1 import pz\n> from penzai.deprecated.v1.example_models import simple_mlp\n> ```\n\n[v2_differences]: https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fstable\u002Fguides\u002Fv2_differences.html\n\n\n## 入门指南\n\n如果你还没有安装 JAX，你应该先安装，因为安装过程取决于你的平台。你可以在 [JAX documentation](https:\u002F\u002Fjax.readthedocs.io\u002Fen\u002Flatest\u002Finstallation.html) 中找到说明。之后，你可以使用以下命令安装 Penzai：\n\n```python\npip install penzai\n```\n\n并使用以下方式导入：\n\n```python\nimport penzai\nfrom penzai import pz\n```\n\n(`penzai.pz` 是一个*别名命名空间*，这使得引用常见的 Penzai 对象更加容易。)\n\n当在 Colab 或 IPython 笔记本中工作时，我们建议还将 Treescope（Penzai 的配套美化打印机）配置为默认的美化打印机，并启用一些交互使用的实用工具：\n\n```python\nimport treescope\ntreescope.basic_interactive_setup(autovisualize_arrays=True)\n```\n\n以下是初始化和可视化简单神经网络的方法：\n\n```python\nfrom penzai.models import simple_mlp\nmlp = simple_mlp.MLP.from_config(\n    name=\"mlp\",\n    init_base_rng=jax.random.key(0),\n    feature_sizes=[8, 32, 32, 8]\n)\n\n# 当你从 Colab\u002FIPython 笔记本单元格输出模型和数组时，它们会自动可视化：\nmlp\n```\n\n以下是捕获和提取逐元素非线性变换之后的激活值的方法：\n\n```python\n@pz.pytree_dataclass\nclass AppendIntermediate(pz.nn.Layer):\n  saved: pz.StateVariable[list[Any]]\n  def __call__(self, x: Any, **unused_side_inputs) -> Any:\n    self.saved.value = self.saved.value + [x]\n    return x\n\nvar = pz.StateVariable(value=[], label=\"my_intermediates\")\n\n# 创建一个保存其激活值的模型副本：\nsaving_model = (\n    pz.select(mlp)\n    .at_instances_of(pz.nn.Elementwise)\n    .insert_after(AppendIntermediate(var))\n)\n\noutput = saving_model(pz.nx.ones({\"features\": 8}))\nintermediates = var.value\n```\n\n要了解如何使用 Penzai 构建和操作神经网络，我们建议从 [\"How to Think in Penzai\" tutorial][how_to_think] 开始，或者查看 [Penzai documentation][] 中的其他教程。\n\n[how_to_think]: https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fstable\u002Fnotebooks\u002Fhow_to_think_in_penzai.html\n[Penzai documentation]: https:\u002F\u002Fpenzai.readthedocs.io\n\n## 引用\n\n如果你发现 Penzai 对你的研究有用，请考虑引用以下文章（也可在 [arXiv](https:\u002F\u002Farxiv.org\u002Fabs\u002F2408.00211) 上获取）：\n\n```\n@article{johnson2024penzai,\n    author={Daniel D. Johnson},\n    title={{Penzai} + {Treescope}: A Toolkit for Interpreting, Visualizing, and Editing Models As Data},\n    year={2024},\n    journal={ICML 2024 Workshop on Mechanistic Interpretability}\n}\n```\n\n---\n\n*这不是官方支持的 Google 产品。*","# Penzai 快速上手指南\n\n**Penzai** 是一个基于 JAX 的库，用于将模型编写为可读性高、功能性的 PyTree 数据结构。它专注于模型训练后的操作（如逆向工程、组件消融、内部激活探测、模型手术等），同时也支持构建和训练模型。\n\n> [!NOTE]\n> **版本提示**: Penzai 0.2 包含神经网络的 V2 API 重大变更。如果您正在使用旧版 V1 API，可通过 `penzai.deprecated.v1` 导入以保持兼容。建议直接采用最新的 V2 系统。\n\n## 1. 环境准备\n\n在使用 Penzai 之前，请确保您的开发环境满足以下要求：\n\n- **Python**: 推荐 Python 3.9 或更高版本。\n- **JAX**: Penzai 依赖 JAX，请先完成 JAX 的安装。\n  - 根据操作系统选择 CPU 或 GPU 版本，具体安装指令请参考 [JAX 官方文档](https:\u002F\u002Fjax.readthedocs.io\u002Fen\u002Flatest\u002Finstallation.html)。\n\n## 2. 安装步骤\n\n通过 pip 安装 Penzai 及其依赖项：\n\n```bash\npip install penzai\n```\n\n安装完成后，在 Python 脚本或 Notebook 中导入核心模块：\n\n```python\nimport penzai\nfrom penzai import pz\n```\n\n> `penzai.pz` 是常用对象的别名命名空间，方便后续调用。\n\n## 3. 基本使用\n\n### 配置交互式可视化\n在 Jupyter Notebook 或 Google Colab 环境中，建议配置 Treescope（Penzai 的配套 pretty-printer）以优化显示效果：\n\n```python\nimport treescope\ntreescope.basic_interactive_setup(autovisualize_arrays=True)\n```\n\n### 初始化并可视化模型\n以下示例展示了如何创建一个简单的多层感知机（MLP）并在 Notebook 单元格中自动可视化其结构：\n\n```python\nfrom penzai.models import simple_mlp\nmlp = simple_mlp.MLP.from_config(\n    name=\"mlp\",\n    init_base_rng=jax.random.key(0),\n    feature_sizes=[8, 32, 32, 8]\n)\n\n# 在 Colab\u002FIPython notebook 单元格中输出模型时会自动可视化\nmlp\n```\n\n### 进阶：提取中间层激活\nPenzai 的核心优势在于对模型结构的灵活修改。以下是利用 `pz.select` 在推理过程中捕获中间激活值的示例：\n\n```python\n@pz.pytree_dataclass\nclass AppendIntermediate(pz.nn.Layer):\n  saved: pz.StateVariable[list[Any]]\n  def __call__(self, x: Any, **unused_side_inputs) -> Any:\n    self.saved.value = self.saved.value + [x]\n    return x\n\nvar = pz.StateVariable(value=[], label=\"my_intermediates\")\n\n# 复制模型并在特定层后插入保存逻辑\nsaving_model = (\n    pz.select(mlp)\n    .at_instances_of(pz.nn.Elementwise)\n    .insert_after(AppendIntermediate(var))\n)\n\noutput = saving_model(pz.nx.ones({\"features\": 8}))\nintermediates = var.value\n```\n\n更多高级用法和教程，请访问 [Penzai 官方文档](https:\u002F\u002Fpenzai.readthedocs.io)。","一位算法研究员正在对预训练的 Gemma 大模型进行可解释性分析，试图通过屏蔽特定注意力头来验证其对长文本逻辑推理的具体影响。\n\n### 没有 penzai 时\n- 面对深层嵌套的 Flax 或 Equinox 模型结构，手动遍历查找特定层参数极其繁琐且易错。\n- 修改权重时需要编写大量样板代码处理 JAX PyTree 的不可变性，无法直接就地更新。\n- 缺乏可视化工具，难以直观观察模型内部激活值的分布变化，调试过程如同在黑盒中摸索。\n- 处理参数共享和可变状态时，常规库往往需要额外的封装逻辑，增加了维护成本。\n\n### 使用 penzai 后\n- 利用 `pz.select` 强大的选择器功能，可直接通过语义路径精准定位并修改任意深度的注意力头。\n- Treescope 交互式渲染让复杂的神经网络树形结构清晰可见，瞬间确认修改范围与层级关系。\n- 内置的 named axes 系统自动管理张量维度，无需手动 reshape 即可无缝切换编程风格。\n- 支持原地 Patch 操作和可变状态追踪，无需重新加载模型即可高效完成多次消融实验。\n\npenzai 将复杂的模型手术转化为直观的树形编辑，大幅提升了可解释性研究与架构调试的效率。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fgoogle-deepmind_penzai_73d482ab.png","google-deepmind","Google DeepMind","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fgoogle-deepmind_06b1dd17.png","",null,"https:\u002F\u002Fwww.deepmind.com\u002F","https:\u002F\u002Fgithub.com\u002Fgoogle-deepmind",[83,87],{"name":84,"color":85,"percentage":86},"Python","#3572A5",72,{"name":88,"color":89,"percentage":90},"Jupyter Notebook","#DA5B0B",28,1873,69,"2026-04-03T06:31:40","Apache-2.0","未说明",{"notes":97,"python":95,"dependencies":98},"1. 必须先安装 JAX，具体安装步骤取决于平台，请参考 JAX 文档；2. 推荐使用 Colab 或 IPython 环境，并配置 Treescope 为默认打印器以增强可视化体验；3. 当前版本为 V2 API，存在破坏性变更，旧版 V1 功能可通过 deprecated.v1 子模块保留；4. 该项目非 Google 官方支持产品。",[99,100],"jax","treescope",[13],[103,104,99,105,106],"fine-tuning","interpretability","neural-networks","visualization","2026-03-27T02:49:30.150509","2026-04-06T08:10:37.581153",[110,115,120,125,129,134],{"id":111,"question_zh":112,"answer_zh":113,"source_url":114},2421,"在 Penzai 中如何处理额外的轴名称以避免命名冲突？","通常情况下，额外的轴名称不会引起问题，因为操作轴通常需要知道其名称。如果遇到冲突风险，可以将轴标记（tag）为一个新鲜的 Python object() 来隐藏它，稍后再取消标记（untag）。例如：x=x.tag(\"foo\", \"bar\")，然后在函数内部使用 x.untag(\"foo\")。","https:\u002F\u002Fgithub.com\u002Fgoogle-deepmind\u002Fpenzai\u002Fissues\u002F7",{"id":116,"question_zh":117,"answer_zh":118,"source_url":119},2422,"如何在 NamedArray 上使用类似 jax.numpy.ndarray.at 的语法进行修改？","目前仅支持位置索引。可以使用 untag 解包轴，执行 .at[] 操作，然后再 tag 重新包装。例如：\n```python\narr = pz.nx.zeros({'batch': 3, 'a': 2})\narr.untag('a').at[0].set(pz.nx.ones({'batch': 3})).tag('a')\n```\n注意：目前尚不支持 dict 样式的索引。","https:\u002F\u002Fgithub.com\u002Fgoogle-deepmind\u002Fpenzai\u002Fissues\u002F36",{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},2423,"在 Pytree 数据类中定义 _repr_html_ 导致无限循环如何解决？","这是因为 render_to_html 会调用类的 _repr_html_。解决方法是移除 wrapper_hooks 列表中的 repr_html_postprocessor.append_repr_html_when_present 钩子以禁用该行为。或者避免直接使用 pz.ts.render_to_html，而是构建针对你类型的特定渲染器并调用 renderer.to_html。","https:\u002F\u002Fgithub.com\u002Fgoogle-deepmind\u002Fpenzai\u002Fissues\u002F26",{"id":126,"question_zh":127,"answer_zh":128,"source_url":124},2424,"如何将 Treescope 注册为默认打印机并配置自定义处理器？","运行以下代码进行配置：\n```python\n# 安装到 IPython\npz.ts.register_as_default()\npz.ts.register_autovisualize_magic()\n# 启用全局覆盖\npz.enable_interactive_context()\n# 配置自定义处理器\nmy_custom_renderer = pz.ts.active_renderer.get().extended_with(\u003Cstuff here>)\npz.ts.active_renderer.set_interactive(my_custom_renderer)\n```",{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},2425,"如何在本地运行 Penzai 的单元测试和类型检查？","使用 uv 工具运行以下命令：\n```bash\n# Lint \u002F formatting:\nuv run pyink penzai tests --check\nuv run pylint penzai\n# Unittests\nuv run python run_tests.py\n# Typechecking\nuv run pytype --jobs auto penzai\n```","https:\u002F\u002Fgithub.com\u002Fgoogle-deepmind\u002Fpenzai\u002Fissues\u002F109",{"id":135,"question_zh":136,"answer_zh":137,"source_url":133},2426,"pick_nth_selected 方法是否支持负数索引来选择最后一个节点？","目前该功能正在讨论中（Feature Request）。维护者建议实现时可能需要单独检查负数（例如加上选中路径的长度），而不是使用取模运算，以防止越界选择。当前版本可能不支持直接传入 -1。",[139,144,149,154,159,164,169,174,179,184,189,194],{"id":140,"version":141,"summary_zh":142,"released_at":143},111636,"v0.2.2","- Added the ability to catch exceptions during rendering of `Selection` objects\r\n- Added additional methods to Penzai variables to facilitate interoperability with other JAX ecosystem libraries\r\n- Removed references to deprecated `named_shape` field of `jax.ShapeDtypeStruct`\r\n- Added citation info for Penzai\u002FTreescope paper (https:\u002F\u002Farxiv.org\u002Fabs\u002F2408.00211)","2024-09-11T19:25:12",{"id":145,"version":146,"summary_zh":147,"released_at":148},111637,"v0.2.1","### New features:\r\n\r\n- Added support for the Gemma 2 pretrained models.\r\n \r\n### Improvements:\r\n\r\n- Adjusted colors for `TransformerBlock` and `Attention` when rendered with Treescope.\r\n- Fixed an outdated link in the README.","2024-08-07T02:16:02",{"id":150,"version":151,"summary_zh":152,"released_at":153},111633,"v0.2.5","### Bug fixes\r\n\r\n- Fixed a broken test when running with Treescope 0.1.9 (#108)","2025-04-08T05:45:15",{"id":155,"version":156,"summary_zh":157,"released_at":158},111634,"v0.2.4","### Bug fixes and improvements\r\n\r\n- Conversion from Llama and Mistral models now correctly converts the RoPE wavelength (#102)\r\n- Conversion of all HuggingFace models now checks all changed attributes for possible incompatibilities (#104)\r\n\r\n### Other changes\r\n\r\n- Updates uv lockfile to use more recent package versions for development and tests.\r\n","2024-12-16T08:42:41",{"id":160,"version":161,"summary_zh":162,"released_at":163},111635,"v0.2.3","### New features and improvements\r\n\r\n- Named array shape mismatch errors inside Linear layers now give a more informative error message based on the parameter name, if possible (#92).\r\n- The custom PyTree key `LayerStackGetAttrKey` used by `penzai.nn.layer_stack.LayerStack` no longer directly subclasses `jax.tree_util.GetAttrKey` (#96), making it robust to future planned changes in JAX.\r\n\r\n### Other changes\r\n\r\n- Project now includes a `uv` lockfile and can be easily installed using the `uv` package manager.\r\n- Checks for formatting (via `pyink`), linting (via `pylint`), and type annotations (via `pytype`) are now run on every PR.\r\n- `pyink` and `pylint` are configured to automatically run when editing the project in VSCode.\r\n- Made minor tweaks to documentation configuration to avoid a build error.\r\n","2024-11-21T23:24:59",{"id":165,"version":166,"summary_zh":167,"released_at":168},111638,"v0.2.0","Penzai 0.2.0 includes a number of substantial changes to the neural network and visualization systems, with the goal of improving usability and removing boilerplate.\r\n\r\n### ⚠️ Breaking changes: ⚠️\r\n\r\n- **`penzai.nn` now uses the V2 API.**\r\n  - The V2 neural network API, initially introduced in release 0.1.3 and previously available at `penzai.experimental.v2`, has been moved to the main Penzai namespace. References to `penzai.nn` or `from penzai import pz` will now refer to the V2 versions.\r\n  - The V2 API supports a number of additional features beyond V1:\r\n    - First-class mutable state and variable sharing\r\n    - Generalized transformer implementation with support for Llama, Mistral, and GPT-NeoX \u002F Pythia\r\n    - Support for layer stacks and gradient checkpointing (to reduce memory usage)\r\n  - The original V1 API and data-effects system have been deprecated and moved to `penzai.deprecated.v1`.\r\n  - See the [\"Changes in the V2 API\"](https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fv0.2.0\u002Fguides\u002Fv2_differences.html) for details and migration help.\r\n- **Treescope has moved to a standalone package.**\r\n  - Penzai's interactive pretty-printer and array visualizer, Treescope, has moved into the separate [treescope package](https:\u002F\u002Fgithub.com\u002Fgoogle-deepmind\u002Ftreescope).\r\n  - Treescope can be installed independently of Penzai, and now supports visualizing PyTorch models and tensors as well as JAX arrays and Penzai models. See the [Treescope 0.1.0 release notes](https:\u002F\u002Fgithub.com\u002Fgoogle-deepmind\u002Ftreescope\u002Freleases\u002Ftag\u002Fv0.1.0) for details.\r\n  - Most top-level functions (e.g. `pz.ts.basic_interactive_setup` and `pz.show`) are still available through Penzai for compatibility, but users are encouraged to switch to using `treescope` directly instead.\r\n  - The extension API for custom node handlers has changed, and existing custom node handlers will need to be updated.\r\n\r\n### Other changes:\r\n\r\n- Penzai no longer requires Equinox to be installed.\r\n- `Selection.at(...)` now takes an explicit keyword argument `multiple` to distinguish single nodes from collections of nodes, instead of magically inferring this based on whether the collection existed in the tree.\r\n- `Selection.at(...)` now correctly handles selecting the singleton nodes `None` and `()`.\r\n- Outdated tutorials for the V1 API have been removed.\r\n","2024-07-26T23:39:46",{"id":170,"version":171,"summary_zh":172,"released_at":173},111639,"v0.1.5","### New features:\r\n\r\n- Added a gradient checkpointing combinator `Checkpointed` in `penzai.experimental.v2.toolshed.gradient_checkpointing`. This can reduce memory usage when taking gradients through a model.\r\n \r\n### Bug fixes and improvements:\r\n\r\n- Fixed an issue where rendering logic would run out of order in some situations (in particular, using a treescope rendering inside an iframe inside another treescope rendering).\r\n\r\n### Documentation changes:\r\n\r\n- Added documentation of gradient checkpointing on the \"how-to\" guide page.","2024-07-16T21:42:17",{"id":175,"version":176,"summary_zh":177,"released_at":178},111640,"v0.1.4","### New features:\r\n\r\n- Added `pz.nx.scan`, a named-axis wrapper around `jax.lax.scan` that handles tagging\u002Funtagging the scanned-over axis automatically.\r\n- Improved support for dict-style indexing and index updates on `pz.nx.NamedArray` and `pz.nx.NamedArrayView`:\r\n  - Dict-style indexing of named arrays now supports integer advanced indexing with positional axes.\r\n  - Dict-style index updates (e.g. `array.at[{ \"foo\": 3 }].set( ... )`) are now supported.\r\n \r\n### Bug fixes and improvements:\r\n\r\n- Output views in JupyterLab (and other non-sandboxed IPython notebook interfaces) should no longer interfere with each other.\r\n  - Creating multiple output views no longer corrupts the rendering.\r\n  - Saved outputs from different Penzai versions no longer interfere due to global browser Javascript state.\r\n- Added CSS scoping and content visibility annotations to Treescope renderings, which should improve performance in modern browsers for documents with many treescope renderings.\r\n\r\n### Documentation changes:\r\n\r\n- Fixed broken links in the README and documentation homepage.\r\n- Updated the image in the README.\r\n- Added some details on how to customize the attention masks in the \"how-to\" guide page.","2024-07-09T22:35:27",{"id":180,"version":181,"summary_zh":182,"released_at":183},111641,"v0.1.3","### New features:\r\n\r\n- **V2 neural network API** (`penzai.experimental.v2`)\r\n  - A redesign of Penzai's neural network system, which introduces first-class mutable state and variable sharing, and removes boilerplate.\r\n  - You can read more about the differences and how to migrate [here](https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fv0.1.3\u002Fguides\u002Fv2_differences.html).\r\n  - We plan to replace the original neural network system with this V2 API in Penzai release 0.2.0.\r\n- **Llama, Mistral, and GPT-NeoX \u002F Pythia support**\r\n  - The pretrained transformer implementation has been generalized, and now supports Llama, Mistral, and GPT-NeoX \u002F Pythia pretrained models.\r\n  - (This implementation is specific to the V2 neural network API.)\r\n- Other features:\r\n  - New `LayerStack` combinator, which uses `jax.lax.scan` to efficiently repeat layers with the same structure\r\n  - Named arrays can now be updated using `.at[...].set(...)` operations. For now, only positional indexing is supported (with broadcasting over named axes).\r\n\r\n### Bug fixes and improvements:\r\n\r\n- Fixed issue where unit test discovery was not picking up tests in subdirectories (#38)\r\n- Fixed issue where adding a NamedArray to a JAX array would not correctly lift the JAX array to a NamedArray (#37)\r\n\r\n### Documentation changes:\r\n\r\n- Added documentation of the V2 API, along with instructions on how to migrate.\r\n- Added a \"How-To Guide\" for common tasks (V2 API only)\r\n","2024-06-28T01:57:09",{"id":185,"version":186,"summary_zh":187,"released_at":188},111642,"v0.1.2","### New features:\r\n- Penzai's pretty printer Treescope can now be more easily extended to work with custom types, by defining the special method `__penzai_repr__`, which will be detected during pretty-printing. Renderings of these custom types can be built using `penzai.treescope.repr_lib`, a stable extension API that can be used to implement `__penzai_repr__` in a forwards-compatible way. (Note that the exact internal representation of Treescope renderings is still unstable and may change in the future; see [the documentation for `penzai.treescope`](https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fv0.1.2\u002Fapi\u002Ftreescope.html#adding-treescope-support-for-new-types) for details.)\r\n- Added `pz.ts.basic_interactive_setup()`, which simplifies setting up the pretty-printer in an IPython notebook.\r\n\r\n### Bug fixes and improvements:\r\n- Improved detection of mutable vs immutable objects during pretty-printing.\r\n- Fixed detection of special methods `_repr_html_` and `__penzai_repr__` to avoid objects that generate arbitrary attributes dynamically.\r\n- Copy-path buttons are no longer shown for the root node.\r\n\r\n### Documentation changes:\r\n- Documentation has been added for how to extend `penzai.treescope` to render custom types in a stable way.\r\n- The right-hand sidebar now shows more detail in tutorial notebooks.","2024-05-28T20:09:08",{"id":190,"version":191,"summary_zh":192,"released_at":193},111643,"v0.1.1","Penzai 0.1.1 fixes a number of bugs and adds a few convenience features.\r\n\r\n### New features:\r\n- `NamedArray` can now be converted automatically to a JAX array without unwrapping it if it has no more named axes (e.g. after calling `untag`).\r\n- Lifting JAX functions to operate over `NamedArray`s can be accomplished with less boilerplate using `penzai.toolshed.auto_nmap`: if you set `njnp = auto_nmap.wrap_module(jnp)`, you can use `njnp.{method}` instead of `pz.nx.nmap(jnp.{method})`.\r\n\r\n### Bug fixes and improvements:\r\n- Bugfix: Array data in array visualization tooltips now correctly accounts for slider offsets.\r\n- Improvements to compatibility of `penzai.treescope` renderings:\r\n  - Copy-path buttons no longer require internet access.\r\n  - Pretty-printed outputs should now appear in the correct location in JupyterLab.\r\n  - Perfomance improvements for non-Chrome browsers.\r\n\r\n### Documentation changes:\r\n- Fixed typos and formatting issues.\r\n- Fixed notebook output display bug in Firefox.\r\n- Source links in ReadTheDocs now link to a specific commit.\r\n- Cross-page links in ReadTheDocs now support hover tooltip previews.\r\n","2024-05-03T22:19:46",{"id":195,"version":196,"summary_zh":197,"released_at":198},111644,"v0.1.0","Initial release of Penzai.\r\n\r\nRead the documentation at https:\u002F\u002Fpenzai.readthedocs.io\u002Fen\u002Fv0.1.0\u002F.","2024-04-18T15:39:06"]