[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-meta-pytorch--opacus":3,"tool-meta-pytorch--opacus":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",159636,2,"2026-04-17T23:33:34",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":76,"owner_twitter":76,"owner_website":77,"owner_url":78,"languages":79,"stars":106,"forks":107,"last_commit_at":108,"license":109,"difficulty_score":110,"env_os":111,"env_gpu":112,"env_ram":111,"env_deps":113,"category_tags":120,"github_topics":121,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":128,"updated_at":129,"faqs":130,"releases":160},8952,"meta-pytorch\u002Fopacus","opacus","Training PyTorch models with differential privacy","Opacus 是一个专为 PyTorch 设计的开源库，旨在让开发者能够轻松地为机器学习模型添加差分隐私保护。在数据隐私日益重要的今天，训练模型时往往面临泄露用户敏感信息的风险，而 Opacus 通过引入差分隐私技术，有效解决了这一难题，确保模型在学习数据规律的同时，无法反推出任何单个样本的具体信息。\n\n这款工具特别适合机器学习从业者希望快速上手隐私保护训练，以及差分隐私研究人员需要灵活实验场景的需求。其最大的亮点在于“低门槛”与“高性能”：用户只需对现有代码进行极少量的修改，实例化一个 `PrivacyEngine` 并调用 `make_private()` 方法，即可将普通模型转化为隐私安全模型。此外，Opacus 支持实时追踪隐私预算消耗，让隐私开销透明可控。近期更新还引入了快速梯度裁剪等技术，显著降低了内存占用，甚至支持与 LoRA 等高效微调技术结合，使得在资源受限环境下训练大型隐私模型成为可能。无论是构建文本分类器还是图像识别模型，Opacus 都能帮助你在不牺牲太多训练效率的前提下，筑牢数据安全的防线。","\u003Cp align=\"center\">\u003Cimg src=\"https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Fwebsite\u002Fstatic\u002Fimg\u002Fopacus_logo.svg\" alt=\"Opacus\" width=\"500\"\u002F>\u003C\u002Fp>\n\n\u003Chr\u002F>\n\n[![PyPI Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmeta-pytorch_opacus_readme_4c816aaf47e8.png)](https:\u002F\u002Fpepy.tech\u002Fprojects\u002Fopacus)\n[![GitHub Actions](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Factions\u002Fworkflows\u002Fci_cpu.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Factions\u002Fworkflows\u002Fci_cpu.yml)\n[![Coverage Status](https:\u002F\u002Fcoveralls.io\u002Frepos\u002Fgithub\u002Fpytorch\u002Fopacus\u002Fbadge.svg?branch=main)](https:\u002F\u002Fcoveralls.io\u002Fgithub\u002Fpytorch\u002Fopacus?branch=main)\n[![PRs Welcome](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPRs-welcome-brightgreen.svg)](CONTRIBUTING.md)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-apache2-green.svg)](LICENSE)\n\n[Opacus](https:\u002F\u002Fopacus.ai) is a library that enables training PyTorch models\nwith differential privacy. It supports training with minimal code changes\nrequired on the client, has little impact on training performance, and allows\nthe client to online track the privacy budget expended at any given moment.\n\n\n## Target audience\n\nThis code release is aimed at two target audiences:\n\n1. ML practitioners will find this to be a gentle introduction to training a\n   model with differential privacy as it requires minimal code changes.\n2. Differential Privacy researchers will find this easy to experiment and tinker\n   with, allowing them to focus on what matters.\n\n\n## Latest updates\n\n2024-12-18: We updated this [tutorial](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_text_classifier.ipynb) to show how [LoRA](https:\u002F\u002Farxiv.org\u002Fabs\u002F2106.09685) and [peft](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Fpeft\u002Fen\u002Findex) library could be used in conjuncture with DP-SGD.\n\n2024-08-20: We introduced [Fast Gradient Clipping](https:\u002F\u002Farxiv.org\u002Fabs\u002F2009.03106) and Ghost Clipping(https:\u002F\u002Farxiv.org\u002Fabs\u002F2110.05679) to Opacus, significantly reducing the memory requirements of DP-SGD. Please refer to our [blogpost](https:\u002F\u002Fpytorch.org\u002Fblog\u002Fclipping-in-opacus\u002F) for more information.\n\n## Installation\n\nThe latest release of Opacus can be installed via `pip`:\n\n```bash\npip install opacus\n```\n\nOR, alternatively, via `conda`:\n\n```bash\nconda install -c conda-forge opacus\n```\n\nYou can also install directly from the source for the latest features (along\nwith its quirks and potentially occasional bugs):\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus.git\ncd opacus\npip install -e .\n```\n\n## Getting started\n\nTo train your model with differential privacy, all you need to do is to\ninstantiate a `PrivacyEngine` and pass your model, data_loader, and optimizer to\nthe engine's `make_private()` method to obtain their private counterparts.\n\n```python\n# define your components as usual\nmodel = Net()\noptimizer = SGD(model.parameters(), lr=0.05)\ndata_loader = torch.utils.data.DataLoader(dataset, batch_size=1024)\n\n# enter PrivacyEngine\nprivacy_engine = PrivacyEngine()\nmodel, optimizer, data_loader = privacy_engine.make_private(\n    module=model,\n    optimizer=optimizer,\n    data_loader=data_loader,\n    noise_multiplier=1.1,\n    max_grad_norm=1.0,\n)\n# Now it's business as usual\n```\n\nThe\n[MNIST example](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002Fexamples\u002Fmnist.py)\nshows an end-to-end run using Opacus. The\n[examples](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002Fexamples\u002F) folder\ncontains more such examples.\n\n## Learn more\n\n### Interactive tutorials\n\nWe've built a series of IPython-based tutorials as a gentle introduction to\ntraining models with privacy and using various Opacus features.\n\n- [Building text classifier with Differential Privacy on BERT](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_text_classifier.ipynb)\n- [Building an Image Classifier with Differential Privacy](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_image_classifier.ipynb)\n- [Training a differentially private LSTM model for name classification](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_lstm_name_classifier.ipynb)\n- [Opacus Guide: Introduction to advanced features](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fintro_to_advanced_features.ipynb)\n- [Opacus Guide: Grad samplers](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fguide_to_grad_sampler.ipynb)\n- [Opacus Guide: Module Validator and Fixer](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fguide_to_module_validator.ipynb)\n- [Opacus Guide: Training with Non-Wrapping Mode](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fnon_wrapping_mode.ipynb)\n\n## Technical report and citation\n\nThe technical report introducing Opacus, presenting its design principles,\nmathematical foundations, and benchmarks can be found\n[here](https:\u002F\u002Farxiv.org\u002Fabs\u002F2109.12298).\n\nConsider citing the report if you use Opacus in your papers, as follows:\n\n```\n@article{opacus,\n  title={Opacus: {U}ser-Friendly Differential Privacy Library in {PyTorch}},\n  author={Ashkan Yousefpour and Igor Shilov and Alexandre Sablayrolles and Davide Testuggine and Karthik Prasad and Mani Malek and John Nguyen and Sayan Ghosh and Akash Bharadwaj and Jessica Zhao and Graham Cormode and Ilya Mironov},\n  journal={arXiv preprint arXiv:2109.12298},\n  year={2021}\n}\n```\n\n### Blogposts and talks\n\nIf you want to learn more about DP-SGD and related topics, check out our series\nof blogposts and talks:\n\n- [Enabling Fast Gradient Clipping and Ghost Clipping in Opacus](https:\u002F\u002Fpytorch.org\u002Fblog\u002Fclipping-in-opacus\u002F)\n- [Differential Privacy Series Part 1 | DP-SGD Algorithm Explained](https:\u002F\u002Fmedium.com\u002Fpytorch\u002Fdifferential-privacy-series-part-1-dp-sgd-algorithm-explained-12512c3959a3)\n- [Differential Privacy Series Part 2 | Efficient Per-Sample Gradient Computation in Opacus](https:\u002F\u002Fmedium.com\u002Fpytorch\u002Fdifferential-privacy-series-part-2-efficient-per-sample-gradient-computation-in-opacus-5bf4031d9e22)\n- [PriCon 2020 Tutorial: Differentially Private Model Training with Opacus](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=MWPwofiQMdE&list=PLUNOsx6Az_ZGKQd_p4StdZRFQkCBwnaY6&index=52)\n- [Differential Privacy on PyTorch | PyTorch Developer Day 2020](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=l6fbl2CBnq0)\n- [Opacus v1.0 Highlights | PyTorch Developer Day 2021](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=U1mszp8lzUI)\n\n## FAQ\n\nCheck out the [FAQ](https:\u002F\u002Fopacus.ai\u002Fdocs\u002Ffaq) page for answers to some of the\nmost frequently asked questions about differential privacy and Opacus.\n\n## Contributing\n\nSee the\n[CONTRIBUTING](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002FCONTRIBUTING.md) file\nfor how to help out. Do also check out the README files inside the repo to learn\nhow the code is organized.\n\n## License\n\nThis code is released under Apache 2.0, as found in the\n[LICENSE](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002FLICENSE) file.\n","\u003Cp align=\"center\">\u003Cimg src=\"https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Fwebsite\u002Fstatic\u002Fimg\u002Fopacus_logo.svg\" alt=\"Opacus\" width=\"500\"\u002F>\u003C\u002Fp>\n\n\u003Chr\u002F>\n\n[![PyPI 下载量](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmeta-pytorch_opacus_readme_4c816aaf47e8.png)](https:\u002F\u002Fpepy.tech\u002Fprojects\u002Fopacus)\n[![GitHub Actions](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Factions\u002Fworkflows\u002Fci_cpu.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Factions\u002Fworkflows\u002Fci_cpu.yml)\n[![覆盖率](https:\u002F\u002Fcoveralls.io\u002Frepos\u002Fgithub\u002Fpytorch\u002Fopacus\u002Fbadge.svg?branch=main)](https:\u002F\u002Fcoveralls.io\u002Fgithub\u002Fpytorch\u002Fopacus?branch=main)\n[![欢迎提交 PR](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPRs-welcome-brightgreen.svg)](CONTRIBUTING.md)\n[![许可证](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-apache2-green.svg)](LICENSE)\n\n[Opacus](https:\u002F\u002Fopacus.ai) 是一个支持使用差分隐私训练 PyTorch 模型的库。它只需对客户端代码进行极小的改动即可实现训练，对训练性能的影响也很小，并且允许客户端实时跟踪当前已消耗的隐私预算。\n\n\n## 目标用户\n\n本次代码发布面向两类目标用户：\n\n1. 机器学习从业者会发现，由于只需少量代码改动，这为他们提供了一个以温和方式入门差分隐私模型训练的途径。\n2. 差分隐私领域的研究人员则会发现，该库易于实验和调试，使他们能够专注于核心问题。\n\n\n## 最新动态\n\n2024年12月18日：我们更新了此 [教程](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_text_classifier.ipynb)，展示了如何将 [LoRA](https:\u002F\u002Farxiv.org\u002Fabs\u002F2106.09685) 和 [peft](https:\u002F\u002Fhuggingface.co\u002Fdocs\u002Fpeft\u002Fen\u002Findex) 库与 DP-SGD 结合使用。\n\n2024年8月20日：我们在 Opacus 中引入了 [快速梯度裁剪](https:\u002F\u002Farxiv.org\u002Fabs\u002F2009.03106) 和 [Ghost 裁剪](https:\u002F\u002Farxiv.org\u002Fabs\u002F2110.05679)，显著降低了 DP-SGD 的内存需求。更多信息请参阅我们的 [博客文章](https:\u002F\u002Fpytorch.org\u002Fblog\u002Fclipping-in-opacus\u002F)。\n\n## 安装\n\n最新版本的 Opacus 可通过 `pip` 安装：\n\n```bash\npip install opacus\n```\n\n或者，也可以通过 `conda` 安装：\n\n```bash\nconda install -c conda-forge opacus\n```\n\n你还可以直接从源码安装以获取最新功能（但可能伴随一些小问题或偶尔出现的 bug）：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus.git\ncd opacus\npip install -e .\n```\n\n## 快速开始\n\n要使用差分隐私训练你的模型，你只需实例化一个 `PrivacyEngine`，并将你的模型、数据加载器和优化器传递给引擎的 `make_private()` 方法，即可获得对应的私有版本。\n\n```python\n# 按照常规方式定义你的组件\nmodel = Net()\noptimizer = SGD(model.parameters(), lr=0.05)\ndata_loader = torch.utils.data.DataLoader(dataset, batch_size=1024)\n\n# 使用 PrivacyEngine\nprivacy_engine = PrivacyEngine()\nmodel, optimizer, data_loader = privacy_engine.make_private(\n    module=model,\n    optimizer=optimizer,\n    data_loader=data_loader,\n    noise_multiplier=1.1,\n    max_grad_norm=1.0,\n)\n# 现在就可以像往常一样继续训练了\n```\n\n[MNIST 示例](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002Fexamples\u002Fmnist.py) 展示了使用 Opacus 的端到端运行流程。[示例文件夹](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002Fexamples\u002F) 中还包含更多类似的示例。\n\n## 深入学习\n\n### 交互式教程\n\n我们构建了一系列基于 IPython 的教程，旨在以温和的方式介绍如何使用隐私保护技术训练模型以及 Opacus 的各项功能。\n\n- [使用 BERT 在差分隐私下构建文本分类器](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_text_classifier.ipynb)\n- [使用差分隐私构建图像分类器](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_image_classifier.ipynb)\n- [训练用于姓名分类的差分隐私 LSTM 模型](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fbuilding_lstm_name_classifier.ipynb)\n- [Opacus 指南：高级功能介绍](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fintro_to_advanced_features.ipynb)\n- [Opacus 指南：梯度采样器](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fguide_to_grad_sampler.ipynb)\n- [Opacus 指南：模块验证器和修复工具](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fguide_to_module_validator.ipynb)\n- [Opacus 指南：非包装模式下的训练](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Ftutorials\u002Fnon_wrapping_mode.ipynb)\n\n## 技术报告与引用\n\n介绍 Opacus 的技术报告，其中阐述了其设计原则、数学基础和基准测试结果，可在此处找到：\n[https:\u002F\u002Farxiv.org\u002Fabs\u002F2109.12298](https:\u002F\u002Farxiv.org\u002Fabs\u002F2109.12298)。\n\n如果你在论文中使用了 Opacus，请参考以下引用格式：\n\n```\n@article{opacus,\n  title={Opacus: {U}ser-Friendly Differential Privacy Library in {PyTorch}},\n  author={Ashkan Yousefpour and Igor Shilov and Alexandre Sablayrolles and Davide Testuggine and Karthik Prasad and Mani Malek and John Nguyen and Sayan Ghosh and Akash Bharadwaj and Jessica Zhao and Graham Cormode and Ilya Mironov},\n  journal={arXiv preprint arXiv:2109.12298},\n  year={2021}\n}\n```\n\n### 博客文章与演讲\n\n如果你想深入了解 DP-SGD 及相关主题，可以查看我们的系列博客文章和演讲：\n\n- [在 Opacus 中启用快速梯度裁剪和 Ghost 裁剪](https:\u002F\u002Fpytorch.org\u002Fblog\u002Fclipping-in-opacus\u002F)\n- [差分隐私系列第一部分 | 解释 DP-SGD 算法](https:\u002F\u002Fmedium.com\u002Fpytorch\u002Fdifferential-privacy-series-part-1-dp-sgd-algorithm-explained-12512c3959a3)\n- [差分隐私系列第二部分 | 在 Opacus 中高效计算每样本梯度](https:\u002F\u002Fmedium.com\u002Fpytorch\u002Fdifferential-privacy-series-part-2-efficient-per-sample-gradient-computation-in-opacus-5bf4031d9e22)\n- [PriCon 2020 教程：使用 Opacus 进行差分隐私模型训练](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=MWPwofiQMdE&list=PLUNOsx6Az_ZGKQd_p4StdZRFQkCBwnaY6&index=52)\n- [PyTorch 上的差分隐私 | PyTorch 开发者日 2020](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=l6fbl2CBnq0)\n- [Opacus v1.0 亮点 | PyTorch 开发者日 2021](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=U1mszp8lzUI)\n\n## 常见问题解答\n\n请访问 [FAQ](https:\u002F\u002Fopacus.ai\u002Fdocs\u002Ffaq) 页面，获取关于差分隐私和 Opacus 的一些常见问题的答案。\n\n## 贡献\n\n有关如何参与贡献的信息，请参阅 [CONTRIBUTING](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002FCONTRIBUTING.md) 文件。同时，也请查阅仓库内的 README 文件，了解代码的组织结构。\n\n## 许可证\n\n本项目采用 Apache 2.0 许可证发布，详情请参阅 [LICENSE](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Ftree\u002Fmain\u002FLICENSE) 文件。","# Opacus 快速上手指南\n\nOpacus 是一个用于在 PyTorch 中训练差分隐私（Differential Privacy, DP）模型的库。它只需极少的代码改动即可实现隐私保护训练，支持实时追踪隐私预算消耗，且对训练性能影响较小。\n\n## 环境准备\n\n*   **系统要求**：支持 Linux、macOS 和 Windows。\n*   **前置依赖**：\n    *   Python 3.8+\n    *   PyTorch 1.8+ (建议安装最新稳定版)\n    *   `torchvision` (可选，用于图像示例)\n\n> **注意**：请确保已正确安装 PyTorch。国内用户推荐使用清华或阿里镜像源安装 PyTorch 基础环境。\n\n## 安装步骤\n\n你可以选择通过 `pip` 或 `conda` 进行安装。国内开发者建议使用国内镜像源以加速下载。\n\n### 方式一：使用 pip 安装（推荐）\n\n```bash\npip install opacus -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n### 方式二：使用 conda 安装\n\n```bash\nconda install -c conda-forge opacus\n```\n\n### 方式三：从源码安装（获取最新特性）\n\n如果你需要体验最新的功能（可能包含未发布的修复或实验性特性），可以从 GitHub 克隆源码安装：\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus.git\ncd opacus\npip install -e . -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n## 基本使用\n\n使用 Opacus 进行差分隐私训练非常简单，核心步骤是实例化 `PrivacyEngine` 并调用 `make_private()` 方法包装你的模型、优化器和数据加载器。\n\n以下是最小化的使用示例：\n\n```python\nimport torch\nfrom torch.utils.data import DataLoader\nfrom torch.optim import SGD\nfrom opacus import PrivacyEngine\n\n# 1. 定义常规组件 (模型、优化器、数据加载器)\nmodel = Net()  # 替换为你的模型定义\noptimizer = SGD(model.parameters(), lr=0.05)\ndata_loader = DataLoader(dataset, batch_size=1024)\n\n# 2. 初始化 PrivacyEngine\nprivacy_engine = PrivacyEngine()\n\n# 3. 将组件转换为隐私保护版本\nmodel, optimizer, data_loader = privacy_engine.make_private(\n    module=model,\n    optimizer=optimizer,\n    data_loader=data_loader,\n    noise_multiplier=1.1,      # 噪声乘数，控制隐私强度\n    max_grad_norm=1.0,         # 最大梯度范数，用于梯度裁剪\n)\n\n# 4. 开始正常训练循环\n# 接下来的训练代码 (forward, loss.backward, optimizer.step) 无需更改\nfor epoch in range(num_epochs):\n    for inputs, targets in data_loader:\n        optimizer.zero_grad()\n        outputs = model(inputs)\n        loss = criterion(outputs, targets)\n        loss.backward()\n        optimizer.step()\n        \n    # 可选：查看当前消耗的隐私预算\n    epsilon = privacy_engine.get_epsilon(delta=1e-5)\n    print(f\"Epoch {epoch}: Epsilon = {epsilon}\")\n```\n\n**关键参数说明：**\n*   `noise_multiplier`: 添加到梯度的噪声标准差与裁剪阈值的比率。值越大，隐私性越强，但模型效用可能降低。\n*   `max_grad_norm`: 每个样本梯度的最大范数阈值，超过此值的梯度将被裁剪。\n\n更多完整示例（如 MNIST 分类、BERT 文本分类等）请参考官方 `examples` 目录或交互式教程。","某医疗科技公司的算法团队正在利用患者的电子病历数据训练疾病预测模型，必须严格防止敏感信息从模型参数中泄露。\n\n### 没有 opacus 时\n- 开发人员需手动重写反向传播算法来实现差分隐私（DP-SGD），代码复杂且极易出错，导致项目延期。\n- 缺乏自动化的隐私预算追踪机制，团队难以量化模型训练过程中的隐私泄露风险，无法通过合规审计。\n- 传统的隐私保护实现方式内存占用极高，导致无法在现有显卡资源上训练较大的批量尺寸，模型收敛缓慢。\n- 每次调整隐私参数都需要大幅重构代码，研究人员难以快速实验不同噪声水平对模型准确率的影响。\n\n### 使用 opacus 后\n- 仅需实例化 `PrivacyEngine` 并调用 `make_private()` 方法，即可在几乎不修改原有 PyTorch 代码的情况下启用差分隐私训练。\n- 内置的隐私会计（Privacy Accountant）功能可实时在线追踪并报告当前的隐私预算消耗，让合规性评估透明可控。\n- 借助快速梯度裁剪和 Ghost Clipping 技术，显著降低了显存需求，使得在大规模批次下高效训练成为可能。\n- 支持灵活配置噪声乘数和最大梯度范数，团队能快速迭代实验，轻松找到隐私保护与模型效用之间的最佳平衡点。\n\nopacus 将复杂的差分隐私理论转化为简单的工程实践，让开发者能在确保用户数据绝对安全的前提下，高效构建可信的 AI 模型。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fmeta-pytorch_opacus_631002dc.png","meta-pytorch","Meta PyTorch","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fmeta-pytorch_1dfd3f76.jpg","",null,"https:\u002F\u002Fpytorch.org","https:\u002F\u002Fgithub.com\u002Fmeta-pytorch",[80,84,87,91,95,99,103],{"name":81,"color":82,"percentage":83},"Jupyter Notebook","#DA5B0B",48.2,{"name":85,"color":86,"percentage":83},"Python","#3572A5",{"name":88,"color":89,"percentage":90},"CSS","#663399",1.9,{"name":92,"color":93,"percentage":94},"JavaScript","#f1e05a",1.3,{"name":96,"color":97,"percentage":98},"Shell","#89e051",0.4,{"name":100,"color":101,"percentage":102},"Batchfile","#C1F12E",0,{"name":104,"color":105,"percentage":102},"Makefile","#427819",1924,392,"2026-04-17T14:33:46","Apache-2.0",1,"未说明","未说明 (支持 CPU 和 GPU 训练，具体取决于 PyTorch 环境；近期更新引入了快速梯度裁剪技术以降低显存需求)",{"notes":114,"python":111,"dependencies":115},"Opacus 是一个用于在 PyTorch 中进行差分隐私训练的库。安装可通过 pip 或 conda 进行。它支持与 LoRA 和 PEFT 库结合使用。2024 年 8 月的更新引入了快速梯度裁剪和 Ghost Clipping 功能，显著降低了 DP-SGD 的内存需求。具体版本依赖需参考 PyTorch 兼容性，README 中未列出确切版本号。",[116,117,118,119],"torch","numpy","scipy","opt-einsum",[14],[122,123,124,125,126,127],"differential-privacy","privacy-preserving-machine-learning","deep-learning","machine-learning","neural-network","pytorch","2026-03-27T02:49:30.150509","2026-04-18T14:13:35.433502",[131,136,141,146,151,156],{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},40173,"使用 Opacus 时遇到 'Parameter' 对象没有 'grad_sample' 属性的错误怎么办？","这通常是因为使用了不支持的模型架构（如包含 BatchNorm 的预训练模型）或代码版本过旧。解决方案包括：1. 确保将模型中的 BatchNorm 模块替换为 GroupNorm；2. 由于该问题涉及旧版本，建议创建一个新的 Issue 并提供可复现的 Colab 代码以便调试，因为新版 Opacus 已有很多变化并提供了报错模板。","https:\u002F\u002Fgithub.com\u002Fmeta-pytorch\u002Fopacus\u002Fissues\u002F4",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},40174,"运行 Opacus 时报错 'Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!' 如何解决？","这是因为张量设备不一致（部分在 CPU，部分在 GPU）。如果是 Docker 环境或特定线性层问题，可以尝试修改 torch\u002Fnn\u002Fmodules\u002Flinear.py 文件，在第 116 行将 `return F.linear(input, self.weight, self.bias)` 改为 `return F.linear(input.to(self.device), self.weight.to(self.device), self.bias.to(self.device))` 以强制统一设备。官方已在 PR #631 中发布了修复程序，建议更新到最新版本。","https:\u002F\u002Fgithub.com\u002Fmeta-pytorch\u002Fopacus\u002Fissues\u002F612",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},40175,"初始化 PrivacyEngine 时提示 'missing 1 required positional argument: module' 错误是什么原因？","该错误通常是因为实例化 `PrivacyEngine` 的方式不正确。在较新的 Opacus 版本中，`PrivacyEngine` 的初始化可能不需要直接传入 module，或者调用方式有所改变。请检查文档确认当前版本的正确初始化流程。如果涉及每轮调整噪声参数等高级用法，建议参考 PyTorch 论坛的相关讨论，因为这与基础初始化错误不同。","https:\u002F\u002Fgithub.com\u002Fmeta-pytorch\u002Fopacus\u002Fissues\u002F336",{"id":147,"question_zh":148,"answer_zh":149,"source_url":150},40176,"使用 Opacus 时出现关于 'non-full backward hook' 的弃用警告如何处理？","当 forward 包含多个 autograd 节点时，使用非完整的 backward hook 已被弃用。警告信息建议改用 `register_full_backward_hook` 来获取预期的行为。这通常意味着需要更新 Opacus 库到最新版本，或者检查自定义模型中钩子函数的注册方式，确保符合 PyTorch 最新版本的规范。","https:\u002F\u002Fgithub.com\u002Fmeta-pytorch\u002Fopacus\u002Fissues\u002F328",{"id":152,"question_zh":153,"answer_zh":154,"source_url":155},40177,"Opacus 是否支持 GAN 中的 Wasserstein Loss（多次 loss.backward()）？","早期版本的 pytorch-dp (Opacus 前身) 不支持在调用 optimizer.step() 之前进行多次 loss.backward()，因此无法直接支持带有梯度惩罚的 Wasserstein Loss。虽然社区曾提出通过修改 `_create_or_extend_grad_sample` 函数将梯度样本从拼接改为累加和作为临时变通方案，但维护者建议针对具体复现代码重新提交 Issue 以获取针对新版本的支持或确认当前状态。","https:\u002F\u002Fgithub.com\u002Fmeta-pytorch\u002Fopacus\u002Fissues\u002F31",{"id":157,"question_zh":158,"answer_zh":159,"source_url":145},40178,"如何在 Opacus 中动态调整每轮的噪声增加参数或获取当前的隐私预算？","当前的噪声增加参数通常绑定在优化器上，意味着每次梯度下降使用相同的系数。如果需要自动更改噪声系数或获取当前隐私预算，这属于高级用法。维护者建议此类具体问题在 PyTorch 官方论坛（discuss.pytorch.org）上进行讨论，那里有更活跃的社区针对动态调整隐私预算和噪声参数的策略进行深入交流。",[161,166,171,176,181,186,191,196,201,206,211,216,221,226,231,236,241,246,251,256],{"id":162,"version":163,"summary_zh":164,"released_at":165},323678,"v1.5.4","## v1.5.4\n\n### 新特性\n\n#### 改进\n* 支持 `register_full_backward_hook` (#720, #750)\n* 添加 `RMSNorm` 的钩子函数 (#755)\n* 支持 NumPy 2.0 (#746)\n\n### Bug 修复\n* 修复测试失败问题 (#727, #739)\n* 修复 Lint 问题 (#741, #760)\n* 修复幽灵裁剪下偏置的归一化计算问题 (#751)\n* 修复幽灵裁剪下的 `to_standard_module` 问题 (#754)\n* 修复 `make_private` 的返回类型问题 (#759)\n\n### 其他\n* 为 DISK 添加版权信息 (#719)\n* 改进日志系统 (#735)\n* 更新教程 (#733, #745)\n* 对幽灵裁剪优化器进行小幅调整 (#756)\n* 添加关于自适应裁剪限制的警告 (#758)","2025-05-27T16:23:36",{"id":167,"version":168,"summary_zh":169,"released_at":170},323679,"v1.5.3","### 新特性\n\n#### 幽灵裁剪的改进\n* 幽灵裁剪的接口现与 PyTorch 和原生 DP-SGD 的接口一致 (#668)\n* 更新了使用 DP-SGD 训练语言模型的教程，新增了幽灵裁剪 (#667) 和 LoRA (#698) 的内容\n* 为幽灵裁剪增加了自适应裁剪支持 (#711)\n* 为嵌入层添加了幽灵裁剪支持 (#694)\n* 支持在生成式 NLP 任务中使用幽灵裁剪 (#722)\n* 增加了在幽灵裁剪下访问每个样本梯度的功能 (#724)\n\n#### 更好地支持外部贡献\n* 新增了一个 research 文件夹，用于接收和整合 PPML 领域有前景的新方法的外部贡献 (#700)\n* 现在可以在 research 文件夹中找到带有卡尔曼滤波器的 DP-SGD 优化器 (#706)\n* 简化了定义 PrivacyEngine 自定义扩展的方式 (#703、#704、#710)\n\n### Bug 修复\n* 修复了在使用 PrivacyEngine 接口时幽灵裁剪的裁剪操作问题 (#664)\n* 修复了幽灵裁剪与 BatchMemoryManager 配合使用时的问题\n* 在 `GradSampleModuleFastGradientClipping` 的初始化中添加了 `strict` 和 `force_functorch` 参数 (#675)\n* 修复了一些测试用例的失败问题（例如 #726、#713、#727、#674）\n\n### 其他\n* 将测试平台从 CircleCI 切换至 GitHub Actions CI (#701)\n* 对官网和 GitHub 进行了多项改进 (#723、#721、#677、#712)\n* 为幽灵裁剪新增了多 GPU 测试 (#665)\n","2025-02-18T22:02:53",{"id":172,"version":173,"summary_zh":174,"released_at":175},323680,"v1.5.2","新功能\n添加“double_backward”函数，简化训练循环 (#661)\n\n错误修复\n修复DPOptimizer包装器中param_group设置的问题（问题649）(#660)\n修复DDP优化器在FGC场景下的问题：step函数错误地调用了“original_optimizer.original_optimizer”(#662)\n将“opt_einsum.contract”替换为“torch.einsum”(#663)","2024-08-03T10:32:36",{"id":177,"version":178,"summary_zh":179,"released_at":180},323681,"v.1.5.1","错误修复  \n显式导入 opt_einsum.contract（linear.py）（[#658](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fpull\u002F658)）。","2024-07-26T16:25:38",{"id":182,"version":183,"summary_zh":184,"released_at":185},323682,"v1.5","新功能\n快速梯度裁剪和幽灵裁剪（https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fpull\u002F656）\n\n错误修复\n修复 DPMultiheadAttention 的梯度形状错误（问题 650）（https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fpull\u002F651）\n将关键字参数从 make_private 传递到 _prepare_optimizer（https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fpull\u002F648）\n修复 BatchMemoryManager 的长度问题（https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fpull\u002F641）\n修复 util 中 filter_dilated_rows 的 GPU-CPU 设备不匹配错误（https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fpull\u002F633）\n修复 Opacus 在空批次情况下的运行时错误（问题 612）（https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fpull\u002F631）","2024-07-26T15:22:08",{"id":187,"version":188,"summary_zh":189,"released_at":190},323683,"v1.4.1","### 错误修复\n* 修复 DP MultiheadAttention (#598)\n* 修复：使 prv 会计器对较大的 ε 值更加鲁棒 (#606)\n* 修复优化器没有可训练参数时的边界情况 (#619)","2024-02-11T17:28:09",{"id":192,"version":193,"summary_zh":194,"released_at":195},323684,"v1.4.0","亮点：已将 PyTorch 升级至 1.13+ 作为必需依赖项\n\n### 新特性\n* 添加了裁剪调度器 (#556)\n* 增加了用于检查每个样本梯度的工具 (#532)\n\n### Bug 修复\n* 使 DataLoader 接口与原生 PyTorch 保持一致 (#543)\n* 修复 GDP 会计 epsilon 获取会改变内部状态的问题 (#541)\n* 添加在 UniformSampler 中指定步数的选项 (#550)\n* 修复隐私计算脚本 (#565)","2023-03-24T15:59:54",{"id":197,"version":198,"summary_zh":199,"released_at":200},323685,"v1.3","### 新特性\n* 基于论文《差分隐私的数值组合》（[arXiv:2106.02848](https:\u002F\u002Farxiv.org\u002Fabs\u002F2106.02848)）实现 `PRVAccountant` (#493)\n* 支持 `nn.EmbeddingBag` (#519)\n\n### Bug 修复\n* 修复基准测试相关问题 (#503, #507, #508)\n* 使 `make_private_with_epsilon` 与 `make_private` 行为一致 (#509, #526)\n* 测试相关修复 (#513, #515, #527, #533)\n* 将判别器损失求和后执行一次反向传播步骤 (#474)\n* 修复 MNIST 示例中缺少参数的问题 (#520)\n* 对 Functorch 梯度进行调查并修复 (#510)\n* 支持空批次 (#530)","2022-11-14T13:48:34",{"id":202,"version":203,"summary_zh":204,"released_at":205},323686,"v1.2.0","我们很高兴地推出 Opacus v1.2，该版本对逐样本梯度计算机制进行了多项重大更新，并整合了近期 PyTorch 发布中的所有优秀特性。\n\n## 亮点\n### Functorch —— 全面支持逐样本梯度\n随着 [functorch](https:\u002F\u002Fpytorch.org\u002Ffunctorch\u002Fstable\u002F) 的最新发布，现在可以轻松地为任意模块计算逐样本梯度，而无需再受到我们此前设定的限制（参见 [Opacus 文档中的常见问题解答](https:\u002F\u002Fopacus.ai\u002Fdocs\u002Ffaq#my-model-throws-incompatiblemoduleexception-what-is-going-wrong)）。\n\n新的默认行为如下：\n1. 首先，我们会检查输入模块中是否存在与 DP-SGD 不兼容的层（例如 BatchNorm）。需要注意的是，这些限制是 DP-SGD 工作原理的基础，始终适用。\n2. 接着，我们会为每一层选择一种逐样本梯度的计算方法。出于性能考虑，对于已支持的层，我们仍使用手动编写的旧版梯度采样器；而对于其他层，则回退到基于 functorch 的通用梯度采样器。\n\n您也可以通过将 `grad_sample_mode=\"functorch\"` 传递给 `PrivacyEngine.make_private()`，或在 `GradSampleModule` 的构造函数中设置 `force_functorch=False`，来强制对所有层使用 functorch 基础的梯度采样器。\n\n如果您已经在训练流水线中使用了 functorch，不妨考虑直接使用 `GradSampleModuleNoOp`（即 `grad_sample_mode=\"no_op\"`）。顾名思义，该模块不会执行任何操作，而是由客户端自行计算逐样本梯度。有关代码示例，请参阅我们的 [CIFAR-10 示例](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Fexamples\u002Fcifar10.py)。\n\n请注意，此功能目前仍处于 Beta 阶段，我们尚未完全探索其局限性。如果您遇到任何异常行为或不一致之处，请及时向我们的 GitHub 问题追踪器提交反馈，我们将不胜感激。\n\n### ExpandedWeights —— 又一种逐样本梯度计算方式\nPyTorch 核心库中新增的一项令人振奋的功能是 `ExpandedWeights`。该功能沿用了 Opacus 早期手动编写、经过向量化优化的逐样本梯度计算方法，但性能有了显著提升。\n\n要启用 `ExpandedWeights`，只需将 `grad_sample_mode=\"ew\"` 传递给 `PrivacyEngine.make_private()`，或直接使用 `GradSampleModuleExpandedWeights` 即可。\n\n### 总结：三种不同的逐样本梯度计算方式\n借助最近的更新，Opacus 现在支持三种不同的逐样本梯度计算方式。以下是简要对比。更多详细信息请参阅梯度采样的 [README.md](https:\u002F\u002Fgithub.com\u002Fpytorch\u002Fopacus\u002Fblob\u002Fmain\u002Fopacus\u002Fgrad_sample\u002FREADME.md)。\n\n**TL;DR：** 如果您需要稳定的实现方案，请使用 `GradSampleModule`（`grad_sample_mode=\"hooks\"`）。  \n如果您希望尝试新功能，则有两种选择：追求更高性能时可选用 `GradSampleModuleExpandedWeights`（`grad_sample_mode=\"ew\"`），而当您的模型不受支持时，则可选择 `grad_sample_mode=functorch`。","2022-09-09T17:50:10",{"id":207,"version":208,"summary_zh":209,"released_at":210},323687,"v1.1.3","### 改进\n* 检查点支持 (#429)\n* 支持包含冻结参数和可训练参数的混合层 (#437)\n* 优化了 einsum 计算 (#440)\n* 改进了参数合理性检查 (#439)\n\n### 错误修复\n* 修复 unfold2d (#443)\n* 将 CI 切换到最新版 PyTorch (#434)\n* 修正错别字及编辑内容 (#430, #438, #449)\n\n### 其他\n* 分布式训练教程 (#428)","2022-07-13T13:36:07",{"id":212,"version":213,"summary_zh":214,"released_at":215},323688,"v1.1.2","### Bug fixes\r\n* Support tied parameters (#417)\r\n* Fix callsite sensitiveness of `zero_grad()` (#422, #423)\r\n* Improve microbenchmark argument parsing and tests (#425)\r\n* Fix opacus nn.functional import (#426) \r\n### Miscellaneous\r\n* Add microbenchmarks (#412, #416)\r\n* Add more badges to readme (#424) ","2022-05-06T09:42:44",{"id":217,"version":218,"summary_zh":219,"released_at":220},323689,"v1.1.1","### Bug fixes\r\n* Fix accountant when using number of steps instead of epochs\r\n* Add params check when converting BatchNorm to GroupNorm (#390)\r\n* Fix typo in gdp accountant mechansim name (#386)\r\n* Fix linter errors (#392)\r\n* Add friendly and detailed message for unsupported layers (#401)\r\n* Run linter on nightly workflow (#399)\r\n* Add warning for Gaussian DP accounting (#400)\r\n* Clone replacement modules on the same device as original (#356)\r\n* Implementing 3D dilation (#408)\r\n* fix(batch_memory_manager): Ensures split_idxs use native python types (#410)\r\n### Miscellaneous\r\n* Migrate nightly CircleCI flows to scheduled pipelines (#402)\r\n* Migrate from ubuntu 16.04 to 20.04 on CircleCI (#403)","2022-04-08T18:54:49",{"id":222,"version":223,"summary_zh":224,"released_at":225},323690,"v.1.1.0","\r\n## v1.1.0\r\n\r\n### New Feature\r\n* Add support for GDP accounting in get_noise_multiplier (#303)\r\n\r\n### Bug fixes\r\n* Conservative search for target epsilon in get_noise_multiplier (#348)\r\n* Warn and ignore \"drop_last\" when set in DPDataLoader (#357)\r\n* Fix per-layer clipping in distributed (#347)\r\n\r\n### Miscellaneous\r\n* Update code of conduct and file headers\r\n* Add \"Support Ukraine\" banner to opacus website homepage\r\n* Lint fixes","2022-03-15T12:52:24",{"id":227,"version":228,"summary_zh":229,"released_at":230},323691,"v1.0.2","### Bug fixes\r\n* DPOptimizer\r\n  * Passes through `.defaults` field to match pytorch Optimizer (#329)\r\n  * Better exception message in `.step()` when p.grad_sample=None (#331)\r\n  * Correct `closure` call after applying DP noise (#330)\r\n* Proper gradient scaling in DDP mode\r\n* Corrections of typos and errors in tutorials\r\n### Miscellaneous\r\n* Opacus can be installed with conda: added recipe in conda-forge (#326)\r\n* Formatting change in accordance with black-22.1.0","2022-02-09T23:25:14",{"id":232,"version":233,"summary_zh":234,"released_at":235},323692,"v1.0.1","### Bug fixes\r\n* Hidden states of RNN is passed to device (#314)\r\n* Validate and fix trainable modules only (#316)\r\n### Miscellaneous\r\n* Minor corrections and typo fixes in links, documentation, and tutorials.","2022-01-04T00:19:01",{"id":237,"version":238,"summary_zh":239,"released_at":240},323693,"v1.0.0","We are excited to announce the release of Opacus 1.0. This release packs in lot of new features and bug fixes, and most importantly, brings forth new APIs that are simpler, more modular, and easily extensible.\r\n\r\nWe have bumped up the major version number from 0 to 1 and have introduced breaking changes; although, the major version bump also indicates a step-function upgrade in the capabilities.\r\n\r\n\r\n## What's new?\r\n\r\nWith this release we're introducing a slightly different approach to the user-facing library API. While heavily based on the old API, updated API better represents abstractions and algorithms used in DP in ML, enabling private training exactly as it's described in the papers, with no assumptions or simplifications. And in doing so we maintain our focus on high performance training.\r\n\r\n\r\n## Clearer semantics\r\n\r\nPreviously, `PrivacyEngine` accepted model as an argument, and then needed to be explicitly attached to `optimizer`. While simple, it wasn't very clear. The new syntax brings abundant clarity with an explicit `make_private()` method.\r\n\r\n\u003Ctable>\r\n    \u003Ctr>\u003Cth> Opacus 0.x \u003C\u002Fth>\u003Cth> Opacus 1.0 \u003C\u002Fth>\u003C\u002Ftr>\r\n    \u003Ctr>\u003Ctd width=\"42%\">\r\n\r\n```python\r\nprivacy_engine = PrivacyEngine(\r\n    model,\r\n    sample_rate=0.01,\r\n    alphas=[10, 100],\r\n    noise_multiplier=1.3,\r\n    max_grad_norm=1.0,\r\n)\r\nprivacy_engine.attach(optimizer)\r\n```\r\n\u003C\u002Ftd>\r\n\u003Ctd width=\"42%\">\r\n\r\n```python\r\nprivacy_engine = PrivacyEngine()\r\nmodel, optimizer, data_loader = privacy_engine.make_private(\r\n    module=model,\r\n    optimizer=optimizer,\r\n    data_loader=data_loader,\r\n    noise_multiplier=1.1,\r\n    max_grad_norm=1.0,\r\n)\r\n```\r\n\u003C\u002Ftd>\r\n\u003C\u002Ftr>\r\n\u003C\u002Ftable>\r\n\r\nTo avoid mutually exclusive method parameters, we're now providing separate method to initialize training loop if epsilon is to be provided instead of noise_multiplier\r\n\r\n```python\r\nmodel, optimizer, data_loader = privacy_engine.make_private_with_epsilon(\r\n    module=model,\r\n    optimizer=optimizer,\r\n    data_loader=data_loader,\r\n    epochs=EPOCHS,\r\n    target_epsilon=EPSILON,\r\n    target_delta=DELTA,\r\n    max_grad_norm=MAX_GRAD_NORM,\r\n)\r\n```\r\n\r\n\r\n## Increased focus on data handling\r\n\r\nYou might have noticed that we are now passing data loader to `make_private` in addition to module and optimizer. This is intentional. Batch sampling is an important component of DP-SGD (e.g. privacy accounting relies on amplification by sampling) and Poisson sampling is quite tricky to get right, so now Opacus takes control of three PyTorch training objects: model, optimizer, and data loader.\r\n\r\n\r\n## More modularised components\r\n\r\nThis release makes more functionalities modular, allowing for easy extensibility, while embracing cleaner semantics:\r\n\r\n* model is wrapped with `GradSampleModule`, which computes per sample gradients.\r\n* optimizer is wrapped with `DPOptimizer`, which does gradient clipping and noise addition.\r\n* data loader is transformed to a `DPDataLoader`, which performs uniform-with-replacement batch sampling, as required by privacy accountant.\r\n* Module validation and fix follows the same pattern as `GradSampleModule` resulting in compartmentalized validation code that is easily extensible and over-rideable.\r\n\r\n\r\n## Privacy analysis\r\n\r\nPrivacy analysis functions are now promoted into an `Accounant` class allowing for a more generic API. This has already allowed us to implement two accountants: RDP (default and recommended one) and Gaussian DP accountant; and will enable you to add more without having to worry about messing with the core library.\r\n\r\n```diff python\r\n- eps, alpha = privacy_engine.get_privacy_spent(delta=target_delta)\r\n+ eps = privacy_engine.get_epsilon(delta=target_delta)\r\n```\r\n\r\n\r\n## Working around device memory\r\n\r\nTraining with Opacus consumes more memory as it needs to keep track of per-sample gradients. Opacus 0.x featured the concept of virtual steps - you could decouple the logical batch size (that defined how often model weights are updated and how much DP noise is added) and physical batch size (that defined the maximum physical batch size processed by the model at any one time). While the concept is extremely useful, it suffers from serious flaws when used with Poisson sampling. Opacus 1.0 introduces a `BatchMemoryManager` for your dataloader, which takes care of the logical and physical batch sizes internally.\r\n\r\n\r\n## Dynamic privacy parameters\r\n\r\nOpacus now supports changes to the privacy parameters during training, and adjusts the privacy accounting accordingly.\r\nUse various schedulers provided in `opacus.scheduler` module to adjust the amount of noise during training (the implementation mimics the interface of `lr_schedulers`). \r\nFor all the other parameters Opacus supports subsequent calls to `make_private` method, while maintaining consistent privacy accounting.\r\n\r\n\r\n## Designed to be extensible\r\n\r\nOpacus 1.0 is designed to be flexible and extensible.\r\n\r\n* `GradSampleModule` supports user-provided grad samplers for custom modules.\r\n* `DPOptimizer` [can easil","2021-12-01T08:54:00",{"id":242,"version":243,"summary_zh":244,"released_at":245},323694,"v0.15.0","### New Features\r\n* DDP support for faster distributed training (#196)\r\n* Support of GRU and RNN. Refactored LSTM implementation. (#222)\r\n* PyTorch Lightning Demo (#244)\r\n### Bug fixes\r\n* Improve nn.Linear grad sampler memory consumption (#192)\r\n* Update Opacus to stop using deprecated torch.set_deterministic (#197)\r\n* Fix optimizer.step after engine.detach()\r\n* Test fixes\r\n### Miscellaneous\r\n* Better validation error reporting (#199)\r\n* grad sampler type checking (#241)","2021-11-25T01:26:21",{"id":247,"version":248,"summary_zh":249,"released_at":250},323695,"v0.14.0","### New features\r\n* Major refactoring - per-sample gradient computation is separated into its own module - GradSampleModule (#175)\r\n* Improved RDP to (eps, delta)-DP conversion (#162)\r\n* Multi-GPU support (#166)\r\n### Bug fixes\r\n* Handle empty batches in Poisson sampling (#164)\r\n* Fixed memory leak from no_grad execution (#180)","2021-06-23T16:51:29",{"id":252,"version":253,"summary_zh":254,"released_at":255},323696,"v0.13.0","## v0.13.0\r\n### New features\r\n* PackedSequence support for DPLSTM (#150) (thanks @touqir14 !)\r\n### Miscellaneous\r\n* Pytest moved to dev installation (#144)\r\n","2021-03-10T19:24:27",{"id":257,"version":258,"summary_zh":259,"released_at":260},323697,"v0.12.0","## v0.12.0\r\nThis version introduces a **mildly-breaking change**: the privacy engine will now support sampling with variable batch size, just like in the Abadi et al. paper. To accommodate this feature, we have made `batch_size` a kwarg (no longer positional). We are also enforcing that all kwargs must not be specified positionally. If you had code that passed kwargs positionally, you will find an error (which will be very simple to fix).\r\n### New features\r\n* Enforce kwargs to Privacy Engine (#136).\r\n* Fix batch construction and privacy engine (#128). (thanks @ConstanceBeguier!)\r\n* Compute required sigma to reach (epsilon, delta) budget (#126)\r\n* Friendly user message for unused parameters (#118).\r\n* Print helpful message when models are not in train mode (#113)\r\n### Bug fixes\r\n* Now the Opacus package has a `__version__` attribute.\r\n* Fix immer security issue, fix website errors\r\n* Updated setup.py version requirements to support 3.6.8 for Windows (#108) (thanks @madhavajay!)\r\n### Miscellaneous\r\n* Rewrote the grad_sample tests to use Hypothesis (#125). (thanks @touqir14!)","2021-03-03T01:02:20"]