Buckets:

rtrm's picture
download
raw
12.1 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Git 与 HTTP 范式&quot;,&quot;local&quot;:&quot;git-与-http-范式&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;存储库:基于历史的 Git 方法&quot;,&quot;local&quot;:&quot;存储库基于历史的-git-方法&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;HfApi: 一个功能强大且方便的HTTP客户端&quot;,&quot;local&quot;:&quot;hfapi-一个功能强大且方便的http客户端&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;我应该使用什么?以及何时使用?&quot;,&quot;local&quot;:&quot;我应该使用什么以及何时使用&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/huggingface_hub/main/cn/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/entry/start.6c2b313c.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/chunks/scheduler.b108d059.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/chunks/singletons.71724e9f.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/chunks/paths.902507be.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/entry/app.a7176e2c.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/chunks/index.008de539.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/nodes/0.63b578e0.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/nodes/2.b9ebde5b.js">
<link rel="modulepreload" href="/docs/huggingface_hub/main/cn/_app/immutable/chunks/EditOnGithub.d1c48e3d.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Git 与 HTTP 范式&quot;,&quot;local&quot;:&quot;git-与-http-范式&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;存储库:基于历史的 Git 方法&quot;,&quot;local&quot;:&quot;存储库基于历史的-git-方法&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;HfApi: 一个功能强大且方便的HTTP客户端&quot;,&quot;local&quot;:&quot;hfapi-一个功能强大且方便的http客户端&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;我应该使用什么?以及何时使用?&quot;,&quot;local&quot;:&quot;我应该使用什么以及何时使用&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="git-与-http-范式" 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="#git-与-http-范式"><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>Git 与 HTTP 范式</span></h1> <p data-svelte-h="svelte-1sg7tkf"><code>huggingface_hub</code>库是用于与Hugging Face Hub进行交互的库,Hugging Face Hub是一组基于Git的存储库(模型、数据集或Spaces)。使用 <code>huggingface_hub</code>有两种主要方式来访问Hub。</p> <p data-svelte-h="svelte-7v3o49">第一种方法,即所谓的“基于git”的方法,由<code>Repository</code>类驱动。这种方法使用了一个包装器,它在 <code>git</code>命令的基础上增加了专门与Hub交互的额外函数。第二种选择,称为“基于HTTP”的方法,涉及使用<code>HfApi</code>客户端进行HTTP请求。让我们来看一看每种方法的优缺点。</p> <h2 class="relative group"><a id="存储库基于历史的-git-方法" 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="#存储库基于历史的-git-方法"><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>存储库:基于历史的 Git 方法</span></h2> <p data-svelte-h="svelte-4s6lpf">最初,<code>huggingface_hub</code>主要围绕 <code>Repository</code> 类构建。它为常见的 <code>git</code> 命令(如 <code>&quot;git add&quot;</code><code>&quot;git commit&quot;</code><code>&quot;git push&quot;</code><code>&quot;git tag&quot;</code><code>&quot;git checkout&quot;</code> 等)提供了 Python 包装器</p> <p data-svelte-h="svelte-1le7n87">该库还可以帮助设置凭据和跟踪大型文件,这些文件通常在机器学习存储库中使用。此外,该库允许您在后台执行其方法,使其在训练期间上传数据很有用。</p> <p data-svelte-h="svelte-1fh2wgl">使用 <code>Repository</code> 的最大优点是它允许你在本地机器上维护整个存储库的本地副本。这也可能是一个缺点,因为它需要你不断更新和维护这个本地副本。这类似于传统软件开发中,每个开发人员都维护自己的本地副本,并在开发功能时推送更改。但是,在机器学习的上下文中,这可能并不总是必要的,因为用户可能只需要下载推理所需的权重,或将权重从一种格式转换为另一种格式,而无需克隆整个存储库。</p> <h2 class="relative group"><a id="hfapi-一个功能强大且方便的http客户端" 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="#hfapi-一个功能强大且方便的http客户端"><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>HfApi: 一个功能强大且方便的HTTP客户端</span></h2> <p data-svelte-h="svelte-15xbxuy"><code>HfApi</code> 被开发为本地 git 存储库的替代方案,因为本地 git 存储库在处理大型模型或数据集时可能会很麻烦。<code>HfApi</code> 提供与基于 git 的方法相同的功能,例如下载和推送文件以及创建分支和标签,但无需本地文件夹来保持同步。</p> <p data-svelte-h="svelte-t0icw5"><code>HfApi</code>除了提供 <code>git</code> 已经提供的功能外,还提供其他功能,例如:</p> <ul data-svelte-h="svelte-1tfngkq"><li>管理存储库</li> <li>使用缓存下载文件以进行有效的重复使用</li> <li>在 Hub 中搜索存储库和元数据</li> <li>访问社区功能,如讨论、PR和评论</li> <li>配置Spaces</li></ul> <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-ownqpp">总的来说,在大多数情况下,<code>HTTP 方法</code>是使用 huggingface_hub 的推荐方法。但是,在以下几种情况下,维护本地 git 克隆(使用 <code>Repository</code>)可能更有益:</p> <p data-svelte-h="svelte-1h3smco">如果您在本地机器上训练模型,使用传统的 git 工作流程并定期推送更新可能更有效。<code>Repository</code> 被优化为此类情况,因为它能够在后台运行。
如果您需要手动编辑大型文件,<code>git </code>是最佳选择,因为它只会将文件的差异发送到服务器。使用 <code>HfAPI</code> 客户端,每次编辑都会上传整个文件。请记住,大多数大型文件是二进制文件,因此无法从 git 差异中受益。</p> <p data-svelte-h="svelte-pi33ji">并非所有 git 命令都通过 <code>HfApi</code> 提供。有些可能永远不会被实现,但我们一直在努力改进并缩小差距。如果您没有看到您的用例被覆盖。</p> <p data-svelte-h="svelte-1ae98q2">请在<a href="https://github.com/huggingface/huggingface_hub" rel="nofollow">Github</a>打开一个 issue!我们欢迎反馈,以帮助我们与我们的用户一起构建 🤗 生态系统。</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/huggingface_hub/blob/main/docs/source/cn/concepts/git_vs_http.md" target="_blank"><span data-svelte-h="svelte-1kd6by1">&lt;</span> <span data-svelte-h="svelte-x0xyl0">&gt;</span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_1oxq3hu = {
assets: "/docs/huggingface_hub/main/cn",
base: "/docs/huggingface_hub/main/cn",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/huggingface_hub/main/cn/_app/immutable/entry/start.6c2b313c.js"),
import("/docs/huggingface_hub/main/cn/_app/immutable/entry/app.a7176e2c.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 2],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
12.1 kB
·
Xet hash:
175733618a24f816fed9c2254519f41f195b0d1486b5c457f088d10d8701ea9f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.