Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Hub에 파일 업로드하기","local":"upload-files-to-the-hub","sections":[{"title":"파일 업로드하기","local":"upload-a-file","sections":[],"depth":2},{"title":"폴더 업로드","local":"upload-a-folder","sections":[],"depth":2},{"title":"CLI에서 업로드","local":"upload-from-the-cli","sections":[],"depth":2},{"title":"고급 기능","local":"advanced-features","sections":[{"title":"논블로킹 업로드","local":"non-blocking-uploads","sections":[],"depth":3},{"title":"청크 단위로 폴더 업로드하기","local":"upload-a-folder-by-chunks","sections":[],"depth":3},{"title":"예약된 업로드","local":"scheduled-uploads","sections":[{"title":"스페이스 지속성 데모","local":"space-persistence-demo","sections":[],"depth":4},{"title":"사용자 지정 업로드","local":"custom-uploads","sections":[],"depth":4}],"depth":3},{"title":"create_commit","local":"createcommit","sections":[],"depth":3},{"title":"커밋하기 전에 LFS 파일 미리 업로드하기","local":"preupload-lfs-files-before-commit","sections":[],"depth":3}],"depth":2},{"title":"대용량 업로드를 위한 팁과 요령","local":"tips-and-tricks-for-large-uploads","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/entry/start.e4d70577.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/scheduler.0cf4ef2e.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/singletons.7ad9a7dd.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/paths.5be5312b.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/entry/app.3b0f3b68.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/preload-helper.2e746cb0.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/index.abc433bf.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/nodes/0.c6150a55.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/nodes/15.6ec19fb5.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.b2531632.js"> | |
| <link rel="modulepreload" href="/docs/huggingface_hub/pr_4113/ko/_app/immutable/chunks/CodeBlock.db16c7c8.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Hub에 파일 업로드하기","local":"upload-files-to-the-hub","sections":[{"title":"파일 업로드하기","local":"upload-a-file","sections":[],"depth":2},{"title":"폴더 업로드","local":"upload-a-folder","sections":[],"depth":2},{"title":"CLI에서 업로드","local":"upload-from-the-cli","sections":[],"depth":2},{"title":"고급 기능","local":"advanced-features","sections":[{"title":"논블로킹 업로드","local":"non-blocking-uploads","sections":[],"depth":3},{"title":"청크 단위로 폴더 업로드하기","local":"upload-a-folder-by-chunks","sections":[],"depth":3},{"title":"예약된 업로드","local":"scheduled-uploads","sections":[{"title":"스페이스 지속성 데모","local":"space-persistence-demo","sections":[],"depth":4},{"title":"사용자 지정 업로드","local":"custom-uploads","sections":[],"depth":4}],"depth":3},{"title":"create_commit","local":"createcommit","sections":[],"depth":3},{"title":"커밋하기 전에 LFS 파일 미리 업로드하기","local":"preupload-lfs-files-before-commit","sections":[],"depth":3}],"depth":2},{"title":"대용량 업로드를 위한 팁과 요령","local":"tips-and-tricks-for-large-uploads","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="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>Hub에 파일 업로드하기</span></h1> <p data-svelte-h="svelte-1mzkmbb">파일과 작업물을 공유하는 것은 Hub의 주요 특성 중 하나입니다. <code>huggingface_hub</code>는 Hub에 파일을 업로드하기 위한 몇 가지 옵션을 제공합니다. 이러한 기능을 단독으로 사용하거나 라이브러리에 통합하여 해당 라이브러리의 사용자가 Hub와 더 편리하게 상호작용할 수 있도록 도울 수 있습니다.</p> <p data-svelte-h="svelte-nzjamk">Hub에 파일을 업로드 하려면 허깅페이스 계정으로 로그인해야 합니다. 인증에 대한 자세한 내용은 <a href="../quick-start#authentication">이 페이지</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>파일 업로드하기</span></h2> <p data-svelte-h="svelte-19xv9di"><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_repo">create_repo()</a>로 리포지토리를 생성했다면, <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a>을 사용하여 해당 리포지토리에 파일을 업로드할 수 있습니다.</p> <p data-svelte-h="svelte-1xr7gkh">업로드할 파일의 본 경로, 리포지토리에서 파일을 업로드할 위치, 대상 리포지토리의 이름을 지정합니다. 리포지토리의 유형을 <code>dataset</code>, <code>model</code>, <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>폴더 업로드</span></h2> <p data-svelte-h="svelte-f8z3lj">로컬 폴더를 리포지토리에 업로드하려면 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> 함수를 사용합니다. | |
| 업로드할 로컬 폴더의 본 경로, 리포지토리에서 폴더를 업로드할 위치, 대상 리포지토리의 이름을 지정합니다. 리포지토리의 유형을 <code>dataset</code>, <code>model</code>, <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"># 로컬 폴더에 있는 모든 콘텐츠를 원격 Space에 업로드 합니다.</span> | |
| <span class="hljs-comment"># 파일은 기본적으로 리포지토리의 루트 디렉토리에 업로드 됩니다.</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-dsvs1y">기본적으로 어떤 파일을 커밋할지 여부를 알기 위해 <code>.gitignore</code> 파일을 참조하게 됩니다. 기본적으로 커밋에 <code>.gitignore</code> 파일이 있는지 확인하고, 없는 경우 Hub에 파일이 있는지 확인합니다. 디렉터리의 루트 경로에 있는 <code>.gitignore</code> 파일만 사용된다는 점을 주의하세요. 하위 경로에는 <code>.gitignore</code> 파일이 있는지 확인하지 않습니다.</p> <p data-svelte-h="svelte-iyws9s">하드코딩된 <code>.gitignore</code> 파일을 사용하지 않으려면 <code>allow_patterns</code> 와 <code>ignore_patterns</code> 인수를 사용하여 업로드할 파일을 필터링할 수 있습니다. 이 매개변수들은 단일 패턴 또는 패턴 리스트를 허용합니다. 패턴의 형식은 <a href="https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm" rel="nofollow">이 문서</a>에 설명된 대로 표준 와일드카드(글로빙 패턴)입니다. <code>allow_patterns</code>과 <code>ignore_patterns</code>을 모두 사용하면 두 가지 설정이 모두 적용됩니다.</p> <p data-svelte-h="svelte-j5junh"><code>.gitignore</code> 파일과 allow/ignore 패턴 외에 하위 경로 있는 모든 <code>.git/</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>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"># 특정 폴더에 업로드</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"># 모든 로그 텍스트 파일을 무시</span> | |
| <span class="hljs-meta">... </span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1bswka5"><code>delete_patterns</code> 인수를 사용하여 동일한 커밋에서 리포지토리에서 삭제할 파일을 지정할 수도 있습니다. | |
| 이 방법은 파일을 푸시하기 전에 원격 폴더를 정리하고 싶은데 어떤 파일이 이미 존재하는지 모르는 경우에 유용합니다.</p> <p data-svelte-h="svelte-urk51k">다음은 로컬 <code>./logs</code> 폴더를 원격 <code>/experiment/logs/</code> 폴더에 업로드하는 예시입니다. | |
| 폴더 내의 txt 파일만을 업로드 하게 되며 그 전에 리포지토리에 있던 모든 이전 txt 파일이 삭제됩니다. 이 모든 과정이 단 한 번의 커밋으로 이루어집니다.</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"># 모든 로컬 텍스트 파일을 업로드</span> | |
| <span class="hljs-meta">... </span> delete_patterns=<span class="hljs-string">"*.txt"</span>, <span class="hljs-comment"># 모든 이전 텍스트 파일을 삭제</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>CLI에서 업로드</span></h2> <p data-svelte-h="svelte-16wyr5a">터미널에서 <code>hf upload</code> 명령어를 사용하여 Hub에 파일을 직접 업로드할 수 있습니다. 내부적으로는 위에서 설명한 것과 동일한 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> 와 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> 함수를 사용합니다.</p> <p data-svelte-h="svelte-331k2h">다음과 같이 단일 파일 또는 전체 폴더를 업로드할 수 있습니다:</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"># 사용례: hf upload [repo_id] [local_path] [path_in_repo]</span> | |
| <span class="hljs-meta">>>> </span>hf upload Wauplin/my-cool-model ./models/model.safetensors model.safetensors | |
| https://huggingface.co/Wauplin/my-cool-model/blob/main/model.safetensors | |
| <span class="hljs-meta">>>> </span>hf 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-1ey89ug"><code>local_path</code> 와 <code>path_in_repo</code>는 선택 사항이며 주어지지 않을 시 임의로 추정됩니다. | |
| <code>local_path</code>가 설정되지 않은 경우, 이 툴은 로컬 폴더나 파일에 <code>repo_id</code>와 같은 이름이 있는지 확인하며, 발견된 경우 해당 폴더나 파일이 업로드됩니다. | |
| 같은 이름의 폴더나 파일을 찾지 못한다면 사용자에게 <code>local_path</code>를 명시하도록 요청하는 예외 처리가 발생합니다. | |
| 어떤 경우든 <code>path_in_repo</code>가 설정되어 있지 않으면 파일이 리포지토리의 루트 디렉터리에 업로드됩니다.</p> <p data-svelte-h="svelte-1c65iw3">CLI 업로드 명령어에 대한 자세한 내용은 <a href="./cli#hf-upload">CLI 가이드</a>를 참조하세요.</p> <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>고급 기능</span></h2> <p data-svelte-h="svelte-kgq54h">대부분의 경우, Hub에 파일을 업로드하는 데 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a>과 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> 이상이 필요하지 않습니다. | |
| 하지만 <code>huggingface_hub</code>에는 작업을 더 쉽게 할 수 있는 고급 기능이 있습니다. 그 기능들을 살펴봅시다!</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>논블로킹 업로드</span></h3> <p data-svelte-h="svelte-1s8szb4">메인 스레드를 멈추지 않고 데이터를 푸시하고 싶은 경우가 있습니다. | |
| 이는 모델 학습을 계속 진행하면서 로그와 아티팩트를 업로드할 때 특히 유용합니다. | |
| 이렇게 하려면 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a>과 [<a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> 에 <code>run_as_future</code> 인수를 사용하고 <a href="https://docs.python.org/3/library/concurrent.futures.html#future-objects" rel="nofollow"><code>concurrent.futures.Future</code></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><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"># 백그라운드에서 업로드 작업 수행 (논블로킹)</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"># 업로드가 완료될 때까지 대기 (블로킹)</span> | |
| ...<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-n4p8uz"><p><code>run_as_future=True</code>를 사용하면 백그라운드 작업이 큐에 대기됩니다. 이는 작업이 올바른 순서로 실행된다는 것을 의미합니다.</p></blockquote> <p data-svelte-h="svelte-1nwj3g">백그라운드 작업은 주로 데이터를 업로드하거나 커밋을 생성하는 데 유용하지만, 이 외에도 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.run_as_future">run_as_future()</a>를 사용하여 원하는 메소드를 대기열에 넣을 수 있습니다. | |
| 예를 들어, 해당 기능을 사용하여 백그라운드에서 리포지토리를 만든 다음 그대로 데이터를 업로드할 수 있습니다. | |
| 업로드 메소드에 내장된 <code>run_as_future</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.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>청크 단위로 폴더 업로드하기</span></h3> <p data-svelte-h="svelte-emt9nt"><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a>를 사용하면 전체 폴더를 Hub에 쉽게 업로드할 수 있지만, 대용량 폴더(수천 개의 파일 또는 수백 GB의 용량)의 경우 문제가 될 수 있습니다. | |
| 파일이 많은 폴더가 있는 경우 여러 커밋에 걸쳐 업로드하는 것이 좋습니다. | |
| 업로드 중에 오류나 연결 문제가 발생해도 처음부터 다시 시작할 필요는 없습니다.</p> <p data-svelte-h="svelte-it8aee">여러 커밋으로 폴더를 업로드하려면 <code>multi_commits=True</code>를 인수로 전달하면 됩니다. | |
| 내부적으로 <code>huggingface_hub</code>는 업로드/삭제할 파일을 나열하고 여러 커밋으로 분할합니다. | |
| 커밋을 분할하는 전략은 업로드할 파일의 수와 크기에 따라 결정됩니다. | |
| 모든 커밋을 푸시하기 위해 Hub에 PR이 열리게 되며, PR이 준비되면 여러 커밋이 단일 커밋으로 뭉쳐집니다. | |
| 완료하기 전에 프로세스가 중단된 경우 스크립트를 다시 실행하여 업로드를 재개할 수 있습니다. 생성된 PR이 자동으로 감지되고 업로드가 중단된 지점부터 업로드가 재개됩니다. | |
| 업로드 진행 상황을 더 잘 이해하고 싶다면 <code>multi_commits_verbose=True</code>를 인수로 전달하면 됩니다.</p> <p data-svelte-h="svelte-11l534">다음은 여러 커밋으로 체크포인트 폴더를 데이터셋에 업로드하는 예제입니다. | |
| Hub에 PR이 생성되고 업로드가 완료되면 자동으로 병합됩니다. | |
| PR을 계속 열어두고 수동으로 검토하려면 <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-bm1bf">업로드 전략(즉, 생성되는 커밋)을 더 잘 제어하고 싶으면 로우 레벨의 <code>plan_multi_commits</code> 와 <code>create_commits_on_pr</code> 메서드를 살펴보세요.</p> <blockquote class="warning" data-svelte-h="svelte-1silgv5"><p><code>multi_commits</code>은 아직 실험적인 기능입니다. | |
| 해당 API와 동작은 향후 사전 고지 없이 변경될 수 있습니다.</p></blockquote> <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>예약된 업로드</span></h3> <p data-svelte-h="svelte-5ld3fr">허깅 페이스 Hub를 사용하면 데이터를 쉽게 저장하고 버전업할 수 있지만, 동일한 파일을 수천 번 업데이트할 때는 몇 가지 제한이 있습니다. | |
| 예를 들어, 배포된 Space에 대한 교육 프로세스 또는 사용자 로그를 저장하고 싶을 때 Hub에 데이터 집합으로 데이터를 업로드하는 것이 좋아 보이지만, 이를 제대로 하기 어려울 수 있습니다. | |
| 데이터의 모든 업데이트를 버전으로 만들게 되면 git 리포지토리를 사용할 수 없는 상태로 만들어 버리기 때문입니다. | |
| <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a> 클래스는 이 문제에 대한 해결책을 제공합니다.</p> <p data-svelte-h="svelte-p8kqlc">이 클래스는 로컬 폴더를 Hub에 정기적으로 푸시하는 백그라운드 작업을 실행합니다. | |
| 일부 텍스트를 입력으로 받아 두 개의 번역을 생성한 다음, 사용자가 선호하는 번역을 선택할 수 있는 라디오 스페이스가 있다고 가정해 보겠습니다. | |
| 이 스페이스의 각 실행에 대해 입력, 출력 및 사용자 기본 설정을 저장하여 결과를 분석하려고 하는데, 이것은 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>의 완벽한 사용 사례가 될 수 있습니다. | |
| Hub에 데이터(잠재적으로 수백만 개의 사용자 피드백)를 저장하고 싶지만, 굳이 각 사용자의 입력을 <em>실시간</em> 으로 저장할 필요는 없으니 데이터를 로컬 JSON 파일에 저장한 다음 10분마다 업로드하면 됩니다. | |
| 예제 코드는 다음과 같습니다:</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"># 데이터를 저장할 파일을 선언합니다. UUID를 이용하여 중복을 방지합니다.</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"># 정기 업로드를 예약합니다. 원격 리포지토리와 로컬 폴더가 없을시 생성합니다.</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"># 사용자가 피드백을 제출할 때 호출받을 함수를 정의합니다. (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> JSON Lines 파일에 입/출력과 사용자 피드백을 추가합니다. 타 사용자에 의한 동시적인 쓰기를 지양하기 위해 스레드 락을 사용합니다. | |
| <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"># 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"># Gradio 데모를 정의하고 `save_feedback`을 사용합니다</span> | |
| <span class="hljs-meta">>>> </span>demo.launch()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-5h3f55">사용자 입력/출력 및 피드백은 Hub에서 데이터 세트의 형태로 사용할 수 있습니다. | |
| 고유한 JSON 파일 이름을 사용하면 이전 실행이나 다른 스페이스/복제본이 동일한 리포지토리에 동시에 푸시하는 경우의 데이터를 덮어쓰지 않도록 보장할 수 있습니다.</p> <p data-svelte-h="svelte-72a8ki"><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>에 대한 상세 사항은 다음과 같습니다:</p> <ul data-svelte-h="svelte-1rmej1x"><li><strong>추가 전용:</strong> | |
| 스케줄러는 폴더에 콘텐츠를 추가만 한다고 가정합니다. 기존 파일에 데이터를 추가하거나 새 파일을 만들 때만 사용하여야 합니다. | |
| 파일을 삭제하거나 덮어쓰면 리포지토리가 손상될 수 있습니다.</li> <li><strong>git 히스토리</strong>: | |
| 기본적으로 스케줄러는 <code>매 분마다</code> 폴더를 커밋합니다. | |
| git 리포지토리를 너무 많이 오염시키지 않으려면 최소값을 5분으로 설정하는 것이 좋습니다. | |
| 또한 스케줄러는 빈 커밋을 피하도록 설계되었는데, 만약 폴더에서 새 콘텐츠가 감지되지 않으면 예약된 커밋을 삭제합니다.</li> <li><strong>에러:</strong> | |
| 스케줄러는 백그라운드 스레드로 실행되고, 이는 클래스를 인스턴스화할 때 시작되며 절대 멈추지 않습니다. | |
| 만약 업로드 중에 오류가 발생하면(예: 연결 문제), 스케줄러는 이를 아무 말 없이 무시하고 다음 예약된 커밋에서 재시도 합니다.</li> <li><strong>스레드 안전:</strong> | |
| 대부분의 경우 파일 락에 대해 걱정할 필요 없이 파일에 쓰기 작업을 수행 할 수 있습니다. | |
| 스케줄러는 업로드하는 동안 대상 폴더에 콘텐츠를 쓰더라도 충돌하거나 손상되지 않습니다. | |
| 그러나, 부하가 많은 앱의 경우 이런 작업에서 <em>동시성 문제</em> 가 발생할 수 있습니다. | |
| 이 경우, <code>scheduler.lock</code>을 사용하여 스레드 안전을 보장하는 것이 좋습니다. | |
| 이 락은 스케줄러가 폴더에서 변경 사항을 검색할 때만 차단되며, 데이터를 업로드할 때는 차단되지 않습니다. | |
| 따라서 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>스페이스 지속성 데모</span></h4> <p data-svelte-h="svelte-19p8p7h">스페이스에서 Hub의 데이터셋으로 데이터를 영속하는 것이 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>의 주요 사용 사례입니다. | |
| 각 사용 사례에 따라 데이터 구조를 다르게 설정해야 할 수도 있습니다. | |
| 데이터 구조는 동시 사용자와 재시작에 대해 견고해야 하며, 이는 대개 UUID를 생성 해야 함을 의미합니다. | |
| 견고함 뿐만 아니라, 재사용성을 위해 🤗 데이터 세트 라이브러리에서 읽을 수 있는 형식으로 데이터를 업로드해야 합니다. | |
| 이 <a href="https://huggingface.co/spaces/Wauplin/space_to_dataset_saver" rel="nofollow">스페이스</a> | |
| 예제에서 여러 가지 데이터 형식을 저장하는 방법을 보여줍니다(각자의 필요에 맞게 조정해야 할 수도 있습니다).</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>사용자 지정 업로드</span></h4> <p data-svelte-h="svelte-kanvq3"><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>는 데이터가 추가 전용이며 “있는 그대로” 업로드해야 한다고 가정합니다. | |
| 그러나 데이터 업로드 방식을 사용자 스스로 정의하고 싶을 때도 있는데, <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>를 상속받는 클래스를 생성하고 <code>push_to_hub</code> 메서드를 덮어쓰면 됩니다(원하는 방식으로 자유롭게 덮어쓰세요). | |
| 이렇게 하면 해당 클래스가 백그라운드 스레드에서 <code>매 분마다</code> 호출됩니다. | |
| 동시성 및 오류에 대해 걱정할 필요는 없지만 빈 커밋이나 중복된 데이터를 푸시하는 것과 같은 케이스들에 주의해야 합니다.</p> <p data-svelte-h="svelte-1ddro93">아래의 (단순화된) 예제에서는 <code>push_to_hub</code>를 덮어써서 모든 PNG 파일을 단일 아카이브에 압축하여 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. PNG 파일들을 나열합니다.</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"># 커밋할 것이 없다면 일찍 리턴합니다.</span> | |
| <span class="hljs-comment"># 2. png 파일들을 단일 Zip 파일로 압축합니다.</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. 압축된 파일을 업로드 합니다.</span> | |
| self.api.upload_file(..., path_or_fileobj=archive_path) | |
| <span class="hljs-comment"># 4. 로컬 png 파일을 삭제하여 다음에 다시 업로드 되는 일을 방지합니다.</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-1afn05e"><code>push_to_hub</code>를 덮어쓰면 다음과 같은 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitScheduler">CommitScheduler</a>의 속성에 접근할 수 있습니다:</p> <ul data-svelte-h="svelte-1ih47ga"><li><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> 클라이언트: <code>api</code></li> <li>폴더 매개변수: <code>folder_path</code> 및 <code>path_in_repo</code></li> <li>리포지토리 매개변수: <code>repo_id</code>, <code>repo_type</code>, <code>revision</code></li> <li>스레드 락: <code>lock</code></li></ul> <blockquote class="tip" data-svelte-h="svelte-31t6h6"><p>사용자 정의 스케줄러의 더 많은 예제는 사용 사례에 따른 다양한 구현이 포함된 <a href="https://huggingface.co/spaces/Wauplin/space_to_dataset_saver" rel="nofollow">데모 스페이스</a>를 참조하세요.</p></blockquote> <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-t7el3n"><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> 및 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> 함수는 일반적으로 사용하기 편리한 하이 레벨 API입니다. | |
| 로우 레벨에서 작업할 필요가 없다면 이 함수들을 먼저 사용해 볼 것을 권장합니다. | |
| 만약 커밋 레벨에서 작업하고 싶다면 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a> 함수를 직접 사용할 수 있습니다.</p> <p data-svelte-h="svelte-10qtzod"><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>이 지원하는 작업 유형은 세 가지입니다:</p> <ul data-svelte-h="svelte-5d6jbs"><li><p><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitOperationAdd">CommitOperationAdd</a> 는 파일을 Hub에 업로드합니다. 파일이 이미 있는 경우 파일 내용을 덮어씁니다. 이 작업은 두 개의 인수를 받습니다:</p> <ul><li><code>path_in_repo</code>: 파일을 업로드할 리포지토리 경로.</li> <li><code>path_or_fileobj</code>: Hub에 업로드할 파일의 파일 시스템상 파일 경로 또는 파일 스타일 객체.</li></ul></li> <li><p><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitOperationDelete">CommitOperationDelete</a>는 리포지토리에서 파일 또는 폴더를 제거합니다. 이 작업은 <code>path_in_repo</code>를 인수로 받습니다.</p></li> <li><p><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitOperationCopy">CommitOperationCopy</a>는 리포지토리 내의 파일을 복사합니다. 이 작업은 세 가지 인수를 받습니다:</p> <ul><li><code>src_path_in_repo</code>: 복사할 파일의 리포지토리 경로.</li> <li><code>path_in_repo</code>: 파일 붙여넣기를 수행할 리포지토리 경로.</li> <li><code>src_revision</code>: 선택 사항 - 다른 브랜치/리비전에서 파일을 복사하려는 경우 필요한 복사할 파일의 리비전.</li></ul></li></ul> <p data-svelte-h="svelte-144tdyg">예를 들어, Hub 리포지토리에서 두 개의 파일을 업로드하고 한 개의 파일을 삭제하려는 경우:</p> <ol data-svelte-h="svelte-pe0u3z"><li>파일을 추가하거나 삭제하고 폴더를 삭제하기 위해 적절한 <code>CommitOperation</code>을 사용합니다:</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-1a2ohh2"><li>작업을 <a href="/docs/huggingface_hub/pr_4113/ko/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-1cakgxx">다음 함수들은 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a> 및 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> 외에도 내부적으로 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>을 사용합니다:</p> <ul data-svelte-h="svelte-1qq0gp4"><li><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.delete_file">delete_file()</a>은 Hub의 리포지토리에서 단일 파일을 삭제합니다.</li> <li><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.delete_folder">delete_folder()</a>는 Hub의 리포지토리에서 전체 폴더를 삭제합니다.</li> <li><a href="/docs/huggingface_hub/pr_4113/ko/package_reference/cards#huggingface_hub.metadata_update">metadata_update()</a>는 리포지토리의 메타데이터를 업데이트합니다.</li></ul> <p data-svelte-h="svelte-13r3tr5">자세한 내용은 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi">HfApi</a> 의 레퍼런스를 참조하세요.</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>커밋하기 전에 LFS 파일 미리 업로드하기</span></h3> <p data-svelte-h="svelte-1pllxnu">경우에 따라 커밋 호출을 <strong>하기 전에</strong> 대용량 파일을 S3에 업로드해야 할 수도 있습니다. | |
| 예를 들어 인메모리에 생성된 여러 개의 샤드에 있는 데이터 세트를 커밋하는 경우, 샤드를 하나씩 업로드해야 메모리 부족 문제를 피할 수 있을 것입니다. | |
| 이 문제에 대한 해결책은 각 샤드를 리포지토리에 별도의 커밋으로 업로드하는 것입니다. | |
| 이 방법은 완벽하게 유효하지만, 수십 개의 커밋을 생성하여 잠재적으로 git 히스토리를 엉망으로 만들 수 있다는 단점이 있습니다. | |
| 이 문제를 극복하기 위해 파일을 하나씩 S3에 업로드한 다음 마지막에 하나의 커밋을 생성할 수 있습니다. | |
| 이는 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.preupload_lfs_files">preupload_lfs_files()</a>와 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>을 함께 사용하면 됩니다.</p> <blockquote class="warning" data-svelte-h="svelte-15rxxow"><p>이 방법은 고급 사용자를 위한 방식입니다. | |
| 사전에 파일을 미리 업로드하는 로우 레벨 로직을 처리하는 대신 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_file">upload_file()</a>, <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.upload_folder">upload_folder()</a> 또는 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>을 직접 사용하는 것이 대부분의 경우에 적합합니다. | |
| <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.preupload_lfs_files">preupload_lfs_files()</a>의 주요 주의 사항은 커밋이 실제로 이루어질 때까지는 Hub의 리포지토리에서 업로드 파일에 액세스할 수 없다는 것입니다. | |
| 궁금한 점이 있으면 언제든지 Discord나 GitHub 이슈로 문의해 주세요.</p></blockquote> <p data-svelte-h="svelte-ng6ine">다음은 파일을 미리 업로드하는 방법을 보여주는 간단한 예시입니다:</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"># 생성될 모든 `CommitOperationAdd` 객체를 나열합니다.</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"># bin 자료를 생성합니다.</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"># 커밋을 생성합니다.</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-1x43vbz">먼저, <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.CommitOperationAdd">CommitOperationAdd</a> 오브젝트를 하나씩 생성합니다. 실전을 상정한 예제에서는, 여기에 생성된 샤드를 포함합니다. | |
| 각 파일은 다음 파일을 생성하기 전에 업로드됩니다. | |
| <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.preupload_lfs_files">preupload_lfs_files()</a> 단계에서는 <strong><code>CommitOperationAdd</code> 오브젝트가 변경됩니다.</strong> 따라서<a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>에 직접 전달할 때만 사용해야 합니다. | |
| 오브젝트의 주요 업데이트는 <strong>바이너리 콘텐츠가 제거</strong>된다는 것인데, 이는 따로 레퍼런스를 저장하지 않으면 가비지 콜렉팅 됨을 의미합니다. 이미 업로드된 콘텐츠를 메모리상에 남기고 싶지 않기 때문입니다. | |
| 마지막으로 모든 작업을 <a href="/docs/huggingface_hub/pr_4113/ko/package_reference/hf_api#huggingface_hub.HfApi.create_commit">create_commit()</a>에 전달하여 커밋을 생성합니다. | |
| 아직 처리되지 않은 추가 작업(추가, 삭제 또는 복사)도 전달하면 올바르게 처리됩니다.</p> <h2 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>대용량 업로드를 위한 팁과 요령</span></h2> <p data-svelte-h="svelte-nd05oc">리포지토리에 있는 대량의 데이터를 처리할 때 주의해야 할 몇 가지 제한 사항이 있습니다. | |
| 데이터를 스트리밍하는 데 걸리는 시간을 고려하면, 프로세스 마지막에 업로드/푸시가 실패하거나 hf.co에서 또는 로컬에서 작업할 때 성능 저하가 발생하는 것은 매우 성가신 일이 될 수 있습니다.</p> <p data-svelte-h="svelte-1bb9lgx">Hub에서 리포지토리를 구성하는 방법에 대한 모범 사례는 <a href="https://huggingface.co/docs/hub/repositories-recommendations" rel="nofollow">리포지토리 제한 사항 및 권장 사항</a> 가이드를 참조하세요. | |
| 다음으로 업로드 프로세스를 최대한 원활하게 진행할 수 있는 몇 가지 실용적인 팁을 살펴보겠습니다.</p> <ul data-svelte-h="svelte-pb8uw9"><li><strong>작게 시작하세요</strong>: 업로드 스크립트를 테스트할 때는 소량의 데이터로 시작하는 것이 좋습니다. 소량의 데이터를 처리하는데 적은 시간이 들기 때문에 스크립트를 반복하는 것이 더 쉽습니다.</li> <li><strong>실패를 예상하세요</strong>: 대량의 데이터를 스트리밍하는 것은 어려운 일입니다. 어떤 일이 일어날지 알 수 없지만, 항상 컴퓨터, 연결, 서버 등 어떤 이유로든 한 번쯤은 실패할 수 있다는 점을 고려하는 것이 가장 좋습니다. 예를 들어, 많은 양의 파일을 업로드할 계획이라면 다음 파일을 업로드하기 전에 이미 업로드한 파일을 로컬에서 추적하는 것이 가장 좋습니다. 이미 커밋된 LFS 파일은 절대 두 번 다시 업로드되지 않지만 클라이언트 측에서 이를 확인하면 시간을 절약할 수 있습니다.</li> <li><strong><del><code>hf_transfer</code>를 사용하세요</del></strong> (deprecated): <code>hf_transfer</code>는 더 이상 사용되지 않습니다. Hugging Face Hub는 이제 Xet 스토리지 백엔드를 사용하며, 모든 파일 전송은 <code>hf-xet</code>를 통해 이루어집니다. 고성능 전송이 필요한 경우 <code>HF_XET_HIGH_PERFORMANCE=1</code> 환경 변수를 설정하세요. 자세한 내용은 <a href="https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfxethighperformance" rel="nofollow"><code>HF_XET_HIGH_PERFORMANCE</code></a>를 참조하세요.</li></ul> <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/ko/guides/upload.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_1hcjqts = { | |
| assets: "/docs/huggingface_hub/pr_4113/ko", | |
| base: "/docs/huggingface_hub/pr_4113/ko", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/huggingface_hub/pr_4113/ko/_app/immutable/entry/start.e4d70577.js"), | |
| import("/docs/huggingface_hub/pr_4113/ko/_app/immutable/entry/app.3b0f3b68.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 15], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 81.9 kB
- Xet hash:
- 60da7b0b5f2aa3d910467946207d1ceb4c77ceb02c6371d204362353fb280f9d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.