Buckets:

rtrm's picture
download
raw
111 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;การแบ่งปันโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models)&quot;,&quot;local&quot;:&quot;การแบงปนโมเดลทผานการเทรนมาแลว-pretrained-models&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;ใช้ push_to_hub API&quot;,&quot;local&quot;:&quot;ใช-pushtohub-api&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ใช้ huggingface_hub Python library&quot;,&quot;local&quot;:&quot;ใช-huggingfacehub-python-library&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ใช้ web interface&quot;,&quot;local&quot;:&quot;ใช-web-interface&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;การอัพโหลดไฟล์โมเดลต่างๆ&quot;,&quot;local&quot;:&quot;การอพโหลดไฟลโมเดลตางๆ&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;แนวทางแบบใช้ upload_file&quot;,&quot;local&quot;:&quot;แนวทางแบบใช-uploadfile&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;คลาส Repository&quot;,&quot;local&quot;:&quot;คลาส-repository&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;แนวทางแบบใช้ git&quot;,&quot;local&quot;:&quot;แนวทางแบบใช-git&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/course/pr_1069/th/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/entry/start.eeb02c13.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/scheduler.37c15a92.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/singletons.d692cc64.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/index.18351ede.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/paths.f4699845.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/entry/app.25e78aa9.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/index.2bf4358c.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/nodes/0.d0785757.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/nodes/30.da919599.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/Tip.363c041f.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/Youtube.1e50a667.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/CodeBlock.4e987730.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/CourseFloatingBanner.6add7356.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/FrameworkSwitchCourse.8d4d4ab6.js">
<link rel="modulepreload" href="/docs/course/pr_1069/th/_app/immutable/chunks/getInferenceSnippets.24b50994.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;การแบ่งปันโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models)&quot;,&quot;local&quot;:&quot;การแบงปนโมเดลทผานการเทรนมาแลว-pretrained-models&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;ใช้ push_to_hub API&quot;,&quot;local&quot;:&quot;ใช-pushtohub-api&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ใช้ huggingface_hub Python library&quot;,&quot;local&quot;:&quot;ใช-huggingfacehub-python-library&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;ใช้ web interface&quot;,&quot;local&quot;:&quot;ใช-web-interface&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;การอัพโหลดไฟล์โมเดลต่างๆ&quot;,&quot;local&quot;:&quot;การอพโหลดไฟลโมเดลตางๆ&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;แนวทางแบบใช้ upload_file&quot;,&quot;local&quot;:&quot;แนวทางแบบใช-uploadfile&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;คลาส Repository&quot;,&quot;local&quot;:&quot;คลาส-repository&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;แนวทางแบบใช้ git&quot;,&quot;local&quot;:&quot;แนวทางแบบใช-git&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="bg-white leading-none border border-gray-100 rounded-lg flex p-0.5 w-56 text-sm mb-4"><a class="flex justify-center flex-1 py-1.5 px-2.5 focus:outline-none !no-underline rounded-l bg-red-50 dark:bg-transparent text-red-600" href="?fw=pt"><svg class="mr-1.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><defs><clipPath id="a"><rect x="3.05" y="0.5" width="25.73" height="31" fill="none"></rect></clipPath></defs><g clip-path="url(#a)"><path d="M24.94,9.51a12.81,12.81,0,0,1,0,18.16,12.68,12.68,0,0,1-18,0,12.81,12.81,0,0,1,0-18.16l9-9V5l-.84.83-6,6a9.58,9.58,0,1,0,13.55,0ZM20.44,9a1.68,1.68,0,1,1,1.67-1.67A1.68,1.68,0,0,1,20.44,9Z" fill="#ee4c2c"></path></g></svg> Pytorch </a><a class="flex justify-center flex-1 py-1.5 px-2.5 focus:outline-none !no-underline rounded-r text-gray-500 filter grayscale" href="?fw=tf"><svg class="mr-1.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="0.94em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 274"><path d="M145.726 42.065v42.07l72.861 42.07v-42.07l-72.86-42.07zM0 84.135v42.07l36.43 21.03V105.17L0 84.135zm109.291 21.035l-36.43 21.034v126.2l36.43 21.035v-84.135l36.435 21.035v-42.07l-36.435-21.034V105.17z" fill="#E55B2D"></path><path d="M145.726 42.065L36.43 105.17v42.065l72.861-42.065v42.065l36.435-21.03v-84.14zM255.022 63.1l-36.435 21.035v42.07l36.435-21.035V63.1zm-72.865 84.135l-36.43 21.035v42.07l36.43-21.036v-42.07zm-36.43 63.104l-36.436-21.035v84.135l36.435-21.035V210.34z" fill="#ED8E24"></path><path d="M145.726 0L0 84.135l36.43 21.035l109.296-63.105l72.861 42.07L255.022 63.1L145.726 0zm0 126.204l-36.435 21.03l36.435 21.036l36.43-21.035l-36.43-21.03z" fill="#F8BF3C"></path></svg> TensorFlow </a></div> <h1 class="relative group"><a id="การแบงปนโมเดลทผานการเทรนมาแลว-pretrained-models" 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="#การแบงปนโมเดลทผานการเทรนมาแลว-pretrained-models"><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>การแบ่งปันโมเดลที่ผ่านการเทรนมาแล้ว (pretrained models)</span></h1> <div class="flex space-x-1 absolute z-10 right-0 top-0"><a href="https://discuss.huggingface.co/t/chapter-4-questions" target="_blank"><img alt="Ask a Question" class="!m-0" src="https://img.shields.io/badge/Ask%20a%20question-ffcb4c.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgLTEgMTA0IDEwNiI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiMyMzFmMjA7fS5jbHMtMntmaWxsOiNmZmY5YWU7fS5jbHMtM3tmaWxsOiMwMGFlZWY7fS5jbHMtNHtmaWxsOiMwMGE5NGY7fS5jbHMtNXtmaWxsOiNmMTVkMjI7fS5jbHMtNntmaWxsOiNlMzFiMjM7fTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5EaXNjb3Vyc2VfbG9nbzwvdGl0bGU+PGcgaWQ9IkxheWVyXzIiPjxnIGlkPSJMYXllcl8zIj48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik01MS44NywwQzIzLjcxLDAsMCwyMi44MywwLDUxYzAsLjkxLDAsNTIuODEsMCw1Mi44MWw1MS44Ni0uMDVjMjguMTYsMCw1MS0yMy43MSw1MS01MS44N1M4MCwwLDUxLjg3LDBaIi8+PHBhdGggY2xhc3M9ImNscy0yIiBkPSJNNTIuMzcsMTkuNzRBMzEuNjIsMzEuNjIsMCwwLDAsMjQuNTgsNjYuNDFsLTUuNzIsMTguNEwzOS40LDgwLjE3YTMxLjYxLDMxLjYxLDAsMSwwLDEzLTYwLjQzWiIvPjxwYXRoIGNsYXNzPSJjbHMtMyIgZD0iTTc3LjQ1LDMyLjEyYTMxLjYsMzEuNiwwLDAsMS0zOC4wNSw0OEwxOC44Niw4NC44MmwyMC45MS0yLjQ3QTMxLjYsMzEuNiwwLDAsMCw3Ny40NSwzMi4xMloiLz48cGF0aCBjbGFzcz0iY2xzLTQiIGQ9Ik03MS42MywyNi4yOUEzMS42LDMxLjYsMCwwLDEsMzguOCw3OEwxOC44Niw4NC44MiwzOS40LDgwLjE3QTMxLjYsMzEuNiwwLDAsMCw3MS42MywyNi4yOVoiLz48cGF0aCBjbGFzcz0iY2xzLTUiIGQ9Ik0yNi40Nyw2Ny4xMWEzMS42MSwzMS42MSwwLDAsMSw1MS0zNUEzMS42MSwzMS42MSwwLDAsMCwyNC41OCw2Ni40MWwtNS43MiwxOC40WiIvPjxwYXRoIGNsYXNzPSJjbHMtNiIgZD0iTTI0LjU4LDY2LjQxQTMxLjYxLDMxLjYxLDAsMCwxLDcxLjYzLDI2LjI5YTMxLjYxLDMxLjYxLDAsMCwwLTQ5LDM5LjYzbC0zLjc2LDE4LjlaIi8+PC9nPjwvZz48L3N2Zz4="></a> <a href="https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/th/chapter4/section3_pt.ipynb" target="_blank"><img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"></a> <a href="https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/th/chapter4/section3_pt.ipynb" target="_blank"><img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"></a></div> <p data-svelte-h="svelte-q4l2bw">ในขั้นตอนข้างล่างต่อไปนี้ เราจะมาดูวิธีที่ง่ายที่สุดในการแบ่งปันโมเดลที่ผ่านการเทรนมาแล้วบน 🤗 Hub มีเครื่องมือและสิ่งอำนวยความสะดวกมากมายที่ทำให้การแบ่งปันและอัพเดตโมเดลโดยตรงบน Hub เป็นเรื่องง่าย ซึ่งนั่นคือสิ่งที่เราจะมาสำรวจกันต่อจากนี้</p> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/9yY3RB_GSPM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-1ghkmqt">เราส่งเสริมให้ผู้ใช้ทุกคนที่เทรนโมเดลช่วยมีส่วนร่วมโดยการแบ่งปันโมเดลเหล่านั้นให้กับชุมชน การแบ่งปันโมเดลนั้นสามารถช่วยเหลือผู้อื่นได้ ช่วยลดเวลาและทรัพยากรในการประมวลผล และช่วยให้เข้าถึงไฟล์ผลลัพธ์จากการเทรน (artifacts) ที่เป็นประโยชน์ได้ แม้ว่าจะเป็นโมเดลที่ถูกเทรนมากับชุดข้อมูลที่เฉพาะเจาะจงมากก็ตาม ในทางเดียวกันนั้นคุณก็ได้รับประโยชน์จากงานที่คนอื่นได้ทำเช่นกัน!</p> <p data-svelte-h="svelte-srkmsj">มี 3 วิธีที่สามารถใช้สร้าง model repositories ใหม่ได้:</p> <ul data-svelte-h="svelte-15rocxx"><li>ใช้ <code>push_to_hub</code> API</li> <li>ใช้ <code>huggingface_hub</code> Python library</li> <li>ใช้ web interface</li></ul> <p data-svelte-h="svelte-1bjp40d">เมื่อคุณได้สร้าง repository แล้ว คุณสามารถอัพโหลดไฟล์ต่างๆเข้าไปได้ผ่าน git และ git-lfs ในส่วนถัดไปเราจะพาคุณมาดูขั้นตอนการสร้าง model repositories และการอัพโหลดไฟล์ต่างๆเข้าไป</p> <h2 class="relative group"><a id="ใช-pushtohub-api" 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-api"><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 API</span></h2> <iframe class="w-full xl:w-4/6 h-80" src="https://www.youtube-nocookie.com/embed/Zh0FfmVrKX0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> <p data-svelte-h="svelte-1gv70fn">วิธีที่ง่ายที่สุดในการอัพโหลดไฟล์ขึ้นไปสู่ Hub คือการใช้ <code>push_to_hub</code> API</p> <p data-svelte-h="svelte-1v7xpvh">ก่อนจะไปกันต่อ คุณจะต้องสร้างโทเค็นสำหรับรับรองความน่าเชื่อถือ (authentication token) เพื่อให้ <code>huggingface_hub</code> API รู้ว่าคุณคือใครและคุณมีสิทธิ์ในการเขียน (write access) ใน namespaces อะไรบ้าง ในตอนนี้ให้คุณทำให้มั่นใจว่าคุณอยู่ใน environment ที่คุณได้ทำการติดตั้ง <code>transformers</code> เอาไว้แล้ว (ดู <a href="/course/chapter0">ติดตั้งโปรแกรม</a>) ถ้าคุณกำลังอยู่ใน notebook คุณสามารถใช้งานคำสั่งต่อไปนี้ในการเข้าสู่ระบบได้เลย:</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">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login
notebook_login()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1ie86o4">สำหรับใน 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 login<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-gbvhw2">ในทั้งสองกรณี คุณควรจะถูกให้กรอก username และ password ซึ่งเป็นชุดเดียวกันกับที่คุณใช้ในการ login เข้าสู่ Hub ถ้าหากคุณยังไม่มีโปรไฟล์ Hub คุณสามารถสร้างได้ <a href="https://huggingface.co/join" rel="nofollow">ที่นี่</a></p> <p data-svelte-h="svelte-ueggq2">เยี่ยม! ตอนนี้คุณมี authentication token เก็บเอาไว้ใน cache folder ของคุณแล้ว มาเริ่มสร้าง repositories กันเถอะ!</p> <p data-svelte-h="svelte-4q6ikf">ถ้าคุณเคยได้ลองใช้งาน <code>Trainer</code> API ในการเทรนโมเดลมาบ้างแล้ว วิธีที่ง่ายที่สุดที่จะอัพโหลดขึ้นไปสู่ Hub คือการตั้ง <code>push_to_hub=True</code> ตอนที่คุณกำหนด <code>TrainingArguments</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-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments
training_args = TrainingArguments(
<span class="hljs-string">&quot;bert-finetuned-mrpc&quot;</span>, save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>, push_to_hub=<span class="hljs-literal">True</span>
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-zmx9r1">เมื่อคุณเรียกใช้ <code>trainer.train()</code> ตัว <code>Trainer</code> จะทำการอัพโหลดโมเดลของคุณขึ้นสู่ Hub ในทุกๆครั้งที่มันถูกบันทึก (ในที่นี้คือ ทุกๆรอบการเทรน (epoch)) ใน repository และ namespace ของคุณ repository นั้นจะถูกตั้งชื่อให้เหมือนกับโฟลเดอร์ output ที่คุณเลือก (ในที่นี้คือ <code>bert-finetuned-mrpc</code>) แต่คุณสามารถเลือกชื่ออื่นได้โดยการใช้ <code>hub_model_id = &quot;ชื่ออื่น&quot;</code></p> <p data-svelte-h="svelte-7jffnw">สำหรับการอัพโหลดโมเดลของคุณเข้าสู่องค์กรที่คุณเป็นสมาชิกนั้น คุณสามารถทำได้โดย เพียงแค่ผ่านตัวแปล <code>hub_model_id = &quot;องค์กร_ของคุณ/ชื่อ_repo_ของคุณ&quot;</code> เข้าไป</p> <p data-svelte-h="svelte-1gfuffk">เมื่อการเทรนของคุณเสร็จสิ้น คุณควรที่จะใช้ <code>trainer.push_to_hub()</code> อีกครั้งเป็นครั้งสุดท้าย เพื่ออัพโหลดโมเดลเวอร์ชั่นล่าสุดของคุณ มันจะสร้างการ์ดโมเดล (model card) ที่มีข้อมูลเมตา (metadata) ที่เกี่ยวข้อง เช่น รายงาน hyperparameters ที่ใช้ และผลลัพธ์ของการประเมินผล (evaluation result) ให้คุณด้วย! ต่อไปนี้เป็นตัวอย่างของเนื้อหาที่คุณเจอได้ในการ์ดโมเดล:</p> <div class="flex justify-center" data-svelte-h="svelte-1lhrimn"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/model_card.png" alt="An example of an auto-generated model card." width="100%"></div> <p data-svelte-h="svelte-11viki4">ในระดับล่างลงไปนั้น การเข้าถึง Model Hub สามารถทำได้โดยตรงจาก objects ประเภท models, tokenizers และconfiguration ผ่านคำสั่ง <code>push_to_hub()</code> คำสั่งนี้จะจัดการทั้งการสร้าง repository และการดันไฟล์โมเดลและ tokenizer ขึ้นสู่ repository โดยตรง ไม่มีความจำเป็นที่จะต้องทำอะไรด้วยตนเองเลย ไม่เหมือนกับ API ที่เราจะได้เห็นข้างล่างนี้</p> <p data-svelte-h="svelte-8nf739">เพื่อให้เห็นภาพมากขึ้นว่ามันทำงานอย่างไร เรามาเริ่มสร้างโมเดลและ tokenizer ตัวแรกกันเถอะ:</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">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForMaskedLM, AutoTokenizer
checkpoint = <span class="hljs-string">&quot;camembert-base&quot;</span>
model = AutoModelForMaskedLM.from_pretrained(checkpoint)
tokenizer = AutoTokenizer.from_pretrained(checkpoint)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-4pakls">ถึงจุดนี้คุณสามารถทำอะไรก็ได้กับมันตามที่คุณต้องการ ไม่ว่าจะเป็นการเพิ่ม tokens ไปใน tokenizer, การเทรนโมเดล, การ fine-tune โมเดล หลังจากที่คุณพอใจกับผลลัพธ์ของโมเดล, weights และ tokenizer แล้ว คุณสามารถเรียกใช้คำสั่ง <code>push_to_hub()</code> ที่มีอยู่ในตัว <code>model</code> object ได้โดยตรง</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 -->model.push_to_hub(<span class="hljs-string">&quot;dummy-model&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1huaa7d">ขั้นตอนนี้จะสร้าง repository ใหม่ชื่อ <code>dummy-model</code> ในโปรไฟล์ของคุณ และเติมมันด้วยไฟล์โมเดลต่างๆของคุณ
ทำแบบเดียวกันนี้กับ tokenizer นั่นจะทำให้ไฟล์ทั้งหมดอยู่บน 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 -->tokenizer.push_to_hub(<span class="hljs-string">&quot;dummy-model&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-3f1hmi">ถ้าคุณสังกัดองค์กร คุณสามารถระบุชื่อขององค์กรใน <code>organization</code> argument เพื่ออัพโหลดเข้าไปใน namespace ขององค์กร:</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 -->tokenizer.push_to_hub(<span class="hljs-string">&quot;dummy-model&quot;</span>, organization=<span class="hljs-string">&quot;huggingface&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-jcytt">ถ้าคุณต้องการที่จะใช้งานโทเค็นของ Hugging Face โดยเฉพาะเจาะจง คุณสามารถระบุมันไปในคำสั่ง <code>push_to_hub()</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 -->tokenizer.push_to_hub(<span class="hljs-string">&quot;dummy-model&quot;</span>, organization=<span class="hljs-string">&quot;huggingface&quot;</span>, use_auth_token=<span class="hljs-string">&quot;&lt;TOKEN&gt;&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-woivds">ในตอนนี้ให้คุณมุ่งหน้าไปที่ Model Hub เพื่อหาโมเดลที่คุณเพิ่งได้อัพโหลดไป: <em><a href="https://huggingface.co/%E0%B8%8A%E0%B8%B7%E0%B9%88%E0%B8%AD-user-%E0%B8%AB%E0%B8%A3%E0%B8%B7%E0%B8%AD-organization/dummy-model" rel="nofollow">https://huggingface.co/ชื่อ-user-หรือ-organization/dummy-model</a></em></p> <p data-svelte-h="svelte-uojcqu">คลิกไปที่แท็บ “Files and versions” และคุณควรจะเห็นไฟล์แบบในภาพข้างล่างนี้:</p> <div class="flex justify-center" data-svelte-h="svelte-19u1vyv"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/push_to_hub_dummy_model.png" alt="Dummy model containing both the tokenizer and model files." width="80%"></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-61jy1">✏️ <strong>ทดลองใช้ได้เลย!</strong> นำโมเดลและ tokenizer ที่เกี่ยวข้องกับ <code>bert-base-cased</code> checkpoint และอัพโหลดขึ้นไปบน repo ใน namespace ของคุณด้วยคำสั่ง <code>push_to_hub()</code> จากนั้นลองตรวจสอบดูว่า repo ปรากฏออกมาในรูปแบบที่สมควรจะเป็นบนหน้าของคุณ ก่อนที่จะลบมันออกไป</p></div> <p data-svelte-h="svelte-p11xk9">อย่างที่คุณได้เห็น คำสั่ง <code>push_to_hub()</code> สามารถรับ arguments ได้มากมาย ทำให้สามารถอัพไฟล์ไปยัง repository หรือ namespace ขององค์กรแบบเจาะจง หรือใช้งานโทเค็น API ที่ต่างกันได้ เราแนะนำให้คุณลองเปิดดูรายละเอียดของคำสั่งนี้ได้โดยตรงที่ <a href="https://huggingface.co/transformers/model_sharing.html" rel="nofollow">🤗 Transformers documentation</a> เพื่อจะได้เข้าใจมากขึ้นว่าคำสั่งนี้สามารถทำอะไรได้บ้าง</p> <p data-svelte-h="svelte-10gh4tt">คำสั่ง <code>push_to_hub()</code> ได้รับการหนุนหลังโดย <a href="https://github.com/huggingface/huggingface_hub" rel="nofollow"><code>huggingface_hub</code></a> Python package ซึ่งให้ API โดยตรงไปสู่ Hugging Face Hub มันถูกบูรณาการเข้ากับ 🤗 Transformers และ machine learning libraries อื่นๆอีกหลายอันด้วย เช่น <a href="https://github.com/allenai/allennlp" rel="nofollow"><code>allenlp</code></a> แม้ว่าเราเจาะจงแค่การบูรณาการกับ 🤗 Transformers ในบทนี้ แต่การบูรณาการกับการใช้โค้ดของคุณเองหรือ library อื่นนั้นเรียบง่ายมาก</p> <p data-svelte-h="svelte-148ettj">ข้ามไปส่วนสุดท้ายเพื่อดูวิธีการอัพโหลดไฟล์ขึ้นไปบน repository ที่คุณสร้างขึ้นมาใหม่!</p> <h2 class="relative group"><a id="ใช-huggingfacehub-python-library" 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="#ใช-huggingfacehub-python-library"><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>ใช้ huggingface_hub Python library</span></h2> <p data-svelte-h="svelte-1ck62zn"><code>huggingface_hub</code> Python library คือ package หนึ่งที่บรรจุชุดเครื่องมือสำหรับ hub ของโมเดลและชุดข้อมูล มันมีคำสั่งและคลาสที่เรียบง่ายไว้สำหรับงานทั่วไปอย่าง
การดึงข้อมูลเกี่ยวกับ repositories บน hub และการจัดการมัน มันมี API ง่ายๆที่สามารถทำงานบน git เพื่อที่จะจัดการเนื้อหาของ repositories เหล่านั้นและบูรณาการเข้ากับ Hub
ในงานโปรเจคและ libraries ของคุณ</p> <p data-svelte-h="svelte-g98md6">คล้ายคลึงกับการใช้ <code>push_to_hub</code> API คุณจำเป็นจะต้องมีโทเค็น API เก็บไว้ใน cache ของคุณ เพื่อที่จะมีมันได้ คุณจะต้องใช้คำสั่ง <code>login</code> จาก CLI อย่างที่เราเคยกล่าวถึงไปแล้วในส่วนก่อนหน้านี้ (ย้ำอีกครั้ง ทำให้มั่นใจว่าคุณใส่เครื่องหมาย <code>!</code> ไว้ข้างหน้าคำสั่งถ้าคุณกำลังรันใน Google Colab):</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 login<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1d2i9jw"><code>huggingface_hub</code> package บรรจุคำสั่งและคลาสซึ่งเป็นประโยชน์สำหรับจุดประสงค์ของเราเอาไว้หลายอย่าง อย่างแรก มีคำสั่งจำนวนหนึ่งที่ใช้จัดการกับการสร้าง, การลบ และการจัดการอื่นๆของ 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-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> (
<span class="hljs-comment"># User management</span>
login,
logout,
whoami,
<span class="hljs-comment"># Repository creation and management</span>
create_repo,
delete_repo,
update_repo_visibility,
<span class="hljs-comment"># And some methods to retrieve/change information about the content</span>
list_models,
list_datasets,
list_metrics,
list_repo_files,
upload_file,
delete_file,
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-7dd6iy">มากไปกว่านั้น มันยังมี <code>Repository</code> class ที่ทรงพลังมากๆไว้จัดการกับ local repository เราจะมาสำรวจคำสั่งเหล่านี้และคลาสนั้นกันในอีกส่วนไม่ไกลข้างหน้า เพื่อที่จะได้เข้าใจวิธีการนำมันมาใช้</p> <p data-svelte-h="svelte-10xk9n6">คำสั่ง <code>create_repo</code> สามารถใช้ในการสร้าง repository ใหม่บน 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">from</span> huggingface_hub <span class="hljs-keyword">import</span> create_repo
create_repo(<span class="hljs-string">&quot;dummy-model&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-u5z3to">โค้ดนี้จะสร้าง repository ชื่อ <code>dummy-model</code> ใน namespace ของคุณ ถ้าคนชอบ คุณสามารถระบุอย่างเจาะจงไปได้ว่า repository นี้เป็นขององค์กรไหน โดยการใช้ <code>organization</code> argument:</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">from</span> huggingface_hub <span class="hljs-keyword">import</span> create_repo
create_repo(<span class="hljs-string">&quot;dummy-model&quot;</span>, organization=<span class="hljs-string">&quot;huggingface&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-n1dghd">โค้ดนี้จะสร้าง repository ชื่อ <code>dummy-model</code> ใน namespace ของ <code>huggingface</code> สมมุติว่าคุณเป็นคนขององค์กรนั้น
Arguments อื่นที่อาจจะเป็นประโยชน์:</p> <ul data-svelte-h="svelte-3g7ul4"><li><code>private</code> ใช้ในการระบุว่าคนอื่นควรเห็น repository นี้ได้หรือไม่</li> <li><code>token</code> ใช้ในกรณีที่คุณอยากจะแทนที่โทเค็นที่ถูกเก็บเอาไว้ใน cache ของคุณด้วยอีกโทเค็นที่ให้ไว้</li> <li><code>repo_type</code> ใช้ในกรณีที่คุณอยากจะสร้าง <code>dataset</code> หรือ <code>space</code> แทนที่จะเป็นโมเดล ค่าที่รับได้คือ <code>&quot;dataset&quot;</code> และ <code>&quot;space&quot;</code></li></ul> <p data-svelte-h="svelte-ywvx05">เมื่อ repository ถูกสร้างขึ้นมาแล้ว เราสามารถเพิ่มไฟล์ไปในนั้นได้! ข้ามไปส่วนถัดไปเพื่อดูสามวิธีในการทำสิ่งนี้</p> <h2 class="relative group"><a id="ใช-web-interface" 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="#ใช-web-interface"><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>ใช้ web interface</span></h2> <p data-svelte-h="svelte-1uzvd84">web interface บรรจุเครื่องมือมากมายที่ใช้จัดการ repositories โดยตรงใน Hub ด้วยการใช้งาน web interface คุณสามารถสร้าง repositories, เพิ่มไฟล์ (รวมถึงไฟล์ขนาดใหญ่ด้วย!), สำรวจโมเดลต่างๆ, แสดงผลความแตกต่าง และอื่นๆอีกมากมายได้อย่างง่ายดาย</p> <p data-svelte-h="svelte-4ex5u">สร้าง repository ใหม่ได้โดยการไปที่ <a href="https://huggingface.co/new" rel="nofollow">huggingface.co/new</a>:</p> <div class="flex justify-center" data-svelte-h="svelte-4qsgxt"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/new_model.png" alt="Page showcasing the model used for the creation of a new model repository." width="80%"></div> <p data-svelte-h="svelte-1xwu1yh">ขั้นแรก ระบุเจ้าของของ repository ซึ่งสามารถเป็นคุณเองหรือองค์กรใดๆที่คุณเกี่ยวข้องด้วย ถ้าคุณเลือกองค์กร โมเดลจะถูกนำไปขึ้นบนหน้าขององค์กรด้วย และสมาชิกทุกคนขององค์กรนั้นจะมีสิทธิ์ในการมีส่วนร่วมกับ repository นี้</p> <p data-svelte-h="svelte-111h1qv">ถัดไป ใส่ชื่อโมเดลของคุณ ซึ่งจะเหมือนกับชื่อของ repository ก็ได้ และสุดท้าย คุณสามารถระบุได้ว่าคุณต้องการให้โมเดลของคุณเป็นสาธารณะหรือส่วนบุคคล โมเดลส่วนบุคคลนั้นจะถูกซ่อนจากมุมมองสาธารณะ</p> <p data-svelte-h="svelte-17lkx6e">หลังจากที่คุณสร้าง model repository ของคุณแล้ว คุณควรจะเห็นหน้าแบบนี้:</p> <div class="flex justify-center" data-svelte-h="svelte-1xh6nig"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/empty_model.png" alt="An empty model page after creating a new repository." width="80%"></div> <p data-svelte-h="svelte-1rfxu5j">นี่คือที่ที่โมเดลของคุณจะถูก host เอาไว้ สำหรับการเริ่มปรับแต่งเพิ่มเติมนั้น คุณสามารถเพิ่มไฟล์ README ได้โดยตรงจาก web interface</p> <div class="flex justify-center" data-svelte-h="svelte-1jm8l0p"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/dummy_model.png" alt="The README file showing the Markdown capabilities." width="80%"></div> <p data-svelte-h="svelte-15stfpn">ไฟล์ README อยู่ในรูปแบบของ Markdown — สามารถปรับแต่งมันแบบจัดเต็มได้เลย! ในส่วนที่สามของบทนี้ถูกอุทิศให้กับการสร้างการ์ดโมเดล (model card) ซึ่งนี่เป็นส่วนที่สำคัญเป็นอันดับหนึ่งในการสร้างคุณค่าให้โมเดลของคุณ เพราะว่ามันจะเป็นสิ่งที่ใช้บอกคนอื่นว่าโมเดลของคุณทำอะไรได้บ้าง</p> <p data-svelte-h="svelte-117s3lp">ถ้าคุณดูที่แท็บ “Files and versions” คุณจะเห็นว่ามันยังไม่มีไฟล์อะไรมากมายเลย — แค่ไฟล์ <em>README.md</em> ที่คุณเพิ่งได้สร้างและไฟล์ <em>.gitattributes</em> สำหรับไว้ติดตามไฟล์ขนาดใหญ่</p> <div class="flex justify-center" data-svelte-h="svelte-1kuf5jc"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/files.png" alt="The 'Files and versions' tab only shows the .gitattributes and README.md files." width="80%"></div> <p data-svelte-h="svelte-v7tka5">ต่อไปเราจะมาดูวิธีการเพิ่มไฟล์ใหม่กัน</p> <h2 class="relative group"><a id="การอพโหลดไฟลโมเดลตางๆ" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#การอพโหลดไฟลโมเดลตางๆ"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>การอัพโหลดไฟล์โมเดลต่างๆ</span></h2> <p data-svelte-h="svelte-18wxjag">ระบบที่ใช้จัดการไฟล์บน Hugging Face Hub มีพื้นฐานมาจาก git สำหรับไฟล์ทั่วไป และ git-lfs (ย่อมาจาก <a href="https://git-lfs.github.com/" rel="nofollow">Git Large File Storage</a>) สำหรับไฟล์ที่ใหญ่ขึ้น</p> <p data-svelte-h="svelte-snihi">ในส่วนถัดไปนี้ เราจะพามาดูสามวิธีในการอัพโหลดไฟล์ต่างๆไปบน Hub: ผ่าน <code>huggingface_hub</code> และ ผ่านคำสั่ง git ต่างๆ</p> <h3 class="relative group"><a id="แนวทางแบบใช-uploadfile" 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="#แนวทางแบบใช-uploadfile"><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_file</span></h3> <p data-svelte-h="svelte-11nx6k8">การใช้ <code>upload_file</code> ไม่จำเป็นต้องมี git และ git-lfs ติดตั้งอยู่บนระบบของคุณ มันดันไฟล์โดยตรงไปสู่ 🤗 Hub โดยใช้ HTTP POST requests ข้อจำกัดของแนวทางนี้คือมันไม่สามารถรองรับไฟล์ที่มีขนาดมากกว่า 5GB ได้
ถ้าไฟล์ของคุณมีขนาดใหญ่กว่า 5GB โปรดทำตามอีกสองขั้นตอนที่ระบุรายละเอียดไว้ด้านล่าง</p> <p data-svelte-h="svelte-rjusj">API สามารถถูกใช้แบบนี้ได้:</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">from</span> huggingface_hub <span class="hljs-keyword">import</span> upload_file
upload_file(
<span class="hljs-string">&quot;&lt;path_to_file&gt;/config.json&quot;</span>,
path_in_repo=<span class="hljs-string">&quot;config.json&quot;</span>,
repo_id=<span class="hljs-string">&quot;&lt;namespace&gt;/dummy-model&quot;</span>,
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1na2tzz">โค้ดนี้จะทำการอัพโหลดไฟล์ <code>config.json</code> ที่อยู่ใน <code>&lt;path_to_file&gt;</code> ไปสู่รากของ repository โดยใช้ชื่อ <code>config.json</code> ไปสู่ <code>dummy-model</code> repository
Arguments อื่นที่อาจจะเป็นประโยชน์:</p> <ul data-svelte-h="svelte-j0jwp7"><li><code>token</code> ใช้ในกรณีที่คุณอยากจะแทนที่โทเค็นที่ถูกเก็บเอาไว้ใน cache ของคุณด้วยอีกโทเค็นที่ให้ไว้</li> <li><code>repo_type</code> ใช้ในกรณีที่คุณอยากจะสร้าง <code>dataset</code> หรือ <code>space</code> แทนที่จะเป็นโมเดล ค่าที่รับได้คือ <code>&quot;dataset&quot;</code> และ <code>&quot;space&quot;</code></li></ul> <h3 class="relative group"><a id="คลาส-repository" 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="#คลาส-repository"><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>คลาส Repository</span></h3> <p data-svelte-h="svelte-v3i98v">คลาส <code>Repository</code> จัดการ local repository ในลักษณะคล้าย git มันเอาปัญหาส่วนมากที่ผู้คนมักเจอเวลาใช้ git ออกเพื่อจัดสรรทุกฟีเจอร์ทุกอย่างที่เราจำเป็นต้องใช้</p> <p data-svelte-h="svelte-1xiw8xn">การใช้คลาสนี้จำเป็นต้องติดตั้ง git และ git-lfs ดังนั้นคุณควรทำให้มั่นใจว่าคุณได้ติดตั้ง git-lfs แล้ว (ดู <a href="https://git-lfs.github.com/" rel="nofollow">ที่นี่</a> สำหรับขั้นตอนการติดตั้ง) และตั้งค่าให้เสร็จก่อนที่คุณจะเริ่มไปต่อ</p> <p data-svelte-h="svelte-aa6xdx">เพื่อที่จะเริ่มเล่นกับ repository ที่เราเพิ่งจะได้สร้างกัน เราสามารถเริ่มตั้งต้นมันไปใน local folder ได้โดยการโคลน (clone) remote 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-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> Repository
repo = Repository(<span class="hljs-string">&quot;&lt;path_to_dummy_folder&gt;&quot;</span>, clone_from=<span class="hljs-string">&quot;&lt;namespace&gt;/dummy-model&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-kvrbfp">โค้ดนี้จะสร้างโฟลเดอร์ <code>&lt;path_to_dummy_folder&gt;</code> ในไดเรกทอรีที่คุณทำงานอยู่ (working directory) โฟลเดอร์นี้เก็บไฟล์ <code>.gitattributes</code> เอาไว้เพียงไฟล์เดียวเพราะว่ามันเป็นไฟล์เดียวที่จะถูกสร้างเมื่อมีการสร้าง repository ตั้งต้นด้วยคำสั่ง <code>create_repo</code></p> <p data-svelte-h="svelte-ji2296">จากจุดนี้เป็นต้นไป เราสามารถใช้คำสั่ง git แบบดั่งเดิมต่างๆได้:</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 -->repo.git_pull()
repo.git_add()
repo.git_commit()
repo.git_push()
repo.git_tag()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-icveem">และอื่นๆอีก! เราแนะนำให้ลองไปดูที่หนังสืออ้างอิง (documentation) ของ <code>Repository</code> ซึ่งเข้าถึงได้จาก <a href="https://github.com/huggingface/huggingface_hub/tree/main/src/huggingface_hub#advanced-programmatic-repository-management" rel="nofollow">ที่นี่</a> สำหรับภาพรวมของคำสั่งทั้งหมดที่ใช้ได้</p> <p data-svelte-h="svelte-13fpry9">ณ ปัจจุบัน เรามีโมเดลและ tokenizer ซึ่งเราต้องการที่จะดันขึ้นสู่ hub แล้ว เราได้โคลน repository มาอย่างเสร็จสมบูรณ์ ดังนั้นเราสามารถเก็บไฟล์ต่างๆไว้ใน repository นั้นได้แล้ว</p> <p data-svelte-h="svelte-14d584i">อันดับแรกเราต้องทำให้มั่นใจว่า local clone ของเรานั้นเป็นปัจจุบัน ซึ่งทำได้โดยการดึง (pull) การเปลี่ยนแปลงใหม่ล่าสุดเข้ามา:</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 -->repo.git_pull()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-zyb9su">เมื่อโค้ดทำงานเสร็จแล้ว เราเก็บไฟล์โมเดลและ tokenizer:</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 -->model.save_pretrained(<span class="hljs-string">&quot;&lt;path_to_dummy_folder&gt;&quot;</span>)
tokenizer.save_pretrained(<span class="hljs-string">&quot;&lt;path_to_dummy_folder&gt;&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-iam5ee">ที่ <code>&lt;path_to_dummy_folder&gt;</code> ตอนนี้มีไฟล์โมเดลและ tokenizer ทั้งหมดแล้ว เราจะทำตาม workflow ของ git ทั่วไปโดยการ เพิ่มไฟล์ไปยัง staging area, ทำการ commit และดัน (push) ไฟล์เหล่านั้นสู่ 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 -->repo.git_add()
repo.git_commit(<span class="hljs-string">&quot;Add model and tokenizer files&quot;</span>)
repo.git_push()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-lmrpnf">ขอแสดงความยินดีด้วย! คุณเพิ่งได้ทำการดันไฟล์ชุดแรกของคุณสู่ hub</p> <h3 class="relative group"><a id="แนวทางแบบใช-git" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#แนวทางแบบใช-git"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>แนวทางแบบใช้ git</span></h3> <p data-svelte-h="svelte-1yicavc">แนวทางนี้เป็นแนวทางที่ตรงๆมากสำหรับทำการอัพโหลดไฟล์ นั่นคือเราจะใช้ git และ git-lfs โดยตรง ส่วนที่ยากส่วนใหญ่ถูกในออกไปในแนวทางก่อนๆ แต่มันมีข้อแม้บางอย่างกับขั้นตอนแต่ไปนี้ ดังนั้นเราจะทำตามการใช้งานแบบที่ซับซ้อนขึ้นกว่าปกติ</p> <p data-svelte-h="svelte-18i5017">การใช้งานต่อจากนี้จำเป็นต้องติดตั้ง git และ git-lfs ดังนั้นคุณควรทำให้มั่นใจว่าคุณได้ติดตั้ง git-lfs แล้ว (ดู <a href="https://git-lfs.github.com/" rel="nofollow">ที่นี่</a> สำหรับขั้นตอนการติดตั้ง) และตั้งค่าให้เสร็จก่อนที่คุณจะเริ่มไปต่อ</p> <p data-svelte-h="svelte-xzb0ej">เริ่มแรกโดยการเริ่มต้นสร้าง 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 -->git lfs install<!-- HTML_TAG_END --></pre></div> <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 -->Updated git hooks.
Git LFS initialized.<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-g38fkp">เมื่อโค้ดทำงานเสร็จแล้ว ขั้นตอนแรกคือการโคลน model 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 -->git <span class="hljs-built_in">clone</span> https://huggingface.co/&lt;namespace&gt;/&lt;your-model-id&gt;<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-17djtfn">username ของฉันคือ <code>lysandre</code> และฉันใช้ <code>dummy</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 -->git clone https:<span class="hljs-regexp">//</span>huggingface.co<span class="hljs-regexp">/lysandre/</span>dummy<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1dbqziv">ตอนนี้ฉันมีโฟลเดอร์ชื่อ <em>dummy</em> ในไดเรกทอรีที่ฉันทำงานอยู่ (working directory) ฉันสามารถ <code>cd</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-built_in">cd</span> dummy &amp;&amp; <span class="hljs-built_in">ls</span><!-- HTML_TAG_END --></pre></div> <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 -->README.md<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-zlspfv">ถ้าคุณสร้าง repository ด้วยการใช้คำสั่ง <code>create_repo</code> ของ Hugging Face Hub โฟลเดอร์นี้ควรจะมีไฟล์ <code>.gitattributes</code> ถูกซ่อนอยู่ด้วย ถ้าคุณทำตามขั้นตอนในส่วนก่อนหน้านี้ในการสร้าง repository โดยใช้ web interface ในโฟลเดอร์นี้ควรจะมี <em>README.md</em> หนึ่งไฟล์มาพร้อมกับไฟล์ <code>.gitattributes</code> ที่ถูกซ่อนอยู่ อย่างที่แสดงให้เห็นนี้</p> <p data-svelte-h="svelte-5ryrtz">การเพิ่มไฟล์หนึ่งไฟล์ที่มีขนาดปกติ เช่น ไฟล์สำหรับกำหนดค่า (configuration file), ไฟล์สำหรับเก็บคำศัพท์ (vocabulary file) หรือโดยง่ายๆแล้วไฟล์อะไรก็ตามที่มีขนาดน้อยกว่าสองสาม megabytes สามารถทำได้ด้วยการทำแบบที่ทำปกติกับระบบที่พึ่งพา git อย่างไรก็ตามไฟล์ที่ใหญ่กว่านั้นจะต้องถูกลงทะเบียนผ่าน git-lfs เพื่อที่จะดันไฟล์เหล่านั้นขึ้นสู่ <em>huggingface.co</em> ได้</p> <p data-svelte-h="svelte-1k1j974">กลับไปหา Python กันสักหน่อยเพื่อจะสร้างโมเดลและ tokenizer ที่เราต้องการจะ commit ไปสู่ 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-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForMaskedLM, AutoTokenizer
checkpoint = <span class="hljs-string">&quot;camembert-base&quot;</span>
model = AutoModelForMaskedLM.from_pretrained(checkpoint)
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-comment"># Do whatever with the model, train it, fine-tune it...</span>
model.save_pretrained(<span class="hljs-string">&quot;&lt;path_to_dummy_folder&gt;&quot;</span>)
tokenizer.save_pretrained(<span class="hljs-string">&quot;&lt;path_to_dummy_folder&gt;&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1qkg12p">ถึงตอนนี้เราได้ทำการบันทึกไฟล์จากโมเดลและ tokenizer บางส่วนแล้ว ลองไปดูโฟลเดอร์ <em>dummy</em> อีกรอบกันเถอะ:</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-built_in">ls</span><!-- HTML_TAG_END --></pre></div> <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 -->config.json pytorch_model.bin README.md sentencepiece.bpe.model special_tokens_map.json tokenizer_config.json tokenizer.json<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-kiz7ar">ถ้าคุณดูที่ขนาดของไฟล์ (อย่างเช่น ใช้คำสั่ง <code>ls -lh</code>) คุณควรจะเห็นได้ว่าไฟล์ model state dict (<em>pytorch_model.bin</em>) มีขนาดที่โดดมาก นั่นคือมากกว่า 400 MB</p> <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">✏️ ตอนที่สร้าง repository จาก web interface ไฟล์ *.gitattributes* ถูกตั้งค่าอย่างอัตโนมัติเพื่อให้พิจารณาไฟล์บางประเภท เช่น *.bin* และ *.h5* ว่าเป็นไฟล์ขนาดใหญ่ และ git-lfs จะติดตามไฟล์เหล่านั้นโดยคุณไม่จำเป็นต้องตั้งค่าอะไรเลย</div> <p data-svelte-h="svelte-1jnekpr">ต่อไปเราจะทำต่อโดยการทำแบบที่เราทำกับ Git repositories ดั้งเดิม เราสามารถเพิ่มไฟล์ทั้งหมดไปยัง staging environment ของ Git ได้ด้วยการใช้คำสั่ง <code>git add</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 -->git add .<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-clti1z">เราสามารถดูได้ว่าไฟล์ที่อยู่ในสถานะ staged มีอะไรบ้าง:</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 -->git status<!-- HTML_TAG_END --></pre></div> <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 -->On branch main
Your branch is up to <span class="hljs-built_in">date</span> with <span class="hljs-string">&#x27;origin/main&#x27;</span>.
Changes to be committed:
(use <span class="hljs-string">&quot;git restore --staged &lt;file&gt;...&quot;</span> to unstage)
modified: .gitattributes
new file: config.json
new file: pytorch_model.bin
new file: sentencepiece.bpe.model
new file: special_tokens_map.json
new file: tokenizer.json
new file: tokenizer_config.json<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-g6oj6q">ในแบบเดียวกัน เราสามารถทำให้มั่นใจได้ว่า git-lfs กำลังติดตามไฟล์ที่ถูกต้องอยู่ ได้โดยการใช้คำสั่ง status:</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 -->git lfs status<!-- HTML_TAG_END --></pre></div> <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 -->On branch main
Objects to be pushed to origin/main:
Objects to be committed:
config.json (Git: bc20ff2)
pytorch_model.bin (LFS: 35686c2)
sentencepiece.bpe.model (LFS: 988bc5a)
special_tokens_map.json (Git: cb23931)
tokenizer.json (Git: 851ff3e)
tokenizer_config.json (Git: f0f7783)
Objects not staged <span class="hljs-keyword">for</span> commit:
<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1yvmnty">เราสามารถเห็นได้ว่าทุกไฟล์มี <code>Git</code> เป็นตัวจัดการ (handler) ยกเว้น <em>pytorch_model.bin</em> และ <em>sentencepiece.bpe.model</em> ซึ่งเป็น <code>LFS</code> เยี่ยม!</p> <p data-svelte-h="svelte-1dmkq8n">มาทำขั้นตอนสุดท้ายต่อกันเถอะ ทำการ commit และดัน (push) ขึ้นสู่ <em>huggingface.co</em> remote 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 -->git commit -m <span class="hljs-string">&quot;First model version&quot;</span><!-- HTML_TAG_END --></pre></div> <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 -->[main b08aab1] First model version
7 files changed, 29027 insertions(+)
6 files changed, 36 insertions(+)
create mode 100644 config.json
create mode 100644 pytorch_model.bin
create mode 100644 sentencepiece.bpe.model
create mode 100644 special_tokens_map.json
create mode 100644 tokenizer.json
create mode 100644 tokenizer_config.json<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1l0w2ea">การดันไฟล์นั้นอาจจะใช้เวลาสักหน่อย ขึ้นอยู่กับความเร็วของการเชื่อมต่ออินเทอร์เน็ตและขนาดไฟล์ของคุณ:</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 -->git push<!-- HTML_TAG_END --></pre></div> <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 -->Uploading LFS objects: 100% (1/1), 433 MB | 1.3 MB/s, <span class="hljs-keyword">done</span>.
Enumerating objects: 11, <span class="hljs-keyword">done</span>.
Counting objects: 100% (11/11), <span class="hljs-keyword">done</span>.
Delta compression using up to 12 threads
Compressing objects: 100% (9/9), <span class="hljs-keyword">done</span>.
Writing objects: 100% (9/9), 288.27 KiB | 6.27 MiB/s, <span class="hljs-keyword">done</span>.
Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
To https://huggingface.co/lysandre/dummy
891b41d..b08aab1 main -&gt; main<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1vnrfhu">ถ้าเราดูที่ model repository เมื่อโค้ดทำงานเสร็จแล้ว เราจะเห็นทุกไฟล์ที่เพิ่งถูกเพิ่มเข้าไปอยู่ในนั้น:</p> <div class="flex justify-center" data-svelte-h="svelte-1v39mjb"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/full_model.png" alt="The 'Files and versions' tab now contains all the recently uploaded files." width="80%"></div> <p data-svelte-h="svelte-1hb0s3p">UI ช่วยให้คุณสามารถสำรวจไฟล์โมเดลและ commits และดูความแตกต่างของแต่ละ commit ได้:</p> <div class="flex justify-center" data-svelte-h="svelte-1g561m5"><img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter4/diffs.gif" alt="The diff introduced by the recent commit." width="80%"></div> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/course/blob/main/chapters/th/chapter4/3.mdx" target="_blank"><span data-svelte-h="svelte-1kd6by1">&lt;</span> <span data-svelte-h="svelte-x0xyl0">&gt;</span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p>
<script>
{
__sveltekit_1q1y86z = {
assets: "/docs/course/pr_1069/th",
base: "/docs/course/pr_1069/th",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/course/pr_1069/th/_app/immutable/entry/start.eeb02c13.js"),
import("/docs/course/pr_1069/th/_app/immutable/entry/app.25e78aa9.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 30],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
111 kB
·
Xet hash:
7d177278eb3b5d80fcc2d167ffa505370f26e841abfc8c45eb4591e6749229d6

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