Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Upload files to the Hub","local":"upload-files-to-the-hub","sections":[{"title":"Upload a file","local":"upload-a-file","sections":[],"depth":2},{"title":"Upload a folder","local":"upload-a-folder","sections":[],"depth":2},{"title":"Upload from the CLI","local":"upload-from-the-cli","sections":[],"depth":2},{"title":"Upload a large folder","local":"upload-a-large-folder","sections":[{"title":"Tips and tricks for large uploads","local":"tips-and-tricks-for-large-uploads","sections":[],"depth":3}],"depth":2},{"title":"Advanced features","local":"advanced-features","sections":[{"title":"Non-blocking uploads","local":"non-blocking-uploads","sections":[],"depth":3},{"title":"Upload a folder by chunks","local":"upload-a-folder-by-chunks","sections":[],"depth":3},{"title":"Scheduled uploads","local":"scheduled-uploads","sections":[{"title":"Space persistence demo","local":"space-persistence-demo","sections":[],"depth":4},{"title":"Custom uploads","local":"custom-uploads","sections":[],"depth":4}],"depth":3},{"title":"create_commit","local":"createcommit","sections":[],"depth":3},{"title":"Preupload LFS files before commit","local":"preupload-lfs-files-before-commit","sections":[],"depth":3}],"depth":2},{"title":"(legacy) Upload files with Git LFS","local":"legacy-upload-files-with-git-lfs","sections":[{"title":"commit context manager","local":"commit-context-manager","sections":[],"depth":3},{"title":"push_to_hub","local":"pushtohub","sections":[],"depth":3}],"depth":2}],"depth":1}"> | |
| <link href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/entry/start.734e9358.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/scheduler.6062bdaf.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/singletons.19aace4a.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/paths.355f6342.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/entry/app.d5cb78f4.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/index.4bca734e.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/nodes/0.7f67f620.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/nodes/17.7ad86daf.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/Tip.b9ac1f03.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/CodeBlock.fa01571c.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/chunks/EditOnGithub.74ab2baa.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Upload files to the Hub","local":"upload-files-to-the-hub","sections":[{"title":"Upload a file","local":"upload-a-file","sections":[],"depth":2},{"title":"Upload a folder","local":"upload-a-folder","sections":[],"depth":2},{"title":"Upload from the CLI","local":"upload-from-the-cli","sections":[],"depth":2},{"title":"Upload a large folder","local":"upload-a-large-folder","sections":[{"title":"Tips and tricks for large uploads","local":"tips-and-tricks-for-large-uploads","sections":[],"depth":3}],"depth":2},{"title":"Advanced features","local":"advanced-features","sections":[{"title":"Non-blocking uploads","local":"non-blocking-uploads","sections":[],"depth":3},{"title":"Upload a folder by chunks","local":"upload-a-folder-by-chunks","sections":[],"depth":3},{"title":"Scheduled uploads","local":"scheduled-uploads","sections":[{"title":"Space persistence demo","local":"space-persistence-demo","sections":[],"depth":4},{"title":"Custom uploads","local":"custom-uploads","sections":[],"depth":4}],"depth":3},{"title":"create_commit","local":"createcommit","sections":[],"depth":3},{"title":"Preupload LFS files before commit","local":"preupload-lfs-files-before-commit","sections":[],"depth":3}],"depth":2},{"title":"(legacy) Upload files with Git LFS","local":"legacy-upload-files-with-git-lfs","sections":[{"title":"commit context manager","local":"commit-context-manager","sections":[],"depth":3},{"title":"push_to_hub","local":"pushtohub","sections":[],"depth":3}],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="upload-files-to-the-hub" 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="#upload-files-to-the-hub"><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>Upload files to the Hub</span></h1> <p data-svelte-h="svelte-uu6wb2">Sharing your files and work is an important aspect of the Hub. The <code>huggingface_hub</code> offers several options for uploading your files to the Hub. You can use these functions independently or integrate them into your library, making it more convenient for your users to interact with the Hub. This guide will show you how to push files:</p> <ul data-svelte-h="svelte-126zpzz"><li>without using Git.</li> <li>that are very large with <a href="https://git-lfs.github.com/" rel="nofollow">Git LFS</a>.</li> <li>with the <code>commit</code> context manager.</li> <li>with the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository.push_to_hub">push_to_hub()</a> function.</li></ul> <p data-svelte-h="svelte-6kh510">Whenever you want to upload files to the Hub, you need to log in to your Hugging Face account. For more details about authentication, check out <a href="../quick-start#authentication">this section</a>.</p> <h2 class="relative group"><a id="upload-a-file" 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="#upload-a-file"><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>Upload a file</span></h2> <p data-svelte-h="svelte-8tgf3k">Once you’ve created a repository with <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_repo">create_repo()</a>, you can upload a file to your repository using <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a>.</p> <p data-svelte-h="svelte-weizha">Specify the path of the file to upload, where you want to upload the file to in the repository, and the name of the repository you want to add the file to. Depending on your repository type, you can optionally set the repository type as a <code>dataset</code>, <code>model</code>, or <code>space</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> HfApi | |
| <span class="hljs-meta">>>> </span>api = HfApi() | |
| <span class="hljs-meta">>>> </span>api.upload_file( | |
| <span class="hljs-meta">... </span> path_or_fileobj=<span class="hljs-string">"/path/to/local/folder/README.md"</span>, | |
| <span class="hljs-meta">... </span> path_in_repo=<span class="hljs-string">"README.md"</span>, | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"username/test-dataset"</span>, | |
| <span class="hljs-meta">... </span> repo_type=<span class="hljs-string">"dataset"</span>, | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="upload-a-folder" 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="#upload-a-folder"><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>Upload a folder</span></h2> <p data-svelte-h="svelte-13iu2m4">Use the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> function to upload a local folder to an existing repository. Specify the path of the local folder | |
| to upload, where you want to upload the folder to in the repository, and the name of the repository you want to add the | |
| folder to. Depending on your repository type, you can optionally set the repository type as a <code>dataset</code>, <code>model</code>, or <code>space</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> HfApi | |
| <span class="hljs-meta">>>> </span>api = HfApi() | |
| <span class="hljs-comment"># Upload all the content from the local folder to your remote Space.</span> | |
| <span class="hljs-comment"># By default, files are uploaded at the root of the repo</span> | |
| <span class="hljs-meta">>>> </span>api.upload_folder( | |
| <span class="hljs-meta">... </span> folder_path=<span class="hljs-string">"/path/to/local/space"</span>, | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"username/my-cool-space"</span>, | |
| <span class="hljs-meta">... </span> repo_type=<span class="hljs-string">"space"</span>, | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1rk8lnp">By default, the <code>.gitignore</code> file will be taken into account to know which files should be committed or not. By default we check if a <code>.gitignore</code> file is present in a commit, and if not, we check if it exists on the Hub. Please be aware that only a <code>.gitignore</code> file present at the root of the directory with be used. We do not check for <code>.gitignore</code> files in subdirectories.</p> <p data-svelte-h="svelte-1v7onvy">If you don’t want to use an hardcoded <code>.gitignore</code> file, you can use the <code>allow_patterns</code> and <code>ignore_patterns</code> arguments to filter which files to upload. These parameters accept either a single pattern or a list of patterns. Patterns are Standard Wildcards (globbing patterns) as documented <a href="https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm" rel="nofollow">here</a>. If both <code>allow_patterns</code> and <code>ignore_patterns</code> are provided, both constraints apply.</p> <p data-svelte-h="svelte-1nus7g8">Beside the <code>.gitignore</code> file and allow/ignore patterns, any <code>.git/</code> folder present in any subdirectory will be ignored.</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-meta">>>> </span>api.upload_folder( | |
| <span class="hljs-meta">... </span> folder_path=<span class="hljs-string">"/path/to/local/folder"</span>, | |
| <span class="hljs-meta">... </span> path_in_repo=<span class="hljs-string">"my-dataset/train"</span>, <span class="hljs-comment"># Upload to a specific folder</span> | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"username/test-dataset"</span>, | |
| <span class="hljs-meta">... </span> repo_type=<span class="hljs-string">"dataset"</span>, | |
| <span class="hljs-meta">... </span> ignore_patterns=<span class="hljs-string">"**/logs/*.txt"</span>, <span class="hljs-comment"># Ignore all text logs</span> | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1jdk3x1">You can also use the <code>delete_patterns</code> argument to specify files you want to delete from the repo in the same commit. | |
| This can prove useful if you want to clean a remote folder before pushing files in it and you don’t know which files | |
| already exists.</p> <p data-svelte-h="svelte-j2fnkr">The example below uploads the local <code>./logs</code> folder to the remote <code>/experiment/logs/</code> folder. Only txt files are uploaded | |
| but before that, all previous logs on the repo on deleted. All of this in a single commit.</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-meta">>>> </span>api.upload_folder( | |
| <span class="hljs-meta">... </span> folder_path=<span class="hljs-string">"/path/to/local/folder/logs"</span>, | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"username/trained-model"</span>, | |
| <span class="hljs-meta">... </span> path_in_repo=<span class="hljs-string">"experiment/logs/"</span>, | |
| <span class="hljs-meta">... </span> allow_patterns=<span class="hljs-string">"*.txt"</span>, <span class="hljs-comment"># Upload all local text files</span> | |
| <span class="hljs-meta">... </span> delete_patterns=<span class="hljs-string">"*.txt"</span>, <span class="hljs-comment"># Delete all remote text files before</span> | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="upload-from-the-cli" 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="#upload-from-the-cli"><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>Upload from the CLI</span></h2> <p data-svelte-h="svelte-n9dplc">You can use the <code>huggingface-cli upload</code> command from the terminal to directly upload files to the Hub. Internally it uses the same <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> and <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> helpers described above.</p> <p data-svelte-h="svelte-sxpkdv">You can either upload a single file or an entire folder:</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"># Usage: huggingface-cli upload [repo_id] [local_path] [path_in_repo]</span> | |
| >>> huggingface-cli upload Wauplin/my-cool-model ./models/model.safetensors model.safetensors | |
| https://huggingface.co/Wauplin/my-cool-model/blob/main/model.safetensors | |
| >>> huggingface-cli upload Wauplin/my-cool-model ./models . | |
| https://huggingface.co/Wauplin/my-cool-model/tree/main<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1whpdih"><code>local_path</code> and <code>path_in_repo</code> are optional and can be implicitly inferred. If <code>local_path</code> is not set, the tool will | |
| check if a local folder or file has the same name as the <code>repo_id</code>. If that’s the case, its content will be uploaded. | |
| Otherwise, an exception is raised asking the user to explicitly set <code>local_path</code>. In any case, if <code>path_in_repo</code> is not | |
| set, files are uploaded at the root of the repo.</p> <p data-svelte-h="svelte-22tszs">For more details about the CLI upload command, please refer to the <a href="./cli#huggingface-cli-upload">CLI guide</a>.</p> <h2 class="relative group"><a id="upload-a-large-folder" 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="#upload-a-large-folder"><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>Upload a large folder</span></h2> <p data-svelte-h="svelte-1sk9evh">In most cases, the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> method and <code>huggingface-cli upload</code> command should be the go-to solutions to upload files to the Hub. They ensure a single commit will be made, handle a lot of use cases, and fail explicitly when something wrong happens. However, when dealing with a large amount of data, you will usually prefer a resilient process even if it leads to more commits or requires more CPU usage. The <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_large_folder">upload_large_folder()</a> method has been implemented in that spirit:</p> <ul data-svelte-h="svelte-eysscy"><li>it is resumable: the upload process is split into many small tasks (hashing files, pre-uploading them, and committing them). Each time a task is completed, the result is cached locally in a <code>./cache/huggingface</code> folder inside the folder you are trying to upload. By doing so, restarting the process after an interruption will resume all completed tasks.</li> <li>it is multi-threaded: hashing large files and pre-uploading them benefits a lot from multithreading if your machine allows it.</li> <li>it is resilient to errors: a high-level retry-mechanism has been added to retry each independent task indefinitely until it passes (no matter if it’s a OSError, ConnectionError, PermissionError, etc.). This mechanism is double-edged. If transient errors happen, the process will continue and retry. If permanent errors happen (e.g. permission denied), it will retry indefinitely without solving the root cause.</li></ul> <p data-svelte-h="svelte-17cp0lm">If you want more technical details about how <code>upload_large_folder</code> is implemented under the hood, please have a look to the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_large_folder">upload_large_folder()</a> package reference.</p> <p data-svelte-h="svelte-tboyu5">Here is how to use <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_large_folder">upload_large_folder()</a> in a script. The method signature is very similar to <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</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 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-meta">>>> </span>api.upload_large_folder( | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"HuggingFaceM4/Docmatix"</span>, | |
| <span class="hljs-meta">... </span> repo_type=<span class="hljs-string">"dataset"</span>, | |
| <span class="hljs-meta">... </span> folder_path=<span class="hljs-string">"/path/to/local/docmatix"</span>, | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1let5f">You will see the following output in your terminal:</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-attr">Repo created:</span> <span class="hljs-string">https://huggingface.co/datasets/HuggingFaceM4/Docmatix</span> | |
| <span class="hljs-string">Found</span> <span class="hljs-number">5</span> <span class="hljs-string">candidate</span> <span class="hljs-string">files</span> <span class="hljs-string">to</span> <span class="hljs-string">upload</span> | |
| <span class="hljs-attr">Recovering from metadata files:</span> <span class="hljs-number">100</span><span class="hljs-string">%|█████████████████████████████████████|</span> <span class="hljs-number">5</span><span class="hljs-string">/5</span> [<span class="hljs-number">00</span><span class="hljs-string">:00<00:00</span>, <span class="hljs-number">542.</span><span class="hljs-string">66it/s</span>] | |
| <span class="hljs-string">----------</span> <span class="hljs-number">2024-07-22 17:23:17</span> <span class="hljs-string">(0:00:00)</span> <span class="hljs-string">----------</span> | |
| <span class="hljs-attr">Files:</span> <span class="hljs-string">hashed</span> <span class="hljs-number">5</span><span class="hljs-string">/5</span> <span class="hljs-string">(5.0G/5.0G)</span> <span class="hljs-string">|</span> <span class="hljs-attr">pre-uploaded:</span> <span class="hljs-number">0</span><span class="hljs-string">/5</span> <span class="hljs-string">(0.0/5.0G)</span> <span class="hljs-string">|</span> <span class="hljs-attr">committed:</span> <span class="hljs-number">0</span><span class="hljs-string">/5</span> <span class="hljs-string">(0.0/5.0G)</span> <span class="hljs-string">|</span> <span class="hljs-attr">ignored:</span> <span class="hljs-number">0</span> | |
| <span class="hljs-attr">Workers: hashing:</span> <span class="hljs-number">0</span> <span class="hljs-string">|</span> <span class="hljs-attr">get upload mode:</span> <span class="hljs-number">0</span> <span class="hljs-string">|</span> <span class="hljs-attr">pre-uploading:</span> <span class="hljs-number">5</span> <span class="hljs-string">|</span> <span class="hljs-attr">committing:</span> <span class="hljs-number">0</span> <span class="hljs-string">|</span> <span class="hljs-attr">waiting:</span> <span class="hljs-number">11</span> | |
| <span class="hljs-string">---------------------------------------------------</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-10zd3ei">First, the repo is created if it didn’t exist before. Then, the local folder is scanned for files to upload. For each file, we try to recover metadata information (from a previously interrupted upload). From there, it is able to launch workers and print an update status every 1 minute. Here, we can see that 5 files have already been hashed but not pre-uploaded. 5 workers are pre-uploading files while the 11 others are waiting for a task.</p> <p data-svelte-h="svelte-1j2m1uw">A command line is also provided. You can define the number of workers and the level of verbosity in the terminal:</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 -->huggingface-cli upload-large-folder HuggingFaceM4/Docmatix --repo-type=dataset /path/to/local/docmatix --num-workers=16<!-- HTML_TAG_END --></pre></div> <div class="course-tip bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400"><p data-svelte-h="svelte-v3d95u">For large uploads, you have to set <code>repo_type="model"</code> or <code>--repo-type=model</code> explicitly. Usually, this information is implicit in all other <code>HfApi</code> methods. This is to avoid having data uploaded to a repository with a wrong type. If that’s the case, you’ll have to re-upload everything.</p></div> <div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400"><p data-svelte-h="svelte-3pzh59">While being much more robust to upload large folders, <code>upload_large_folder</code> is more limited than <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> feature-wise. In practice:</p> <ul data-svelte-h="svelte-1krn97u"><li>you cannot set a custom <code>path_in_repo</code>. If you want to upload to a subfolder, you need to set the proper structure locally.</li> <li>you cannot set a custom <code>commit_message</code> and <code>commit_description</code> since multiple commits are created.</li> <li>you cannot delete from the repo while uploading. Please make a separate commit first.</li> <li>you cannot create a PR directly. Please create a PR first (from the UI or using <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_pull_request">create_pull_request()</a>) and then commit to it by passing <code>revision</code>.</li></ul></div> <h3 class="relative group"><a id="tips-and-tricks-for-large-uploads" 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="#tips-and-tricks-for-large-uploads"><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>Tips and tricks for large uploads</span></h3> <p data-svelte-h="svelte-ikji1t">There are some limitations to be aware of when dealing with a large amount of data in your repo. Given the time it takes to stream the data, getting an upload/push to fail at the end of the process or encountering a degraded experience, be it on hf.co or when working locally, can be very annoying.</p> <p data-svelte-h="svelte-1oh0qkj">Check out our <a href="https://huggingface.co/docs/hub/repositories-recommendations" rel="nofollow">Repository limitations and recommendations</a> guide for best practices on how to structure your repositories on the Hub. Let’s move on with some practical tips to make your upload process as smooth as possible.</p> <ul data-svelte-h="svelte-3sn1zi"><li><strong>Start small</strong>: We recommend starting with a small amount of data to test your upload script. It’s easier to iterate on a script when failing takes only a little time.</li> <li><strong>Expect failures</strong>: Streaming large amounts of data is challenging. You don’t know what can happen, but it’s always best to consider that something will fail at least once -no matter if it’s due to your machine, your connection, or our servers. For example, if you plan to upload a large number of files, it’s best to keep track locally of which files you already uploaded before uploading the next batch. You are ensured that an LFS file that is already committed will never be re-uploaded twice but checking it client-side can still save some time. This is what <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_large_folder">upload_large_folder()</a> does for you.</li> <li><strong>Use <code>hf_transfer</code></strong>: this is a Rust-based <a href="https://github.com/huggingface/hf_transfer" rel="nofollow">library</a> meant to speed up uploads on machines with very high bandwidth. To use <code>hf_transfer</code>:<ol><li>Specify the <code>hf_transfer</code> extra when installing <code>huggingface_hub</code> | |
| (i.e., <code>pip install huggingface_hub[hf_transfer]</code>).</li> <li>Set <code>HF_HUB_ENABLE_HF_TRANSFER=1</code> as an environment variable.</li></ol></li></ul> <div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400"><p data-svelte-h="svelte-13ykduv"><code>hf_transfer</code> is a power user tool! It is tested and production-ready, but it lacks user-friendly features like advanced error handling or proxies. For more details, please take a look at this <a href="https://huggingface.co/docs/huggingface_hub/hf_transfer" rel="nofollow">section</a>.</p></div> <h2 class="relative group"><a id="advanced-features" 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="#advanced-features"><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>Advanced features</span></h2> <p data-svelte-h="svelte-stbtme">In most cases, you won’t need more than <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> and <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> to upload your files to the Hub. | |
| However, <code>huggingface_hub</code> has more advanced features to make things easier. Let’s have a look at them!</p> <h3 class="relative group"><a id="non-blocking-uploads" 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="#non-blocking-uploads"><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>Non-blocking uploads</span></h3> <p data-svelte-h="svelte-nb2xam">In some cases, you want to push data without blocking your main thread. This is particularly useful to upload logs and | |
| artifacts while continuing a training. To do so, you can use the <code>run_as_future</code> argument in both <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> and | |
| <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a>. This will return a <a href="https://docs.python.org/3/library/concurrent.futures.html#future-objects" rel="nofollow"><code>concurrent.futures.Future</code></a> | |
| object that you can use to check the status of the upload.</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> HfApi | |
| <span class="hljs-meta">>>> </span>api = HfApi() | |
| <span class="hljs-meta">>>> </span>future = api.upload_folder( <span class="hljs-comment"># Upload in the background (non-blocking action)</span> | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"username/my-model"</span>, | |
| <span class="hljs-meta">... </span> folder_path=<span class="hljs-string">"checkpoints-001"</span>, | |
| <span class="hljs-meta">... </span> run_as_future=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>future | |
| Future(...) | |
| <span class="hljs-meta">>>> </span>future.done() | |
| <span class="hljs-literal">False</span> | |
| <span class="hljs-meta">>>> </span>future.result() <span class="hljs-comment"># Wait for the upload to complete (blocking action)</span> | |
| ...<!-- HTML_TAG_END --></pre></div> <div class="course-tip bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400"><p data-svelte-h="svelte-wv2oxh">Background jobs are queued when using <code>run_as_future=True</code>. This means that you are guaranteed that the jobs will be | |
| executed in the correct order.</p></div> <p data-svelte-h="svelte-1b339kh">Even though background jobs are mostly useful to upload data/create commits, you can queue any method you like using | |
| <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.run_as_future">run_as_future()</a>. For instance, you can use it to create a repo and then upload data to it in the background. The | |
| built-in <code>run_as_future</code> argument in upload methods is just an alias around it.</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> HfApi | |
| <span class="hljs-meta">>>> </span>api = HfApi() | |
| <span class="hljs-meta">>>> </span>api.run_as_future(api.create_repo, <span class="hljs-string">"username/my-model"</span>, exists_ok=<span class="hljs-literal">True</span>) | |
| Future(...) | |
| <span class="hljs-meta">>>> </span>api.upload_file( | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"username/my-model"</span>, | |
| <span class="hljs-meta">... </span> path_in_repo=<span class="hljs-string">"file.txt"</span>, | |
| <span class="hljs-meta">... </span> path_or_fileobj=<span class="hljs-string">b"file content"</span>, | |
| <span class="hljs-meta">... </span> run_as_future=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span>) | |
| Future(...)<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="upload-a-folder-by-chunks" 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="#upload-a-folder-by-chunks"><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>Upload a folder by chunks</span></h3> <p data-svelte-h="svelte-9qzhn"><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> makes it easy to upload an entire folder to the Hub. However, for large folders (thousands of files or | |
| hundreds of GB), it can still be challenging. If you have a folder with a lot of files, you might want to upload | |
| it in several commits. If you experience an error or a connection issue during the upload, you would not have to resume | |
| the process from the beginning.</p> <p data-svelte-h="svelte-pwsrx3">To upload a folder in multiple commits, just pass <code>multi_commits=True</code> as argument. Under the hood, <code>huggingface_hub</code> | |
| will list the files to upload/delete and split them in several commits. The “strategy” (i.e. how to split the commits) | |
| is based on the number and size of the files to upload. A PR is open on the Hub to push all the commits. Once the PR is | |
| ready, the commits are squashed into a single commit. If the process is interrupted before completing, you can rerun | |
| your script to resume the upload. The created PR will be automatically detected and the upload will resume from where | |
| it stopped. It is recommended to pass <code>multi_commits_verbose=True</code> to get a better understanding of the upload and its | |
| progress.</p> <p data-svelte-h="svelte-p68hnq">The example below will upload the checkpoints folder to a dataset in multiple commits. A PR will be created on the Hub | |
| and merged automatically once the upload is complete. If you prefer the PR to stay open and review it manually, you can | |
| pass <code>create_pr=True</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-meta">>>> </span>upload_folder( | |
| <span class="hljs-meta">... </span> folder_path=<span class="hljs-string">"local/checkpoints"</span>, | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"username/my-dataset"</span>, | |
| <span class="hljs-meta">... </span> repo_type=<span class="hljs-string">"dataset"</span>, | |
| <span class="hljs-meta">... </span> multi_commits=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span> multi_commits_verbose=<span class="hljs-literal">True</span>, | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-13s60ai">If you want a better control on the upload strategy (i.e. the commits that are created), you can have a look at the | |
| low-level <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.plan_multi_commits">plan_multi_commits()</a> and <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commits_on_pr">create_commits_on_pr()</a> methods.</p> <div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400"><p data-svelte-h="svelte-1hgg4xz"><code>multi_commits</code> is still an experimental feature. Its API and behavior is subject to change in the future without prior | |
| notice.</p></div> <h3 class="relative group"><a id="scheduled-uploads" 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="#scheduled-uploads"><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>Scheduled uploads</span></h3> <p data-svelte-h="svelte-wfh12x">The Hugging Face Hub makes it easy to save and version data. However, there are some limitations when updating the same file thousands of times. For instance, you might want to save logs of a training process or user | |
| feedback on a deployed Space. In these cases, uploading the data as a dataset on the Hub makes sense, but it can be hard to do properly. The main reason is that you don’t want to version every update of your data because it’ll make the git repository unusable. The <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a> class offers a solution to this problem.</p> <p data-svelte-h="svelte-12ye9gf">The idea is to run a background job that regularly pushes a local folder to the Hub. Let’s assume you have a | |
| Gradio Space that takes as input some text and generates two translations of it. Then, the user can select their preferred translation. For each run, you want to save the input, output, and user preference to analyze the results. This is a | |
| perfect use case for <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>; you want to save data to the Hub (potentially millions of user feedback), but | |
| you don’t <em>need</em> to save in real-time each user’s input. Instead, you can save the data locally in a JSON file and | |
| upload it every 10 minutes. For example:</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-meta">>>> </span><span class="hljs-keyword">import</span> json | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> uuid | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> CommitScheduler | |
| <span class="hljs-comment"># Define the file where to save the data. Use UUID to make sure not to overwrite existing data from a previous run.</span> | |
| <span class="hljs-meta">>>> </span>feedback_file = Path(<span class="hljs-string">"user_feedback/"</span>) / <span class="hljs-string">f"data_<span class="hljs-subst">{uuid.uuid4()}</span>.json"</span> | |
| <span class="hljs-meta">>>> </span>feedback_folder = feedback_file.parent | |
| <span class="hljs-comment"># Schedule regular uploads. Remote repo and local folder are created if they don't already exist.</span> | |
| <span class="hljs-meta">>>> </span>scheduler = CommitScheduler( | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"report-translation-feedback"</span>, | |
| <span class="hljs-meta">... </span> repo_type=<span class="hljs-string">"dataset"</span>, | |
| <span class="hljs-meta">... </span> folder_path=feedback_folder, | |
| <span class="hljs-meta">... </span> path_in_repo=<span class="hljs-string">"data"</span>, | |
| <span class="hljs-meta">... </span> every=<span class="hljs-number">10</span>, | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-comment"># Define the function that will be called when the user submits its feedback (to be called in Gradio)</span> | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">save_feedback</span>(<span class="hljs-params">input_text:<span class="hljs-built_in">str</span>, output_1: <span class="hljs-built_in">str</span>, output_2:<span class="hljs-built_in">str</span>, user_choice: <span class="hljs-built_in">int</span></span>) -> <span class="hljs-literal">None</span>: | |
| <span class="hljs-meta">... </span> <span class="hljs-string">""" | |
| <span class="hljs-meta">... </span> Append input/outputs and user feedback to a JSON Lines file using a thread lock to avoid concurrent writes from different users. | |
| <span class="hljs-meta">... </span> """</span> | |
| <span class="hljs-meta">... </span> <span class="hljs-keyword">with</span> scheduler.lock: | |
| <span class="hljs-meta">... </span> <span class="hljs-keyword">with</span> feedback_file.<span class="hljs-built_in">open</span>(<span class="hljs-string">"a"</span>) <span class="hljs-keyword">as</span> f: | |
| <span class="hljs-meta">... </span> f.write(json.dumps({<span class="hljs-string">"input"</span>: input_text, <span class="hljs-string">"output_1"</span>: output_1, <span class="hljs-string">"output_2"</span>: output_2, <span class="hljs-string">"user_choice"</span>: user_choice})) | |
| <span class="hljs-meta">... </span> f.write(<span class="hljs-string">"\n"</span>) | |
| <span class="hljs-comment"># Start Gradio</span> | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">with</span> gr.Blocks() <span class="hljs-keyword">as</span> demo: | |
| <span class="hljs-meta">>>> </span> ... <span class="hljs-comment"># define Gradio demo + use `save_feedback`</span> | |
| <span class="hljs-meta">>>> </span>demo.launch()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-bk7nho">And that’s it! User input/outputs and feedback will be available as a dataset on the Hub. By using a unique JSON file name, you are guaranteed you won’t overwrite data from a previous run or data from another | |
| Spaces/replicas pushing concurrently to the same repository.</p> <p data-svelte-h="svelte-1u92b18">For more details about the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>, here is what you need to know:</p> <ul data-svelte-h="svelte-1md1dub"><li><strong>append-only:</strong> | |
| It is assumed that you will only add content to the folder. You must only append data to existing files or create | |
| new files. Deleting or overwriting a file might corrupt your repository.</li> <li><strong>git history</strong>: | |
| The scheduler will commit the folder every <code>every</code> minutes. To avoid polluting the git repository too much, it is | |
| recommended to set a minimal value of 5 minutes. Besides, the scheduler is designed to avoid empty commits. If no | |
| new content is detected in the folder, the scheduled commit is dropped.</li> <li><strong>errors:</strong> | |
| The scheduler run as background thread. It is started when you instantiate the class and never stops. In particular, | |
| if an error occurs during the upload (example: connection issue), the scheduler will silently ignore it and retry | |
| at the next scheduled commit.</li> <li><strong>thread-safety:</strong> | |
| In most cases it is safe to assume that you can write to a file without having to worry about a lock file. The | |
| scheduler will not crash or be corrupted if you write content to the folder while it’s uploading. In practice, | |
| <em>it is possible</em> that concurrency issues happen for heavy-loaded apps. In this case, we advice to use the | |
| <code>scheduler.lock</code> lock to ensure thread-safety. The lock is blocked only when the scheduler scans the folder for | |
| changes, not when it uploads data. You can safely assume that it will not affect the user experience on your Space.</li></ul> <h4 class="relative group"><a id="space-persistence-demo" 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="#space-persistence-demo"><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>Space persistence demo</span></h4> <p data-svelte-h="svelte-yy5c7t">Persisting data from a Space to a Dataset on the Hub is the main use case for <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>. Depending on the use | |
| case, you might want to structure your data differently. The structure has to be robust to concurrent users and | |
| restarts which often implies generating UUIDs. Besides robustness, you should upload data in a format readable by the 🤗 Datasets library for later reuse. We created a <a href="https://huggingface.co/spaces/Wauplin/space_to_dataset_saver" rel="nofollow">Space</a> | |
| that demonstrates how to save several different data formats (you may need to adapt it for your own specific needs).</p> <h4 class="relative group"><a id="custom-uploads" 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="#custom-uploads"><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>Custom uploads</span></h4> <p data-svelte-h="svelte-1ky9pdl"><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a> assumes your data is append-only and should be uploading “as is”. However, you | |
| might want to customize the way data is uploaded. You can do that by creating a class inheriting from <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a> | |
| and overwrite the <code>push_to_hub</code> method (feel free to overwrite it any way you want). You are guaranteed it will | |
| be called every <code>every</code> minutes in a background thread. You don’t have to worry about concurrency and errors but you | |
| must be careful about other aspects, such as pushing empty commits or duplicated data.</p> <p data-svelte-h="svelte-2fhb7l">In the (simplified) example below, we overwrite <code>push_to_hub</code> to zip all PNG files in a single archive to avoid | |
| overloading the repo on the Hub:</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">class</span> <span class="hljs-title class_">ZipScheduler</span>(<span class="hljs-title class_ inherited__">CommitScheduler</span>): | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">push_to_hub</span>(<span class="hljs-params">self</span>): | |
| <span class="hljs-comment"># 1. List PNG files</span> | |
| png_files = <span class="hljs-built_in">list</span>(self.folder_path.glob(<span class="hljs-string">"*.png"</span>)) | |
| <span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(png_files) == <span class="hljs-number">0</span>: | |
| <span class="hljs-keyword">return</span> <span class="hljs-literal">None</span> <span class="hljs-comment"># return early if nothing to commit</span> | |
| <span class="hljs-comment"># 2. Zip png files in a single archive</span> | |
| <span class="hljs-keyword">with</span> tempfile.TemporaryDirectory() <span class="hljs-keyword">as</span> tmpdir: | |
| archive_path = Path(tmpdir) / <span class="hljs-string">"train.zip"</span> | |
| <span class="hljs-keyword">with</span> zipfile.ZipFile(archive_path, <span class="hljs-string">"w"</span>, zipfile.ZIP_DEFLATED) <span class="hljs-keyword">as</span> <span class="hljs-built_in">zip</span>: | |
| <span class="hljs-keyword">for</span> png_file <span class="hljs-keyword">in</span> png_files: | |
| <span class="hljs-built_in">zip</span>.write(filename=png_file, arcname=png_file.name) | |
| <span class="hljs-comment"># 3. Upload archive</span> | |
| self.api.upload_file(..., path_or_fileobj=archive_path) | |
| <span class="hljs-comment"># 4. Delete local png files to avoid re-uploading them later</span> | |
| <span class="hljs-keyword">for</span> png_file <span class="hljs-keyword">in</span> png_files: | |
| png_file.unlink()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-wid62z">When you overwrite <code>push_to_hub</code>, you have access to the attributes of <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a> and especially:</p> <ul data-svelte-h="svelte-1b96f8n"><li><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> client: <code>api</code></li> <li>Folder parameters: <code>folder_path</code> and <code>path_in_repo</code></li> <li>Repo parameters: <code>repo_id</code>, <code>repo_type</code>, <code>revision</code></li> <li>The thread lock: <code>lock</code></li></ul> <div class="course-tip bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400"><p data-svelte-h="svelte-ndh47j">For more examples of custom schedulers, check out our <a href="https://huggingface.co/spaces/Wauplin/space_to_dataset_saver" rel="nofollow">demo Space</a> | |
| containing different implementations depending on your use cases.</p></div> <h3 class="relative group"><a id="createcommit" 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="#createcommit"><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>create_commit</span></h3> <p data-svelte-h="svelte-otbvnt">The <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> and <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> functions are high-level APIs that are generally convenient to use. We recommend | |
| trying these functions first if you don’t need to work at a lower level. However, if you want to work at a commit-level, | |
| you can use the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a> function directly.</p> <p data-svelte-h="svelte-16sz609">There are three types of operations supported by <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>:</p> <ul data-svelte-h="svelte-4800c3"><li><p><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationAdd">CommitOperationAdd</a> uploads a file to the Hub. If the file already exists, the file contents are overwritten. This operation accepts two arguments:</p> <ul><li><code>path_in_repo</code>: the repository path to upload a file to.</li> <li><code>path_or_fileobj</code>: either a path to a file on your filesystem or a file-like object. This is the content of the file to upload to the Hub.</li></ul></li> <li><p><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationDelete">CommitOperationDelete</a> removes a file or a folder from a repository. This operation accepts <code>path_in_repo</code> as an argument.</p></li> <li><p><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationCopy">CommitOperationCopy</a> copies a file within a repository. This operation accepts three arguments:</p> <ul><li><code>src_path_in_repo</code>: the repository path of the file to copy.</li> <li><code>path_in_repo</code>: the repository path where the file should be copied.</li> <li><code>src_revision</code>: optional - the revision of the file to copy if your want to copy a file from a different branch/revision.</li></ul></li></ul> <p data-svelte-h="svelte-12aa4hm">For example, if you want to upload two files and delete a file in a Hub repository:</p> <ol data-svelte-h="svelte-fvcpkg"><li>Use the appropriate <code>CommitOperation</code> to add or delete a file and to delete a folder:</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> HfApi, CommitOperationAdd, CommitOperationDelete | |
| <span class="hljs-meta">>>> </span>api = HfApi() | |
| <span class="hljs-meta">>>> </span>operations = [ | |
| <span class="hljs-meta">... </span> CommitOperationAdd(path_in_repo=<span class="hljs-string">"LICENSE.md"</span>, path_or_fileobj=<span class="hljs-string">"~/repo/LICENSE.md"</span>), | |
| <span class="hljs-meta">... </span> CommitOperationAdd(path_in_repo=<span class="hljs-string">"weights.h5"</span>, path_or_fileobj=<span class="hljs-string">"~/repo/weights-final.h5"</span>), | |
| <span class="hljs-meta">... </span> CommitOperationDelete(path_in_repo=<span class="hljs-string">"old-weights.h5"</span>), | |
| <span class="hljs-meta">... </span> CommitOperationDelete(path_in_repo=<span class="hljs-string">"logs/"</span>), | |
| <span class="hljs-meta">... </span> CommitOperationCopy(src_path_in_repo=<span class="hljs-string">"image.png"</span>, path_in_repo=<span class="hljs-string">"duplicate_image.png"</span>), | |
| <span class="hljs-meta">... </span>]<!-- HTML_TAG_END --></pre></div> <ol start="2" data-svelte-h="svelte-1gi7nj7"><li>Pass your operations to <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>:</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-meta">>>> </span>api.create_commit( | |
| <span class="hljs-meta">... </span> repo_id=<span class="hljs-string">"lysandre/test-model"</span>, | |
| <span class="hljs-meta">... </span> operations=operations, | |
| <span class="hljs-meta">... </span> commit_message=<span class="hljs-string">"Upload my model weights and license"</span>, | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-12en6o1">In addition to <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> and <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a>, the following functions also use <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a> under the hood:</p> <ul data-svelte-h="svelte-3d1k7g"><li><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.delete_file">delete_file()</a> deletes a single file from a repository on the Hub.</li> <li><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.delete_folder">delete_folder()</a> deletes an entire folder from a repository on the Hub.</li> <li><a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/cards#huggingface_hub.metadata_update">metadata_update()</a> updates a repository’s metadata.</li></ul> <p data-svelte-h="svelte-m179jv">For more detailed information, take a look at the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> reference.</p> <h3 class="relative group"><a id="preupload-lfs-files-before-commit" 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="#preupload-lfs-files-before-commit"><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>Preupload LFS files before commit</span></h3> <p data-svelte-h="svelte-1l870qx">In some cases, you might want to upload huge files to S3 <strong>before</strong> making the commit call. For example, if you are | |
| committing a dataset in several shards that are generated in-memory, you would need to upload the shards one by one | |
| to avoid an out-of-memory issue. A solution is to upload each shard as a separate commit on the repo. While being | |
| perfectly valid, this solution has the drawback of potentially messing the git history by generating tens of commits. | |
| To overcome this issue, you can upload your files one by one to S3 and then create a single commit at the end. This | |
| is possible using <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.preupload_lfs_files">preupload_lfs_files()</a> in combination with <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>.</p> <div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400"><p data-svelte-h="svelte-1g0rqeo">This is a power-user method. Directly using <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a>, <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> or <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a> instead of handling | |
| the low-level logic of pre-uploading files is the way to go in the vast majority of cases. The main caveat of | |
| <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.preupload_lfs_files">preupload_lfs_files()</a> is that until the commit is actually made, the upload files are not accessible on the repo on | |
| the Hub. If you have a question, feel free to ping us on our Discord or in a GitHub issue.</p></div> <p data-svelte-h="svelte-1mshy2g">Here is a simple example illustrating how to pre-upload files:</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> CommitOperationAdd, preupload_lfs_files, create_commit, create_repo | |
| <span class="hljs-meta">>>> </span>repo_id = create_repo(<span class="hljs-string">"test_preupload"</span>).repo_id | |
| <span class="hljs-meta">>>> </span>operations = [] <span class="hljs-comment"># List of all `CommitOperationAdd` objects that will be generated</span> | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>): | |
| <span class="hljs-meta">... </span> content = ... <span class="hljs-comment"># generate binary content</span> | |
| <span class="hljs-meta">... </span> addition = CommitOperationAdd(path_in_repo=<span class="hljs-string">f"shard_<span class="hljs-subst">{i}</span>_of_5.bin"</span>, path_or_fileobj=content) | |
| <span class="hljs-meta">... </span> preupload_lfs_files(repo_id, additions=[addition]) | |
| <span class="hljs-meta">... </span> operations.append(addition) | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Create commit</span> | |
| <span class="hljs-meta">>>> </span>create_commit(repo_id, operations=operations, commit_message=<span class="hljs-string">"Commit all shards"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-pndzau">First, we create the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.CommitOperationAdd">CommitOperationAdd</a> objects one by one. In a real-world example, those would contain the | |
| generated shards. Each file is uploaded before generating the next one. During the <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.preupload_lfs_files">preupload_lfs_files()</a> step, <strong>the | |
| <code>CommitOperationAdd</code> object is mutated</strong>. You should only use it to pass it directly to <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>. The main | |
| update of the object is that <strong>the binary content is removed</strong> from it, meaning that it will be garbage-collected if | |
| you don’t store another reference to it. This is expected as we don’t want to keep in memory the content that is | |
| already uploaded. Finally we create the commit by passing all the operations to <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>. You can pass | |
| additional operations (add, delete or copy) that have not been processed yet and they will be handled correctly.</p> <h2 class="relative group"><a id="legacy-upload-files-with-git-lfs" 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="#legacy-upload-files-with-git-lfs"><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>(legacy) Upload files with Git LFS</span></h2> <p data-svelte-h="svelte-1trldzp">All the methods described above use the Hub’s API to upload files. This is the recommended way to upload files to the Hub. | |
| However, we also provide <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository">Repository</a>, a wrapper around the git tool to manage a local repository.</p> <div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400"><p data-svelte-h="svelte-ibm86h">Although <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository">Repository</a> is not formally deprecated, we recommend using the HTTP-based methods described above instead. | |
| For more details about this recommendation, please have a look at <a href="../concepts/git_vs_http">this guide</a> explaining the | |
| core differences between HTTP-based and Git-based approaches.</p></div> <p data-svelte-h="svelte-ckpv1u">Git LFS automatically handles files larger than 10MB. But for very large files (>5GB), you need to install a custom transfer agent for Git LFS:</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 -->huggingface-cli lfs-enable-largefiles<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1su1bae">You should install this for each repository that has a very large file. Once installed, you’ll be able to push files larger than 5GB.</p> <h3 class="relative group"><a id="commit-context-manager" 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="#commit-context-manager"><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>commit context manager</span></h3> <p data-svelte-h="svelte-1euyrt0">The <code>commit</code> context manager handles four of the most common Git commands: pull, add, commit, and push. <code>git-lfs</code> automatically tracks any file larger than 10MB. In the following example, the <code>commit</code> context manager:</p> <ol data-svelte-h="svelte-jfle7b"><li>Pulls from the <code>text-files</code> repository.</li> <li>Adds a change made to <code>file.txt</code>.</li> <li>Commits the change.</li> <li>Pushes the change to the <code>text-files</code> repository.</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> Repository | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">with</span> Repository(local_dir=<span class="hljs-string">"text-files"</span>, clone_from=<span class="hljs-string">"<user>/text-files"</span>).commit(commit_message=<span class="hljs-string">"My first file :)"</span>): | |
| <span class="hljs-meta">... </span> <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"file.txt"</span>, <span class="hljs-string">"w+"</span>) <span class="hljs-keyword">as</span> f: | |
| <span class="hljs-meta">... </span> f.write(json.dumps({<span class="hljs-string">"hey"</span>: <span class="hljs-number">8</span>}))<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1pjnw9q">Here is another example of how to use the <code>commit</code> context manager to save and upload a file to a repository:</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-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span>model = torch.nn.Transformer() | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">with</span> Repository(<span class="hljs-string">"torch-model"</span>, clone_from=<span class="hljs-string">"<user>/torch-model"</span>, token=<span class="hljs-literal">True</span>).commit(commit_message=<span class="hljs-string">"My cool model :)"</span>): | |
| <span class="hljs-meta">... </span> torch.save(model.state_dict(), <span class="hljs-string">"model.pt"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1t3cobo">Set <code>blocking=False</code> if you would like to push your commits asynchronously. Non-blocking behavior is helpful when you want to continue running your script while your commits are being pushed.</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-meta">>>> </span><span class="hljs-keyword">with</span> repo.commit(commit_message=<span class="hljs-string">"My cool model :)"</span>, blocking=<span class="hljs-literal">False</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-147hmo">You can check the status of your push with the <code>command_queue</code> method:</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-meta">>>> </span>last_command = repo.command_queue[-<span class="hljs-number">1</span>] | |
| <span class="hljs-meta">>>> </span>last_command.status<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-i7szos">Refer to the table below for the possible statuses:</p> <table data-svelte-h="svelte-13yxo7x"><thead><tr><th>Status</th> <th>Description</th></tr></thead> <tbody><tr><td>-1</td> <td>The push is ongoing.</td></tr> <tr><td>0</td> <td>The push has completed successfully.</td></tr> <tr><td>Non-zero</td> <td>An error has occurred.</td></tr></tbody></table> <p data-svelte-h="svelte-1j9orlr">When <code>blocking=False</code>, commands are tracked, and your script will only exit when all pushes are completed, even if other errors occur in your script. Some additional useful commands for checking the status of a push include:</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"># Inspect an error.</span> | |
| <span class="hljs-meta">>>> </span>last_command.stderr | |
| <span class="hljs-comment"># Check whether a push is completed or ongoing.</span> | |
| <span class="hljs-meta">>>> </span>last_command.is_done | |
| <span class="hljs-comment"># Check whether a push command has errored.</span> | |
| <span class="hljs-meta">>>> </span>last_command.failed<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="pushtohub" 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="#pushtohub"><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>push_to_hub</span></h3> <p data-svelte-h="svelte-1ve7643">The <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository">Repository</a> class has a <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository.push_to_hub">push_to_hub()</a> function to add files, make a commit, and push them to a repository. Unlike the <code>commit</code> context manager, you’ll need to pull from a repository first before calling <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository.push_to_hub">push_to_hub()</a>.</p> <p data-svelte-h="svelte-ou5qb0">For example, if you’ve already cloned a repository from the Hub, then you can initialize the <code>repo</code> from the local directory:</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-meta">>>> </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> Repository | |
| <span class="hljs-meta">>>> </span>repo = Repository(local_dir=<span class="hljs-string">"path/to/local/repo"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1hkr4dv">Update your local clone with <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository.git_pull">git_pull()</a> and then push your file to the Hub:</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-meta">>>> </span>repo.git_pull() | |
| <span class="hljs-meta">>>> </span>repo.push_to_hub(commit_message=<span class="hljs-string">"Commit my-awesome-file to the Hub"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-5d2fbk">However, if you aren’t ready to push a file yet, you can use <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository.git_add">git_add()</a> and <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository.git_commit">git_commit()</a> to only add and commit your file:</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-meta">>>> </span>repo.git_add(<span class="hljs-string">"path/to/file"</span>) | |
| <span class="hljs-meta">>>> </span>repo.git_commit(commit_message=<span class="hljs-string">"add my first model config file :)"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-9x5qfi">When you’re ready, push the file to your repository with <a href="/docs/huggingface_hub/v0.25.0.rc0/en/package_reference/repository#huggingface_hub.Repository.git_push">git_push()</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 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-meta">>>> </span>repo.git_push()<!-- HTML_TAG_END --></pre></div> <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/guides/upload.md" target="_blank"><span data-svelte-h="svelte-1kd6by1"><</span> <span data-svelte-h="svelte-x0xyl0">></span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_82f581 = { | |
| assets: "/docs/huggingface_hub/v0.25.0.rc0/en", | |
| base: "/docs/huggingface_hub/v0.25.0.rc0/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/entry/start.734e9358.js"), | |
| import("/docs/huggingface_hub/v0.25.0.rc0/en/_app/immutable/entry/app.d5cb78f4.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 17], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 116 kB
- Xet hash:
- ad19a6598e5780b9888f851ee2a5f00e712f3759cd85fd512dcbf8cd6de4d5a0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.