[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-lezcano--geotorch":3,"tool-lezcano--geotorch":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",140436,2,"2026-04-05T23:32:43",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":80,"owner_email":80,"owner_twitter":80,"owner_website":80,"owner_url":81,"languages":82,"stars":87,"forks":88,"last_commit_at":89,"license":90,"difficulty_score":23,"env_os":91,"env_gpu":92,"env_ram":92,"env_deps":93,"category_tags":100,"github_topics":101,"view_count":10,"oss_zip_url":80,"oss_zip_packed_at":80,"status":16,"created_at":110,"updated_at":111,"faqs":112,"releases":138},955,"lezcano\u002Fgeotorch","geotorch","Constrained optimization toolkit for PyTorch","GeoTorch 是一个为 PyTorch 设计的约束优化工具库，专注于深度学习中的约束优化和流形优化。它让开发者能够轻松地在神经网络中添加各种数学约束，例如正交性、低秩矩阵或正定矩阵等，而无需修改训练代码或使用复杂的额外逻辑。只需在模型定义时声明约束条件，其余部分可以像普通 PyTorch 代码一样运行。\n\n它解决了深度学习模型中对参数施加特定结构约束的需求，比如确保权重矩阵具有某些数学性质。这类需求在研究中很常见，但实现起来通常复杂且容易出错。GeoTorch 提供了一种简洁优雅的解决方案，使得研究人员和开发者能够专注于模型设计，而不必担心底层实现细节。\n\nGeoTorch 非常适合从事深度学习研究的研究人员，以及需要构建特殊结构模型的开发者。无论是探索新型神经网络架构，还是优化现有模型性能，它都能提供强大的支持。其独特的亮点在于与 PyTorch 的无缝集成，支持所有优化器和模型层，并提供了丰富的预定义约束类型，如对称矩阵、正交矩阵、低秩矩阵等。此外，它的设计注重易用性，用户只需几行代码即可完成复杂约束的设置，大大降低了使用门槛。","GeoTorch\n========\n\n|Build| |Docs| |Codecov| |Codestyle Black| |License|\n\n    A library for constrained optimization and manifold optimization for deep learning in PyTorch\n\nOverview\n--------\n\nGeoTorch provides a simple way to perform constrained optimization and optimization on manifolds in PyTorch.\nIt is compatible out of the box with any optimizer, layer, and model implemented in PyTorch without any boilerplate in the training code. Just state the constraints when you construct the model and you are ready to go!\n\n.. code:: python\n\n    import torch\n    import torch.nn as nn\n    import geotorch\n\n    class Model(nn.Module):\n        def __init__(self):\n            super().__init__()\n            # One line suffices: Instantiate a linear layer with orthonormal columns\n            self.linear = nn.Linear(64, 128)\n            geotorch.orthogonal(self.linear, \"weight\")\n\n            # Works with tensors: Instantiate a CNN with kernels of rank 1\n            self.cnn = nn.Conv2d(16, 32, 3)\n            geotorch.low_rank(self.cnn, \"weight\", rank=1)\n\n            # Weights are initialized to a random value when you put the constraints, but\n            # you may re-initialize them to a different value by assigning to them\n            self.linear.weight = torch.eye(128, 64)\n            # And that's all you need to do. The rest is regular PyTorch code\n\n        def forward(self, x):\n            # self.linear is orthogonal and every 3x3 kernel in self.cnn is of rank 1\n\n    # Use the model as you would normally do. Everything just works\n    model = Model().cuda()\n\n    # Use your optimizer of choice. Any optimizer works out of the box with any parametrization\n    optim = torch.optim.Adam(model.parameters(), lr=lr)\n\nConstraints\n-----------\n\nThe following constraints are implemented and may be used as in the example above:\n\n- |symmetric|_. Symmetric matrices\n- |skew_constr|_. Skew-symmetric matrices\n- |sphere_constr|_. Vectors of norm ``1``\n- |orthogonal|_. Matrices with orthogonal columns\n- |grassmannian|_. Skew-symmetric matrices\n- |almost_orthogonal|_. Matrices with singular values in  the interval ``[1-λ, 1+λ]``\n- |invertible|_. Invertible matrices with positive determinant\n- |sln|_. Matrices of determinant equal to ``1``\n- |low_rank|_. Matrices of rank at most ``r``\n- |fixed_rank|_. Matrices of rank ``r``\n- |positive_definite|_. Positive definite matrices\n- |positive_semidefinite|_. Positive semidefinite matrices\n- |positive_semidefinite_low_rank|_. Positive semidefinite matrices of rank at most ``r``\n- |positive_semidefinite_fixed_rank|_. Positive semidefinite matrices of rank ``r``\n\n.. |symmetric| replace:: ``geotorch.symmetric``\n.. _symmetric: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.symmetric\n.. |skew_constr| replace:: ``geotorch.skew``\n.. _skew_constr: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.skew\n.. |sphere_constr| replace:: ``geotorch.sphere``\n.. _sphere_constr: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.sphere\n.. |orthogonal| replace:: ``geotorch.orthogonal``\n.. _orthogonal: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.orthogonal\n.. |grassmannian| replace:: ``geotorch.grassmannian``\n.. _grassmannian: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.grassmannian\n.. |almost_orthogonal| replace:: ``geotorch.almost_orthogonal(λ)``\n.. _almost_orthogonal: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.almost_orthogonal\n.. |invertible| replace:: ``geotorch.invertible``\n.. _invertible: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.invertible\n.. |sln| replace:: ``geotorch.sln``\n.. _sln: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.sln\n.. |low_rank| replace:: ``geotorch.low_rank(r)``\n.. _low_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.low_rank\n.. |fixed_rank| replace:: ``geotorch.fixed_rank(r)``\n.. _fixed_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.fixed_rank\n.. |positive_definite| replace:: ``geotorch.positive_definite``\n.. _positive_definite: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_definite\n.. |positive_semidefinite| replace:: ``geotorch.positive_semidefinite``\n.. _positive_semidefinite: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_semidefinite\n.. |positive_semidefinite_low_rank| replace:: ``geotorch.positive_semidefinite_low_rank(r)``\n.. _positive_semidefinite_low_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_semidefinite_low_rank\n.. |positive_semidefinite_fixed_rank| replace:: ``geotorch.positive_semidefinite_fixed_rank(r)``\n.. _positive_semidefinite_fixed_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_semidefinite_fixed_rank\n\nEach of these constraints have some extra parameters which can be used to tailor the\nbehavior of each constraint to the problem in hand. For more on this, see the documentation.\n\nThese constraints are a fronted for the families of spaces listed below.\n\nSupported Spaces\n----------------\n\nEach constraint in GeoTorch is implemented as a manifold. These give the user more flexibility\non the options that they choose for each parametrization. All these support Riemannian Gradient\nDescent (more on this `here`_), but they also support optimization via any other PyTorch optimizer.\n\nGeoTorch currently supports the following spaces:\n\n- |reals|_: ``Rⁿ``. Unrestricted optimization\n- |sym|_: Vector space of symmetric matrices\n- |skew|_: Vector space of skew-symmetric matrices\n- |sphere|_: Sphere in ``Rⁿ``. ``{ x ∈ Rⁿ | ||x|| = 1 } ⊂ Rⁿ``\n- |so|_: Manifold of ``n×n`` orthogonal matrices\n- |st|_: Manifold of ``n×k`` matrices with orthonormal columns\n- |almost|_: Manifold of ``n×k`` matrices with singular values in the interval ``[1-λ, 1+λ]``\n- |grass|_: Manifold of ``k``-dimensional subspaces in ``Rⁿ``\n- |glp|_: Manifold of invertible ``n×n`` matrices with positive determinant\n- |sl|_: Manifold of ``n×n`` matrices with determinant equal to `1`\n- |low|_: Variety of ``n×k`` matrices of rank ``r`` or less\n- |fixed|_: Manifold of ``n×k`` matrices of rank ``r``\n- |psd|_: Cone of ``n×n`` symmetric positive definite matrices\n- |pssd|_: Cone of ``n×n`` symmetric positive semi-definite matrices\n- |pssdlow|_: Variety of ``n×n`` symmetric positive semi-definite matrices of rank ``r`` or less\n- |pssdfixed|_: Manifold of ``n×n`` symmetric positive semi-definite matrices of rank ``r``\n- |product|_: Product of manifolds ``M₁ × ... × Mₖ``\n\nEvery space of dimension ``(n, k)`` can be applied to tensors of shape ``(*, n, k)``, so we also get efficient parallel implementations of product spaces such as\n\n- ``ObliqueManifold(n,k)``: Matrix with unit length columns, ``Sⁿ⁻¹ × ...ᵏ⁾ × Sⁿ⁻¹``\n\nUsing GeoTorch in your Code\n---------------------------\n\nThe files in `examples\u002Fcopying_problem.py`_ and `examples\u002Fsequential_mnist.py`_ serve as tutorials to see how to handle the initialization and usage of GeoTorch in some real code. They also show how to implement Riemannian Gradient Descent and some other tricks. For an introduction to how the library is actually implemented, see the Jupyter Notebook `examples\u002Fparametrisations.ipynb`_.\n\nYou may try GeoTorch installing it as\n\n.. code:: bash\n\n    pip install git+https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002F\n\nGeoTorch is tested in Linux, Mac, and Windows environments for Python >= 3.6 and supports PyTorch >= 1.9\n\nSharing Weights, Parametrizations, and Normalizing Flows\n--------------------------------------------------------\n\nIf one wants to use a parametrized tensor in different places in their model, or uses one parametrized layer many times, for example in an RNN, it is recommended to wrap the forward pass as follows to avoid each parametrization to be computed many times:\n\n.. code:: python\n\n    with geotorch.parametrize.cached():\n        logits = model(input_)\n\nOf course, this ``with`` statement may be used simply inside the forward function where the parametrized layer is used several times.\n\nThese ideas fall in the context of parametrized optimization, where one wraps a tensor ``X`` with a function ``f``, and rather than using ``X``, uses ``f(X)``. Particular examples of this idea are pruning, weight normalization, and spectral normalization among others. This repository implements a framework to approach this kind of problems. This framework was accepted to core PyTorch 1.8. It can be found under `torch.nn.utils.parametrize`_ and `torch.nn.utils.parametrizations`_. When using PyTorch 1.10 or higher, the native PyTorch functions are used within GeoTorch. In this case, the user can interact with the parametrizations in GeoTorch using the PyTorch functions.\n\nAs every space in GeoTorch is, at its core, a map from a flat space into a manifold, the tools implemented here also serve as a building block in normalizing flows. Using a factorized space such as |low|_ it is direct to compute the determinant of the transformation it defines, as we have direct access to the singular values of the layer.\n\n.. |reals| replace:: ``Rn(n)``\n.. _reals: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fvector_spaces\u002Freals.html\n.. |sym| replace:: ``Sym(n)``\n.. _sym: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fvector_spaces\u002Fsymmetric.html\n.. |skew| replace:: ``Skew(n)``\n.. _skew: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fvector_spaces\u002Fskew.html\n.. |sphere| replace:: ``Sphere(n)``\n.. _sphere: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fsphere.html\n.. |so| replace:: ``SO(n)``\n.. _so: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fso.html\n.. |st| replace:: ``St(n,k)``\n.. _st: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fstiefel.html\n.. |almost| replace:: ``AlmostOrthogonal(n,k,λ)``\n.. _almost: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Falmostorthogonal.html\n.. |grass| replace:: ``Gr(n,k)``\n.. _grass: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fgrassmannian.html\n.. |glp| replace:: ``GLp(n)``\n.. _glp: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Finvertibility\u002Fglp.html\n.. |sl| replace:: ``SL(n)``\n.. _sl: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Finvertibility\u002Fsl.html\n.. |low| replace:: ``LowRank(n,k,r)``\n.. _low: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Flowrank\u002Flowrank.html\n.. |fixed| replace:: ``FixedRank(n,k,r)``\n.. _fixed: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Flowrank\u002Ffixedrank.html\n.. |psd| replace:: ``PSD(n)``\n.. _psd: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpsd.html\n.. |pssd| replace:: ``PSSD(n)``\n.. _pssd: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpssd.html\n.. |pssdlow| replace:: ``PSSDLowRank(n,r)``\n.. _pssdlow: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpssdlowrank.html\n.. |pssdfixed| replace:: ``PSSDFixedRank(n,r)``\n.. _pssdfixed: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpssdfixedrank.html\n.. |product| replace:: ``ProductManifold(M₁, ..., Mₖ)``\n.. _product: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fproduct.html\n\n\nBibliography\n------------\n\nPlease cite the following work if you found GeoTorch useful. This paper exposes a simplified mathematical explanation of part of the inner-workings of GeoTorch.\n\n.. code:: bibtex\n\n    @inproceedings{lezcano2019trivializations,\n        title = {Trivializations for gradient-based optimization on manifolds},\n        author = {Lezcano-Casado, Mario},\n        booktitle={Advances in Neural Information Processing Systems, NeurIPS},\n        pages = {9154--9164},\n        year = {2019},\n    }\n\n\n.. |Build| image:: https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fworkflows\u002FBuild\u002Fbadge.svg\n   :target: https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fworkflows\u002FBuild\u002Fbadge.svg\n   :alt: Build\n.. |Docs| image:: https:\u002F\u002Freadthedocs.org\u002Fprojects\u002Fgeotorch\u002Fbadge\u002F?version=latest\n   :target: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002F?badge=latest\n.. |Codecov| image:: https:\u002F\u002Fcodecov.io\u002Fgh\u002FLezcano\u002Fgeotorch\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg?token=1AKM2EQ7RT\n   :target: https:\u002F\u002Fcodecov.io\u002Fgh\u002FLezcano\u002Fgeotorch\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg?token=1AKM2EQ7RT\n   :alt: Code coverage\n.. |Codestyle Black| image:: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fcode%20style-black-000000.svg\n   :target: https:\u002F\u002Fgithub.com\u002Fambv\u002Fblack\n   :alt: Codestyle Black\n.. |License| image:: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-green.svg\n   :target: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002FLICENSE\n   :alt: License\n\n.. _here: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fcopying_problem.py#L16\n.. _torch.nn.utils.parametrize: https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.utils.parametrize.register_parametrization.html\n.. _torch.nn.utils.parametrizations: https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.utils.parametrizations.orthogonal.html\n.. _geotorch\u002Fparametrize.py: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fgeotorch\u002Fparametrize.py\n.. _examples\u002Fsequential_mnist.py: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fsequential_mnist.py\n.. _examples\u002Fcopying_problem.py: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fcopying_problem.py\n.. _examples\u002Fparametrisations.ipynb: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fparametrisations.ipynb\n\n","GeoTorch\n========\n\n|Build| |Docs| |Codecov| |Codestyle Black| |License|\n\n    一个用于在 PyTorch 中进行约束优化和流形优化（manifold optimization）的深度学习库\n\n概述\n--------\n\nGeoTorch 提供了一种简单的方法，可以在 PyTorch 中执行约束优化和流形优化。  \n它开箱即用，兼容任何在 PyTorch 中实现的优化器、层和模型，无需在训练代码中添加任何样板代码。只需在构建模型时声明约束条件，就可以直接开始使用！\n\n.. code:: python\n\n    import torch\n    import torch.nn as nn\n    import geotorch\n\n    class Model(nn.Module):\n        def __init__(self):\n            super().__init__()\n            # 只需一行代码：实例化一个具有正交列的线性层\n            self.linear = nn.Linear(64, 128)\n            geotorch.orthogonal(self.linear, \"weight\")\n\n            # 支持张量：实例化一个秩为 1 的卷积核 CNN\n            self.cnn = nn.Conv2d(16, 32, 3)\n            geotorch.low_rank(self.cnn, \"weight\", rank=1)\n\n            # 在施加约束时，权重会被初始化为随机值，\n            # 但您可以通过赋值重新初始化它们\n            self.linear.weight = torch.eye(128, 64)\n            # 就是这么简单。剩下的就是常规的 PyTorch 代码了\n\n        def forward(self, x):\n            # self.linear 是正交的，self.cnn 中每个 3x3 卷积核的秩为 1\n\n    # 像平常一样使用模型。一切都正常工作\n    model = Model().cuda()\n\n    # 使用您选择的优化器。任何优化器都可以与任何参数化方法无缝协作\n    optim = torch.optim.Adam(model.parameters(), lr=lr)\n\n约束条件\n-----------\n\n以下约束条件已实现，并可像上面的示例一样使用：\n\n- |symmetric|_. 对称矩阵\n- |skew_constr|_. 反对称矩阵\n- |sphere_constr|_. 范数为 ``1`` 的向量\n- |orthogonal|_. 具有正交列的矩阵\n- |grassmannian|_. 反对称矩阵\n- |almost_orthogonal|_. 奇异值位于区间 ``[1-λ, 1+λ]`` 的矩阵\n- |invertible|_. 行列式为正的可逆矩阵\n- |sln|_. 行列式等于 ``1`` 的矩阵\n- |low_rank|_. 秩至多为 ``r`` 的矩阵\n- |fixed_rank|_. 秩为 ``r`` 的矩阵\n- |positive_definite|_. 正定矩阵\n- |positive_semidefinite|_. 半正定矩阵\n- |positive_semidefinite_low_rank|_. 秩至多为 ``r`` 的半正定矩阵\n- |positive_semidefinite_fixed_rank|_. 秩为 ``r`` 的半正定矩阵\n\n.. |symmetric| replace:: ``geotorch.symmetric``\n.. _symmetric: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.symmetric\n.. |skew_constr| replace:: ``geotorch.skew``\n.. _skew_constr: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.skew\n.. |sphere_constr| replace:: ``geotorch.sphere``\n.. _sphere_constr: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.sphere\n.. |orthogonal| replace:: ``geotorch.orthogonal``\n.. _orthogonal: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.orthogonal\n.. |grassmannian| replace:: ``geotorch.grassmannian``\n.. _grassmannian: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.grassmannian\n.. |almost_orthogonal| replace:: ``geotorch.almost_orthogonal(λ)``\n.. _almost_orthogonal: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.almost_orthogonal\n.. |invertible| replace:: ``geotorch.invertible``\n.. _invertible: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.invertible\n.. |sln| replace:: ``geotorch.sln``\n.. _sln: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.sln\n.. |low_rank| replace:: ``geotorch.low_rank(r)``\n.. _low_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.low_rank\n.. |fixed_rank| replace:: ``geotorch.fixed_rank(r)``\n.. _fixed_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.fixed_rank\n.. |positive_definite| replace:: ``geotorch.positive_definite``\n.. _positive_definite: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_definite\n.. |positive_semidefinite| replace:: ``geotorch.positive_semidefinite``\n.. _positive_semidefinite: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_semidefinite\n.. |positive_semidefinite_low_rank| replace:: ``geotorch.positive_semidefinite_low_rank(r)``\n.. _positive_semidefinite_low_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_semidefinite_low_rank\n.. |positive_semidefinite_fixed_rank| replace:: ``geotorch.positive_semidefinite_fixed_rank(r)``\n.. _positive_semidefinite_fixed_rank: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fconstraints.html#geotorch.positive_semidefinite_fixed_rank\n\n这些约束条件都有额外的参数，可以用来根据具体问题调整行为。更多内容请参阅文档。\n\n这些约束条件是以下列出的空间族的前端实现。\n\n支持的空间\n----------------\n\nGeoTorch 中的每个约束条件都实现为一个流形（manifold）。这为用户提供了更大的灵活性，可以选择每种参数化的选项。所有这些空间都支持黎曼梯度下降法（Riemannian Gradient Descent，更多信息请参见 `这里`_），但也支持通过任何其他 PyTorch 优化器进行优化。\n\nGeoTorch 当前支持以下空间：\n\n- |reals|_: ``Rⁿ``. 无限制优化\n- |sym|_: 对称矩阵的向量空间\n- |skew|_: 反对称矩阵的向量空间\n- |sphere|_: ``Rⁿ`` 中的球面。``{ x ∈ Rⁿ | ||x|| = 1 } ⊂ Rⁿ``\n- |so|_: ``n×n`` 正交矩阵的流形\n- |st|_: 具有正交列的 ``n×k`` 矩阵的流形\n- |almost|_: 奇异值位于区间 ``[1-λ, 1+λ]`` 的 ``n×k`` 矩阵的流形\n- |grass|_: ``Rⁿ`` 中 ``k`` 维子空间的流形\n- |glp|_: 行列式为正的可逆 ``n×n`` 矩阵的流形\n- |sl|_: 行列式等于 ``1`` 的 ``n×n`` 矩阵的流形\n- |low|_: 秩为 ``r`` 或更小的 ``n×k`` 矩阵的簇\n- |fixed|_: 秩为 ``r`` 的 ``n×k`` 矩阵的流形\n- |psd|_: ``n×n`` 对称正定矩阵的锥体\n- |pssd|_: ``n×n`` 对称半正定矩阵的锥体\n- |pssdlow|_: 秩为 ``r`` 或更小的 ``n×n`` 对称半正定矩阵的簇\n- |pssdfixed|_: 秩为 ``r`` 的 ``n×n`` 对称半正定矩阵的流形\n- |product|_: 流形的乘积 ``M₁ × ... × Mₖ``\n\n每个维度为 ``(n, k)`` 的空间都可以应用于形状为 ``(*, n, k)`` 的张量，因此我们还可以高效地实现并行化的乘积空间，例如：\n\n- ``ObliqueManifold(n,k)``: 具有单位长度列的矩阵，``Sⁿ⁻¹ × ...ᵏ⁾ × Sⁿ⁻¹``\n\n在您的代码中使用 GeoTorch\n---------------------------\n\n`examples\u002Fcopying_problem.py`_ 和 `examples\u002Fsequential_mnist.py`_ 文件作为教程，展示了如何在实际代码中处理 GeoTorch（几何优化工具包）的初始化和使用。它们还展示了如何实现黎曼梯度下降（Riemannian Gradient Descent）以及一些其他技巧。如果想了解该库的实际实现方式，请参阅 Jupyter Notebook 文件 `examples\u002Fparametrisations.ipynb`_。\n\n你可以通过以下方式安装 GeoTorch：\n\n.. code:: bash\n\n    pip install git+https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002F\n\nGeoTorch 在 Linux、Mac 和 Windows 环境下经过测试，支持 Python >= 3.6，并兼容 PyTorch >= 1.9。\n\n共享权重、参数化与归一化流\n--------------------------------------------------------\n\n如果希望在模型的不同地方使用一个参数化的张量，或者多次使用某个参数化的层（例如在 RNN 中），建议如下包装前向传播过程，以避免每个参数化被重复计算多次：\n\n.. code:: python\n\n    with geotorch.parametrize.cached():\n        logits = model(input_)\n\n当然，这个 ``with`` 语句也可以简单地用在前向函数中，特别是当参数化层被多次使用时。\n\n这些思想属于参数化优化（parametrized optimization）的范畴，其中将一个张量 ``X`` 包装在一个函数 ``f`` 中，而不是直接使用 ``X``，而是使用 ``f(X)``。这种思想的具体例子包括剪枝（pruning）、权重归一化（weight normalization）和谱归一化（spectral normalization）等。本仓库实现了一个框架来解决这类问题。该框架已被纳入 PyTorch 1.8 核心功能，可以在 `torch.nn.utils.parametrize`_ 和 `torch.nn.utils.parametrizations`_ 下找到。当使用 PyTorch 1.10 或更高版本时，GeoTorch 内部会使用原生的 PyTorch 函数。在这种情况下，用户可以使用 PyTorch 函数与 GeoTorch 中的参数化进行交互。\n\n由于 GeoTorch 中的每个空间本质上都是从平坦空间到流形的映射，因此这里实现的工具也可作为归一化流（normalizing flows）的构建模块。例如，使用像 |low|_ 这样的分解空间，可以直接计算其定义的变换的行列式，因为我们能够直接访问层的奇异值。\n\n.. |reals| replace:: ``Rn(n)``\n.. _reals: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fvector_spaces\u002Freals.html\n.. |sym| replace:: ``Sym(n)``\n.. _sym: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fvector_spaces\u002Fsymmetric.html\n.. |skew| replace:: ``Skew(n)``\n.. _skew: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fvector_spaces\u002Fskew.html\n.. |sphere| replace:: ``Sphere(n)``\n.. _sphere: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fsphere.html\n.. |so| replace:: ``SO(n)``\n.. _so: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fso.html\n.. |st| replace:: ``St(n,k)``\n.. _st: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fstiefel.html\n.. |almost| replace:: ``AlmostOrthogonal(n,k,λ)``\n.. _almost: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Falmostorthogonal.html\n.. |grass| replace:: ``Gr(n,k)``\n.. _grass: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fgrassmannian.html\n.. |glp| replace:: ``GLp(n)``\n.. _glp: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Finvertibility\u002Fglp.html\n.. |sl| replace:: ``SL(n)``\n.. _sl: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Finvertibility\u002Fsl.html\n.. |low| replace:: ``LowRank(n,k,r)``\n.. _low: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Flowrank\u002Flowrank.html\n.. |fixed| replace:: ``FixedRank(n,k,r)``\n.. _fixed: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Flowrank\u002Ffixedrank.html\n.. |psd| replace:: ``PSD(n)``\n.. _psd: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpsd.html\n.. |pssd| replace:: ``PSSD(n)``\n.. _pssd: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpssd.html\n.. |pssdlow| replace:: ``PSSDLowRank(n,r)``\n.. _pssdlow: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpssdlowrank.html\n.. |pssdfixed| replace:: ``PSSDFixedRank(n,r)``\n.. _pssdfixed: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fpsd\u002Fpssdfixedrank.html\n.. |product| replace:: ``ProductManifold(M₁, ..., Mₖ)``\n.. _product: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Fproduct.html\n\n\n参考文献\n------------\n\n如果你发现 GeoTorch 有用，请引用以下工作。这篇论文提供了一个简化的数学解释，部分揭示了 GeoTorch 的内部工作机制。\n\n.. code:: bibtex\n\n    @inproceedings{lezcano2019trivializations,\n        title = {Trivializations for gradient-based optimization on manifolds},\n        author = {Lezcano-Casado, Mario},\n        booktitle={Advances in Neural Information Processing Systems, NeurIPS},\n        pages = {9154--9164},\n        year = {2019},\n    }\n\n\n.. |Build| image:: https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fworkflows\u002FBuild\u002Fbadge.svg\n   :target: https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fworkflows\u002FBuild\u002Fbadge.svg\n   :alt: Build\n.. |Docs| image:: https:\u002F\u002Freadthedocs.org\u002Fprojects\u002Fgeotorch\u002Fbadge\u002F?version=latest\n   :target: https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002F?badge=latest\n   :alt: 文档\n.. |Codecov| image:: https:\u002F\u002Fcodecov.io\u002Fgh\u002FLezcano\u002Fgeotorch\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg?token=1AKM2EQ7RT\n   :target: https:\u002F\u002Fcodecov.io\u002Fgh\u002FLezcano\u002Fgeotorch\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg?token=1AKM2EQ7RT\n   :alt: 代码覆盖率\n.. |Codestyle Black| image:: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fcode%20style-black-000000.svg\n   :target: https:\u002F\u002Fgithub.com\u002Fambv\u002Fblack\n   :alt: 黑色代码风格\n.. |License| image:: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-green.svg\n   :target: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002FLICENSE\n   :alt: 许可证\n\n.. _here: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fcopying_problem.py#L16\n.. _torch.nn.utils.parametrize: https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.utils.parametrize.register_parametrization.html\n.. _torch.nn.utils.parametrizations: https:\u002F\u002Fpytorch.org\u002Fdocs\u002Fstable\u002Fgenerated\u002Ftorch.nn.utils.parametrizations.orthogonal.html\n.. _geotorch\u002Fparametrize.py: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fgeotorch\u002Fparametrize.py\n.. _examples\u002Fsequential_mnist.py: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fsequential_mnist.py\n.. _examples\u002Fcopying_problem.py: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fcopying_problem.py\n.. _examples\u002Fparametrisations.ipynb: https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002Fblob\u002Fmaster\u002Fexamples\u002Fparametrisations.ipynb","# GeoTorch 快速上手指南\n\nGeoTorch 是一个用于 PyTorch 的约束优化和流形优化库，支持在深度学习模型中轻松实现各种约束。\n\n---\n\n## 环境准备\n\n### 系统要求\n- 操作系统：Linux、Mac 或 Windows\n- Python 版本：>= 3.6\n- PyTorch 版本：>= 1.9\n\n### 前置依赖\n确保已安装以下依赖：\n- PyTorch（推荐使用最新稳定版本）\n- Git（用于从源码安装）\n\n---\n\n## 安装步骤\n\n通过以下命令安装 GeoTorch：\n\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002F\n```\n\n如果需要加速安装，可以尝试使用国内镜像源（如阿里云）：\n\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002FLezcano\u002Fgeotorch\u002F -i https:\u002F\u002Fmirrors.aliyun.com\u002Fpypi\u002Fsimple\n```\n\n---\n\n## 基本使用\n\n以下是一个简单的示例，展示如何在模型中使用 GeoTorch 添加约束：\n\n```python\nimport torch\nimport torch.nn as nn\nimport geotorch\n\nclass Model(nn.Module):\n    def __init__(self):\n        super().__init__()\n        # 创建一个具有正交列的线性层\n        self.linear = nn.Linear(64, 128)\n        geotorch.orthogonal(self.linear, \"weight\")\n\n        # 创建一个秩为 1 的卷积层\n        self.cnn = nn.Conv2d(16, 32, 3)\n        geotorch.low_rank(self.cnn, \"weight\", rank=1)\n\n        # 可以重新初始化权重\n        self.linear.weight = torch.eye(128, 64)\n\n    def forward(self, x):\n        # self.linear 是正交的，self.cnn 的每个 3x3 核是秩为 1 的\n        return self.linear(x)\n\n# 实例化模型并移动到 GPU\nmodel = Model().cuda()\n\n# 使用任意优化器，无需额外配置\noptim = torch.optim.Adam(model.parameters(), lr=0.001)\n```\n\n---\n\n以上代码展示了如何在模型中添加正交性和低秩约束，并正常训练模型。更多约束类型和高级用法，请参考 [官方文档](https:\u002F\u002Fgeotorch.readthedocs.io\u002F)。","一位深度学习工程师正在开发一个用于医学影像分类的卷积神经网络（CNN），需要确保模型的权重满足特定约束以提高稳定性和可解释性。\n\n### 没有 geotorch 时\n- **手动实现约束逻辑**：工程师需要自己编写代码来确保卷积层的权重矩阵满足低秩约束，这不仅增加了开发工作量，还容易引入错误。\n- **训练过程复杂化**：为了在每次参数更新后重新施加约束，工程师必须修改优化器的更新步骤，导致训练流程变得难以维护。\n- **性能调优困难**：由于手动实现的约束可能不够高效，模型的训练速度受到影响，尤其是在大规模数据集上表现尤为明显。\n- **兼容性问题**：自定义约束代码可能无法很好地与现有的 PyTorch 层或优化器配合，进一步增加了调试和优化的难度。\n\n### 使用 geotorch 后\n- **一键添加约束**：通过简单的 `geotorch.low_rank` 调用，工程师可以轻松为卷积层添加低秩约束，无需编写额外代码，显著减少了开发时间。\n- **无缝集成优化器**：geotorch 的约束机制与 PyTorch 原生优化器完全兼容，工程师无需修改训练流程，保持了代码的简洁性和可维护性。\n- **高效的约束实现**：geotorch 内部经过优化，能够在保证约束条件的同时最小化对训练速度的影响，提升了整体效率。\n- **广泛的约束支持**：除了低秩约束，工程师还可以方便地尝试其他约束（如正交性或正定性），快速探索不同约束对模型性能的影响。\n\ngeotorch 让工程师专注于模型设计本身，而无需为复杂的约束实现分心，从而显著提高了开发效率和模型质量。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flezcano_geotorch_63b22d18.png","lezcano","Mario Lezcano Casado","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Flezcano_4f1ab620.jpg","compilers go brrrr","OpenAI",null,"https:\u002F\u002Fgithub.com\u002Flezcano",[83],{"name":84,"color":85,"percentage":86},"Python","#3572A5",100,708,35,"2026-03-25T02:06:08","MIT","Linux, macOS, Windows","未说明",{"notes":94,"python":95,"dependencies":96},"需要通过 pip 安装 geotorch，支持 PyTorch 1.9 及以上版本。建议在使用时参考官方文档中的示例代码和教程。",">=3.6",[97,98,99],"torch>=1.9","torch.nn.utils.parametrize","torch.nn.utils.parametrizations",[13],[102,103,104,105,106,107,108,109],"pytorch","constrained-optimization","manifold-optimization","orthogonality","invertible-neural-networks","positive-definite-matrices","positive-semi-definite","low-rank","2026-03-27T02:49:30.150509","2026-04-06T11:32:02.784231",[113,118,123,128,133],{"id":114,"question_zh":115,"answer_zh":116,"source_url":117},4215,"在大型张量上使用 geotorch 的正交参数化时性能很差，如何解决？","这是预期行为，建议使用 PyTorch 核心中的 `householder` 参数化方法替代。可以尝试以下代码：\n```python\nfrom torch.nn.utils.parametrizations import orthogonal\northogonal(layer, \"weight\")\n```\n如果问题仍然存在，请考虑切换到 GPU 或使用双精度计算（尽管这会降低性能）。","https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fissues\u002F30",{"id":119,"question_zh":120,"answer_zh":121,"source_url":122},4216,"为什么 geotorch 使用欧几里得优化器而不是几何优化器来优化几何参数？","geotorch 的设计允许直接使用 PyTorch 的标准优化器（如 SGD 或 Adam）来优化几何参数。这种设计简化了实现，并利用了自动微分的能力。如果需要更高的精度，可以通过以下方式检查正交性：\n```python\nW = model.rnn.recurrent_kernel.weight\nprint(torch.dist(W.T @ W, torch.eye(W.shape[-1], device=W.device)))\n```","https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fissues\u002F26",{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},4217,"如何在卷积层的权重上施加正交约束？","可以通过自定义 `FlattenedStiefel` 类来实现。以下是完整代码示例：\n```python\nfrom numpy import prod\nimport torch\nimport torch.nn as nn\nimport geotorch\n\ndef size_flattened(size, dim):\n    size = list(size)\n    size_dim = size[dim]\n    size[dim] = 1\n    return (size_dim, prod(size))\n\nclass FlattenedStiefel(geotorch.Stiefel):\n    def __init__(self, size, triv=\"expm\"):\n        super().__init__(size_flattened(size, 0), triv)\n        self.size = list(size)\n        self.transposed = self.size[0] \u003C prod(self.size[1:])\n\n    def _unfold(self, X):\n        return X.flatten(1)\n\n    def _fold(self, X):\n        return X.view(self.size)\n\n    def forward(self, X):\n        X = self._unfold(X)\n        X = super().forward(X)\n        return self._fold(X)\n```\n确保在注册约束之前测试 `forward` 和 `right_inverse` 方法。","https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fissues\u002F38",{"id":129,"question_zh":130,"answer_zh":131,"source_url":132},4218,"在超网络中使用 geotorch 的正交约束时，为什么每次调用前向方法时权重都会变化？","这是因为每次应用约束时，权重会被重新初始化为随机采样的正交矩阵。可以通过手动设置初始权重来避免此行为。例如：\n```python\nwith torch.no_grad():\n    layer.weight.copy_(initial_orthogonal_matrix)\ngeotorch.orthogonal(layer, \"weight\")\n```\n更多细节请参考 [官方文档](https:\u002F\u002Fgeotorch.readthedocs.io\u002Fen\u002Flatest\u002Forthogonal\u002Fstiefel.html#geotorch.Stiefel.sample)。","https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fissues\u002F12",{"id":134,"question_zh":135,"answer_zh":136,"source_url":137},4219,"是否有计划将 geotorch 移植到 Jax？","目前没有官方移植计划，但 geotorch 的核心思想是通过自动微分维护约束。你可以参考 `Symmetric` 或 `Skew` 类的实现，尝试在 Jax 中实现类似功能。具体来说，geotorch 是通过映射矩形矩阵到正交矩阵等约束空间来工作的。","https:\u002F\u002Fgithub.com\u002Flezcano\u002Fgeotorch\u002Fissues\u002F29",[139,144,149],{"id":140,"version":141,"summary_zh":142,"released_at":143},113359,"0.3.0","GeoTorch now is fully compatible with `torch.nn.utils.parametrize` and it uses it whenever possible.","2021-11-14T21:53:26",{"id":145,"version":146,"summary_zh":147,"released_at":148},113360,"0.2.0","# More flexible initialisation\r\nThe current release implements a number of important changes\r\n- Now it's possible to initialise a constraint to a fixed matrix by simply assigning to the constrained weight\r\n- Complete rewrite of the logic that allowed to heavily simplify it\r\n- Updated to be compatible with `torch.nn.utils.parametrize`, which will be part of PyTorch 1.9\r\n- Added many new spaces\r\n- More thorough testing. All the possible constructions are now tested for every manifold\r\n","2021-06-01T13:35:59",{"id":150,"version":151,"summary_zh":152,"released_at":153},113361,"0.1.0","# Initial release\r\n\r\nImplements the following manifolds:\r\n- ``Rn(n)``: Rⁿ. Unrestricted optimization\r\n- ``Sym(n)``: Vector space of symmetric matrices\r\n- ``Skew(n)``: Vector space of skew-symmetric matrices\r\n- ``Sphere(n)``: Sphere in Rⁿ. It is Sⁿ⁻¹ = { x ∈ Rⁿ | ||x|| = 1 }\r\n- ``SO(n)``: Manifold of n×n orthogonal matrices\r\n- ``Stiefel(n,k)``: Manifold of n×k matrices with orthonormal columns\r\n- ``Grassmannian(n,k)``: Manifold of k-dimensional subspaces in Rⁿ\r\n- ``LowRank(n,k,r)``: Variety of n×k matrices of rank r or less\r\n\r\nAnd the following constructions:\r\n- ``Manifold``: Manifold that supports Riemannian Gradient Descent and trivializations\r\n- ``Fibration``: Fibred space π : E → M, constructed from a ``Manifold`` E, a submersion π and local sections of dπ\r\n- ``ProductManifold``: M₁ × ... × Mₖ","2020-07-13T17:46:47"]