Buckets:

HuggingFaceDocBuilder's picture
download
raw
15 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Git vs HTTP paradigm&quot;,&quot;local&quot;:&quot;git-vs-http-paradigm&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Git: the historical CLI-based approach&quot;,&quot;local&quot;:&quot;git-the-historical-cli-based-approach&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;HfApi: a flexible and convenient HTTP client&quot;,&quot;local&quot;:&quot;hfapi-a-flexible-and-convenient-http-client&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;What should I use ? And when ?&quot;,&quot;local&quot;:&quot;what-should-i-use--and-when-&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/huggingface_hub/pr_4113/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/entry/start.cad533c1.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/scheduler.0cf4ef2e.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/singletons.2cc47ca0.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/paths.69a55a12.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/entry/app.b1cfe321.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/preload-helper.d23a64db.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/index.abc433bf.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/nodes/0.3b235bd8.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/nodes/2.b4acada9.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/CopyLLMTxtMenu.f735f320.js">
<link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.f083e07d.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Git vs HTTP paradigm&quot;,&quot;local&quot;:&quot;git-vs-http-paradigm&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Git: the historical CLI-based approach&quot;,&quot;local&quot;:&quot;git-the-historical-cli-based-approach&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;HfApi: a flexible and convenient HTTP client&quot;,&quot;local&quot;:&quot;hfapi-a-flexible-and-convenient-http-client&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;What should I use ? And when ?&quot;,&quot;local&quot;:&quot;what-should-i-use--and-when-&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;: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 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>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> </div> <h1 class="relative group"><a id="git-vs-http-paradigm" 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-vs-http-paradigm"><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 vs HTTP paradigm</span></h1> <p data-svelte-h="svelte-t8k8ce">The <code>huggingface_hub</code> library is a library for interacting with the Hugging Face Hub, which is a collection of git-based repositories (models, datasets or Spaces). There are two main ways to access the Hub using <code>huggingface_hub</code>.</p> <p data-svelte-h="svelte-1pnl5y5">The first approach, the so-called “git-based” approach, relies on using standard <code>git</code> commands directly in a terminal. This method allows you to clone repositories, create commits, and push changes manually. The second option, called the “HTTP-based” approach, involves making HTTP requests using the <a href="/docs/huggingface_hub/pr_4113/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> client. Let’s examine the pros and cons of each approach.</p> <h2 class="relative group"><a id="git-the-historical-cli-based-approach" 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-the-historical-cli-based-approach"><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: the historical CLI-based approach</span></h2> <p data-svelte-h="svelte-11hpll7">At first, most users interacted with the Hugging Face Hub using plain <code>git</code> commands such as <code>git clone</code>, <code>git add</code>, <code>git commit</code>, <code>git push</code>, <code>git tag</code>, or <code>git checkout</code>.</p> <p data-svelte-h="svelte-w6v2v4">This approach lets you work with a full local copy of the repository on your machine, just like in traditional software development. This can be an advantage when you need offline access or want to work with the full history of a repository. However, it also comes with downsides: you are responsible for keeping the repository up-to-date locally, handling credentials, and managing large files (via <code>git-lfs</code>), which can become cumbersome when working with large machine learning models or datasets.</p> <p data-svelte-h="svelte-hx7les">In many machine learning workflows, you may only need to download a few files for inference or convert weights without needing to clone the entire repository. In such cases, using <code>git</code> can be overkill and introduce unnecessary complexity.</p> <h2 class="relative group"><a id="hfapi-a-flexible-and-convenient-http-client" 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-a-flexible-and-convenient-http-client"><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: a flexible and convenient HTTP client</span></h2> <p data-svelte-h="svelte-gdwhyi">The <a href="/docs/huggingface_hub/pr_4113/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> class was developed to provide an alternative to using local git repositories, which can be cumbersome to maintain, especially when dealing with large models or datasets. The <a href="/docs/huggingface_hub/pr_4113/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> class offers the same functionality as git-based workflows -such as downloading and pushing files and creating branches and tags- but without the need for a local folder that needs to be kept in sync.</p> <p data-svelte-h="svelte-hcfvep">In addition to the functionalities already provided by <code>git</code>, the <a href="/docs/huggingface_hub/pr_4113/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> class offers additional features, such as the ability to manage repos, download files using caching for efficient reuse, search the Hub for repos and metadata, access community features such as discussions, PRs, and comments, and configure Spaces hardware and secrets.</p> <h2 class="relative group"><a id="what-should-i-use--and-when-" 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="#what-should-i-use--and-when-"><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>What should I use ? And when ?</span></h2> <p data-svelte-h="svelte-5ob9py">Overall, the <strong>HTTP-based approach is the recommended way to use</strong> <code>huggingface_hub</code> in all cases. <a href="/docs/huggingface_hub/pr_4113/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> allows you to pull and push changes, work with PRs, tags and branches, interact with discussions and much more.</p> <p data-svelte-h="svelte-itei4f">However, not all git commands are available through <a href="/docs/huggingface_hub/pr_4113/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a>. Some may never be implemented, but we are always trying to improve and close the gap. If you don’t see your use case covered, please open <a href="https://github.com/huggingface/huggingface_hub" rel="nofollow">an issue on GitHub</a>! We welcome feedback to help build the HF ecosystem with and for our users.</p> <p data-svelte-h="svelte-2clj1c">This preference for the HTTP-based <a href="/docs/huggingface_hub/pr_4113/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> over direct <code>git</code> commands does not mean that git versioning will disappear from the Hugging Face Hub anytime soon. It will always be possible to use <code>git</code> locally in workflows where it makes sense.</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/en/concepts/git_vs_http.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_1c3kngw = {
assets: "/docs/huggingface_hub/pr_4113/en",
base: "/docs/huggingface_hub/pr_4113/en",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/huggingface_hub/pr_4113/en/_app/immutable/entry/start.cad533c1.js"),
import("/docs/huggingface_hub/pr_4113/en/_app/immutable/entry/app.b1cfe321.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 2],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
15 kB
·
Xet hash:
635ea1c260ca768f65701f5f3d9e703e54e9a06bacdbb389157816bdf2d0493b

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