Buckets:

download
raw
44 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;πŸ€— PEFT둜 μ–΄λŒ‘ν„° κ°€μ Έμ˜€κΈ°&quot;,&quot;local&quot;:&quot;load-adapters-with-peft&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;μ„€μ •&quot;,&quot;local&quot;:&quot;setup&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;μ§€μ›λ˜λŠ” PEFT λͺ¨λΈ&quot;,&quot;local&quot;:&quot;supported-peft-models&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;PEFT μ–΄λŒ‘ν„° κ°€μ Έμ˜€κΈ°&quot;,&quot;local&quot;:&quot;load-a-peft-adapter&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;8λΉ„νŠΈ λ˜λŠ” 4λΉ„νŠΈλ‘œ κ°€μ Έμ˜€κΈ°&quot;,&quot;local&quot;:&quot;load-in-8bit-or-4bit&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;μƒˆ μ–΄λŒ‘ν„° μΆ”κ°€&quot;,&quot;local&quot;:&quot;add-a-new-adapter&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;μ–΄λŒ‘ν„° ν™œμ„±ν™” 및 λΉ„ν™œμ„±ν™”&quot;,&quot;local&quot;:&quot;enable-and-disable-adapters&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;PEFT μ–΄λŒ‘ν„° ν›ˆλ ¨&quot;,&quot;local&quot;:&quot;train-a-peft-adapter&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/transformers/main/ko/_app/immutable/entry/start.yqDdfIah.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/L0MID6Lt.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/BkyfusOu.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/entry/app.Caw9CuWs.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/CDRgxHoV.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/1EV5EJPW.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/CKPTQsoU.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/nodes/0.CiqegfoO.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/BoVSaMb7.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/nodes/130.DOhbLbiv.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/cFKPlByr.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/BxKcLc1c.js" rel="modulepreload">
<link href="/docs/transformers/main/ko/_app/immutable/chunks/juS24bn6.js" rel="modulepreload">
<!--7uqcei--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;πŸ€— PEFT둜 μ–΄λŒ‘ν„° κ°€μ Έμ˜€κΈ°&quot;,&quot;local&quot;:&quot;load-adapters-with-peft&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;μ„€μ •&quot;,&quot;local&quot;:&quot;setup&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;μ§€μ›λ˜λŠ” PEFT λͺ¨λΈ&quot;,&quot;local&quot;:&quot;supported-peft-models&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;PEFT μ–΄λŒ‘ν„° κ°€μ Έμ˜€κΈ°&quot;,&quot;local&quot;:&quot;load-a-peft-adapter&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;8λΉ„νŠΈ λ˜λŠ” 4λΉ„νŠΈλ‘œ κ°€μ Έμ˜€κΈ°&quot;,&quot;local&quot;:&quot;load-in-8bit-or-4bit&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;μƒˆ μ–΄λŒ‘ν„° μΆ”κ°€&quot;,&quot;local&quot;:&quot;add-a-new-adapter&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;μ–΄λŒ‘ν„° ν™œμ„±ν™” 및 λΉ„ν™œμ„±ν™”&quot;,&quot;local&quot;:&quot;enable-and-disable-adapters&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;PEFT μ–΄λŒ‘ν„° ν›ˆλ ¨&quot;,&quot;local&quot;:&quot;train-a-peft-adapter&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/transformers/main/ko/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><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> <!--[-1--><!--]--></div><!----> <div class="flex space-x-1 " style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><!----> <!--[1--><div class="relative colab-dropdown "><button class=" " type="button"><!--[0--><!--[-1--><img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"/><!--]--><!----><!--]--></button> <!--[-1--><!--]--></div><!--]--> <!--[1--><div class="relative colab-dropdown "><button class=" " type="button"><!--[0--><!--[-1--><img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"/><!--]--><!----><!--]--></button> <!--[-1--><!--]--></div><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="load-adapters-with-peft" 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="#load-adapters-with-peft"><span><svg 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>πŸ€— PEFT둜 μ–΄λŒ‘ν„° κ°€μ Έμ˜€κΈ°</span></h1><!--]--><!----> <p><a href="https://huggingface.co/blog/peft" rel="nofollow">Parameter-Efficient Fine Tuning (PEFT)</a> 방법은 μ‚¬μ „ν›ˆλ ¨λœ λͺ¨λΈμ˜ λ§€κ°œλ³€μˆ˜λ₯Ό λ―Έμ„Έ μ‘°μ • 쀑 κ³ μ •μ‹œν‚€κ³ , κ·Έ μœ„μ— ν›ˆλ ¨ν•  수 μžˆλŠ” 맀우 적은 수의 λ§€κ°œλ³€μˆ˜(μ–΄λŒ‘ν„°)λ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€. μ–΄λŒ‘ν„°λŠ” μž‘μ—…λ³„ 정보λ₯Ό ν•™μŠ΅ν•˜λ„λ‘ ν›ˆλ ¨λ©λ‹ˆλ‹€. 이 μ ‘κ·Ό 방식은 μ™„μ „νžˆ λ―Έμ„Έ μ‘°μ •λœ λͺ¨λΈμ— ν•„μ ν•˜λŠ” κ²°κ³Όλ₯Ό μƒμ„±ν•˜λ©΄μ„œ, λ©”λͺ¨λ¦¬ 효율적이고 비ꡐ적 적은 μ»΄ν“¨νŒ… λ¦¬μ†ŒμŠ€λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.</p> <p>λ˜ν•œ PEFT둜 ν›ˆλ ¨λœ μ–΄λŒ‘ν„°λŠ” 일반적으둜 전체 λͺ¨λΈλ³΄λ‹€ 훨씬 μž‘κΈ° λ•Œλ¬Έμ— 곡유, μ €μž₯ 및 κ°€μ Έμ˜€κΈ°κ°€ νŽΈλ¦¬ν•©λ‹ˆλ‹€.</p> <div class="flex flex-col justify-center"><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/peft/PEFT-hub-screenshot.png"/> <figcaption class="text-center">Hub에 μ €μž₯된 OPTForCausalLM λͺ¨λΈμ˜ μ–΄λŒ‘ν„° κ°€μ€‘μΉ˜λŠ” μ΅œλŒ€ 700MB에 λ‹¬ν•˜λŠ” λͺ¨λΈ κ°€μ€‘μΉ˜μ˜ 전체 크기에 λΉ„ν•΄ μ•½ 6MB에 λΆˆκ³Όν•©λ‹ˆλ‹€.</figcaption></div> <p>πŸ€— PEFT λΌμ΄λΈŒλŸ¬λ¦¬μ— λŒ€ν•΄ μžμ„Ένžˆ μ•Œμ•„λ³΄λ €λ©΄ <a href="https://huggingface.co/docs/peft/index" rel="nofollow">λ¬Έμ„œ</a>λ₯Ό ν™•μΈν•˜μ„Έμš”.</p> <!--[1--><h2 class="relative group"><a id="setup" 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="#setup"><span><svg 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>πŸ€— PEFTλ₯Ό μ„€μΉ˜ν•˜μ—¬ μ‹œμž‘ν•˜μ„Έμš”:</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 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="language-bash "><!---->pip install peft<!----></pre></div><!----> <p>μƒˆλ‘œμš΄ κΈ°λŠ₯을 μ‚¬μš©ν•΄λ³΄κ³  μ‹Άλ‹€λ©΄, λ‹€μŒ μ†ŒμŠ€μ—μ„œ 라이브러리λ₯Ό μ„€μΉ˜ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€:</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 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="language-bash "><!---->pip install git+https://github.com/huggingface/peft.git<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="supported-peft-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="#supported-peft-models"><span><svg 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>μ§€μ›λ˜λŠ” PEFT λͺ¨λΈ</span></h2><!--]--><!----> <p>πŸ€— TransformersλŠ” 기본적으둜 일뢀 PEFT 방법을 μ§€μ›ν•˜λ©°, λ‘œμ»¬μ΄λ‚˜ Hub에 μ €μž₯된 μ–΄λŒ‘ν„° κ°€μ€‘μΉ˜λ₯Ό κ°€μ Έμ˜€κ³  λͺ‡ μ€„μ˜ μ½”λ“œλ§ŒμœΌλ‘œ μ‰½κ²Œ μ‹€ν–‰ν•˜κ±°λ‚˜ ν›ˆλ ¨ν•  수 μžˆμŠ΅λ‹ˆλ‹€. λ‹€μŒ 방법을 μ§€μ›ν•©λ‹ˆλ‹€:</p> <ul><li><a href="https://huggingface.co/docs/peft/conceptual_guides/lora" rel="nofollow">Low Rank Adapters</a></li> <li><a href="https://huggingface.co/docs/peft/conceptual_guides/ia3" rel="nofollow">IA3</a></li> <li><a href="https://huggingface.co/papers/2303.10512" rel="nofollow">AdaLoRA</a></li></ul> <p>πŸ€— PEFT와 κ΄€λ ¨λœ λ‹€λ₯Έ 방법(예: ν”„λ‘¬ν”„νŠΈ ν›ˆλ ¨ λ˜λŠ” ν”„λ‘¬ν”„νŠΈ νŠœλ‹) λ˜λŠ” 일반적인 πŸ€— PEFT λΌμ΄λΈŒλŸ¬λ¦¬μ— λŒ€ν•΄ μžμ„Ένžˆ μ•Œμ•„λ³΄λ €λ©΄ <a href="https://huggingface.co/docs/peft/index" rel="nofollow">λ¬Έμ„œ</a>λ₯Ό μ°Έμ‘°ν•˜μ„Έμš”.</p> <!--[1--><h2 class="relative group"><a id="load-a-peft-adapter" 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="#load-a-peft-adapter"><span><svg 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>PEFT μ–΄λŒ‘ν„° κ°€μ Έμ˜€κΈ°</span></h2><!--]--><!----> <p>πŸ€— Transformersμ—μ„œ PEFT μ–΄λŒ‘ν„° λͺ¨λΈμ„ κ°€μ Έμ˜€κ³  μ‚¬μš©ν•˜λ €λ©΄ Hub μ €μž₯μ†Œλ‚˜ 둜컬 디렉터리에 <code>adapter_config.json</code> 파일과 μ–΄λŒ‘ν„° κ°€μ€‘μΉ˜κ°€ ν¬ν•¨λ˜μ–΄ μžˆλŠ”μ§€ ν™•μΈν•˜μ‹­μ‹œμ˜€. 그런 λ‹€μŒ <code>AutoModelFor</code> 클래슀λ₯Ό μ‚¬μš©ν•˜μ—¬ PEFT μ–΄λŒ‘ν„° λͺ¨λΈμ„ κ°€μ Έμ˜¬ 수 μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ 인과 관계 μ–Έμ–΄ λͺ¨λΈμš© PEFT μ–΄λŒ‘ν„° λͺ¨λΈμ„ κ°€μ Έμ˜€λ €λ©΄ λ‹€μŒ 단계λ₯Ό λ”°λ₯΄μ‹­μ‹œμ˜€:</p> <ol><li>PEFT λͺ¨λΈ IDλ₯Ό μ§€μ •ν•˜μ‹­μ‹œμ˜€.</li> <li><a href="/docs/transformers/main/ko/model_doc/auto#transformers.AutoModelForCausalLM">AutoModelForCausalLM</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 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="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
peft_model_id = <span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>
model = AutoModelForCausalLM.from_pretrained(peft_model_id)<!----></pre></div><!----> <blockquote class="tip"><p><code>AutoModelFor</code> ν΄λž˜μŠ€λ‚˜ κΈ°λ³Έ λͺ¨λΈ 클래슀(예: <code>OPTForCausalLM</code> λ˜λŠ” <code>LlamaForCausalLM</code>) 쀑 ν•˜λ‚˜λ₯Ό μ‚¬μš©ν•˜μ—¬ PEFT μ–΄λŒ‘ν„°λ₯Ό κ°€μ Έμ˜¬ 수 μžˆμŠ΅λ‹ˆλ‹€.</p><!----></blockquote><!----> <p><code>load_adapter</code> λ©”μ†Œλ“œλ₯Ό ν˜ΈμΆœν•˜μ—¬ PEFT μ–΄λŒ‘ν„°λ₯Ό κ°€μ Έμ˜¬ μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.</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 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="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
model_id = <span class="hljs-string">&quot;facebook/opt-350m&quot;</span>
peft_model_id = <span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>
model = AutoModelForCausalLM.from_pretrained(model_id)
model.load_adapter(peft_model_id)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="load-in-8bit-or-4bit" 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="#load-in-8bit-or-4bit"><span><svg 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>8λΉ„νŠΈ λ˜λŠ” 4λΉ„νŠΈλ‘œ κ°€μ Έμ˜€κΈ°</span></h2><!--]--><!----> <p><code>bitsandbytes</code> 톡합은 8λΉ„νŠΈμ™€ 4λΉ„νŠΈ 정밀도 데이터 μœ ν˜•μ„ μ§€μ›ν•˜λ―€λ‘œ 큰 λͺ¨λΈμ„ κ°€μ Έμ˜¬ λ•Œ μœ μš©ν•˜λ©΄μ„œ λ©”λͺ¨λ¦¬λ„ μ ˆμ•½ν•©λ‹ˆλ‹€. λͺ¨λΈμ„ ν•˜λ“œμ›¨μ–΄μ— 효과적으둜 λΆ„λ°°ν•˜λ €λ©΄ <a href="/docs/transformers/main/ko/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a>에 <code>load_in_8bit</code> λ˜λŠ” <code>load_in_4bit</code> λ§€κ°œλ³€μˆ˜λ₯Ό μΆ”κ°€ν•˜κ³  <code>device_map="auto"</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 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="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
peft_model_id = <span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>
model = AutoModelForCausalLM.from_pretrained(peft_model_id, quantization_config=BitsAndBytesConfig(load_in_8bit=<span class="hljs-literal">True</span>))<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="add-a-new-adapter" 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="#add-a-new-adapter"><span><svg 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>μƒˆ μ–΄λŒ‘ν„°κ°€ ν˜„μž¬ μ–΄λŒ‘ν„°μ™€ λ™μΌν•œ μœ ν˜•μΈ κ²½μš°μ— ν•œν•΄ κΈ°μ‘΄ μ–΄λŒ‘ν„°κ°€ μžˆλŠ” λͺ¨λΈμ— μƒˆ μ–΄λŒ‘ν„°λ₯Ό μΆ”κ°€ν•˜λ €λ©΄ <code>add_adapter</code>λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ λͺ¨λΈμ— κΈ°μ‘΄ LoRA μ–΄λŒ‘ν„°κ°€ μ—°κ²°λ˜μ–΄ μžˆλŠ” 경우:</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 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="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, OPTForCausalLM, AutoTokenizer
<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PeftConfig
model_id = <span class="hljs-string">&quot;facebook/opt-350m&quot;</span>
model = AutoModelForCausalLM.from_pretrained(model_id)
lora_config = LoraConfig(
target_modules=[<span class="hljs-string">&quot;q_proj&quot;</span>, <span class="hljs-string">&quot;k_proj&quot;</span>],
init_lora_weights=<span class="hljs-literal">False</span>
)
model.add_adapter(lora_config, adapter_name=<span class="hljs-string">&quot;adapter_1&quot;</span>)<!----></pre></div><!----> <p>μƒˆ μ–΄λŒ‘ν„°λ₯Ό μΆ”κ°€ν•˜λ €λ©΄:</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 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="language-py "><!----><span class="hljs-comment"># attach new adapter with same config</span>
model.add_adapter(lora_config, adapter_name=<span class="hljs-string">&quot;adapter_2&quot;</span>)<!----></pre></div><!----> <p>이제 <code>set_adapter</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 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="language-py "><!----><span class="hljs-comment"># use adapter_1</span>
model.set_adapter(<span class="hljs-string">&quot;adapter_1&quot;</span>)
output = model.generate(**inputs)
<span class="hljs-built_in">print</span>(tokenizer.decode(output_disabled[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>))
<span class="hljs-comment"># use adapter_2</span>
model.set_adapter(<span class="hljs-string">&quot;adapter_2&quot;</span>)
output_enabled = model.generate(**inputs)
<span class="hljs-built_in">print</span>(tokenizer.decode(output_enabled[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>))<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="enable-and-disable-adapters" 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="#enable-and-disable-adapters"><span><svg 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>λͺ¨λΈμ— μ–΄λŒ‘ν„°λ₯Ό μΆ”κ°€ν•œ ν›„ μ–΄λŒ‘ν„° λͺ¨λ“ˆμ„ ν™œμ„±ν™” λ˜λŠ” λΉ„ν™œμ„±ν™”ν•  수 μžˆμŠ΅λ‹ˆλ‹€. μ–΄λŒ‘ν„° λͺ¨λ“ˆμ„ ν™œμ„±ν™”ν•˜λ €λ©΄:</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 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="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, OPTForCausalLM, AutoTokenizer
<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PeftConfig
model_id = <span class="hljs-string">&quot;facebook/opt-350m&quot;</span>
adapter_model_id = <span class="hljs-string">&quot;ybelkada/opt-350m-lora&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_id)
text = <span class="hljs-string">&quot;Hello&quot;</span>
inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
model = AutoModelForCausalLM.from_pretrained(model_id)
peft_config = PeftConfig.from_pretrained(adapter_model_id)
<span class="hljs-comment"># to initiate with random weights</span>
peft_config.init_lora_weights = <span class="hljs-literal">False</span>
model.add_adapter(peft_config)
model.enable_adapters()
output = model.generate(**inputs)<!----></pre></div><!----> <p>μ–΄λŒ‘ν„° λͺ¨λ“ˆμ„ λΉ„ν™œμ„±ν™”ν•˜λ €λ©΄:</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 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="language-py "><!---->model.disable_adapters()
output = model.generate(**inputs)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="train-a-peft-adapter" 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="#train-a-peft-adapter"><span><svg 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>PEFT μ–΄λŒ‘ν„° ν›ˆλ ¨</span></h2><!--]--><!----> <p>PEFT μ–΄λŒ‘ν„°λŠ” <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a> ν΄λž˜μŠ€μ—μ„œ μ§€μ›λ˜λ―€λ‘œ νŠΉμ • μ‚¬μš© 사둀에 맞게 μ–΄λŒ‘ν„°λ₯Ό ν›ˆλ ¨ν•  수 μžˆμŠ΅λ‹ˆλ‹€. λͺ‡ μ€„μ˜ μ½”λ“œλ₯Ό μΆ”κ°€ν•˜κΈ°λ§Œ ν•˜λ©΄ λ©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ LoRA μ–΄λŒ‘ν„°λ₯Ό ν›ˆλ ¨ν•˜λ €λ©΄:</p> <blockquote class="tip"><p><a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</a>λ₯Ό μ‚¬μš©ν•˜μ—¬ λͺ¨λΈμ„ λ―Έμ„Έ μ‘°μ •ν•˜λŠ” 것이 μ΅μˆ™ν•˜μ§€ μ•Šλ‹€λ©΄ <a href="training">μ‚¬μ „ν›ˆλ ¨λœ λͺ¨λΈμ„ λ―Έμ„Έ μ‘°μ •ν•˜κΈ°</a> νŠœν† λ¦¬μ–Όμ„ ν™•μΈν•˜μ„Έμš”.</p><!----></blockquote><!----> <ol><li>μž‘μ—… μœ ν˜• 및 ν•˜μ΄νΌνŒŒλΌλ―Έν„°λ₯Ό μ§€μ •ν•˜μ—¬ μ–΄λŒ‘ν„° ꡬ성을 μ •μ˜ν•©λ‹ˆλ‹€. ν•˜μ΄νΌνŒŒλΌλ―Έν„°μ— λŒ€ν•œ μžμ„Έν•œ λ‚΄μš©μ€ <code>LoraConfig</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 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="language-py "><!----><span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> LoraConfig
peft_config = LoraConfig(
lora_alpha=<span class="hljs-number">16</span>,
lora_dropout=<span class="hljs-number">0.1</span>,
r=<span class="hljs-number">64</span>,
bias=<span class="hljs-string">&quot;none&quot;</span>,
task_type=<span class="hljs-string">&quot;CAUSAL_LM&quot;</span>,
)<!----></pre></div><!----> <ol start="2"><li>λͺ¨λΈμ— μ–΄λŒ‘ν„°λ₯Ό μΆ”κ°€ν•©λ‹ˆλ‹€.</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 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="language-py "><!---->model.add_adapter(peft_config)<!----></pre></div><!----> <ol start="3"><li>이제 λͺ¨λΈμ„ <a href="/docs/transformers/main/ko/main_classes/trainer#transformers.Trainer">Trainer</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 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="language-py "><!---->trainer = Trainer(model=model, ...)
trainer.train()<!----></pre></div><!----> <p>ν›ˆλ ¨ν•œ μ–΄λŒ‘ν„°λ₯Ό μ €μž₯ν•˜κ³  λ‹€μ‹œ κ°€μ Έμ˜€λ €λ©΄:</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 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="language-py "><!---->model.save_pretrained(save_dir)
model = AutoModelForCausalLM.from_pretrained(save_dir)<!----></pre></div><!----> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/ko/peft.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><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]-->
<script>
{
__sveltekit_3y87jt = {
base: "/docs/transformers/main/ko",
assets: "/docs/transformers/main/ko"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/transformers/main/ko/_app/immutable/entry/start.yqDdfIah.js"),
import("/docs/transformers/main/ko/_app/immutable/entry/app.Caw9CuWs.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 130],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
44 kB
Β·
Xet hash:
38ea2b66101ce433026680e114cb12ab2a265757b440e843206070852a16085d

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