Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"为 🤗 Transformers 做贡献","local":"contribute-to--transformers","sections":[{"title":"贡献规则","local":"contribution-rules","sections":[],"depth":2},{"title":"设置","local":"set-up","sections":[{"title":"Windows","local":"windows","sections":[],"depth":3}],"depth":2},{"title":"提交问题","local":"opening-issues","sections":[],"depth":2},{"title":"添加新模型","local":"adding-a-new-model","sections":[{"title":"模型添加时间线","local":"model-addition-timeline","sections":[],"depth":3}],"depth":2},{"title":"文档","local":"docs","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/transformers/main/en/_app/immutable/entry/start.DYIO-UII.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DSYYoqAA.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/BovLmb3z.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/entry/app.D2_KizbC.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/WyYpyc-L.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DYBfcveH.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DOLBYqcr.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/nodes/0.ByO_lNbj.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/ZtBhN-Ei.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/nodes/40.BE1gI297.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/D-dvW--N.js" rel="modulepreload"> | |
| <!--122tzrt--><meta name="hf:doc:metadata" content="{"title":"Contribute to 🤗 Transformers","local":"contribute-to--transformers","sections":[{"title":"Contribution rules","local":"contribution-rules","sections":[],"depth":2},{"title":"Set up","local":"set-up","sections":[{"title":"Windows","local":"windows","sections":[],"depth":3}],"depth":2},{"title":"Opening issues","local":"opening-issues","sections":[],"depth":2},{"title":"Adding a new model","local":"adding-a-new-model","sections":[{"title":"Model addition timeline","local":"model-addition-timeline","sections":[],"depth":3}],"depth":2},{"title":"Docs","local":"docs","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/transformers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm 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 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" 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 dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 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 sm:size-3.5 size-3 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> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="contribute-to--transformers" 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="#contribute-to--transformers"><span><svg 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><!---->为 🤗 Transformers 做贡献<!----></span></h1><!--]--><!----> <!--[1--><h2 class="relative group"><a id="contribution-rules" 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="#contribution-rules"><span><svg 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>打开 PR 有两种方式:修复一个开放贡献的 issue,或者提交一个自带证据的独立 PR。也可以通过独立 PR 添加新模型,参见 <a href="#adding-a-new-model">添加新模型</a>。Hugging Face 员工、维护者以及部分资深贡献者不受这些规则的限制。</p> <p><strong>修复问题。</strong> 在 PR 描述中,使用诸如 <code>Fixes #123</code> 之类的关闭关键字来关联该问题。您可以处理以下问题:</p> <ul><li>您提交的 issue,在维护者将其标记为 <code>triaged</code> 之后</li> <li>一个标记为 <a href="https://github.com/huggingface/transformers/labels/contributions-welcome" rel="nofollow"><code>contributions-welcome</code></a> 的问题</li> <li>一个标记为 <a href="https://github.com/huggingface/transformers/labels/New%20model" rel="nofollow"><code>New model</code></a> 的问题,请参阅 <a href="#adding-a-new-model">添加新模型</a></li></ul> <p>除非维护者明确说明,否则他人的问题不开放用于提交 PR。链接到您无法处理的问题的 PR 将会被关闭。</p> <p>对于符合条件的 issue,你无需事先询问即可着手处理,我们也不会将 issue 分配给特定人员。诸如“我可以处理这个吗?”或“请把这个分配给我”之类的评论只会增加噪音,因此请跳过这些评论,直接提交你的 PR。针对某个 issue 的第一个 PR 会获得优先处理。</p> <p>在处理 <code>contributions-welcome</code> 或 <code>New model</code> 问题之前,请检查是否已有人为此提交了 PR。如果有,请勿再提交另一个。如果你发现错误,请在现有 PR 上留下建议。只有当现有 PR 存在根本性缺陷或已停滞时,才提交竞争性的 PR:即其作者两周未回复审查评论或未推送更改。等待维护者审查的 PR 不算停滞。无论如何,在提交你的 PR 之前,请先在问题中说明原因。</p> <p><strong>独立的 PR。</strong>如果还没有人报告该问题,你可以直接提交 PR 而无需先创建 issue。独立的 PR 适用于具有实际影响的简短更改,例如修复 bug、提升性能,或修复文档中损坏的示例。PR 描述需要提供与 issue 相同的证据:</p> <ul><li>针对某个 bug,提供一个简短的脚本,该脚本在 <code>main</code> 分支上运行失败,但在应用你的修复后运行成功,并且使用已发布的检查点、默认配置或文档中记载的工作流</li> <li>以实现性能提升为目的,需提供在真实工作负载(例如已发布的检查点或默认配置)下运行前后的性能数据,以及你所使用的硬件。针对非关键路径上某个函数的更快的微基准测试不计入在内。</li></ul> <p>如果该问题已存在对应的 issue,无论你是否在 PR 中关联该 issue,你的 PR 都将通过该 issue 进行处理。独立提交且用于修复已有 issue 的 PR,或没有提供相关证据的 PR,将会被关闭。这些要求不适用于新模型。</p> <p><strong>需要先创建 issue 的更改。</strong> 不影响正确性或性能的机械式清理,以及对文档中拼写错误或措辞的批量修正,在提交 PR 之前需要先创建 issue。请提出更改内容、具体实现方式以及涉及的文件数量。单个拼写错误修正太小,无论走哪条路径都不适合单独提交 PR。</p> <p><strong>审查他人的 PR。</strong> 当社区成员的审查意见能带来新信息时,我们非常欢迎。不过,维护者会阅读 PR 上的每一条评论,并且我们也会运行自己的审查工具。在评论一个并非由你发起的 PR 之前,请确保你有具体的内容要表达:</p> <ul><li>如果您发现了问题或有具体的修改建议,请在相关行留下内联评论,最好以 GitHub 建议的形式提交,以便作者可以直接应用。如果您在报告 bug,提供复现步骤会有所帮助。</li> <li>如果您报告了该 PR 所修复的问题,请简短说明它是否解决了您的情况,这将非常有帮助。</li> <li>请不要发布笼统的总结或“我测试过了,可以正常工作”之类的报告。非维护者的批准不会影响 PR 是否被合并,而一条重复 PR 内容的长评论只会浪费我们的时间,却不会改变结果。</li></ul> <p>代码的编写方式由您自行决定,但您需对提交的所有内容负责。对于反复提交低质量 issue 或 PR 的账户,我们可能会将其封禁。同时,请遵守我们的<a href="https://github.com/huggingface/transformers/blob/main/CODE_OF_CONDUCT.md" rel="nofollow">行为准则</a>。</p> <details><summary>What we look for in issues and PRs</summary> <ul><li>准确诊断 bug。快速的临时解决方案往往会导致代码臃肿或与其他模型不兼容。花时间追踪问题的确切原因,尤其是定位首次出现该问题的提交(例如使用 <a href="https://git-scm.com/docs/git-bisect" rel="nofollow">git bisect</a>),是很有价值的。</li> <li>最小化差异。检查你的 PR,消除任何不必要的更改。确保你没有提交任何测试脚本或不相关的文件。仅在真正必要时添加注释。如果你的 PR 可以是一个单行修复,那就让它保持为单行修复。这会让 PR 更容易审查,并提高其被接受的可能性。</li> <li>花些时间复现该问题。用户报告的 issue 往往实际上是由其机器上的环境问题引起的,或者他们误诊了问题并提出了无效的解决方案。过度信任报告会导致糟糕的解决方案,有时甚至是针对根本不存在的问题!编写一个简单的复现脚本并运行它,以确认你确实能看到该问题,这是非常有价值的。</li> <li>与其他模型进行比较。Transformers 仓库非常庞大,许多模型都在做类似的事情。在修复 bug 时,查看该 bug 是否也存在于其他模型中是很有价值的。如果你的 PR 中写道“通过采用与(其他模型)相同的方法来修复”,并附上相关代码的链接,这对维护者非常有帮助,因为这表明该修复方案很可能是正确的,并且与代码库的其余部分兼容。</li> <li>避免提交“琐碎”的 PR。我们没有时间处理小的样式更改或注释中的拼写错误,也不接受针对代码分析发现的“理论性 bug”的修复,除非这些 bug 在实际中几乎从不引发问题,或者可以被攻击者利用。</li> <li>在本地和 CI 中验证测试。在提交 PR 之前,请运行 <code>make fix-repo</code>,并使用 <code>utils/tests_fetcher.py</code> 查看覆盖你在 PR 分支中修改的文件的测试列表。在本地运行这些测试,并确保在提交 PR 之前它们全部通过。提交 PR 后,请确认 CI 状态为绿色,并在通知任何人进行审查之前修复所有问题!这能大幅减少通知干扰,让维护者保持理智。</li></ul></details> <!--[1--><h2 class="relative group"><a id="set-up" 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="#set-up"><span><svg 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><!--]--><!----> <ol><li><p>在 GitHub 上点击 <strong>Fork</strong> 按钮,将 <a href="https://github.com/huggingface/transformers" rel="nofollow">Transformers</a> 分叉到你自己的账户下,然后在本地克隆该仓库。</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 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> 已复制</div><!----></button><!----></div> <pre class="language-bash "><!---->git <span class="hljs-built_in">clone</span> git@github.com:<your Github handle>/transformers.git | |
| <span class="hljs-built_in">cd</span> transformers<!----></pre></div><!----></li> <li><p>将 Transformers 仓库添加为名为 <code>upstream</code> 的远程仓库。<code>origin</code> 指向你的 fork,<code>upstream</code> 指向权威源。这样你就可以在推送到 <code>origin</code> 并打开 PR 之前,先同步本地的 <code>main</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 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> 已复制</div><!----></button><!----></div> <pre class="language-bash "><!---->git remote add upstream https://github.com/huggingface/transformers.git | |
| git remote -v | |
| <span class="hljs-comment"># origin git@github.com:<your Github handle>/transformers.git (fetch)</span> | |
| <span class="hljs-comment"># origin git@github.com:<your Github handle>/transformers.git (push)</span> | |
| <span class="hljs-comment"># upstream https://github.com/huggingface/transformers.git (fetch)</span> | |
| <span class="hljs-comment"># upstream https://github.com/huggingface/transformers.git (push)</span><!----></pre></div><!----></li> <li><p>保持你的 fork 为最新状态,并创建一个分支开始工作。你也可以通过 GitHub 界面使用 <strong>Sync fork</strong> 按钮来同步你的 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 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> 已复制</div><!----></button><!----></div> <pre class="language-bash "><!---->git checkout main && git pull upstream main && git push origin main | |
| git switch -c a-descriptive-name-for-my-branch<!----></pre></div><!----></li> <li><p>以可编辑模式安装该库。对于大多数贡献,请使用 <code>[dev]</code>,因为它包含了用于样式和质量检查所需的开发工具。对于模型贡献,请使用 <code>[torch,testing]</code>;对于仅涉及文档的更改或小型修复,当不需要完整的开发依赖集时,请使用 <code>[quality]</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 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> 已复制</div><!----></button><!----></div> <pre class="language-bash "><!---->pip install -e <span class="hljs-string">".[dev]"</span> | |
| <span class="hljs-comment"># for model contributions</span> | |
| pip install -e <span class="hljs-string">".[torch,testing]"</span> | |
| <span class="hljs-comment"># for docs-only changes and small fixes</span> | |
| pip install -e <span class="hljs-string">".[quality]"</span><!----></pre></div><!----></li></ol> <!--[2--><h3 class="relative group"><a id="windows" 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="#windows"><span><svg 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><!---->Windows<!----></span></h3><!--]--><!----> <p>在 Windows 上,除非你正在使用 <a href="https://learn.microsoft.com/en-us/windows/wsl/" rel="nofollow">WSL</a>,否则请配置 git 将 <code>CRLF</code> 行尾转换为 <code>LF</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 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> 已复制</div><!----></button><!----></div> <pre class="language-bash "><!---->git config core.autocrlf input<!----></pre></div><!----> <p>在 Windows 上运行 <code>make</code> 命令的一种方法是使用 MSYS2。</p> <ol><li><a href="https://www.msys2.org/" rel="nofollow">下载 MSYS2</a>(我们假设其安装在 <code>C:\msys64</code> 中)。</li> <li>打开命令行 <code>C:\msys64\msys2.exe</code>(它应该可以在 <strong>开始</strong> 菜单中找到)。</li> <li>在 shell 中运行:<code>pacman -Syu</code>,并使用 <code>pacman -S make</code> 安装 <code>make</code>。</li> <li>将 <code>C:\msys64\usr\bin</code> 添加到 PATH 环境变量中。</li></ol> <p>现在,您可以从任何终端(PowerShell、cmd.exe 等)中使用 <code>make</code>。</p> <!--[1--><h2 class="relative group"><a id="opening-issues" 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="#opening-issues"><span><svg 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>请使用问题<a href="https://github.com/huggingface/transformers/tree/main/.github/ISSUE_TEMPLATE" rel="nofollow">模板</a>,并确保该问题尚未被报告(使用 GitHub 上 Issues 下的搜索栏)。Bug 报告应针对 Transformers 中的 bug,而非您自己代码中的 bug,并且应影响实际使用场景和实际的检查点;通过阅读代码发现的、需要非常规配置才能触发的“理论性 bug”不会被分诊,除非它是安全问题。请包含一个简短且自包含的脚本,用于在最新发布的版本或 <code>main</code> 上复现该 bug,并使用已发布的检查点或默认配置。没有可运行复现脚本的 Bug 报告将不会被分诊。</p> <p>如果您不确定 bug 是出在自己的代码中还是库中,请先在 <a href="https://discuss.huggingface.co/" rel="nofollow">论坛</a> 或 <a href="https://discord.com/invite/hugging-face-879548962464493619" rel="nofollow">Discord</a> 上提问。这有助于让 GitHub 专注于可操作的库问题。</p> <!--[1--><h2 class="relative group"><a id="adding-a-new-model" 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="#adding-a-new-model"><span><svg 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>将模型添加到 Transformers 后,任何人都可以加载该模型并进行微调或执行推理。在开始实现之前,请梳理你的架构与 Transformers 中已有的最新先进模型之间的差异。在 issue 或 PR 中说明这些差异,以便审阅者能够快速理解该模型带来的挑战、哪些部分可以复用现有模式,以及哪些部分需要在各模型之间进行标准化。</p> <p>请按照以下指南操作。</p> <ol><li><a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/modular_transformers.md" rel="nofollow">使用模块化 Transformers 添加模型</a> — 使用模块化文件实现模型,并生成独立的建模文件。</li> <li><a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/auto_docstring.md" rel="nofollow">自动生成文档字符串</a> — 使用 <code>@auto_docstring</code> 装饰器,无需样板代码即可生成一致的文档字符串。</li> <li><a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/testing.md" rel="nofollow">测试</a> — 编写并运行模型测试以验证正确性,确保贡献易于维护。对于因果语言模型,尽可能继承自因果语言模型测试器。优先进行集成测试,因为它们针对真实检查点验证完整的处理器、分词器和模型路径。</li> <li><a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/modeling_rules.md" rel="nofollow">模型结构规则</a> — 请检查您的文件是否通过了 <code>make typing</code> 强制执行的静态模型结构规则。</li></ol> <p>某些模型的添加需要额外的集成工作。</p> <ul><li>如果模型需要图像或视频输入,请<a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/add_vision_processing_components.md" rel="nofollow">添加视觉处理组件</a>。</li> <li>当已发布的检查点参数名称与 Transformers 实现不匹配时,使用<a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/weightconverter.md" rel="nofollow">动态权重加载</a>。</li></ul> <!--[2--><h3 class="relative group"><a id="model-addition-timeline" 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="#model-addition-timeline"><span><svg 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>根据模型贡献者的情况以及社区对特定架构的需求,模型添加有四种不同的时间线。</p> <ul><li><p>Day-0 集成:在模型发布当天,通过发布新版本使其在 Transformers 中可用。我们提供支持以实现最重要的核心功能(量化、FlashAttention、KV-cache 等),审阅早期草稿,并可根据时间安排负责模型实现。</p> <p>请提前几周向 <a href="mailto:transformers@huggingface.co">transformers@huggingface.co</a> 发送邮件,尤其是针对新颖的架构。我们将会在私有分支上与您进行迭代,直到您的检查点和发布准备就绪。</p></li> <li><p>同周集成:高需求模型通常在一周内上线,即使作者没有主动联系。</p> <p>使用 <a href="https://github.com/huggingface/transformers/issues/new?assignees=&labels=New+model&projects=&template=new-model-addition.yml" rel="nofollow">新模型模板</a> 提交一个 issue 以提出请求。互动越多的 issue 在队列中排得越快。</p></li> <li><p>发布后集成:对于需求不强烈或我们没有足够资源承接的模型,将在上游版本发布之后才进行集成。</p> <p>外部贡献者可以直接为新的模型提交 PR,无论是否已创建 issue。在开始之前,请检查已打开的 <a href="https://github.com/huggingface/transformers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+model%22" rel="nofollow">“New model”</a> issue 和已打开的 PR,以确保没有其他人正在添加该模型。我们将进行审查并指导你完成整个过程。</p></li> <li><p>优先在 Hub 上发布:借助 Transformers 的 <a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/models.md#custom-models" rel="nofollow">remote-code</a> 支持,您可以直接在 Hub 上发布模型,无需提交上游 PR。</p> <p>许多流行的 Hub 优先模型通常会在后续版本中被集成到 Transformers 中,从而获得一流的文档、维护和优化支持。Hub 优先是添加模型时摩擦最小的方式。不过,如果模型需要权重转换或存在其他向后兼容性问题,这种方式可能会更加脆弱。</p></li></ul> <!--[1--><h2 class="relative group"><a id="docs" 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="#docs"><span><svg 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>对于从源文件生成的 API 参考,在适用时使用 <a href="https://github.com/huggingface/transformers/blob/main/docs/source/en/auto_docstring.md" rel="nofollow"><code>@auto_docstring</code></a> 装饰器。有关如何编辑文档以及我们使用的语法的更多详细信息,请参阅文档的 <a href="https://github.com/huggingface/transformers/blob/main/docs/README.md" rel="nofollow">README</a>。</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/en/contributing.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><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_1m6yd5j = { | |
| base: "/docs/transformers/main/en", | |
| assets: "/docs/transformers/main/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/transformers/main/en/_app/immutable/entry/start.DYIO-UII.js"), | |
| import("/docs/transformers/main/en/_app/immutable/entry/app.D2_KizbC.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 40], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 37.7 kB
- Xet hash:
- a92a540c5bd7cb585971f1196d0c07304462643d8e2da3b225b8d001dd9b971e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.