Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"如何为Diffusers 🧨做贡献","local":"如何为diffusers-做贡献","sections":[{"title":"概述","local":"概述","sections":[{"title":"1. 在Diffusers讨论区或Discord提问与解答","local":"1-在diffusers讨论区或discord提问与解答","sections":[],"depth":3},{"title":"2. 在GitHub议题页提交新议题","local":"2-在github议题页提交新议题","sections":[{"title":"2.1 可复现的最小化错误报告","local":"21-可复现的最小化错误报告","sections":[],"depth":4},{"title":"2.2 功能请求","local":"22-功能请求","sections":[],"depth":4},{"title":"2.3 设计反馈","local":"23-设计反馈","sections":[],"depth":4},{"title":"2.4 技术问题","local":"24-技术问题","sections":[],"depth":4},{"title":"2.5 新模型/调度器/pipeline提案","local":"25-新模型调度器pipeline提案","sections":[],"depth":4}],"depth":3},{"title":"3. 解答GitHub问题","local":"3-解答github问题","sections":[],"depth":3},{"title":"4. 修复”Good first issue”类问题","local":"4-修复good-first-issue类问题","sections":[],"depth":3},{"title":"5. 文档贡献","local":"5-文档贡献","sections":[],"depth":3},{"title":"6. 贡献社区流程","local":"6-贡献社区流程","sections":[],"depth":3},{"title":"7. 贡献训练示例","local":"7-贡献训练示例","sections":[],"depth":3},{"title":"8. 处理”Good second issue”类问题","local":"8-处理good-second-issue类问题","sections":[],"depth":3},{"title":"9. 添加管道、模型和调度器","local":"9-添加管道模型和调度器","sections":[{"title":"复制机制(Copied from)","local":"复制机制copied-from","sections":[],"depth":4}],"depth":3}],"depth":2},{"title":"如何撰写优质问题","local":"如何撰写优质问题","sections":[],"depth":2},{"title":"优质PR编写规范","local":"优质pr编写规范","sections":[],"depth":2},{"title":"提交PR流程","local":"提交pr流程","sections":[{"title":"测试","local":"测试","sections":[],"depth":3},{"title":"将派生仓库的 main 分支与上游(HuggingFace)main 分支同步","local":"将派生仓库的-main-分支与上游huggingfacemain-分支同步","sections":[],"depth":3},{"title":"风格指南","local":"风格指南","sections":[],"depth":3}],"depth":2}],"depth":1}"> | |
| <link href="/docs/diffusers/pr_11739/zh/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/entry/start.95a8faef.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/scheduler.e4ff9b64.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/singletons.0a6f1d19.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/index.f9be34a7.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/paths.37f6e25a.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/entry/app.a988cdaf.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/preload-helper.3e2c3f46.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/index.09f1bca0.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/nodes/0.0ec3fec6.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/nodes/3.6521e164.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.f5199cd9.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/CodeBlock.1680a1fd.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11739/zh/_app/immutable/chunks/HfOption.44827c7f.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"如何为Diffusers 🧨做贡献","local":"如何为diffusers-做贡献","sections":[{"title":"概述","local":"概述","sections":[{"title":"1. 在Diffusers讨论区或Discord提问与解答","local":"1-在diffusers讨论区或discord提问与解答","sections":[],"depth":3},{"title":"2. 在GitHub议题页提交新议题","local":"2-在github议题页提交新议题","sections":[{"title":"2.1 可复现的最小化错误报告","local":"21-可复现的最小化错误报告","sections":[],"depth":4},{"title":"2.2 功能请求","local":"22-功能请求","sections":[],"depth":4},{"title":"2.3 设计反馈","local":"23-设计反馈","sections":[],"depth":4},{"title":"2.4 技术问题","local":"24-技术问题","sections":[],"depth":4},{"title":"2.5 新模型/调度器/pipeline提案","local":"25-新模型调度器pipeline提案","sections":[],"depth":4}],"depth":3},{"title":"3. 解答GitHub问题","local":"3-解答github问题","sections":[],"depth":3},{"title":"4. 修复”Good first issue”类问题","local":"4-修复good-first-issue类问题","sections":[],"depth":3},{"title":"5. 文档贡献","local":"5-文档贡献","sections":[],"depth":3},{"title":"6. 贡献社区流程","local":"6-贡献社区流程","sections":[],"depth":3},{"title":"7. 贡献训练示例","local":"7-贡献训练示例","sections":[],"depth":3},{"title":"8. 处理”Good second issue”类问题","local":"8-处理good-second-issue类问题","sections":[],"depth":3},{"title":"9. 添加管道、模型和调度器","local":"9-添加管道模型和调度器","sections":[{"title":"复制机制(Copied from)","local":"复制机制copied-from","sections":[],"depth":4}],"depth":3}],"depth":2},{"title":"如何撰写优质问题","local":"如何撰写优质问题","sections":[],"depth":2},{"title":"优质PR编写规范","local":"优质pr编写规范","sections":[],"depth":2},{"title":"提交PR流程","local":"提交pr流程","sections":[{"title":"测试","local":"测试","sections":[],"depth":3},{"title":"将派生仓库的 main 分支与上游(HuggingFace)main 分支同步","local":"将派生仓库的-main-分支与上游huggingfacemain-分支同步","sections":[],"depth":3},{"title":"风格指南","local":"风格指南","sections":[],"depth":3}],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 max-sm:gap-0.5 h-6 max-sm:h-5 px-2 max-sm:px-1.5 text-[11px] max-sm:text-[9px] font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0"><svg class="w-3 h-3 max-sm:w-2.5 max-sm:h-2.5" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-6 max-sm:h-5 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible w-3 h-3 max-sm:w-2.5 max-sm:h-2.5 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="如何为diffusers-做贡献" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#如何为diffusers-做贡献"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>如何为Diffusers 🧨做贡献</span></h1> <p data-svelte-h="svelte-1qn44q4">我们❤️来自开源社区的贡献!欢迎所有人参与,所有类型的贡献——不仅仅是代码——都受到重视和赞赏。回答问题、帮助他人、主动交流以及改进文档对社区都极具价值,所以如果您愿意参与,请不要犹豫!</p> <p data-svelte-h="svelte-xpok1k">我们鼓励每个人先在公开Discord频道里打招呼👋。在那里我们讨论扩散模型的最新趋势、提出问题、展示个人项目、互相协助贡献,或者只是闲聊☕。<a href="https://Discord.gg/G7tWnz98XR"><img alt="加入Discord社区" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a></p> <p data-svelte-h="svelte-7l4s9o">无论您选择以何种方式贡献,我们都致力于成为一个开放、友好、善良的社区。请阅读我们的<a href="https://github.com/huggingface/diffusers/blob/main/CODE_OF_CONDUCT.md" rel="nofollow">行为准则</a>,并在互动时注意遵守。我们也建议您了解指导本项目的<a href="https://huggingface.co/docs/diffusers/conceptual/ethical_guidelines" rel="nofollow">伦理准则</a>,并请您遵循同样的透明度和责任原则。</p> <p data-svelte-h="svelte-1n5851n">我们高度重视社区的反馈,所以如果您认为自己有能帮助改进库的有价值反馈,请不要犹豫说出来——每条消息、评论、issue和拉取请求(PR)都会被阅读和考虑。</p> <h2 class="relative group"><a id="概述" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#概述"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>概述</span></h2> <p data-svelte-h="svelte-1wvc5ur">您可以通过多种方式做出贡献,从在issue和讨论区回答问题,到向核心库添加新的diffusion模型。</p> <p data-svelte-h="svelte-16182hn">下面我们按难度升序列出不同的贡献方式,所有方式对社区都很有价值:</p> <ul data-svelte-h="svelte-5eac3r"><li><ol><li>在<a href="https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers" rel="nofollow">Diffusers讨论论坛</a>或<a href="https://discord.gg/G7tWnz98XR" rel="nofollow">Discord</a>上提问和回答问题</li></ol></li> <li><ol start="2"><li>在<a href="https://github.com/huggingface/diffusers/issues/new/choose" rel="nofollow">GitHub Issues标签页</a>提交新issue,或在<a href="https://github.com/huggingface/diffusers/discussions/new/choose" rel="nofollow">GitHub Discussions标签页</a>发起新讨论</li></ol></li> <li><ol start="3"><li>在<a href="https://github.com/huggingface/diffusers/issues" rel="nofollow">GitHub Issues标签页</a>解答issue,或在<a href="https://github.com/huggingface/diffusers/discussions" rel="nofollow">GitHub Discussions标签页</a>参与讨论</li></ol></li> <li><ol start="4"><li>解决标记为”Good first issue”的简单问题,详见<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22" rel="nofollow">此处</a></li></ol></li> <li><ol start="5"><li>参与<a href="https://github.com/huggingface/diffusers/tree/main/docs/source" rel="nofollow">文档</a>建设</li></ol></li> <li><ol start="6"><li>贡献<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3Acommunity-examples" rel="nofollow">社区Pipeline</a></li></ol></li> <li><ol start="7"><li>完善<a href="https://github.com/huggingface/diffusers/tree/main/examples" rel="nofollow">示例代码</a></li></ol></li> <li><ol start="8"><li>解决标记为”Good second issue”的中等难度问题,详见<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22Good+second+issue%22" rel="nofollow">此处</a></li></ol></li> <li><ol start="9"><li>添加新pipeline/模型/调度器,参见<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22" rel="nofollow">“New Pipeline/Model”</a>和<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22" rel="nofollow">“New scheduler”</a>类issue。此类贡献请先阅读<a href="https://github.com/huggingface/diffusers/blob/main/PHILOSOPHY.md" rel="nofollow">设计哲学</a></li></ol></li></ul> <p data-svelte-h="svelte-1onykq6">重申:<strong>所有贡献对社区都具有重要价值。</strong>下文将详细说明各类贡献方式。</p> <p data-svelte-h="svelte-11f9p20">对于4-9类贡献,您需要提交PR(拉取请求),具体操作详见<a href="#how-to-open-a-pr">如何提交PR</a>章节。</p> <h3 class="relative group"><a id="1-在diffusers讨论区或discord提问与解答" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#1-在diffusers讨论区或discord提问与解答"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>1. 在Diffusers讨论区或Discord提问与解答</span></h3> <p data-svelte-h="svelte-1usmksq">任何与Diffusers库相关的问题或讨论都可以发布在<a href="https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/" rel="nofollow">官方论坛</a>或<a href="https://discord.gg/G7tWnz98XR" rel="nofollow">Discord频道</a>,包括但不限于:</p> <ul data-svelte-h="svelte-1hr4s09"><li>分享训练/推理实验报告</li> <li>展示个人项目</li> <li>咨询非官方训练示例</li> <li>项目提案</li> <li>通用反馈</li> <li>论文解读</li> <li>基于Diffusers库的个人项目求助</li> <li>一般性问题</li> <li>关于diffusion模型的伦理讨论</li> <li>…</li></ul> <p data-svelte-h="svelte-36iqb6">论坛/Discord上的每个问题都能促使社区公开分享知识,很可能帮助未来遇到相同问题的初学者。请务必提出您的疑问。 | |
| 同样地,通过回答问题您也在为社区创造公共知识文档,这种贡献极具价值。</p> <p data-svelte-h="svelte-480kqf"><strong>请注意</strong>:提问/回答时投入的精力越多,产生的公共知识质量就越高。精心构建的问题与专业解答能形成高质量知识库,而表述不清的问题则可能降低讨论价值。</p> <p data-svelte-h="svelte-1eif8kx">低质量的问题或回答会降低公共知识库的整体质量。<br> | |
| 简而言之,高质量的问题或回答应具备<em>精确性</em>、<em>简洁性</em>、<em>相关性</em>、<em>易于理解</em>、<em>可访问性</em>和<em>格式规范/表述清晰</em>等特质。更多详情请参阅<a href="#how-to-write-a-good-issue">如何提交优质议题</a>章节。</p> <p data-svelte-h="svelte-142gyxy"><strong>关于渠道的说明</strong>:<br> <a href="https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63" rel="nofollow"><em>论坛</em></a>的内容能被谷歌等搜索引擎更好地收录,且帖子按热度而非时间排序,便于查找历史问答。此外,论坛内容更容易被直接链接引用。<br> | |
| 而<em>Discord</em>采用即时聊天模式,适合快速交流。虽然在Discord上可能更快获得解答,但信息会随时间淹没,且难以回溯历史讨论。因此我们强烈建议在论坛发布优质问答,以构建可持续的社区知识库。若Discord讨论产生有价值结论,建议将成果整理发布至论坛以惠及更多读者。</p> <h3 class="relative group"><a id="2-在github议题页提交新议题" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#2-在github议题页提交新议题"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2. 在GitHub议题页提交新议题</span></h3> <p data-svelte-h="svelte-13zxmq2">🧨 Diffusers库的稳健性离不开用户的问题反馈,感谢您的报错。</p> <p data-svelte-h="svelte-15g0idg">请注意:GitHub议题仅限处理与Diffusers库代码直接相关的技术问题、错误报告、功能请求或库设计反馈。<br> | |
| 简言之,<strong>与Diffusers库代码(含文档)无关</strong>的内容应发布至<a href="https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63" rel="nofollow">论坛</a>或<a href="https://discord.gg/G7tWnz98XR" rel="nofollow">Discord</a>。</p> <p data-svelte-h="svelte-1xijok8"><strong>提交新议题时请遵循以下准则</strong>:</p> <ul data-svelte-h="svelte-129r616"><li>确认是否已有类似议题(使用GitHub议题页的搜索栏)</li> <li>请勿在现有议题下追加新问题。若存在高度关联议题,应新建议题并添加相关链接</li> <li>确保使用英文提交。非英语用户可通过<a href="https://www.deepl.com/translator" rel="nofollow">DeepL</a>等免费工具翻译</li> <li>检查升级至最新Diffusers版本是否能解决问题。提交前请确认<code>python -c "import diffusers; print(diffusers.__version__)"</code>显示的版本号不低于最新版本</li> <li>记请记住,你在提交新issue时投入的精力越多,得到的回答质量就越高,Diffusers项目的整体issue质量也会越好。</li></ul> <p data-svelte-h="svelte-1cb6np7">新issue通常包含以下内容:</p> <h4 class="relative group"><a id="21-可复现的最小化错误报告" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#21-可复现的最小化错误报告"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2.1 可复现的最小化错误报告</span></h4> <p data-svelte-h="svelte-1bsld36">错误报告应始终包含可复现的代码片段,并尽可能简洁明了。具体而言:</p> <ul data-svelte-h="svelte-1wrfgbf"><li>尽量缩小问题范围,<strong>不要直接粘贴整个代码文件</strong></li> <li>规范代码格式</li> <li>除Diffusers依赖库外,不要包含其他外部库</li> <li><strong>务必</strong>提供环境信息:可在终端运行<code>diffusers-cli env</code>命令,然后将显示的信息复制到issue中</li> <li>详细说明问题。如果读者不清楚问题所在及其影响,就无法解决问题</li> <li><strong>确保</strong>读者能以最小成本复现问题。如果代码片段因缺少库或未定义变量而无法运行,读者将无法提供帮助。请确保提供的可复现代码尽可能精简,可直接复制到Python shell运行</li> <li>如需特定模型/数据集复现问题,请确保读者能获取这些资源。可将模型/数据集上传至<a href="https://huggingface.co" rel="nofollow">Hub</a>便于下载。尽量保持模型和数据集体积最小化,降低复现难度</li></ul> <p data-svelte-h="svelte-18lve1">更多信息请参阅<a href="#how-to-write-a-good-issue">如何撰写优质issue</a>章节。</p> <p data-svelte-h="svelte-12b70x8">提交错误报告请点击<a href="https://github.com/huggingface/diffusers/issues/new?assignees=&labels=bug&projects=&template=bug-report.yml" rel="nofollow">此处</a>。</p> <h4 class="relative group"><a id="22-功能请求" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#22-功能请求"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2.2 功能请求</span></h4> <p data-svelte-h="svelte-b10w78">优质的功能请求应包含以下要素:</p> <ol data-svelte-h="svelte-1xu51pt"><li>首先说明动机:</li></ol> <ul data-svelte-h="svelte-173awu3"><li>是否与库的使用痛点相关?若是,请解释原因,最好提供演示问题的代码片段</li> <li>是否因项目需求产生?我们很乐意了解详情!</li> <li>是否是你已实现且认为对社区有价值的功能?请说明它为你解决了什么问题</li></ul> <ol start="2" data-svelte-h="svelte-jdhjs6"><li>用<strong>完整段落</strong>描述功能特性</li> <li>提供<strong>代码片段</strong>演示预期用法</li> <li>如涉及论文,请附上链接</li> <li>可补充任何有助于理解的辅助材料(示意图、截图等)</li></ol> <p data-svelte-h="svelte-qt0ebo">提交功能请求请点击<a href="https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feature_request.md&title=" rel="nofollow">此处</a>。</p> <h4 class="relative group"><a id="23-设计反馈" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#23-设计反馈"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2.3 设计反馈</span></h4> <p data-svelte-h="svelte-bswle1">关于库设计的反馈(无论正面还是负面)能极大帮助核心维护者打造更友好的库。要了解当前设计理念,请参阅<a href="https://huggingface.co/docs/diffusers/conceptual/philosophy" rel="nofollow">此文档</a>如果您认为某个设计选择与当前理念不符,请说明原因及改进建议。如果某个设计选择因过度遵循理念而限制了使用场景,也请解释原因并提出调整方案。<br> | |
| 若某个设计对您特别实用,请同样留下备注——这对未来的设计决策极具参考价值。</p> <p data-svelte-h="svelte-r62n5s">您可通过<a href="https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feedback.md&title=" rel="nofollow">此链接</a>提交设计反馈。</p> <h4 class="relative group"><a id="24-技术问题" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#24-技术问题"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2.4 技术问题</span></h4> <p data-svelte-h="svelte-1cbux99">技术问题主要涉及库代码的实现逻辑或特定功能模块的作用。提问时请务必:</p> <ul data-svelte-h="svelte-19z1nhp"><li>附上相关代码链接</li> <li>详细说明难以理解的具体原因</li></ul> <p data-svelte-h="svelte-1fz735q">技术问题提交入口:<a href="https://github.com/huggingface/diffusers/issues/new?assignees=&labels=bug&template=bug-report.yml" rel="nofollow">点击此处</a></p> <h4 class="relative group"><a id="25-新模型调度器pipeline提案" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#25-新模型调度器pipeline提案"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>2.5 新模型/调度器/pipeline提案</span></h4> <p data-svelte-h="svelte-tcjkhp">若diffusion模型社区发布了您希望集成到Diffusers库的新模型、pipeline或调度器,请提供以下信息:</p> <ul data-svelte-h="svelte-umqmdj"><li>简要说明并附论文或发布链接</li> <li>开源实现链接(如有)</li> <li>模型权重下载链接(如已公开)</li></ul> <p data-svelte-h="svelte-1u7b98c">若您愿意参与开发,请告知我们以便指导。另请尝试通过GitHub账号标记原始组件作者。</p> <p data-svelte-h="svelte-jscy0t">提案提交地址:<a href="https://github.com/huggingface/diffusers/issues/new?assignees=&labels=New+model%2Fpipeline%2Fscheduler&template=new-model-addition.yml" rel="nofollow">新建请求</a></p> <h3 class="relative group"><a id="3-解答github问题" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#3-解答github问题"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>3. 解答GitHub问题</span></h3> <p data-svelte-h="svelte-42ae55">回答GitHub问题可能需要Diffusers的技术知识,但我们鼓励所有人尝试参与——即使您对答案不完全正确。高质量回答的建议:</p> <ul data-svelte-h="svelte-1un155y"><li>保持简洁精炼</li> <li>严格聚焦问题本身</li> <li>提供代码/论文等佐证材料</li> <li>优先用代码说话:若代码片段能解决问题,请提供完整可复现代码</li></ul> <p data-svelte-h="svelte-1he2xcp">许多问题可能存在离题、重复或无关情况。您可以通过以下方式协助维护者:</p> <ul data-svelte-h="svelte-1frj604"><li>引导提问者精确描述问题</li> <li>标记重复issue并附原链接</li> <li>推荐用户至<a href="https://discuss.huggingface.co/c/discussion-related-to-httpsgithubcomhuggingfacediffusers/63" rel="nofollow">论坛</a>或<a href="https://discord.gg/G7tWnz98XR" rel="nofollow">Discord</a></li></ul> <p data-svelte-h="svelte-d2n0yn">在确认提交的Bug报告正确且需要修改源代码后,请继续阅读以下章节内容。</p> <p data-svelte-h="svelte-a0wg0p">以下所有贡献都需要提交PR(拉取请求)。具体操作步骤详见<a href="#how-to-open-a-pr">如何提交PR</a>章节。</p> <h3 class="relative group"><a id="4-修复good-first-issue类问题" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#4-修复good-first-issue类问题"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>4. 修复”Good first issue”类问题</span></h3> <p data-svelte-h="svelte-tqr4n7">标有<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22" rel="nofollow">Good first issue</a>标签的问题通常已说明解决方案建议,便于修复。若该问题尚未关闭且您想尝试解决,只需留言”我想尝试解决这个问题”。通常有三种情况:</p> <ul data-svelte-h="svelte-1qa7szj"><li>a.) 问题描述已提出解决方案。若您认可该方案,可直接提交PR或草稿PR进行修复</li> <li>b.) 问题描述未提出解决方案。您可询问修复建议,Diffusers团队会尽快回复。若有成熟解决方案,也可直接提交PR</li> <li>c.) 已有PR但问题未关闭。若原PR停滞,可新开PR并关联原PR(开源社区常见现象)。若PR仍活跃,您可通过建议、审查或协作等方式帮助原作者</li></ul> <h3 class="relative group"><a id="5-文档贡献" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#5-文档贡献"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>5. 文档贡献</span></h3> <p data-svelte-h="svelte-84vwwb">优秀库<strong>必然</strong>拥有优秀文档!官方文档是新用户的首要接触点,因此文档贡献具有<strong>极高价值</strong>。贡献形式包括:</p> <ul data-svelte-h="svelte-1kj7pc4"><li>修正拼写/语法错误</li> <li>修复文档字符串格式错误(如显示异常或链接失效)</li> <li>修正文档字符串中张量的形状/维度描述</li> <li>优化晦涩或错误的说明</li> <li>更新过时代码示例</li> <li>文档翻译</li></ul> <p data-svelte-h="svelte-1lqmkwb"><a href="https://huggingface.co/docs/diffusers/index" rel="nofollow">官方文档页面</a>所有内容均属可修改范围,对应<a href="https://github.com/huggingface/diffusers/tree/main/docs/source" rel="nofollow">文档源文件</a>可进行编辑。修改前请查阅<a href="https://github.com/huggingface/diffusers/tree/main/docs" rel="nofollow">验证说明</a>。</p> <h3 class="relative group"><a id="6-贡献社区流程" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#6-贡献社区流程"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>6. 贡献社区流程</span></h3> <blockquote class="tip" data-svelte-h="svelte-1en0qnb"><p>阅读<a href="../using-diffusers/custom_pipeline_overview#community-pipelines">社区流程</a>指南了解GitHub与Hugging Face Hub社区流程的区别。若想了解我们设立社区流程的原因,请查看GitHub Issue <a href="https://github.com/huggingface/diffusers/issues/841" rel="nofollow">#841</a>(简而言之,我们无法维护diffusion模型所有可能的推理使用方式,但也不希望限制社区构建这些流程)。</p></blockquote> <p data-svelte-h="svelte-1d90lxf">贡献社区流程是向社区分享创意与成果的绝佳方式。您可以在<code>DiffusionPipeline</code>基础上构建流程,任何人都能通过设置<code>custom_pipeline</code>参数加载使用。本节将指导您创建一个简单的”单步”流程——UNet仅执行单次前向传播并调用调度器一次。</p> <ol data-svelte-h="svelte-1ilxxnd"><li><p>为社区流程创建one_step_unet.py文件。只要用户已安装相关包,该文件可包含任意所需包。确保仅有一个继承自<code>DiffusionPipeline</code>的流程类,用于从Hub加载模型权重和调度器配置。在<code>__init__</code>函数中添加UNet和调度器。</p> <p>同时添加<code>register_modules</code>函数,确保您的流程及其组件可通过<code>save_pretrained()</code>保存。</p></li></ol> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| <span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">UnetSchedulerOneForwardPipeline</span>(<span class="hljs-title class_ inherited__">DiffusionPipeline</span>): | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, unet, scheduler</span>): | |
| <span class="hljs-built_in">super</span>().__init__() | |
| self.register_modules(unet=unet, scheduler=scheduler)<!-- HTML_TAG_END --></pre></div> <ol start="2" data-svelte-h="svelte-cww69"><li>在前向传播中(建议定义为<code>__call__</code>),可添加任意功能。对于”单步”流程,创建随机图像并通过设置<code>timestep=1</code>调用UNet和调度器一次。</li></ol> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --> <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| <span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">UnetSchedulerOneForwardPipeline</span>(<span class="hljs-title class_ inherited__">DiffusionPipeline</span>): | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, unet, scheduler</span>): | |
| <span class="hljs-built_in">super</span>().__init__() | |
| self.register_modules(unet=unet, scheduler=scheduler) | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self</span>): | |
| image = torch.randn( | |
| (<span class="hljs-number">1</span>, self.unet.config.in_channels, self.unet.config.sample_size, self.unet.config.sample_size), | |
| ) | |
| timestep = <span class="hljs-number">1</span> | |
| model_output = self.unet(image, timestep).sample | |
| scheduler_output = self.scheduler.step(model_output, timestep, image).prev_sample | |
| <span class="hljs-keyword">return</span> scheduler_output<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-qsk5t1">现在您可以通过传入UNet和调度器来运行流程,若流程结构相同也可加载预训练权重。</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDPMScheduler, UNet2DModel | |
| scheduler = DDPMScheduler() | |
| unet = UNet2DModel() | |
| pipeline = UnetSchedulerOneForwardPipeline(unet=unet, scheduler=scheduler) | |
| output = pipeline() | |
| <span class="hljs-comment"># 加载预训练权重</span> | |
| pipeline = UnetSchedulerOneForwardPipeline.from_pretrained(<span class="hljs-string">"google/ddpm-cifar10-32"</span>, use_safetensors=<span class="hljs-literal">True</span>) | |
| output = pipeline()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-6z7qrw">您可以选择将pipeline作为GitHub社区pipeline或Hub社区pipeline进行分享。</p> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">GitHub pipeline </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Hub pipeline </div></div> <div class="language-select"><p data-svelte-h="svelte-to1fu5">通过向Diffusers<a href="https://github.com/huggingface/diffusers" rel="nofollow">代码库</a>提交拉取请求来分享GitHub pipeline,将one_step_unet.py文件添加到<a href="https://github.com/huggingface/diffusers/tree/main/examples/community" rel="nofollow">examples/community</a>子文件夹中。</p> </div> <h3 class="relative group"><a id="7-贡献训练示例" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#7-贡献训练示例"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>7. 贡献训练示例</span></h3> <p data-svelte-h="svelte-1h3x9m3">Diffusers训练示例是位于<a href="https://github.com/huggingface/diffusers/tree/main/examples" rel="nofollow">examples</a>目录下的训练脚本集合。</p> <p data-svelte-h="svelte-imrs1x">我们支持两种类型的训练示例:</p> <ul data-svelte-h="svelte-1rjzlhy"><li>官方训练示例</li> <li>研究型训练示例</li></ul> <p data-svelte-h="svelte-19dwwdd">研究型训练示例位于<a href="https://github.com/huggingface/diffusers/tree/main/examples/research_projects" rel="nofollow">examples/research_projects</a>,而官方训练示例包含<a href="https://github.com/huggingface/diffusers/tree/main/examples" rel="nofollow">examples</a>目录下除<code>research_projects</code>和<code>community</code>外的所有文件夹。 | |
| 官方训练示例由Diffusers核心维护者维护,研究型训练示例则由社区维护。 | |
| 这与<a href="#6-contribute-a-community-pipeline">6. 贡献社区pipeline</a>中关于官方pipeline与社区pipeline的原因相同:核心维护者不可能维护diffusion模型的所有可能训练方法。 | |
| 如果Diffusers核心维护者和社区认为某种训练范式过于实验性或不够普及,相应训练代码应放入<code>research_projects</code>文件夹并由作者维护。</p> <p data-svelte-h="svelte-1qekzf7">官方训练和研究型示例都包含一个目录,其中含有一个或多个训练脚本、<code>requirements.txt</code>文件和<code>README.md</code>文件。用户使用时需要先克隆代码库:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->git <span class="hljs-built_in">clone</span> https://github.com/huggingface/diffusers<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-14cfyxb">并安装训练所需的所有额外依赖:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-built_in">cd</span> diffusers | |
| pip install -r examples/<your-example-folder>/requirements.txt<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-2sd496">因此添加示例时,<code>requirements.txt</code>文件应定义训练示例所需的所有pip依赖项,安装完成后用户即可运行示例训练脚本。可参考<a href="https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/requirements.txt" rel="nofollow">DreamBooth的requirements.txt文件</a>。</p> <ul data-svelte-h="svelte-1d6vkoo"><li>运行示例所需的所有代码应集中在单个Python文件中</li> <li>用户应能通过命令行<code>python <your-example>.py --args</code>直接运行示例</li> <li><strong>示例</strong>应保持简洁,主要展示如何使用Diffusers进行训练。示例脚本的目的<strong>不是</strong>创建最先进的diffusion模型,而是复现已知训练方案,避免添加过多自定义逻辑。因此,这些示例也力求成为优质的教学材料。</li></ul> <p data-svelte-h="svelte-18l6g0f">提交示例时,强烈建议参考现有示例(如<a href="https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth.py" rel="nofollow">dreambooth</a>)来了解规范格式。<br> | |
| 我们强烈建议贡献者使用<a href="https://github.com/huggingface/accelerate" rel="nofollow">Accelerate库</a>,因其与Diffusers深度集成。<br> | |
| 当示例脚本完成后,请确保添加详细的<code>README.md</code>说明使用方法,包括:</p> <ul data-svelte-h="svelte-bkbzb0"><li>运行示例的具体命令(示例参见<a href="https://github.com/huggingface/diffusers/tree/main/examples/dreambooth#running-locally-with-pytorch" rel="nofollow">此处</a>)</li> <li>训练结果链接(日志/模型等),展示用户可预期的效果(示例参见<a href="https://api.wandb.ai/report/patrickvonplaten/xm6cd5q5" rel="nofollow">此处</a>)</li> <li>若添加非官方/研究性训练示例,<strong>必须注明</strong>维护者信息(含Git账号),格式参照<a href="https://github.com/huggingface/diffusers/tree/main/examples/research_projects/intel_opts#diffusers-examples-with-intel-optimizations" rel="nofollow">此处</a></li></ul> <p data-svelte-h="svelte-17bobdp">贡献官方训练示例时,还需在对应目录添加测试文件(如<a href="https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/test_dreambooth.py" rel="nofollow">examples/dreambooth/test_dreambooth.py</a>),非官方示例无需此步骤。</p> <h3 class="relative group"><a id="8-处理good-second-issue类问题" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#8-处理good-second-issue类问题"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>8. 处理”Good second issue”类问题</span></h3> <p data-svelte-h="svelte-1mi8h3s">标有<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22Good+second+issue%22" rel="nofollow">Good second issue</a>标签的问题通常比<a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22" rel="nofollow">Good first issues</a>更复杂。<br> | |
| 这类问题的描述通常不会提供详细解决指引,需要贡献者对库有较深理解。<br> | |
| 若您想解决此类问题,可直接提交PR并关联对应issue。若已有未合并的PR,请分析原因后提交改进版。需注意,Good second issue类PR的合并难度通常高于good first issues。在需要帮助的时候请不要犹豫,大胆的向核心维护者询问。</p> <h3 class="relative group"><a id="9-添加管道模型和调度器" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#9-添加管道模型和调度器"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>9. 添加管道、模型和调度器</span></h3> <p data-svelte-h="svelte-1u2aq5i">管道(pipelines)、模型(models)和调度器(schedulers)是Diffusers库中最重要的组成部分。它们提供了对最先进diffusion技术的便捷访问,使得社区能够构建强大的生成式AI应用。</p> <p data-svelte-h="svelte-2kzt34">通过添加新的模型、管道或调度器,您可能为依赖Diffusers的任何用户界面开启全新的强大用例,这对整个生成式AI生态系统具有巨大价值。</p> <p data-svelte-h="svelte-34bmxg">Diffusers针对这三类组件都有一些开放的功能请求——如果您还不确定要添加哪个具体组件,可以浏览以下链接:</p> <ul data-svelte-h="svelte-1qrt9h4"><li><a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22" rel="nofollow">模型或管道</a></li> <li><a href="https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22" rel="nofollow">调度器</a></li></ul> <p data-svelte-h="svelte-1sy2gbg">在添加任何组件之前,强烈建议您阅读<a href="philosophy">设计哲学指南</a>,以更好地理解这三类组件的设计理念。请注意,如果添加的模型、调度器或管道与我们的设计理念存在严重分歧,我们将无法合并,因为这会导致API不一致。如果您从根本上不同意某个设计选择,请改为提交<a href="https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feedback.md&title=" rel="nofollow">反馈问题</a>,以便讨论是否应该更改库中的特定设计模式/选择,以及是否更新我们的设计哲学。保持库内的一致性对我们非常重要。</p> <p data-svelte-h="svelte-yzsivt">请确保在PR中添加原始代码库/论文的链接,并最好直接在PR中@原始作者,以便他们可以跟踪进展并在有疑问时提供帮助。</p> <p data-svelte-h="svelte-5fonfe">如果您在PR过程中遇到不确定或卡住的情况,请随时留言请求初步审查或帮助。</p> <h4 class="relative group"><a id="复制机制copied-from" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#复制机制copied-from"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>复制机制(Copied from)</span></h4> <p data-svelte-h="svelte-1omyspz">在添加任何管道、模型或调度器代码时,理解<code># Copied from</code>机制是独特且重要的。您会在整个Diffusers代码库中看到这种机制,我们使用它的原因是为了保持代码库易于理解和维护。用<code># Copied from</code>机制标记代码会强制标记的代码与复制来源的代码完全相同。这使得每当您运行<code>make fix-copies</code>时,可以轻松更新并将更改传播到多个文件。</p> <p data-svelte-h="svelte-4papp9">例如,在下面的代码示例中,<code>StableDiffusionPipelineOutput</code>是原始代码,而<code>AltDiffusionPipelineOutput</code>使用<code># Copied from</code>机制来复制它。唯一的区别是将类前缀从<code>Stable</code>改为<code>Alt</code>。</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># 从 diffusers.pipelines.stable_diffusion.pipeline_output.StableDiffusionPipelineOutput 复制并将 Stable 替换为 Alt</span> | |
| <span class="hljs-keyword">class</span> <span class="hljs-title class_">AltDiffusionPipelineOutput</span>(<span class="hljs-title class_ inherited__">BaseOutput</span>): | |
| <span class="hljs-string">""" | |
| Output class for Alt Diffusion pipelines. | |
| Args: | |
| images (`List[PIL.Image.Image]` or `np.ndarray`) | |
| List of denoised PIL images of length `batch_size` or NumPy array of shape `(batch_size, height, width, | |
| num_channels)`. | |
| nsfw_content_detected (`List[bool]`) | |
| List indicating whether the corresponding generated image contains "not-safe-for-work" (nsfw) content or | |
| `None` if safety checking could not be performed. | |
| """</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-ys1xsf">要了解更多信息,请阅读<a href="https://huggingface.co/blog/transformers-design-philosophy#4-machine-learning-models-are-static" rel="nofollow">~不要~重复自己*</a>博客文章的相应部分。</p> <h2 class="relative group"><a id="如何撰写优质问题" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#如何撰写优质问题"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>如何撰写优质问题</span></h2> <p data-svelte-h="svelte-32t3jk"><strong>问题描述越清晰,被快速解决的可能性就越高。</strong></p> <ol data-svelte-h="svelte-1qpba7e"><li>确保使用了正确的issue模板。您可以选择<em>错误报告</em>、<em>功能请求</em>、<em>API设计反馈</em>、<em>新模型/流水线/调度器添加</em>、<em>论坛</em>或空白issue。在<a href="https://github.com/huggingface/diffusers/issues/new/choose" rel="nofollow">新建issue</a>时务必选择正确的模板。</li> <li><strong>精确描述</strong>:为issue起一个恰当的标题。尽量用最简练的语言描述问题。提交issue时越精确,理解问题和潜在解决方案所需的时间就越少。确保一个issue只针对一个问题,不要将多个问题放在同一个issue中。如果发现多个问题,请分别创建多个issue。如果是错误报告,请尽可能精确描述错误类型——不应只写”diffusers出错”。</li> <li><strong>可复现性</strong>:无法复现的代码片段 == 无法解决问题。如果遇到错误,维护人员必须能够<strong>复现</strong>它。确保包含一个可以复制粘贴到Python解释器中复现问题的代码片段。确保您的代码片段是可运行的,即没有缺少导入或图像链接等问题。issue应包含错误信息和可直接复制粘贴以复现相同错误的代码片段。如果issue涉及本地模型权重或无法被读者访问的本地数据,则问题无法解决。如果无法共享数据或模型,请尝试创建虚拟模型或虚拟数据。</li> <li><strong>最小化原则</strong>:通过尽可能简洁的描述帮助读者快速理解问题。删除所有与问题无关的代码/信息。如果发现错误,请创建最简单的代码示例来演示问题,不要一发现错误就把整个工作流程都转储到issue中。例如,如果在训练模型时某个阶段出现错误或训练过程中遇到问题时,应首先尝试理解训练代码的哪部分导致了错误,并用少量代码尝试复现。建议使用模拟数据替代完整数据集进行测试。</li> <li>添加引用链接。当提及特定命名、方法或模型时,请务必提供引用链接以便读者理解。若涉及具体PR或issue,请确保添加对应链接。不要假设读者了解你所指内容。issue中引用链接越丰富越好。</li> <li>规范格式。请确保规范格式化issue内容:Python代码使用代码语法块,错误信息使用标准代码语法。详见<a href="https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax" rel="nofollow">GitHub官方格式文档</a>。</li> <li>请将issue视为百科全书的精美词条,而非待解决的工单。每个规范撰写的issue不仅是向维护者有效传递问题的方式,更是帮助社区深入理解库特性的公共知识贡献。</li></ol> <h2 class="relative group"><a id="优质pr编写规范" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#优质pr编写规范"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>优质PR编写规范</span></h2> <ol data-svelte-h="svelte-2jqclh"><li>保持风格统一。理解现有设计模式和语法规范,确保新增代码与代码库现有结构无缝衔接。显著偏离现有设计模式或用户界面的PR将不予合并。</li> <li>聚焦单一问题。每个PR应当只解决一个明确问题,避免”顺手修复其他问题”的陷阱。包含多个无关修改的PR会极大增加审查难度。</li> <li>如适用,建议添加代码片段演示新增功能的使用方法。</li> <li>PR标题应准确概括其核心贡献。</li> <li>若PR针对某个issue,请在描述中注明issue编号以建立关联(也让关注该issue的用户知晓有人正在处理);</li> <li>进行中的PR请在标题添加<code>[WIP]</code>前缀。这既能避免重复劳动,也可与待合并PR明确区分;</li> <li>文本表述与格式要求请参照<a href="#how-to-write-a-good-issue">优质issue编写规范</a>;</li> <li>确保现有测试用例全部通过;</li> <li>必须添加高覆盖率测试。未经充分测试的代码不予合并。</li></ol> <ul data-svelte-h="svelte-93l93c"><li>若新增<code>@slow</code>测试,请使用<code>RUN_SLOW=1 python -m pytest tests/test_my_new_model.py</code>确保通过。 | |
| CircleCI不执行慢速测试,但GitHub Actions会每日夜间运行!</li></ul> <ol start="10" data-svelte-h="svelte-vs6upj"><li>所有公开方法必须包含格式规范、兼容markdown的说明文档。可参考<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py" rel="nofollow"><code>pipeline_latent_diffusion.py</code></a></li> <li>由于代码库快速增长,必须确保不会添加明显增加仓库体积的文件(如图片、视频等非文本文件)。建议优先使用托管在hf.co的<code>dataset</code>(例如<a href="https://huggingface.co/hf-internal-testing" rel="nofollow"><code>hf-internal-testing</code></a>或<a href="https://huggingface.co/datasets/huggingface/documentation-images" rel="nofollow">huggingface/documentation-images</a>)存放这类文件。若为外部贡献,可将图片添加到PR中并请Hugging Face成员将其迁移至该数据集。</li></ol> <h2 class="relative group"><a id="提交pr流程" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#提交pr流程"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>提交PR流程</span></h2> <p data-svelte-h="svelte-tao8tn">编写代码前,强烈建议先搜索现有PR或issue,确认没有重复工作。如有疑问,建议先创建issue获取反馈。</p> <p data-svelte-h="svelte-twmkg5">贡献至🧨 Diffusers需要基本的<code>git</code>技能。虽然<code>git</code>学习曲线较高,但其拥有最完善的手册。在终端输入<code>git --help</code>即可查阅,或参考书籍<a href="https://git-scm.com/book/en/v2" rel="nofollow">Pro Git</a>。</p> <p data-svelte-h="svelte-nwyxnn">请按以下步骤操作(<a href="https://github.com/huggingface/diffusers/blob/83bc6c94eaeb6f7704a2a428931cf2d9ad973ae9/setup.py#L270" rel="nofollow">支持的Python版本</a>):</p> <ol><li data-svelte-h="svelte-ul650h"><p>在<a href="https://github.com/huggingface/diffusers" rel="nofollow">仓库页面</a>点击”Fork”按钮创建代码副本至您的GitHub账户</p></li> <li><p data-svelte-h="svelte-huhm2">克隆fork到本地,并添加主仓库为远程源:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ git <span class="hljs-built_in">clone</span> git@github.com:<您的GitHub账号>/diffusers.git | |
| $ <span class="hljs-built_in">cd</span> diffusers | |
| $ git remote add upstream https://github.com/huggingface/diffusers.git<!-- HTML_TAG_END --></pre></div></li> <li><p data-svelte-h="svelte-pqojzq">创建新分支进行开发:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ git checkout -b 您的开发分支名称<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-10mupoj"><strong>禁止</strong>直接在<code>main</code>分支上修改</p></li> <li><p data-svelte-h="svelte-18hh8wb">在虚拟环境中运行以下命令配置开发环境:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ pip install -e <span class="hljs-string">".[dev]"</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-xrp2o7">若已克隆仓库,可能需要先执行<code>git pull</code>获取最新代码</p></li> <li data-svelte-h="svelte-lxtfyr"><p>在您的分支上开发功能</p></li></ol> <p data-svelte-h="svelte-1mrk96m">开发过程中应确保测试通过。可运行受影响测试:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ pytest tests/<待测文件>.py<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-g3ivl8">执行测试前请安装测试依赖:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ pip install -e <span class="hljs-string">".[test]"</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-173ydxc">也可运行完整测试套件(需高性能机器):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ make <span class="hljs-built_in">test</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1cyk3wx">🧨 Diffusers使用<code>black</code>和<code>isort</code>工具保持代码风格统一。修改后请执行自动化格式校正与代码验证,以下内容无法通过以下命令一次性自动化完成:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ make style<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-16mq3ns">🧨 Diffusers 还使用 <code>ruff</code> 和一些自定义脚本来检查代码错误。虽然质量控制流程会在 CI 中运行,但您也可以通过以下命令手动执行相同的检查:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ make quality<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-vortfw">当您对修改满意后,使用 <code>git add</code> 添加更改的文件,并通过 <code>git commit</code> 在本地记录这些更改:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ git add modified_file.py | |
| $ git commit -m <span class="hljs-string">"关于您所做更改的描述性信息。"</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-t2ekcs">定期将您的代码副本与原始仓库同步是一个好习惯。这样可以快速适应上游变更:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ git pull upstream main<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-kvo6v3">使用以下命令将更改推送到您的账户:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ git push -u origin 此处替换为您的描述性分支名称<!-- HTML_TAG_END --></pre></div> <ol start="6" data-svelte-h="svelte-15s5zf8"><li><p>确认无误后,请访问您 GitHub 账户中的派生仓库页面。点击「Pull request」将您的更改提交给项目维护者审核。</p></li> <li><p>如果维护者要求修改,这很正常——核心贡献者也会遇到这种情况!为了让所有人能在 Pull request 中看到变更,请在本地分支继续工作并将修改推送到您的派生仓库,这些变更会自动出现在 Pull request 中。</p></li></ol> <h3 class="relative group"><a id="测试" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#测试"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>测试</span></h3> <p data-svelte-h="svelte-1r3uyr2">我们提供了全面的测试套件来验证库行为和多个示例。库测试位于 <a href="https://github.com/huggingface/diffusers/tree/main/tests" rel="nofollow">tests 文件夹</a>。</p> <p data-svelte-h="svelte-2dfaki">我们推荐使用 <code>pytest</code> 和 <code>pytest-xdist</code>,因为它们速度更快。在仓库根目录下运行以下命令执行库测试:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ python -m pytest -n auto --dist=loadfile -s -v ./tests/<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-fo1ll0">实际上,这就是 <code>make test</code> 的实现方式!</p> <p data-svelte-h="svelte-bopoxk">您可以指定更小的测试范围来仅验证您正在开发的功能。</p> <p data-svelte-h="svelte-y21ima">默认情况下会跳过耗时测试。设置 <code>RUN_SLOW</code> 环境变量为 <code>yes</code> 可运行这些测试。注意:这将下载数十 GB 的模型文件——请确保您有足够的磁盘空间、良好的网络连接或充足的耐心!</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ RUN_SLOW=<span class="hljs-built_in">yes</span> python -m pytest -n auto --dist=loadfile -s -v ./tests/<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-vuyb8y">我们也完全支持 <code>unittest</code>,运行方式如下:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ python -m unittest discover -s tests -t . -v | |
| $ python -m unittest discover -s examples -t examples -v<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="将派生仓库的-main-分支与上游huggingfacemain-分支同步" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#将派生仓库的-main-分支与上游huggingfacemain-分支同步"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>将派生仓库的 main 分支与上游(HuggingFace)main 分支同步</span></h3> <p data-svelte-h="svelte-lo3h0i">为避免向上游仓库发送引用通知(这会给相关 PR 添加注释并向开发者发送不必要的通知),在同步派生仓库的 main 分支时,请遵循以下步骤:</p> <ol data-svelte-h="svelte-17jnyfc"><li>尽可能避免通过派生仓库的分支和 PR 来同步上游,而是直接合并到派生仓库的 main 分支</li> <li>如果必须使用 PR,请在检出分支后执行以下操作:</li></ol> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->$ git checkout -b 您的同步分支名称 | |
| $ git pull --squash --no-commit upstream main | |
| $ git commit -m <span class="hljs-string">'提交信息(不要包含 GitHub 引用)'</span> | |
| $ git push --set-upstream origin 您的分支名称<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="风格指南" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#风格指南"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>风格指南</span></h3> <p data-svelte-h="svelte-1f6y4bw">对于文档字符串,🧨 Diffusers 遵循 <a href="https://google.github.io/styleguide/pyguide.html" rel="nofollow">Google 风格指南</a>。</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/zh/conceptual/contribution.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_pa8cr6 = { | |
| assets: "/docs/diffusers/pr_11739/zh", | |
| base: "/docs/diffusers/pr_11739/zh", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/diffusers/pr_11739/zh/_app/immutable/entry/start.95a8faef.js"), | |
| import("/docs/diffusers/pr_11739/zh/_app/immutable/entry/app.a988cdaf.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 3], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 105 kB
- Xet hash:
- 105306a6977440ca74d7ce2e844359df0b3a71256d67c71fc7af68552467dd2b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.