[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-metaopt--torchopt":3,"tool-metaopt--torchopt":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 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[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":75,"owner_avatar_url":76,"owner_bio":77,"owner_company":78,"owner_location":78,"owner_email":79,"owner_twitter":78,"owner_website":78,"owner_url":80,"languages":81,"stars":106,"forks":107,"last_commit_at":108,"license":109,"difficulty_score":23,"env_os":110,"env_gpu":111,"env_ram":112,"env_deps":113,"category_tags":119,"github_topics":120,"view_count":23,"oss_zip_url":78,"oss_zip_packed_at":78,"status":16,"created_at":134,"updated_at":135,"faqs":136,"releases":165},1994,"metaopt\u002Ftorchopt","torchopt","TorchOpt is an efficient library for differentiable optimization built upon PyTorch.","TorchOpt 是一个基于 PyTorch 的高效可微优化库，专为需要在训练过程中对优化器本身进行微分的场景设计。它解决了传统优化算法无法通过梯度反向传播更新优化策略的问题，例如元学习、超参数优化和可微分超网络等前沿任务。用户可以直接将优化器（如 Adam、SGD）作为可学习模块，让模型自动学习更好的更新方式。\n\nTorchOpt 适合机器学习研究人员和深度学习开发者使用，尤其在研究新型优化方法或构建端到端可微系统时非常有用。它不面向普通用户或非技术背景的设计师，而是为需要精细控制优化过程的进阶用户提供底层支持。\n\n其独特亮点在于支持三种可微分模式：显式微分、隐式微分和零阶微分，覆盖从简单到复杂的优化场景。同时提供函数式和面向对象两种 API 风格，兼容 PyTorch 和 JAX 的编程习惯，让代码更灵活、易读。所有操作均原生支持 CPU\u002FGPU 加速，性能高效，文档和示例完整，便于快速上手。","\u003C!-- markdownlint-disable first-line-h1 -->\n\u003C!-- markdownlint-disable html -->\n\u003C!-- markdownlint-disable no-duplicate-header -->\n\n\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_463964dd4495.png\" width=\"75%\" \u002F>\n\u003C\u002Fdiv>\n\n\u003Cdiv align=\"center\">\n\n  \u003Ca>![Python 3.8+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPython-3.8%2B-brightgreen.svg)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fpypi.org\u002Fproject\u002Ftorchopt\">![PyPI](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Ftorchopt?logo=pypi)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002FHEAD\u002Ftests\">![GitHub Workflow Status](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Factions\u002Fworkflow\u002Fstatus\u002Fmetaopt\u002Ftorchopt\u002Ftests.yml?label=tests&logo=github)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fcodecov.io\u002Fgh\u002Fmetaopt\u002Ftorchopt\">![CodeCov](https:\u002F\u002Fimg.shields.io\u002Fcodecov\u002Fc\u002Fgithub\u002Fmetaopt\u002Ftorchopt\u002Fmain?logo=codecov)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Ftorchopt.readthedocs.io\">![Documentation Status](https:\u002F\u002Fimg.shields.io\u002Freadthedocs\u002Ftorchopt?logo=readthedocs)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fpepy.tech\u002Fproject\u002Ftorchopt\">![Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_6f58acece851.png)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fblob\u002FHEAD\u002FLICENSE\">![License](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fmetaopt\u002Ftorchopt?label=license&logo=data:image\u002Fsvg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSIjZmZmZmZmIj48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi43NSAyLjc1YS43NS43NSAwIDAwLTEuNSAwVjQuNUg5LjI3NmExLjc1IDEuNzUgMCAwMC0uOTg1LjMwM0w2LjU5NiA1Ljk1N0EuMjUuMjUgMCAwMTYuNDU1IDZIMi4zNTNhLjc1Ljc1IDAgMTAwIDEuNUgzLjkzTC41NjMgMTUuMThhLjc2Mi43NjIgMCAwMC4yMS44OGMuMDguMDY0LjE2MS4xMjUuMzA5LjIyMS4xODYuMTIxLjQ1Mi4yNzguNzkyLjQzMy42OC4zMTEgMS42NjIuNjIgMi44NzYuNjJhNi45MTkgNi45MTkgMCAwMDIuODc2LS42MmMuMzQtLjE1NS42MDYtLjMxMi43OTItLjQzMy4xNS0uMDk3LjIzLS4xNTguMzEtLjIyM2EuNzUuNzUgMCAwMC4yMDktLjg3OEw1LjU2OSA3LjVoLjg4NmMuMzUxIDAgLjY5NC0uMTA2Ljk4NC0uMzAzbDEuNjk2LTEuMTU0QS4yNS4yNSAwIDAxOS4yNzUgNmgxLjk3NXYxNC41SDYuNzYzYS43NS43NSAwIDAwMCAxLjVoMTAuNDc0YS43NS43NSAwIDAwMC0xLjVIMTIuNzVWNmgxLjk3NGMuMDUgMCAuMS4wMTUuMTQuMDQzbDEuNjk3IDEuMTU0Yy4yOS4xOTcuNjMzLjMwMy45ODQuMzAzaC44ODZsLTMuMzY4IDcuNjhhLjc1Ljc1IDAgMDAuMjMuODk2Yy4wMTIuMDA5IDAgMCAuMDAyIDBhMy4xNTQgMy4xNTQgMCAwMC4zMS4yMDZjLjE4NS4xMTIuNDUuMjU2Ljc5LjRhNy4zNDMgNy4zNDMgMCAwMDIuODU1LjU2OCA3LjM0MyA3LjM0MyAwIDAwMi44NTYtLjU2OWMuMzM4LS4xNDMuNjA0LS4yODcuNzktLjM5OWEzLjUgMy41IDAgMDAuMzEtLjIwNi43NS43NSAwIDAwLjIzLS44OTZMMjAuMDcgNy41aDEuNTc4YS43NS43NSAwIDAwMC0xLjVoLTQuMTAyYS4yNS4yNSAwIDAxLS4xNC0uMDQzbC0xLjY5Ny0xLjE1NGExLjc1IDEuNzUgMCAwMC0uOTg0LS4zMDNIMTIuNzVWMi43NXpNMi4xOTMgMTUuMTk4YTUuNDE4IDUuNDE4IDAgMDAyLjU1Ny42MzUgNS40MTggNS40MTggMCAwMDIuNTU3LS42MzVMNC43NSA5LjM2OGwtMi41NTcgNS44M3ptMTQuNTEtLjAyNGMuMDgyLjA0LjE3NC4wODMuMjc1LjEyNi41My4yMjMgMS4zMDUuNDUgMi4yNzIuNDVhNS44NDYgNS44NDYgMCAwMDIuNTQ3LS41NzZMMTkuMjUgOS4zNjdsLTIuNTQ3IDUuODA3eiI+PC9wYXRoPjwvc3ZnPgo=)\u003C\u002Fa>\n\u003C\u002Fdiv>\n\n\u003Cp align=\"center\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt#installation\">Installation\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Ftorchopt.readthedocs.io\">Documentation\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002FHEAD\u002Ftutorials\">Tutorials\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002FHEAD\u002Fexamples\">Examples\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2211.06934\">Paper\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt#citing-torchopt\">Citation\u003C\u002Fa>\n\u003C\u002Fp>\n\n**TorchOpt** is an efficient library for differentiable optimization built upon [PyTorch](https:\u002F\u002Fpytorch.org).\nTorchOpt is:\n\n- **Comprehensive**: TorchOpt provides three differentiation modes - explicit differentiation, implicit differentiation, and zero-order differentiation for handling different differentiable optimization situations.\n- **Flexible**: TorchOpt provides both functional and objective-oriented API for users' different preferences. Users can implement differentiable optimization in JAX-like or PyTorch-like style.\n- **Efficient**: TorchOpt provides (1) CPU\u002FGPU acceleration differentiable optimizer (2) RPC-based distributed training framework (3) Fast Tree Operations, to largely increase the training efficiency for bi-level optimization problems.\n\nBeyond differentiable optimization, TorchOpt can also be regarded as a functional optimizer that enables [JAX-like](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fjax) composable functional optimizer for PyTorch.\nWith TorchOpt, users can easily conduct neural network optimization in PyTorch with a functional style optimizer, similar to [Optax](https:\u002F\u002Fgithub.com\u002Fdeepmind\u002Foptax) in JAX.\n\n--------------------------------------------------------------------------------\n\nThe README is organized as follows:\n\n- [TorchOpt as Functional Optimizer](#torchopt-as-functional-optimizer)\n  - [Optax-Like API](#optax-like-api)\n  - [PyTorch-Like API](#pytorch-like-api)\n  - [Differentiable](#differentiable)\n- [TorchOpt for Differentiable Optimization](#torchopt-for-differentiable-optimization)\n  - [Explicit Gradient (EG)](#explicit-gradient-eg)\n  - [Implicit Gradient (IG)](#implicit-gradient-ig)\n  - [Zero-order Differentiation (ZD)](#zero-order-differentiation-zd)\n- [High-Performance and Distributed Training](#high-performance-and-distributed-training)\n  - [CPU\u002FGPU accelerated differentiable optimizer](#cpugpu-accelerated-differentiable-optimizer)\n  - [Distributed Training](#distributed-training)\n  - [OpTree](#optree)\n- [Visualization](#visualization)\n- [Examples](#examples)\n- [Installation](#installation)\n- [Changelog](#changelog)\n- [Citing TorchOpt](#citing-torchopt)\n- [The Team](#the-team)\n- [License](#license)\n\n--------------------------------------------------------------------------------\n\n## TorchOpt as Functional Optimizer\n\nThe design of TorchOpt follows the philosophy of functional programming.\nAligned with [`functorch`](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Ffunctorch), users can conduct functional style programming with models, optimizers and training in PyTorch.\nWe use the Adam optimizer as an example in the following illustration.\nYou can also check out the tutorial notebook [Functional Optimizer](tutorials\u002F1_Functional_Optimizer.ipynb) for more details.\n\n### Optax-Like API\n\nFor those users who prefer fully functional programming, we offer Optax-Like API by passing gradients and optimizer states to the optimizer function.\nHere is an example coupled with `functorch`:\n\n```python\nclass Net(nn.Module): ...\n\nclass Loader(DataLoader): ...\n\nnet = Net()  # init\nloader = Loader()\noptimizer = torchopt.adam()\n\nmodel, params = functorch.make_functional(net)           # use functorch extract network parameters\nopt_state = optimizer.init(params)                       # init optimizer\n\nxs, ys = next(loader)                                    # get data\npred = model(params, xs)                                 # forward\nloss = F.cross_entropy(pred, ys)                         # compute loss\n\ngrads = torch.autograd.grad(loss, params)                # compute gradients\nupdates, opt_state = optimizer.update(grads, opt_state)  # get updates\nparams = torchopt.apply_updates(params, updates)         # update network parameters\n```\n\nWe also provide a wrapper `torchopt.FuncOptimizer` to make maintaining the optimizer state easier:\n\n```python\nnet = Net()  # init\nloader = Loader()\noptimizer = torchopt.FuncOptimizer(torchopt.adam())      # wrap with `torchopt.FuncOptimizer`\n\nmodel, params = functorch.make_functional(net)           # use functorch extract network parameters\n\nfor xs, ys in loader:                                    # get data\n    pred = model(params, xs)                             # forward\n    loss = F.cross_entropy(pred, ys)                     # compute loss\n\n    params = optimizer.step(loss, params)                # update network parameters\n```\n\n### PyTorch-Like API\n\nWe also design a base class `torchopt.Optimizer` that has the same interface as `torch.optim.Optimizer`.\nWe offer origin PyTorch APIs (e.g. `zero_grad()` or `step()`) by wrapping our Optax-Like API for traditional PyTorch users.\n\n```python\nnet = Net()  # init\nloader = Loader()\noptimizer = torchopt.Adam(net.parameters())\n\nxs, ys = next(loader)             # get data\npred = net(xs)                    # forward\nloss = F.cross_entropy(pred, ys)  # compute loss\n\noptimizer.zero_grad()             # zero gradients\nloss.backward()                   # backward\noptimizer.step()                  # step updates\n```\n\n### Differentiable\n\nOn top of the same optimization function as `torch.optim`, an important benefit of the functional optimizer is that one can implement differentiable optimization easily.\nThis is particularly helpful when the algorithm requires differentiation through optimization updates (such as meta-learning practices).\nWe take as the inputs the gradients and optimizer states, and use non-in-place operators to compute and output the updates.\nThe processes can be automatically implemented, with the only need from users being to pass the argument `inplace=False` to the functions.\nCheck out the section [Explicit Gradient (EG)](#explicit-gradient-eg) functional API for example.\n\n--------------------------------------------------------------------------------\n\n## TorchOpt for Differentiable Optimization\n\nWe design a bilevel-optimization updating scheme, which can be easily extended to realize various differentiable optimization processes.\n\n\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_ec1af9f9bf35.png\" width=\"90%\" \u002F>\n\u003C\u002Fdiv>\n\nAs shown above, the scheme contains an outer level that has parameters $\\phi$ that can be learned end-to-end through the inner level parameters solution $\\theta^{\\prime}(\\phi)$ by using the best-response derivatives $\\partial \\theta^{\\prime}(\\phi) \u002F \\partial \\phi$.\nTorchOpt supports three differentiation modes.\nIt can be seen that the key component of this algorithm is to calculate the best-response (BR) Jacobian.\nFrom the BR-based perspective, existing gradient methods can be categorized into three groups: explicit gradient over unrolled optimization, implicit differentiation, and zero-order gradient differentiation.\n\n### Explicit Gradient (EG)\n\nThe idea of the explicit gradient is to treat the gradient step as a differentiable function and try to backpropagate through the unrolled optimization path.\nThis differentiation mode is suitable for algorithms when the inner-level optimization solution is obtained by a few gradient steps, such as [MAML](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03400) and [MGRL](https:\u002F\u002Farxiv.org\u002Fabs\u002F1805.09801).\nTorchOpt offers both functional and object-oriented API for EG to fit different user applications.\n\n#### Functional API  \u003C!-- omit in toc -->\n\nThe functional API is to conduct optimization in a functional programming style.\nNote that we pass the argument `inplace=False` to the functions to make the optimization differentiable.\nRefer to the tutorial notebook [Functional Optimizer](tutorials\u002F1_Functional_Optimizer.ipynb) for more guidance.\n\n```python\n# Define functional optimizer\noptimizer = torchopt.adam()\n# Define meta and inner parameters\nmeta_params = ...\nfmodel, params = make_functional(model)\n# Initial state\nstate = optimizer.init(params)\n\nfor iter in range(iter_times):\n    loss = inner_loss(fmodel, params, meta_params)\n    grads = torch.autograd.grad(loss, params)\n    # Apply non-inplace parameter update\n    updates, state = optimizer.update(grads, state, inplace=False)\n    params = torchopt.apply_updates(params, updates)\n\nloss = outer_loss(fmodel, params, meta_params)\nmeta_grads = torch.autograd.grad(loss, meta_params)\n```\n\n#### OOP API  \u003C!-- omit in toc -->\n\nTorchOpt also provides OOP API compatible with the PyTorch programming style.\nRefer to the example and the tutorial notebook [Meta-Optimizer](tutorials\u002F3_Meta_Optimizer.ipynb), [Stop Gradient](tutorials\u002F4_Stop_Gradient.ipynb) for more guidance.\n\n```python\n# Define meta and inner parameters\nmeta_params = ...\nmodel = ...\n# Define differentiable optimizer\noptimizer = torchopt.MetaAdam(model)  # a model instance as the argument instead of model.parameters()\n\nfor iter in range(iter_times):\n    # Perform inner update\n    loss = inner_loss(model, meta_params)\n    optimizer.step(loss)\n\nloss = outer_loss(model, meta_params)\nloss.backward()\n```\n\n### Implicit Gradient (IG)\n\nBy treating the solution $\\theta^{\\prime}$ as an implicit function of $\\phi$, the idea of IG is to directly get analytical best-response derivatives $\\partial \\theta^{\\prime} (\\phi) \u002F \\partial \\phi$ by [implicit function theorem](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FImplicit_function_theorem).\nThis is suitable for algorithms when the inner-level optimal solution is achieved ${\\left. \\frac{\\partial F (\\theta, \\phi)}{\\partial \\theta} \\right\\rvert}_{\\theta=\\theta^{\\prime}} = 0$ or reaches some stationary conditions $F (\\theta^{\\prime}, \\phi) = 0$, such as [iMAML](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.04630) and [DEQ](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.01377).\nTorchOpt offers both functional and OOP APIs for supporting both [conjugate gradient-based](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.04630) and [Neumann series-based](https:\u002F\u002Farxiv.org\u002Fabs\u002F1911.02590) IG methods.\nRefer to the example [iMAML](https:\u002F\u002Fgithub.com\u002Fwaterhorse1\u002Ftorchopt\u002Ftree\u002Freadme\u002Fexamples\u002FiMAML) and the notebook [Implicit Gradient](tutorials\u002F5_Implicit_Differentiation.ipynb) for more guidance.\n\n#### Functional API  \u003C!-- omit in toc -->\n\nFor the implicit gradient, similar to [JAXopt](https:\u002F\u002Fjaxopt.github.io\u002Fstable\u002Fimplicit_diff.html), users need to define the stationary condition and TorchOpt provides the decorator to wrap the solve function for enabling implicit gradient computation.\n\n```python\n# The stationary condition for the inner-loop\ndef stationary(params, meta_params, data):\n    # Stationary condition construction\n    return stationary condition\n\n# Decorator for wrapping the function\n# Optionally specify the linear solver (conjugate gradient or Neumann series)\n@torchopt.diff.implicit.custom_root(stationary, solve=linear_solver)\ndef solve(params, meta_params, data):\n    # Forward optimization process for params\n    return output\n\n# Define params, meta_params and get data\nparams, meta_prams, data = ..., ..., ...\noptimal_params = solve(params, meta_params, data)\nloss = outer_loss(optimal_params)\n\nmeta_grads = torch.autograd.grad(loss, meta_params)\n```\n\n#### OOP API  \u003C!-- omit in toc -->\n\nTorchOpt also offers an OOP API, which users need to inherit from the class `torchopt.nn.ImplicitMetaGradientModule` to construct the inner-loop network.\nUsers need to define the stationary condition\u002Fobjective function and the inner-loop solve function to enable implicit gradient computation.\n\n```python\n# Inherited from the class ImplicitMetaGradientModule\n# Optionally specify the linear solver (conjugate gradient or Neumann series)\nclass InnerNet(ImplicitMetaGradientModule, linear_solve=linear_solver):\n    def __init__(self, meta_param):\n        super().__init__()\n        self.meta_param = meta_param\n        ...\n\n    def forward(self, batch):\n        # Forward process\n        ...\n\n    def optimality(self, batch, labels):\n        # Stationary condition construction for calculating implicit gradient\n        # NOTE: If this method is not implemented, it will be automatically\n        # derived from the gradient of the `objective` function.\n        ...\n\n    def objective(self, batch, labels):\n        # Define the inner-loop optimization objective\n        ...\n\n    def solve(self, batch, labels):\n        # Conduct the inner-loop optimization\n        ...\n\n# Get meta_params and data\nmeta_params, data = ..., ...\ninner_net = InnerNet(meta_params)\n\n# Solve for inner-loop process related to the meta-parameters\noptimal_inner_net = inner_net.solve(data)\n\n# Get outer loss and solve for meta-gradient\nloss = outer_loss(optimal_inner_net)\nmeta_grads = torch.autograd.grad(loss, meta_params)\n```\n\n### Zero-order Differentiation (ZD)\n\nWhen the inner-loop process is non-differentiable or one wants to eliminate the heavy computation burdens in the previous two modes (brought by Hessian), one can choose Zero-order Differentiation (ZD).\nZD typically gets gradients based on zero-order estimation, such as finite-difference, or [Evolutionary Strategy](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03864).\nInstead of optimizing the objective $F$, ES optimizes a smoothed objective.\nTorchOpt provides both functional and OOP APIs for the ES method.\nRefer to the tutorial notebook [Zero-order Differentiation](tutorials\u002F6_Zero_Order_Differentiation.ipynb) for more guidance.\n\n#### Functional API  \u003C!-- omit in toc -->\n\nFor zero-order differentiation, users need to define the forward pass calculation and the noise sampling procedure. TorchOpt provides the decorator to wrap the forward function for enabling zero-order differentiation.\n\n```python\n# Customize the noise sampling function in ES\ndef distribution(sample_shape):\n    # Generate a batch of noise samples\n    # NOTE: The distribution should be spherical symmetric and with a constant variance of 1.\n    ...\n    return noise_batch\n\n# Distribution can also be an instance of `torch.distributions.Distribution`, e.g., `torch.distributions.Normal(...)`\ndistribution = torch.distributions.Normal(loc=0, scale=1)\n\n# Specify method and hyper-parameter of ES\n@torchopt.diff.zero_order(distribution, method)\ndef forward(params, batch, labels):\n    # Forward process\n    ...\n    return objective  # the returned tensor should be a scalar tensor\n```\n\n#### OOP API  \u003C!-- omit in toc -->\n\nTorchOpt also offers an OOP API, which users need to inherit from the class `torchopt.nn.ZeroOrderGradientModule` to construct the network as an `nn.Module` following a classical PyTorch style.\nUsers need to define the forward process zero-order gradient procedures `forward()` and a noise sampling function `sample()`.\n\n```python\n# Inherited from the class ZeroOrderGradientModule\n# Optionally specify the `method` and\u002For `num_samples` and\u002For `sigma` used for sampling\nclass Net(ZeroOrderGradientModule, method=method, num_samples=num_samples, sigma=sigma):\n    def __init__(self, ...):\n        ...\n\n    def forward(self, batch):\n        # Forward process\n        ...\n        return objective  # the returned tensor should be a scalar tensor\n\n    def sample(self, sample_shape=torch.Size()):\n        # Generate a batch of noise samples\n        # NOTE: The distribution should be spherical symmetric and with a constant variance of 1.\n        ...\n        return noise_batch\n\n# Get model and data\nnet = Net(...)\ndata = ...\n\n# Forward pass\nloss = Net(data)\n# Backward pass using zero-order differentiation\ngrads = torch.autograd.grad(loss, net.parameters())\n```\n\n--------------------------------------------------------------------------------\n\n## High-Performance and Distributed Training\n\n### CPU\u002FGPU accelerated differentiable optimizer\n\nWe take the optimizer as a whole instead of separating it into several basic operators (e.g., `sqrt` and `div`).\nTherefore, by manually writing the forward and backward functions, we can perform the symbolic reduction.\nIn addition, we can store some intermediate data that can be reused during the backpropagation.\nWe write the accelerated functions in C++ OpenMP and CUDA, bind them by [`pybind11`](https:\u002F\u002Fgithub.com\u002Fpybind\u002Fpybind11) to allow they can be called by Python, and then define the forward and backward behavior using `torch.autograd.Function`.\nUsers can use it by simply setting the `use_accelerated_op` flag as `True`.\nRefer to the corresponding sections in the tutorials [Functional Optimizer](tutorials\u002F1_Functional_Optimizer.ipynb)](tutorials\u002F1_Functional_Optimizer.ipynb) and [Meta-Optimizer](tutorials\u002F3_Meta_Optimizer.ipynb)\n\n```python\noptimizer = torchopt.MetaAdam(model, lr, use_accelerated_op=True)\n```\n\n### Distributed Training\n\n`TorchOpt` provides distributed training features based on the PyTorch RPC module for better training speed and multi-node multi-GPU support.\nDifferent from the MPI-like parallelization paradigm, which uses multiple homogeneous workers and requires carefully designed communication hooks, the RPC APIs allow users to build their optimization pipeline more flexibly.\nExperimental results show that we achieve an approximately linear relationship between the speed-up ratio and the number of workers.\nCheck out the [Distributed Training Documentation](https:\u002F\u002Ftorchopt.readthedocs.io\u002Fen\u002Flatest\u002Fdistributed\u002Fdistributed.html) and [distributed MAML example](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002Fmain\u002Fexamples\u002Fdistributed\u002Ffew-shot) for more specific guidance.\n\n### OpTree\n\nWe implement the *PyTree* to enable fast nested structure flattening using C++.\nThe tree operations (e.g., flatten and unflatten) are very important in enabling functional and Just-In-Time (JIT) features of deep learning frameworks.\nBy implementing it in C++, we can use some cache\u002Fmemory-friendly structures (e.g., `absl::InlinedVector`) to improve the performance.\nFor more guidance and comparison results, please refer to our open-source project [`OpTree`](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Foptree).\n\n--------------------------------------------------------------------------------\n\n## Visualization\n\nComplex gradient flow in meta-learning brings in a great challenge for managing the gradient flow and verifying its correctness of it.\nTorchOpt provides a visualization tool that draws variable (e.g., network parameters or meta-parameters) names on the gradient graph for better analysis.\nThe visualization tool is modified from [`torchviz`](https:\u002F\u002Fgithub.com\u002Fszagoruyko\u002Fpytorchviz).\nRefer to the example [visualization code](examples\u002Fvisualize.py) and the tutorial notebook [Visualization](tutorials\u002F2_Visualization.ipynb) for more details.\n\nThe figure below shows the visualization result.\nCompared with [`torchviz`](https:\u002F\u002Fgithub.com\u002Fszagoruyko\u002Fpytorchviz), TorchOpt fuses the operations within the `Adam` together (orange) to reduce the complexity and provide simpler visualization.\n\n\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_ed9258b8fcd4.jpg\" width=\"80%\" \u002F>\n\u003C\u002Fdiv>\n\n--------------------------------------------------------------------------------\n\n## Examples\n\nIn the [`examples`](examples) directory, we offer several examples of functional optimizers and lightweight meta-learning examples with TorchOpt.\n\n- [Model-Agnostic Meta-Learning (MAML) - Supervised Learning](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03400) (ICML 2017)\n- [Learning to Reweight Examples for Robust Deep Learning](https:\u002F\u002Farxiv.org\u002Fabs\u002F1803.09050) (ICML 2018)\n- [Model-Agnostic Meta-Learning (MAML) - Reinforcement Learning](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03400) (ICML 2017)\n- [Meta-Gradient Reinforcement Learning (MGRL)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1805.09801) (NeurIPS 2018)\n- [Learning through opponent learning process (LOLA)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1709.04326) (AAMAS 2018)\n- [Meta-Learning with Implicit Gradients](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.04630) (NeurIPS 2019)\n\nAlso, check [`examples`](examples) for more distributed\u002Fvisualization\u002Ffunctorch-compatible examples.\n\n--------------------------------------------------------------------------------\n\n## Installation\n\nRequirements\n\n- PyTorch\n- (Optional) For visualizing computation graphs\n  - [Graphviz](https:\u002F\u002Fgraphviz.org\u002Fdownload) (for Linux users use `apt\u002Fyum install graphviz` or `conda install -c anaconda python-graphviz`)\n\n**Please follow the instructions at \u003Chttps:\u002F\u002Fpytorch.org> to install PyTorch in your Python environment first.**\nThen run the following command to install TorchOpt from PyPI ([![PyPI](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Ftorchopt?label=pypi&logo=pypi)](https:\u002F\u002Fpypi.org\u002Fproject\u002Ftorchopt) \u002F ![Status](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fstatus\u002Ftorchopt?label=status)):\n\n```bash\npip3 install torchopt\n```\n\nIf the minimum version of PyTorch is not satisfied, `pip` will install\u002Fupgrade it for you. Please be careful about the `torch` build for CPU \u002F CUDA support (e.g. `cpu`, `cu118`, `cu121`).\nYou may need to specify the extra index URL for the `torch` package:\n\n```bash\npip3 install torchopt --extra-index-url https:\u002F\u002Fdownload.pytorch.org\u002Fwhl\u002Fcu121\n```\n\nSee \u003Chttps:\u002F\u002Fpytorch.org> for more information about installing PyTorch.\n\nYou can also build shared libraries from source, use:\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt.git\ncd torchopt\npip3 install .\n```\n\nWe provide a [conda](https:\u002F\u002Fgithub.com\u002Fconda\u002Fconda) environment recipe to install the build toolchain such as `cmake`, `g++`, and `nvcc`.\nYou can use the following commands with [`conda`](https:\u002F\u002Fgithub.com\u002Fconda\u002Fconda) \u002F [`mamba`](https:\u002F\u002Fgithub.com\u002Fmamba-org\u002Fmamba) to create a new isolated environment.\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt.git\ncd torchopt\n\n# You may need `CONDA_OVERRIDE_CUDA` if conda fails to detect the NVIDIA driver (e.g. in docker or WSL2)\nCONDA_OVERRIDE_CUDA=12.1 conda env create --file conda-recipe-minimal.yaml\n\nconda activate torchopt\nmake install-editable  # or run `pip3 install --no-build-isolation --editable .`\n```\n\n--------------------------------------------------------------------------------\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md).\n\n--------------------------------------------------------------------------------\n\n## Citing TorchOpt\n\nIf you find TorchOpt useful, please cite it in your publications.\n\n```bibtex\n@article{JMLR:TorchOpt,\n  author  = {Jie Ren* and Xidong Feng* and Bo Liu* and Xuehai Pan* and Yao Fu and Luo Mai and Yaodong Yang},\n  title   = {TorchOpt: An Efficient Library for Differentiable Optimization},\n  journal = {Journal of Machine Learning Research},\n  year    = {2023},\n  volume  = {24},\n  number  = {367},\n  pages   = {1--14},\n  url     = {http:\u002F\u002Fjmlr.org\u002Fpapers\u002Fv24\u002F23-0191.html}\n}\n```\n\n## The Team\n\nTorchOpt is a work by [Jie Ren](https:\u002F\u002Fgithub.com\u002FJieRen98), [Xidong Feng](https:\u002F\u002Fgithub.com\u002Fwaterhorse1), [Bo Liu](https:\u002F\u002Fbenjamin-eecs.github.io\u002F), [Xuehai Pan](https:\u002F\u002Fgithub.com\u002FXuehaiPan), [Luo Mai](https:\u002F\u002Fluomai.github.io), and [Yaodong Yang](https:\u002F\u002Fwww.yangyaodong.com).\n\n## License\n\nTorchOpt is released under the Apache License, Version 2.0.\n","\u003C!-- markdownlint-disable first-line-h1 -->\n\u003C!-- markdownlint-disable html -->\n\u003C!-- markdownlint-disable no-duplicate-header -->\n\n\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_463964dd4495.png\" width=\"75%\" \u002F>\n\u003C\u002Fdiv>\n\n\u003Cdiv align=\"center\">\n\n  \u003Ca>![Python 3.8+](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPython-3.8%2B-brightgreen.svg)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fpypi.org\u002Fproject\u002Ftorchopt\">![PyPI](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Ftorchopt?logo=pypi)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002FHEAD\u002Ftests\">![GitHub Workflow Status](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Factions\u002Fworkflow\u002Fstatus\u002Fmetaopt\u002Ftorchopt\u002Ftests.yml?label=tests&logo=github)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fcodecov.io\u002Fgh\u002Fmetaopt\u002Ftorchopt\">![CodeCov](https:\u002F\u002Fimg.shields.io\u002Fcodecov\u002Fc\u002Fgithub\u002Fmetaopt\u002Ftorchopt\u002Fmain?logo=codecov)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Ftorchopt.readthedocs.io\">![Documentation Status](https:\u002F\u002Fimg.shields.io\u002Freadthedocs\u002Ftorchopt?logo=readthedocs)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fpepy.tech\u002Fproject\u002Ftorchopt\">![Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_6f58acece851.png)\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fblob\u002FHEAD\u002FLICENSE\">![License](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Flicense\u002Fmetaopt\u002Ftorchopt?label=license&logo=data:image\u002Fsvg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSIjZmZmZmZmIj48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xMi43NSAyLjc1YS43NS43NSAwIDAwLTEuNSAwVjQuNUg5LjI3NmExLjc1IDEuNzUgMCAwMC4yMS44OGMuMDguMDY0LjE2MS4xMjUuMzA5LjIyMS4xODYuMTIxLjQ1Mi4yNzguNzkyLjQzMy42OC4zMTEgMS42NjIuNjIgMi44NzYuNjJhNi45MTkgNi45MTkgMCAwMDIuODc2LS42MmMuMzQtLjE1NS42MDYtLjMxMi43OTItLjQzMy4xNS0uMDk3LjIzLS4xNTguMzEtLjIyM2EuNzUuNzUgMCAwMC4yMDktLjg3OEw1LjU2OSA3LjVoLjg4NmMuMzUxIDAgLjY5NC0uMTA2Ljk4NC0uMzAzbDEuNjk2LTEuMTU0QS4yNS4yNSAwIDAxOS4yNzUgNmgxLjk3NXYxNC41SDYuNzYzYS43NS43NSAwIDAwMC0xLjVoMTAuNDc0YS43NS43NSAwIDAwMC0xLjVoLTQuMTAyYS4yNS4yNSAwIDAxLS4xNC0uMDQzbC0xLjY5Ny0xLjE1NGExLjc1IDEuNzUgMCAwMC0uOTg0LS4zMDNIMTIuNzVWMi43NXpNMi4xOTMgMTUuMTk4YTUuNDE4IDUuNDE4IDAgMDAyLjU1Ny42MzUgNS40MTggNS40MTggMCAwMDIuNTU3LS42MzVMNC43NSA5LjM2OGwtMi41NTcgNS44M3ptMTQuNTEtLjAyNGMuMDgyLjA0LjE3NC4wODMuMjc1LjEyNi41My4yMjMgMS4zMDUuNDUgMi4yNzIuNDVhNS44NDYgNS44NDYgMCAwMDIuNTQ3LS41NzZMMTkuMjUgOS4zNjdsLTIuNTQ3IDUuODA3eiI+PC9wYXRoPjwvc3ZnPgo=)\u003C\u002Fa>\n\u003C\u002Fdiv>\n\n\u003Cp align=\"center\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt#installation\">安装\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Ftorchopt.readthedocs.io\">文档\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002FHEAD\u002Ftutorials\">教程\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002FHEAD\u002Fexamples\">示例\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2211.06934\">论文\u003C\u002Fa> |\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt#citing-torchopt\">引用\u003C\u002Fa>\n\u003C\u002Fp>\n\n**TorchOpt** 是一个基于 [PyTorch](https:\u002F\u002Fpytorch.org) 构建的高效可微优化库。\nTorchOpt 具有以下特点：\n\n- **全面性**：TorchOpt 提供了三种不同的微分模式——显式微分、隐式微分和零阶微分，以应对各种可微优化场景。\n- **灵活性**：TorchOpt 同时提供了函数式和面向目标的 API，满足用户的不同偏好。用户可以采用类似 JAX 或 PyTorch 的风格实现可微优化。\n- **高效性**：TorchOpt 提供了（1）CPU\u002FGPU 加速的可微优化器；（2）基于 RPC 的分布式训练框架；（3）快速树运算，从而大幅提高双层优化问题的训练效率。\n\n除了可微优化之外，TorchOpt 还可以被视为一种函数式优化器，支持类似 [JAX](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fjax) 的可组合函数式优化器用于 PyTorch。\n借助 TorchOpt，用户可以轻松地以函数式风格在 PyTorch 中进行神经网络优化，类似于 JAX 中的 [Optax](https:\u002F\u002Fgithub.com\u002Fdeepmind\u002Foptax)。\n\n--------------------------------------------------------------------------------\n\n本 README 的组织结构如下：\n\n- [TorchOpt 作为函数式优化器](#torchopt-as-functional-optimizer)\n  - [类似 Optax 的 API](#optax-like-api)\n  - [类似 PyTorch 的 API](#pytorch-like-api)\n  - [可微性](#differentiable)\n- [TorchOpt 用于可微优化](#torchopt-for-differentiable-optimization)\n  - [显式梯度 (EG)](#explicit-gradient-eg)\n  - [隐式梯度 (IG)](#implicit-gradient-ig)\n  - [零阶微分 (ZD)](#zero-order-differentiation-zd)\n- [高性能与分布式训练](#high-performance-and-distributed-training)\n  - [CPU\u002FGPU 加速的可微优化器](#cpugpu-accelerated-differentiable-optimizer)\n  - [分布式训练](#distributed-training)\n  - [OpTree](#optree)\n- [可视化](#visualization)\n- [示例](#examples)\n- [安装](#installation)\n- [更新日志](#changelog)\n- [引用 TorchOpt](#citing-torchopt)\n- [团队](#the-team)\n- [许可](#license)\n\n--------------------------------------------------------------------------------\n\n## TorchOpt 作为函数式优化器\n\nTorchOpt 的设计遵循函数式编程的理念。\n与 [`functorch`](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Ffunctorch) 保持一致，用户可以在 PyTorch 中使用模型、优化器和训练进行函数式编程。\n我们以 Adam 优化器为例进行说明。\n您还可以查看教程笔记本 [函数式优化器](tutorials\u002F1_Functional_Optimizer.ipynb) 以获取更多细节。\n\n### 类似Optax的API\n\n对于偏好全功能编程的用户，我们提供类似Optax的API，只需将梯度和优化器状态传递给优化器函数即可。\n以下是与`functorch`结合使用的示例：\n\n```python\nclass Net(nn.Module): ...\n\nclass Loader(DataLoader): ...\n\nnet = Net()  # 初始化\nloader = Loader()\noptimizer = torchopt.adam()\n\nmodel, params = functorch.make_functional(net)           # 使用functorch提取网络参数\nopt_state = optimizer.init(params)                       # 初始化优化器\n\nxs, ys = next(loader)                                    # 获取数据\npred = model(params, xs)                                 # 前向传播\nloss = F.cross_entropy(pred, ys)                         # 计算损失\n\ngrads = torch.autograd.grad(loss, params)                # 计算梯度\nupdates, opt_state = optimizer.update(grads, opt_state)  # 获取更新\nparams = torchopt.apply_updates(params, updates)         # 更新网络参数\n```\n\n我们还提供了一个包装器`torchopt.FuncOptimizer`，以简化优化器状态的维护：\n\n```python\nnet = Net()  # 初始化\nloader = Loader()\noptimizer = torchopt.FuncOptimizer(torchopt.adam())      # 使用torchopt.FuncOptimizer包装\n\nmodel, params = functorch.make_functional(net)           # 使用functorch提取网络参数\n\nfor xs, ys in loader:                                    # 获取数据\n    pred = model(params, xs)                             # 前向传播\n    loss = F.cross_entropy(pred, ys)                     # 计算损失\n\n    params = optimizer.step(loss, params)                # 更新网络参数\n```\n\n### 类似PyTorch的API\n\n我们还设计了一个基类`torchopt.Optimizer`，其接口与`torch.optim.Optimizer`完全相同。\n我们通过包装我们的类似Optax的API，为传统PyTorch用户提供原生PyTorch API（例如`zero_grad()`或`step()`）。\n\n```python\nnet = Net()  # 初始化\nloader = Loader()\noptimizer = torchopt.Adam(net.parameters())\n\nxs, ys = next(loader)             # 获取数据\npred = net(xs)                    # 前向传播\nloss = F.cross_entropy(pred, ys)  # 计算损失\n\noptimizer.zero_grad()             # 清零梯度\nloss.backward()                   # 反向传播\noptimizer.step()                  # 执行更新\n```\n\n### 可微分性\n\n除了与`torch.optim`相同的优化函数外，函数式优化器的一个重要优势是能够轻松实现可微分优化。\n这一点在算法需要通过优化更新进行微分时尤其有用（例如元学习实践）。\n我们以梯度和优化器状态作为输入，并使用非就地操作符来计算并输出更新。\n这些过程可以自动实现，用户只需在函数中传入参数`inplace=False`即可。\n请查看[显式梯度（EG）](#explicit-gradient-eg)函数式API部分以获取示例。\n\n--------------------------------------------------------------------------------\n\n## TorchOpt用于可微分优化\n\n我们设计了一种双层优化更新方案，该方案可轻松扩展以实现各种可微分优化过程。\n\n\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_ec1af9f9bf35.png\" width=\"90%\" \u002F>\n\u003C\u002Fdiv>\n\n如上图所示，该方案包含一个外层，其参数$\\phi$可通过内层参数解$\\theta^{\\prime}(\\phi)$端到端地学习，利用最优响应导数$\\partial \\theta^{\\prime}(\\phi) \u002F \\partial \\phi$。\nTorchOpt支持三种微分模式。\n可以看出，该算法的关键组件是计算最优响应（BR）雅可比矩阵。\n从基于最优响应的角度来看，现有的梯度方法可分为三类：对展开优化路径的显式梯度、隐式微分以及零阶梯度微分。\n\n### 显式梯度（EG）\n\n显式梯度的思想是将梯度步视为一个可微分函数，并尝试通过展开的优化路径进行反向传播。\n这种微分模式适用于内层优化解由少量梯度步得到的算法，例如[MAML](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03400)和[MGRL](https:\u002F\u002Farxiv.org\u002Fabs\u002F1805.09801)。\nTorchOpt同时提供了函数式和面向对象的API，以适应不同的用户应用。\n\n#### 函数式API  \u003C!-- omit in toc -->\n\n函数式API以函数式编程风格进行优化。\n请注意，我们向函数传递了参数`inplace=False`，以使优化过程可微分。\n更多指导请参阅教程笔记本[函数式优化器](tutorials\u002F1_Functional_Optimizer.ipynb)。\n\n```python\n# 定义函数式优化器\noptimizer = torchopt.adam()\n# 定义元参数和内层参数\nmeta_params = ...\nfmodel, params = make_functional(model)\n# 初始状态\nstate = optimizer.init(params)\n\nfor iter in range(iter_times):\n    loss = inner_loss(fmodel, params, meta_params)\n    grads = torch.autograd.grad(loss, params)\n    # 应用非就地参数更新\n    updates, state = optimizer.update(grads, state, inplace=False)\n    params = torchopt.apply_updates(params, updates)\n\nloss = outer_loss(fmodel, params, meta_params)\nmeta_grads = torch.autograd.grad(loss, meta_params)\n```\n\n#### 面向对象API  \u003C!-- omit in toc -->\n\nTorchOpt还提供了兼容PyTorch编程风格的面向对象API。\n更多指导请参阅示例和教程笔记本[元优化器](tutorials\u002F3_Meta_Optimizer.ipynb)、[停止梯度](tutorials\u002F4_Stop_Gradient.ipynb)。\n\n```python\n# 定义元参数和内层参数\nmeta_params = ...\nmodel = ...\n# 定义可微分优化器\noptimizer = torchopt.MetaAdam(model)  # 将模型实例作为参数，而非model.parameters()\n\nfor iter in range(iter_times):\n    # 执行内层更新\n    loss = inner_loss(model, meta_params)\n    optimizer.step(loss)\n\nloss = outer_loss(model, meta_params)\nloss.backward()\n```\n\n### 隐式梯度（IG）\n\n通过将解 $\\theta^{\\prime}$ 视为 $\\phi$ 的隐函数，隐式梯度的思想是直接利用[隐函数定理](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FImplicit_function_theorem)求得解析的最优响应导数 $\\partial \\theta^{\\prime} (\\phi) \u002F \\partial \\phi$。\n\n这种方法适用于内层优化解达到以下条件的情况：$\\left. \\frac{\\partial F (\\theta, \\phi)}{\\partial \\theta} \\right\\rvert_{\\theta=\\theta^{\\prime}} = 0$ 或者满足某些驻点条件 $F (\\theta^{\\prime}, \\phi) = 0$，例如 [iMAML](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.04630) 和 [DEQ](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.01377)。\n\nTorchOpt 提供了函数式和面向对象两种 API，以支持基于[共轭梯度法](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.04630)和[Neumann 级数法](https:\u002F\u002Farxiv.org\u002Fabs\u002F1911.02590)的隐式梯度方法。\n\n更多指导请参阅示例 [iMAML](https:\u002F\u002Fgithub.com\u002Fwaterhorse1\u002Ftorchopt\u002Ftree\u002Freadme\u002Fexamples\u002FiMAML) 和笔记本 [隐式梯度](tutorials\u002F5_Implicit_Differentiation.ipynb)。\n\n#### 函数式 API  \u003C!-- omit in toc -->\n\n对于隐式梯度，与 [JAXopt](https:\u002F\u002Fjaxopt.github.io\u002Fstable\u002Fimplicit_diff.html) 类似，用户需要定义驻点条件，TorchOpt 提供了一个装饰器来包装求解函数，从而启用隐式梯度计算。\n\n```python\n# 内层循环的驻点条件\ndef stationary(params, meta_params, data):\n    # 驻点条件构建\n    return 驻点条件\n\n# 包装函数的装饰器\n# 可选指定线性求解器（共轭梯度或 Neumann 级数）\n@torchopt.diff.implicit.custom_root(stationary, solve=linear_solver)\ndef solve(params, meta_params, data):\n    # 参数的前向优化过程\n    return 输出\n\n# 定义参数、元参数并获取数据\nparams, meta_prams, data = ..., ..., ...\noptimal_params = solve(params, meta_params, data)\nloss = outer_loss(optimal_params)\n\nmeta_grads = torch.autograd.grad(loss, meta_params)\n```\n\n#### 面向对象 API  \u003C!-- omit in toc -->\n\nTorchOpt 还提供了面向对象的 API，用户需要继承自类 `torchopt.nn.ImplicitMetaGradientModule` 来构造内层网络。\n\n用户需要定义驻点条件\u002F目标函数以及内层循环的求解函数，以启用隐式梯度计算。\n\n```python\n# 继承自类 ImplicitMetaGradientModule\n# 可选指定线性求解器（共轭梯度或 Neumann 级数）\nclass InnerNet(ImplicitMetaGradientModule, linear_solve=linear_solver):\n    def __init__(self, meta_param):\n        super().__init__()\n        self.meta_param = meta_param\n        ...\n\n    def forward(self, batch):\n        # 前向过程\n        ...\n\n    def optimality(self, batch, labels):\n        # 构建驻点条件以计算隐式梯度\n        # 注意：如果未实现此方法，则会自动从 `objective` 函数的梯度推导出来。\n        ...\n\n    def objective(self, batch, labels):\n        # 定义内层循环的优化目标\n        ...\n\n    def solve(self, batch, labels):\n        # 执行内层循环的优化\n        ...\n\n# 获取元参数和数据\nmeta_params, data = ..., ...\ninner_net = InnerNet(meta_params)\n\n# 求解与元参数相关的内层循环过程\noptimal_inner_net = inner_net.solve(data)\n\n# 获取外层损失并求解元梯度\nloss = outer_loss(optimal_inner_net)\nmeta_grads = torch.autograd.grad(loss, meta_params)\n```\n\n### 零阶微分（ZD）\n\n当内层循环过程不可微或者希望消除前两种模式中由 Hessian 带来的繁重计算负担时，可以选择零阶微分（ZD）。\n\n零阶微分通常基于零阶估计获取梯度，例如有限差分或 [进化策略](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03864)。\n\n与优化目标 $F$ 不同，进化策略优化的是一个平滑后的目标。\n\nTorchOpt 提供了函数式和面向对象两种 API，用于进化策略方法。\n\n更多指导请参阅教程笔记本 [零阶微分](tutorials\u002F6_Zero_Order_Differentiation.ipynb)。\n\n#### 函数式 API  \u003C!-- omit in toc -->\n\n对于零阶微分，用户需要定义前向计算过程和噪声采样程序。TorchOpt 提供了一个装饰器来包装前向函数，从而启用零阶微分。\n\n```python\n# 自定义进化策略中的噪声采样函数\ndef distribution(sample_shape):\n    # 生成一批噪声样本\n    # 注意：分布应为球对称且方差恒为 1。\n    ...\n    return 噪声批次\n\n# 分布也可以是 `torch.distributions.Distribution` 的实例，例如 `torch.distributions.Normal(...)`\ndistribution = torch.distributions.Normal(loc=0, scale=1)\n\n# 指定进化策略的方法和超参数\n@torchopt.diff.zero_order(distribution, method)\ndef forward(params, batch, labels):\n    # 前向过程\n    ...\n    return 目标值  # 返回的张量应为标量张量\n```\n\n#### 面向对象 API  \u003C!-- omit in toc -->\n\nTorchOpt 还提供了面向对象的 API，用户需要继承自类 `torchopt.nn.ZeroOrderGradientModule`，以按照经典的 PyTorch 风格将网络构造为 `nn.Module`。\n\n用户需要定义零阶梯度的前向过程 `forward()` 和噪声采样函数 `sample()`。\n\n```python\n# 继承自类 ZeroOrderGradientModule\n# 可选指定使用的 `method` 和\u002F或 `num_samples` 和\u002F或 `sigma` 用于采样\nclass Net(ZeroOrderGradientModule, method=method, num_samples=num_samples, sigma=sigma):\n    def __init__(self, ...):\n        ...\n\n    def forward(self, batch):\n        # 前向过程\n        ...\n        return 目标值  # 返回的张量应为标量张量\n\n    def sample(self, sample_shape=torch.Size()):\n        # 生成一批噪声样本\n        # 注意：分布应为球对称且方差恒为 1。\n        ...\n        return 噪声批次\n\n# 获取模型和数据\nnet = Net(...)\ndata = ...\n\n# 前向传播\nloss = Net(data)\n# 使用零阶微分进行反向传播\ngrads = torch.autograd.grad(loss, net.parameters())\n```\n\n--------------------------------------------------------------------------------\n\n## 高性能与分布式训练\n\n### CPU\u002FGPU加速的可微优化器\n\n我们把优化器作为一个整体来处理，而不是将其拆分为若干基本算子（例如 `sqrt` 和 `div`）。\n因此，通过手动编写前向和反向函数，我们可以进行符号化简化。\n此外，我们还可以存储一些中间数据，这些数据在反向传播过程中可以被重复使用。\n我们用 C++ OpenMP 和 CUDA 编写了加速函数，并通过 [`pybind11`](https:\u002F\u002Fgithub.com\u002Fpybind\u002Fpybind11) 将它们绑定，以便能够从 Python 中调用，然后使用 `torch.autograd.Function` 定义前向和反向行为。\n用户只需将 `use_accelerated_op` 标志设为 `True` 即可使用该优化器。\n请参考教程中的相应章节 [功能优化器](tutorials\u002F1_Functional_Optimizer.ipynb) 和 [元优化器](tutorials\u002F3_Meta_Optimizer.ipynb)。\n\n```python\noptimizer = torchopt.MetaAdam(model, lr, use_accelerated_op=True)\n```\n\n### 分布式训练\n\n`TorchOpt` 提供了基于 PyTorch RPC 模块的分布式训练功能，以实现更快的训练速度并支持多节点多 GPU。\n与类似 MPI 的并行化范式不同，后者使用多个同质工作进程并需要精心设计的通信钩子，RPC API 允许用户更灵活地构建自己的优化流水线。\n实验结果表明，我们实现了加速比与工作进程数量之间的近似线性关系。\n请查看 [分布式训练文档](https:\u002F\u002Ftorchopt.readthedocs.io\u002Fen\u002Flatest\u002Fdistributed\u002Fdistributed.html) 和 [分布式 MAML 示例](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Ftree\u002Fmain\u002Fexamples\u002Fdistributed\u002Ffew-shot)，获取更具体的指导。\n\n### OpTree\n\n我们实现了 *PyTree*，以利用 C++ 实现快速的嵌套结构扁平化。\n树操作（例如扁平化和反扁平化）对于实现深度学习框架的功能性和即时编译（JIT）特性至关重要。\n通过在 C++ 中实现，我们可以使用一些缓存和内存友好的数据结构（例如 `absl::InlinedVector`），从而提升性能。\n如需更多指导和对比结果，请参阅我们的开源项目 [`OpTree`](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Foptree)。\n\n--------------------------------------------------------------------------------\n\n## 可视化\n\n元学习中复杂的梯度流给梯度流的管理和正确性验证带来了巨大挑战。\nTorchOpt 提供了一个可视化工具，可在梯度图上标注变量（例如网络参数或元参数）名称，以便更好地分析。\n该可视化工具基于 [`torchviz`](https:\u002F\u002Fgithub.com\u002Fszagoruyko\u002Fpytorchviz) 修改而来。\n请参阅示例 [可视化代码](examples\u002Fvisualize.py) 和教程笔记本 [可视化](tutorials\u002F2_Visualization.ipynb)，了解更多信息。\n\n下图展示了可视化结果。\n与 [`torchviz`](https:\u002F\u002Fgithub.com\u002Fszagoruyko\u002Fpytorchviz) 相比，TorchOpt 将 `Adam` 内的操作融合在一起（橙色），以降低复杂度并提供更简单的可视化效果。\n\n\u003Cdiv align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_readme_ed9258b8fcd4.jpg\" width=\"80%\" \u002F>\n\u003C\u002Fdiv>\n\n--------------------------------------------------------------------------------\n\n## 示例\n\n在 [`examples`](examples) 目录中，我们提供了几个使用 TorchOpt 的功能优化器示例和轻量级元学习示例。\n\n- [模型无关元学习 (MAML) - 监督学习](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03400) (ICML 2017)\n- [学习重新加权样本以实现鲁棒深度学习](https:\u002F\u002Farxiv.org\u002Fabs\u002F1803.09050) (ICML 2018)\n- [模型无关元学习 (MAML) - 强化学习](https:\u002F\u002Farxiv.org\u002Fabs\u002F1703.03400) (ICML 2017)\n- [元梯度强化学习 (MGRL)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1805.09801) (NeurIPS 2018)\n- [通过对手学习过程学习 (LOLA)](https:\u002F\u002Farxiv.org\u002Fabs\u002F1709.04326) (AAMAS 2018)\n- [带有隐式梯度的元学习](https:\u002F\u002Farxiv.org\u002Fabs\u002F1909.04630) (NeurIPS 2019)\n\n此外，也请查看 [`examples`](examples) 中更多分布式\u002F可视化\u002F与 functorch 兼容的示例。\n\n--------------------------------------------------------------------------------\n\n## 安装\n\n要求\n\n- PyTorch\n- （可选）用于可视化计算图\n  - [Graphviz](https:\u002F\u002Fgraphviz.org\u002Fdownload)（对于 Linux 用户，使用 `apt\u002Fyum install graphviz` 或 `conda install -c anaconda python-graphviz`）\n\n**请先按照 \u003Chttps:\u002F\u002Fpytorch.org> 上的说明，在您的 Python 环境中安装 PyTorch。**\n然后运行以下命令，从 PyPI 安装 TorchOpt（[![PyPI](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Ftorchopt?label=pypi&logo=pypi)](https:\u002F\u002Fpypi.org\u002Fproject\u002Ftorchopt) \u002F ![状态](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fstatus\u002Ftorchopt?label=status))：\n\n```bash\npip3 install torchopt\n```\n\n如果 PyTorch 的最低版本不满足要求，`pip` 会为您安装或升级。请注意 `torch` 的构建版本，以支持 CPU 或 CUDA（例如 `cpu`、`cu118`、`cu121`）。\n您可能需要指定额外的索引 URL 来安装 `torch` 包：\n\n```bash\npip3 install torchopt --extra-index-url https:\u002F\u002Fdownload.pytorch.org\u002Fwhl\u002Fcu121\n```\n\n有关安装 PyTorch 的更多信息，请参阅 \u003Chttps:\u002F\u002Fpytorch.org>。\n\n您也可以从源码构建共享库，使用：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt.git\ncd torchopt\npip3 install .\n```\n\n我们提供了一个 [conda](https:\u002F\u002Fgithub.com\u002Fconda\u002Fconda) 环境配方，用于安装构建工具链，例如 `cmake`、`g++` 和 `nvcc`。\n您可以使用以下命令，借助 [`conda`](https:\u002F\u002Fgithub.com\u002Fconda\u002Fconda) \u002F [`mamba`](https:\u002F\u002Fgithub.com\u002Fmamba-org\u002Fmamba) 创建一个新的隔离环境。\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt.git\ncd torchopt\n\n# 如果 conda 无法检测到 NVIDIA 驱动程序（例如在 docker 或 WSL2 中），您可能需要设置 `CONDA_OVERRIDE_CUDA`\nCONDA_OVERRIDE_CUDA=12.1 conda env create --file conda-recipe-minimal.yaml\n\nconda activate torchopt\nmake install-editable  # 或运行 `pip3 install --no-build-isolation --editable .`\n```\n\n--------------------------------------------------------------------------------\n\n## 更改日志\n\n请参阅 [CHANGELOG.md](CHANGELOG.md)。\n\n--------------------------------------------------------------------------------\n\n## 引用 TorchOpt\n\n如果您觉得 TorchOpt 有用，请在您的论文中引用它。\n\n```bibtex\n@article{JMLR:TorchOpt,\n  author  = {Jie Ren* and Xidong Feng* and Bo Liu* and Xuehai Pan* and Yao Fu and Luo Mai and Yaodong Yang},\n  title   = {TorchOpt: 一个高效的可微优化库},\n  journal = {机器学习研究杂志},\n  year    = {2023},\n  volume  = {24},\n  number  = {367},\n  pages   = {1--14},\n  url     = {http:\u002F\u002Fjmlr.org\u002Fpapers\u002Fv24\u002F23-0191.html}\n}\n```\n\n## 团队\n\nTorchOpt 由 [Jie Ren](https:\u002F\u002Fgithub.com\u002FJieRen98)、[Xidong Feng](https:\u002F\u002Fgithub.com\u002Fwaterhorse1)、[Bo Liu](https:\u002F\u002Fbenjamin-eecs.github.io\u002F)、[Xuehai Pan](https:\u002F\u002Fgithub.com\u002FXuehaiPan)、[Luo Mai](https:\u002F\u002Fluomai.github.io) 和 [Yaodong Yang](https:\u002F\u002Fwww.yangyaodong.com) 共同完成。\n\n## 许可协议\n\nTorchOpt 采用 Apache 许可协议第 2.0 版发布。","# TorchOpt 快速上手指南\n\n## 环境准备\n\n- **Python 版本**：3.8+\n- **前置依赖**：PyTorch（推荐 2.0+）\n- 推荐使用 `conda` 或 `pip` 管理环境，支持 CPU\u002FGPU 加速\n\n> 建议使用国内镜像源加速安装：  \n> `pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple torchopt`\n\n## 安装步骤\n\n```bash\npip install torchopt\n```\n\n如需使用最新开发版，可从 GitHub 安装：\n\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt.git\n```\n\n## 基本使用\n\n### 方式一：Functional 风格（推荐用于可微优化）\n\n```python\nimport torch\nimport torch.nn as nn\nimport torchopt\nfrom functorch import make_functional\n\nclass Net(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.lin = nn.Linear(2, 1)\n\nnet = Net()\noptimizer = torchopt.adam()  # 创建优化器\n\nmodel, params = make_functional(net)  # 转为函数式模型\nopt_state = optimizer.init(params)    # 初始化状态\n\n# 模拟训练步骤\nxs = torch.randn(4, 2)\nys = torch.randn(4, 1)\npred = model(params, xs)\nloss = torch.nn.functional.mse_loss(pred, ys)\n\ngrads = torch.autograd.grad(loss, params)\nupdates, opt_state = optimizer.update(grads, opt_state, inplace=False)  # 非原地更新，支持自动微分\nparams = torchopt.apply_updates(params, updates)\n```\n\n### 方式二：PyTorch 风格（传统接口）\n\n```python\nimport torch\nimport torch.nn as nn\nimport torchopt\n\nnet = nn.Linear(2, 1)\noptimizer = torchopt.Adam(net.parameters())  # 与 torch.optim.Adam 接口一致\n\nxs = torch.randn(4, 2)\nys = torch.randn(4, 1)\n\npred = net(xs)\nloss = torch.nn.functional.mse_loss(pred, ys)\n\noptimizer.zero_grad()\nloss.backward()\noptimizer.step()\n```\n\n> ✅ 推荐初学者从 **PyTorch 风格** 开始，进阶用户使用 **Functional 风格** 实现元学习、可微优化等高级场景。","在深度强化学习研究中，一名博士生正在训练一个元强化学习（Meta-RL）模型，目标是让智能体在5个不同动力学环境（如不同摩擦系数的机器人）中快速适应，需对内循环优化过程进行端到端微分。\n\n### 没有 torchopt 时\n- 手动实现内循环优化器（如Adam）的梯度传播极其繁琐，需手动展开每一步更新，代码冗长且易出错。\n- PyTorch默认不支持对优化器状态（如动量、二阶矩）进行可微分追踪，导致元梯度计算不准确，模型收敛缓慢。\n- 每次修改优化器超参数（如学习率、β值）都需重写整个反向传播逻辑，实验迭代周期长达数天。\n- 无法在GPU上高效并行处理多个环境的内循环优化，训练效率低下，单次实验耗时超过24小时。\n- 缺乏统一接口，不同优化策略（如MAML、Reptile）需重复造轮子，代码复用率低于30%。\n\n### 使用 torchopt 后\n- 仅用几行代码即可通过 `torchopt.adam` 直接对优化器步骤进行可微分封装，自动追踪所有内部状态，无需手动展开。\n- 支持隐式与显式微分模式，能精确计算元梯度，模型在5个环境上的平均适应速度提升47%，收敛稳定性显著增强。\n- 超参数可作为可学习参数直接参与外循环优化，调整学习率或动量系数只需修改一行张量定义，实验迭代周期缩短至6小时。\n- 内置CPU\u002FGPU加速的优化器原语，支持批量环境并行优化，单次训练时间从24小时降至4小时以内。\n- 提供函数式与面向对象双接口，MAML与Reptile等算法可复用同一套基础模块，代码量减少60%，团队协作效率大幅提升。\n\ntorchopt 让元学习中的可微分优化从“手工雕刻”变为“一键调用”，彻底释放了研究人员在复杂优化结构上的创造力。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmetaopt_torchopt_463964dd.png","metaopt","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fmetaopt_d6fc36e3.png","",null,"benjaminliu.eecs@gmail.com","https:\u002F\u002Fgithub.com\u002Fmetaopt",[82,86,90,94,98,102],{"name":83,"color":84,"percentage":85},"Python","#3572A5",88,{"name":87,"color":88,"percentage":89},"C++","#f34b7d",4.7,{"name":91,"color":92,"percentage":93},"Cuda","#3A4E3A",4.1,{"name":95,"color":96,"percentage":97},"CMake","#DA3434",1.7,{"name":99,"color":100,"percentage":101},"Makefile","#427819",1.1,{"name":103,"color":104,"percentage":105},"Dockerfile","#384d54",0.4,628,42,"2026-04-01T05:15:38","Apache-2.0","Linux, macOS, Windows","推荐使用 NVIDIA GPU，显存 8GB+，CUDA 11.7+（用于加速计算，非绝对必需）","8GB+",{"notes":114,"python":115,"dependencies":116},"建议使用 PyTorch 生态环境（如 conda），依赖 functorch 实现函数式编程风格；支持 CPU 和 GPU 运行，分布式训练需配置 RPC 环境；不同iable 优化场景需注意 inplace=False 参数设置以保证梯度可微。","3.8+",[117,118],"torch>=1.12","functorch",[13],[121,122,123,124,125,126,127,128,129,130,131,132,133],"functional-programming","optimizer","pytorch","meta-reinforcement-learning","deep-learning","meta-learning","meta-rl","bilevel-optimization","differentiable-optimization","implicit-differentiation","optimization","differentiable-programming","automatic-differentiation","2026-03-27T02:49:30.150509","2026-04-06T05:17:33.947196",[137,142,147,152,157,161],{"id":138,"question_zh":139,"answer_zh":140,"source_url":141},9008,"如何安装 torchopt 的开发版本？","建议创建新的 conda 环境并使用提供的配置文件安装：使用命令 `CONDA_OVERRIDE_CUDA=11.7 conda env create --file conda-recipe.yaml` 创建环境，激活后运行 `conda activate torchopt` 和 `make install-editable`。若仅需 CPU 版本，可使用 `docs\u002Fconda-recipe.yaml` 加快安装速度。确保 PyTorch 版本不低于 1.13.0，因 torchopt 依赖 functorch。","https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fissues\u002F114",{"id":143,"question_zh":144,"answer_zh":145,"source_url":146},9009,"如何解决在使用 torchopt.stop_gradient 时出现的 'Trying to backward through the graph a second time' 错误？","该错误通常因计算图被重复反向传播导致。解决方案是确保在每次 meta-update 前重新构建计算图，或在调用 .backward() 时设置 retain_graph=True。同时，检查是否对同一张量多次调用 .backward()，建议在 inner_opt 和 meta_opt 更新之间使用 torchopt.stop_gradient 明确截断梯度，并避免在循环中复用已释放的中间变量。","https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fissues\u002F221",{"id":148,"question_zh":149,"answer_zh":150,"source_url":151},9010,"torchopt 的 OOP API 和函数式 API 有什么区别？","OOP API 使用类封装，如 `torchopt.nn.ImplicitMetaGradientModule`，适合面向对象编程风格；函数式 API 使用纯函数，如 `torchopt.diff.implicit.custom_root`，更适合函数式编程和灵活的梯度控制。两者功能等价，选择取决于代码架构偏好。","https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fissues\u002F163",{"id":153,"question_zh":154,"answer_zh":155,"source_url":156},9011,"optree 仓库为何无法访问？","optree 原为私有仓库，现已开源。可访问公开仓库 https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Foptree 获取源码并从源码编译安装，解决了此前因私有仓库导致的编译和依赖问题。","https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fissues\u002F94",{"id":158,"question_zh":159,"answer_zh":160,"source_url":141},9012,"安装 torchopt 开发版时遇到 gcc 编译错误怎么办？","尝试更换 gcc 版本（如从 10 降为 9.3.0），并移除 conda-recipe.yaml 中的 gxx 依赖。若使用 conda 环境，确保通过 `CONDA_OVERRIDE_CUDA=11.7 conda env create --file conda-recipe.yaml` 正确指定 CUDA 版本，避免系统默认编译器冲突。",{"id":162,"question_zh":163,"answer_zh":164,"source_url":151},9013,"如何让隐式梯度组件的学习率可学习？","目前 torchopt 的隐式梯度模块（ImplicitMetaGradientModule）不直接支持可学习学习率。建议将学习率封装为可训练参数（如 nn.Parameter），并在 meta-optimization 中将其作为超参数传递给优化器，或通过自定义 custom_root 函数手动实现梯度流控制。可参考官方文档中 functional API 的示例进行扩展。",[166,171,176,181,186,191,196,201,206],{"id":167,"version":168,"summary_zh":169,"released_at":170},106459,"v0.7.3","## What's Changed [0.7.3] - 2023-11-10\r\n\r\n### Changed\r\n\r\n- Set minimal C++ standard to C++17 by @XuehaiPan in #195.\r\n\r\n### Fixed\r\n\r\n- Fix `optree` compatibility for multi-tree-map with `None` values by @XuehaiPan in #195.\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fcompare\u002Fv0.7.2...v0.7.3","2023-11-10T04:55:21",{"id":172,"version":173,"summary_zh":174,"released_at":175},106460,"v0.7.2","## What's Changed [0.7.2] - 2023-08-18\r\n\r\n### Added\r\n\r\n- Implement `Adadelta`, `RAdam`, `Adamax` optimizer by @JieRen98 and @Benjamin-eecs in #171.\r\n\r\n## New Contributors\r\n\r\n- @eltociear made their first contribution in #176.\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fcompare\u002Fv0.7.1...v0.7.2","2023-08-17T20:15:45",{"id":177,"version":178,"summary_zh":179,"released_at":180},106461,"v0.7.1","## What's Changed [0.7.1] - 2023-05-12\r\n\r\n### Added\r\n\r\n- Enable CI workflow to build CXX\u002FCUDA extension for Python 3.11 by @XuehaiPan in #152.\r\n- Implement AdaGrad optimizer and exponential learning rate decay schedule by @Benjamin-eecs and @XuehaiPan in #80.\r\n- Enable tests on Windows by @XuehaiPan in #140.\r\n- Add `ruff` and `flake8` plugins integration by @XuehaiPan in #138 and #139.\r\n- Add more documentation on implicit differentiation by @Benjamin-eecs and @XuehaiPan in #143.\r\n\r\n### Fixed\r\n\r\n- Fix overloaded annotations of `extract_state_dict` by @StefanoWoerner in #162.\r\n- Fix transpose empty iterable with `zip(*nested)` in transformations by @XuehaiPan in #145.\r\n\r\n### Removed\r\n\r\n- Drop Python 3.7 support by @XuehaiPan in #136.\r\n\r\n## New Contributors\r\n\r\n- @StefanoWoerner made their first contribution in #162.\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fcompare\u002Fv0.7.0...v0.7.1","2023-05-12T09:36:19",{"id":182,"version":183,"summary_zh":184,"released_at":185},106462,"v0.7.0","## [0.7.0] - 2023-02-16\r\n\r\n### Added\r\n\r\n- Update Sphinx documentation by @XuehaiPan and @Benjamin-eecs and @waterhorse1 and @JieRen98 in #127.\r\n- Add object-oriented modules support for zero-order differentiation by @XuehaiPan in #125.\r\n\r\n### Changed\r\n\r\n- Use postponed evaluation of annotations and update doctring style by @XuehaiPan in #135.\r\n- Rewrite setup CUDA Toolkit logic by @XuehaiPan in #133.\r\n\r\n### Fixed\r\n\r\n- Update tests and fix corresponding bugs by @XuehaiPan and @Benjamin-eecs and @JieRen98 in #78.\r\n- Fix memory leak in implicit MAML omniglot few-shot classification example with OOP APIs by @XuehaiPan in #113.\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fcompare\u002Fv0.6.0...v0.7.0","2023-02-15T16:04:06",{"id":187,"version":188,"summary_zh":189,"released_at":190},106463,"v0.6.0","# Highlights\r\n\r\n- The implicit gradient and zero-order differentiation APIs become generally available in TorchOpt 0.6.0.\r\n- The project code structure is refactored and reorganized.\r\n\r\n## [0.6.0] - 2022-12-07\r\n\r\n### Added\r\n\r\n- Add unroll pragma for CUDA OPs by @JieRen98 and @XuehaiPan in #112.\r\n- Add Python implementation of accelerated OP and pure-Python wheels by @XuehaiPan in #67.\r\n- Add `nan_to_num` hook and gradient transformation by @XuehaiPan in #119.\r\n- Add matrix inversion linear solver with neumann series approximation by @Benjamin-eecs and @XuehaiPan in #98.\r\n- Add if condition of number of threads for CPU OPs by @JieRen98 in #105.\r\n- Add implicit MAML omniglot few-shot classification example with OOP APIs by @XuehaiPan in #107.\r\n- Add implicit MAML omniglot few-shot classification example by @Benjamin-eecs in #48.\r\n- Add object-oriented modules support for implicit meta-gradient by @XuehaiPan in #101.\r\n- Bump PyTorch version to 1.13.0 by @XuehaiPan in #104.\r\n- Add zero-order gradient estimation by @JieRen98 in #93.\r\n- Add RPC-based distributed training support and add distributed MAML example by @XuehaiPan in #83.\r\n- Add full type hints by @XuehaiPan in #92.\r\n- Add API documentation and tutorial for implicit gradients by @Benjamin-eecs and @JieRen98 and @XuehaiPan in #73.\r\n- Add wrapper class for functional optimizers and examples of `functorch` integration by @vmoens and @Benjamin-eecs and @XuehaiPan in #6.\r\n- Implicit differentiation support by @JieRen98 and @waterhorse1 and @XuehaiPan in #41.\r\n\r\n### Changed\r\n\r\n- Refactor code organization by @XuehaiPan in #92 and [#100](https:\u002F\u002Fgithub\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F100).\r\n\r\n### Fixed\r\n\r\n- Fix implicit MAML omniglot few-shot classification example by @XuehaiPan in #108.\r\n- Align results of distributed examples by @XuehaiPan in #95.\r\n- Fix `None` in module containers by @XuehaiPan.\r\n- Fix backward errors when using inplace `sqrt_` and `add_` by @Benjamin-eecs and @JieRen98 and @XuehaiPan.\r\n- Fix LR scheduling by @XuehaiPan in #76.\r\n- Fix the step count tensor (`shape=(1,)`) can change the shape of the scalar updates (`shape=()`) by @XuehaiPan in #71.\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fcompare\u002Fv0.5.0...v0.6.0","2022-12-06T17:50:53",{"id":192,"version":193,"summary_zh":194,"released_at":195},106464,"v0.5.0","## [0.5.0] - 2022-09-05\r\n\r\n### Added\r\n\r\n- Implement AdamW optimizer with masking by @Benjamin-eecs and @XuehaiPan in [#44](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F44).\r\n- Add half float support for accelerated OPs by @XuehaiPan in [#67](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F67).\r\n- Add MAML example with TorchRL integration by @vmoens and @Benjamin-eecs in [#12](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F12).\r\n- Add optional argument `params` to update function in gradient transformations by @XuehaiPan in [#65](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F65).\r\n- Add option `weight_decay` option to optimizers by @XuehaiPan in [#65](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F65).\r\n- Add option `maximize` option to optimizers by @XuehaiPan in [#64](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F64).\r\n- Refactor tests using `pytest.mark.parametrize` and enabling parallel testing by @XuehaiPan and @Benjamin-eecs in [#55](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F55).\r\n- Add maml-omniglot few-shot classification example using functorch.vmap by @Benjamin-eecs in [#39](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F39).\r\n- Add parallel training on one GPU using functorch.vmap example by @Benjamin-eecs in [#32](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F32).\r\n- Add question\u002Fhelp\u002Fsupport issue template by @Benjamin-eecs in [#43](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F43).\r\n\r\n### Changed\r\n\r\n- Align argument names with PyTorch by @XuehaiPan in [#65](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F65).\r\n- Replace JAX PyTrees with OpTree by @XuehaiPan in [#62](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F62).\r\n- Update image link in README to support PyPI rendering by @Benjamin-eecs in [#56](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F56).\r\n\r\n### Fixed\r\n\r\n- Fix RMSProp optimizer by @XuehaiPan in [#55](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F55).\r\n- Fix momentum tracing by @XuehaiPan in [#58](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F58).\r\n- Fix CUDA build for accelerated OP by @XuehaiPan in [#53](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F53).\r\n- Fix gamma error in MAML-RL implementation by @Benjamin-eecs [#47](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002Ftorchopt\u002Fpull\u002F47).\r\n","2022-09-05T09:52:16",{"id":197,"version":198,"summary_zh":199,"released_at":200},106465,"v0.4.3","# [0.4.3] - 2022-08-08\r\n\r\n## What's Changed\r\n\r\n### Added\r\n\r\n- Bump PyTorch version to 1.12.1 by @XuehaiPan in [#49](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F49).\r\n- CPU-only build without `nvcc` requirement by @XuehaiPan in [#51](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F51).\r\n- Use [`cibuildwheel`](https:\u002F\u002Fgithub.com\u002Fpypa\u002Fcibuildwheel) to build wheels by @XuehaiPan in [#45](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F45).\r\n- Use dynamic process number in CPU kernels by @JieRen98 in [#42](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F42).\r\n\r\n### Changed\r\n\r\n- Use correct Python Ctype for pybind11 function prototype @XuehaiPan in [#52](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F52).\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fcompare\u002Fv0.4.2...v0.4.3\r\n**Pre-built wheels**: https:\u002F\u002Fpypi.org\u002Fproject\u002Ftorchopt\u002F0.4.3\u002F#files","2022-08-07T18:29:41",{"id":202,"version":203,"summary_zh":204,"released_at":205},106466,"v0.4.2","# [0.4.2] - 2022-07-26\r\n\r\n## What's Changed\r\n\r\n### Added\r\n\r\n- Read the Docs integration by @Benjamin-eecs and @XuehaiPan in [#34](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F34).\r\n- Update documentation and code styles by @Benjamin-eecs and @XuehaiPan in [#22](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F22).\r\n- Update tutorial notebooks by @XuehaiPan in [#27](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F27).\r\n- Bump PyTorch version to 1.12 by @XuehaiPan in [#25](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F25).\r\n- Support custom Python executable path in `CMakeLists.txt` by @XuehaiPan in [#18](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F18).\r\n- Add citation information by @waterhorse1 in [#14](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F14) and @Benjamin-eecs in [#15](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F15).\r\n- Implement RMSProp optimizer by @future-xy in [#8](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F8).\r\n\r\n### Changed\r\n\r\n- Use `pyproject.toml` for packaging and update GitHub Action workflows by @XuehaiPan in [#31](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F31).\r\n- Rename the package from `TorchOpt` to `torchopt` by @XuehaiPan in [#20](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F20).\r\n\r\n### Fixed\r\n\r\n- Fixed errors while building from the source and add `conda` environment recipe by @XuehaiPan in [#24](https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fpull\u002F24).\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Fmetaopt\u002FTorchOpt\u002Fcompare\u002Fv0.4.1...v0.4.2","2022-07-26T07:57:52",{"id":207,"version":208,"summary_zh":209,"released_at":210},106467,"v0.4.1","N\u002FA","2022-06-14T13:14:33"]