import{s as De,f as Ke,o as Pe,n as W}from"../chunks/scheduler.9bc65507.js";import{S as Oe,i as lt,g as U,s as c,r as u,A as et,h as m,f as s,c as M,j as ue,u as h,x as y,k as kl,y as tt,a as n,v as w,d as f,t as b,w as j}from"../chunks/index.707bf1b6.js";import{T as N}from"../chunks/Tip.c2ecdbf4.js";import{C as X}from"../chunks/CodeBlock.54a9f38d.js";import{H as P,E as st}from"../chunks/EditOnGithub.922df6ba.js";import{H as he,a as Gl}from"../chunks/HfOption.6d864328.js";function at(V){let e,i='Hugging Face는 LLM을 추론에 최적화하여 배포하고 서비스하는 데 전념하는 라이브러리인 <a href="https://hf.co/docs/text-generation-inference" rel="nofollow">Text Generation Inference (TGI)</a>을 제공합니다. 이 라이브러리는 처리량 증가를 위한 지속적인 배칭과 다중 GPU 추론을 위한 텐서 병렬화와 같은 Transformers에 포함되지 않은 배포 지향 최적화 기능을 포함합니다.';return{c(){e=U("p"),e.innerHTML=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-9ielvc"&&(e.innerHTML=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function nt(V){let e,i='현재 <a href="./model_doc/llama2">Llama</a> 및 몇 가지 다른 모델만 정적 kv-cache와 <code>torch.compile</code>을 지원합니다. 실시간 모델 호환성 목록은 <a href="https://github.com/huggingface/transformers/issues/28981" rel="nofollow">이 이슈</a>를 확인하십시오.';return{c(){e=U("p"),e.innerHTML=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-1oypbst"&&(e.innerHTML=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function ot(V){let e,i='<code>torch.compile</code>을 사용할 때 어떤 전략을 사용하든, LLM 입력을 제한된 값 세트로 왼쪽에 패딩하면 모양과 관련된 재컴파일을 피할 수 있습니다. <a href="https://huggingface.co/docs/transformers/main_classes/tokenizer#transformers.PreTrainedTokenizer.__call__.pad_to_multiple_of" rel="nofollow"><code>pad_to_multiple_of</code> tokenizer flag</a>가 유용할 것입니다!';return{c(){e=U("p"),e.innerHTML=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-1y0azda"&&(e.innerHTML=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function pt(V){let e,i="다중 턴 대화와 같은 정적 캐시의 고급 사용을 위해서는, 캐시 객체를 <code>generate()</code> 외부에서 인스턴스화하고 조작하는 것을 권장합니다. 고급 사용법 탭을 참조하세요.";return{c(){e=U("p"),e.innerHTML=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-yqcq0i"&&(e.innerHTML=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function Jt(V){let e,i='이 예제에서는 <a href="https://hf.co/google/gemma-2b" rel="nofollow">Gemma</a> 모델을 사용해 보겠습니다. 필요한 작업은 다음과 같습니다:',t,o,p="<li>모델의 <code>generation_config</code> 속성에 접근하여 <code>cache_implementation</code>을 “static”으로 설정합니다;</li> <li>모델의 <code>forward</code> 패스를 정적 kv-cache와 함께 컴파일하기 위해 <code>torch.compile</code>을 호출합니다.</li>",J,T,Z="이렇게 하면 끝입니다!",$,C,B,I,G="<code>generate</code> 함수는 내부적으로 동일한 캐시 객체를 재사용하려고 시도하며, 이를 통해 각 호출 시 재컴파일의 필요성을 제거합니다. 재컴파일을 피하는 것은 <code>torch.compile</code>의 성능을 최대한 활용하는 데 매우 중요하며, 다음 사항에 유의해야 합니다:",Q,v,R="<li>배치 크기가 변경되거나 호출 간 최대 출력 길이가 증가하면 캐시를 다시 초기화해야 하며, 이로 인해 새로 컴파일을 해야 합니다;</li> <li>컴파일된 함수의 첫 몇 번의 호출은 함수가 컴파일되는 동안 더 느립니다.</li>",F,_,g;return C=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQWltcG9ydCUyMHRvcm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ZGElMjIpJTBBJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRfaWRzKSUwQXByaW50KHRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSklMEElNUInVGhlJTIwdGhlb3J5JTIwb2YlMjBzcGVjaWFsJTIwcmVsYXRpdml0eSUyMHN0YXRlcyUyMDEuJTIwVGhlJTIwc3BlZWQlMjBvZiUyMGxpZ2h0JTIwaXMlMjBjb25zdGFudCUyMGluJTIwYWxsJTIwaW5lcnRpYWwlMjByZWZlcmVuY2UnJTVE",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> os
os.environ[<span class="hljs-string">&quot;TOKENIZERS_PARALLELISM&quot;</span>] = <span class="hljs-string">&quot;false&quot;</span>  <span class="hljs-comment"># 긴 경고 메시지를 방지하기 위해 설정 :)</span>

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/gemma-2b&quot;</span>)
model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;google/gemma-2b&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)

model.generation_config.cache_implementation = <span class="hljs-string">&quot;static&quot;</span>

model.forward = torch.<span class="hljs-built_in">compile</span>(model.forward, mode=<span class="hljs-string">&quot;reduce-overhead&quot;</span>, fullgraph=<span class="hljs-literal">True</span>)
input_text = <span class="hljs-string">&quot;The theory of special relativity states &quot;</span>
input_ids = tokenizer(input_text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)

outputs = model.generate(**input_ids)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&#x27;The theory of special relativity states 1. The speed of light is constant in all inertial reference&#x27;</span>]`,wrap:!1}}),_=new N({props:{warning:!0,$$slots:{default:[pt]},$$scope:{ctx:V}}}),{c(){e=U("p"),e.innerHTML=i,t=c(),o=U("ol"),o.innerHTML=p,J=c(),T=U("p"),T.textContent=Z,$=c(),u(C.$$.fragment),B=c(),I=U("p"),I.innerHTML=G,Q=c(),v=U("ol"),v.innerHTML=R,F=c(),u(_.$$.fragment)},l(d){e=m(d,"P",{"data-svelte-h":!0}),y(e)!=="svelte-zgi424"&&(e.innerHTML=i),t=M(d),o=m(d,"OL",{"data-svelte-h":!0}),y(o)!=="svelte-1eyfj2k"&&(o.innerHTML=p),J=M(d),T=m(d,"P",{"data-svelte-h":!0}),y(T)!=="svelte-1li9iek"&&(T.textContent=Z),$=M(d),h(C.$$.fragment,d),B=M(d),I=m(d,"P",{"data-svelte-h":!0}),y(I)!=="svelte-13n4tf3"&&(I.innerHTML=G),Q=M(d),v=m(d,"OL",{"data-svelte-h":!0}),y(v)!=="svelte-1b9xyp9"&&(v.innerHTML=R),F=M(d),h(_.$$.fragment,d)},m(d,r){n(d,e,r),n(d,t,r),n(d,o,r),n(d,J,r),n(d,T,r),n(d,$,r),w(C,d,r),n(d,B,r),n(d,I,r),n(d,Q,r),n(d,v,r),n(d,F,r),w(_,d,r),g=!0},p(d,r){const k={};r&2&&(k.$$scope={dirty:r,ctx:d}),_.$set(k)},i(d){g||(f(C.$$.fragment,d),f(_.$$.fragment,d),g=!0)},o(d){b(C.$$.fragment,d),b(_.$$.fragment,d),g=!1},d(d){d&&(s(e),s(t),s(o),s(J),s(T),s($),s(B),s(I),s(Q),s(v),s(F)),j(C,d),j(_,d)}}}function it(V){let e,i="동일한 <code>StaticCache</code> 객체를 새로운 프롬프트에 사용하려면, 호출 간에 <code>.reset()</code> 메서드를 사용하여 그 내용을 초기화하는 것이 좋습니다.";return{c(){e=U("p"),e.innerHTML=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-1bnncq4"&&(e.innerHTML=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function ct(V){let e,i="<code>StaticCache</code> 객체는 <code>past_key_values</code> 인수로 모델의 <code>generate()</code> 함수에 전달할 수 있습니다. 이 객체는 캐시 내용을 유지하므로, 동적 캐시를 사용하는 것처럼 새로운 <code>generate()</code> 호출에 이를 전달하여 생성을 계속할 수 있습니다.",t,o,p,J,T,Z,$="더 깊이 들어가고 싶다면, <code>StaticCache</code> 객체를 모델의 <code>forward</code> 패스에 동일한 <code>past_key_values</code> 인수로 전달할 수도 있습니다. 이 전략을 사용하면, 현재 토큰과 이전에 생성된 토큰의 위치 및 캐시 위치를 바탕으로 다음 토큰을 디코딩하는 자체 함수를 작성할 수 있습니다.",C,B,I,G,Q="<code>StaticCache</code> 메서드를 사용하여 정적 kv-cache와 <code>torch.compile</code>을 활성화하려면 몇 가지 중요한 작업을 수행해야 합니다:",v,R,F='<li>추론에 모델을 사용하기 전에 <code>StaticCache</code> 인스턴스를 초기화합니다. 여기서 최대 배치 크기와 시퀀스 길이와 같은 매개변수를 설정할 수 있습니다.</li> <li>정적 kv-cache와 함께 순전파를 컴파일하기 위해 모델에 <code>torch.compile</code>을 호출합니다.</li> <li><a href="https://pytorch.org/docs/master/generated/torch.nn.functional.scaled_dot_product_attention.html" rel="nofollow">torch.backends.cuda.sdp_kernel</a> 컨텍스트 관리자에서 <code>enable_math=True</code>를 설정하여 네이티브 PyTorch C++ 구현된 스케일된 점곱 어텐션(scaled dot product attention)을 활성화하여 추론 속도를 더욱 높입니다.</li>',_,g,d;return o=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUyQyUyMFN0YXRpY0NhY2hlJTBBaW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBvcyUwQW9zLmVudmlyb24lNUIlMjJUT0tFTklaRVJTX1BBUkFMTEVMSV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CU5NSVBMCUyMCVFQyU4OCU5OCUyMCVFQyU5RSU4OCVFQyU4QSVCNSVFQiU4QiU4OCVFQiU4QiVBNC4lMEFuZXdfaW5wdXRfaWRzJTIwJTNEJTIwb3V0cHV0cyUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZShuZXdfaW5wdXRfaWRzJTJDJTIwcGFzdF9rZXlfdmFsdWVzJTNEcGFzdF9rZXlfdmFsdWVzKSUwQXByaW50KHRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSklMEElNUInVGhlJTIwdGhlb3J5JTIwb2YlMjBzcGVjaWFsJTIwcmVsYXRpdml0eSUyMHN0YXRlcyUyMDEuJTIwVGhlJTIwc3BlZWQlMjBvZiUyMGxpZ2h0JTIwaXMlMjBjb25zdGFudCUyMGluJTIwYWxsJTIwaW5lcnRpYWwlMjByZWZlcmVuY2UlMjBmcmFtZXMuJTIwMi4lMjBUaGUlMjBzcGVlZCUyMG9mJTIwbGlnaHQlMjBpcyUyMGNvbnN0YW50JTIwaW4lMjBhbGwlMjBpbmVydGlhbCUyMHJlZmVyZW5jZSUyMGZyYW1lcy4lMjAzLiclNUQ=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM, StaticCache
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> os
os.environ[<span class="hljs-string">&quot;TOKENIZERS_PARALLELISM&quot;</span>] = <span class="hljs-string">&quot;false&quot;</span>  <span class="hljs-comment"># 긴 경고 메시지를 방지하기 위해 설정 :)</span>

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/gemma-2b&quot;</span>)
model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;google/gemma-2b&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)

model.forward = torch.<span class="hljs-built_in">compile</span>(model.forward, mode=<span class="hljs-string">&quot;reduce-overhead&quot;</span>, fullgraph=<span class="hljs-literal">True</span>)
input_text = <span class="hljs-string">&quot;The theory of special relativity states &quot;</span>
input_ids = tokenizer(input_text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)
prompt_length = input_ids.input_ids.shape[<span class="hljs-number">1</span>]
model.generation_config.max_new_tokens = <span class="hljs-number">16</span>

past_key_values = StaticCache(
    config=model.config,
    batch_size=<span class="hljs-number">1</span>,
    <span class="hljs-comment"># 캐시를 재사용할 계획이 있는 경우, 모든 경우에 충분한 캐시 길이를 설정해야 합니다</span>
    max_cache_len=prompt_length+(model.generation_config.max_new_tokens*<span class="hljs-number">2</span>),
    device=model.device,
    dtype=model.dtype
)
outputs = model.generate(**input_ids, past_key_values=past_key_values)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&#x27;The theory of special relativity states 1. The speed of light is constant in all inertial reference frames. 2&#x27;</span>]

<span class="hljs-comment"># 생성된 텍스트와 동일한 캐시 객체를 전달하여, 중단한 곳에서 생성을 계속합니다. </span>
<span class="hljs-comment"># 다중 턴 대화의 경우, 생성된 텍스트에 새로운 사용자 입력을 추가할 수 있습니다.</span>
new_input_ids = outputs
outputs = model.generate(new_input_ids, past_key_values=past_key_values)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&#x27;The theory of special relativity states 1. The speed of light is constant in all inertial reference frames. 2. The speed of light is constant in all inertial reference frames. 3.&#x27;</span>]`,wrap:!1}}),J=new N({props:{warning:!1,$$slots:{default:[it]},$$scope:{ctx:V}}}),B=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMExsYW1hVG9rZW5pemVyJTJDJTIwTGxhbWFGb3JDYXVzYWxMTSUyQyUyMFN0YXRpY0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vZGVsJTJDJTIwY3VyX3Rva2VuJTJDJTIwaW5wdXRfcG9zJTJDJTIwY2FjaGVfcG9zaXRpb24lMkMlMjBwYXN0X2tleV92YWx1ZXMpJTNBJTBBJTIwJTIwJTIwJTIwbG9naXRzJTIwJTNEJTIwbW9kZWwoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY3VyX3Rva2VuJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcG9zaXRpb25faWRzJTNEaW5wdXRfcG9zJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY2FjaGVfcG9zaXRpb24lM0RjYWNoZV9wb3NpdGlvbiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHBhc3Rfa2V5X3ZhbHVlcyUzRHBhc3Rfa2V5X3ZhbHVlcyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybl9kaWN0JTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB1c2VfY2FjaGUlM0RUcnVlJTBBJTIwJTIwJTIwJTIwKSU1QjAlNUQlMEElMjAlMjAlMjAlMjBuZXdfdG9rZW4lMjAlM0QlMjB0b3JjaC5hcmdtYXgobG9naXRzJTVCJTNBJTJDJTIwLTElNUQlMkMlMjBkaW0lM0QtMSklNUIlM0ElMkMlMjBOb25lJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwbmV3X3Rva2Vu",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> LlamaTokenizer, LlamaForCausalLM, StaticCache, logging
<span class="hljs-keyword">from</span> transformers.testing_utils <span class="hljs-keyword">import</span> CaptureLogger
<span class="hljs-keyword">import</span> torch

prompts = [
    <span class="hljs-string">&quot;Simply put, the theory of relativity states that &quot;</span>,
    <span class="hljs-string">&quot;My favorite all time favorite condiment is ketchup.&quot;</span>,
]

NUM_TOKENS_TO_GENERATE = <span class="hljs-number">40</span>
torch_device = <span class="hljs-string">&quot;cuda&quot;</span>

tokenizer = LlamaTokenizer.from_pretrained(<span class="hljs-string">&quot;meta-llama/Llama-2-7b-hf&quot;</span>, pad_token=<span class="hljs-string">&quot;&lt;/s&gt;&quot;</span>, padding_side=<span class="hljs-string">&quot;right&quot;</span>)
model = LlamaForCausalLM.from_pretrained(<span class="hljs-string">&quot;meta-llama/Llama-2-7b-hf&quot;</span>, device_map=<span class="hljs-string">&quot;sequential&quot;</span>)
inputs = tokenizer(prompts, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>, padding=<span class="hljs-literal">True</span>).to(model.device)

<span class="hljs-keyword">def</span> <span class="hljs-title function_">decode_one_tokens</span>(<span class="hljs-params">model, cur_token, input_pos, cache_position, past_key_values</span>):
    logits = model(
        cur_token,
        position_ids=input_pos,
        cache_position=cache_position,
        past_key_values=past_key_values,
        return_dict=<span class="hljs-literal">False</span>,
        use_cache=<span class="hljs-literal">True</span>
    )[<span class="hljs-number">0</span>]
    new_token = torch.argmax(logits[:, -<span class="hljs-number">1</span>], dim=-<span class="hljs-number">1</span>)[:, <span class="hljs-literal">None</span>]
    <span class="hljs-keyword">return</span> new_token`,wrap:!1}}),g=new X({props:{code:"YmF0Y2hfc2l6ZSUyQyUyMHNlcV9sZW5ndGglMjAlM0QlMjBpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQuc2hhcGUlMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwcGFzdF9rZXlfdmFsdWVzJTIwJTNEJTIwU3RhdGljQ2FjaGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29uZmlnJTNEbW9kZWwuY29uZmlnJTJDJTIwbWF4X2JhdGNoX3NpemUlM0QyJTJDJTIwbWF4X2NhY2hlX2xlbiUzRDQwOTYlMkMlMjBkZXZpY2UlM0R0b3JjaF9kZXZpY2UlMkMlMjBkdHlwZSUzRG1vZGVsLmR0eXBlJT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wJTIwJTIwJTIwJTIwJTIwY2FjaGVfcG9zaXRpb24lMjAlMkIlM0QlMjAxJTBBJTBBdGV4dCUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUoZ2VuZXJhdGVkX2lkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQXRleHQlMEElNUInU2ltcGx5JTIwcHV0JTJDJTIwdGhlJTIwdGhlb3J5JTIwb2YlMjByZWxhdGl2aXR5JTIwc3RhdGVzJTIwdGhhdCUyMDEpJTIwdGhlJTIwc3BlZWQlMjBvZiUyMGxpZ2h0JTIwaXMlMjBjb25zdGFudCUyQyUyMDIpJTIwdGhlJTIwc3BlZWQlMjBvZiUyMGxpZ2h0JTIwaXMlMjB0aGUlMjBzYW1lJTIwZm9yJTIwYWxsJTIwb2JzZXJ2ZXJzJTJDJTIwYW5kJTIwMyklMjB0aGUlMjBsYXdzJTIwb2YlMjBwaHlzaWNzJTIwYXJlJTIwdGhlJTIwc2FtZSUyMGZvciUyMGFsbCUyMG9ic2VydmVycy4nJTJDJTBBJTIwJ015JTIwZmF2b3JpdGUlMjBhbGwlMjB0aW1lJTIwZmF2b3JpdGUlMjBjb25kaW1lbnQlMjBpcyUyMGtldGNodXAuJTIwSSUyMGxvdmUlMjBpdCUyMG9uJTIwZXZlcnl0aGluZy4lMjBJJTIwbG92ZSUyMGl0JTIwb24lMjBteSUyMGVnZ3MlMkMlMjBteSUyMGZyaWVzJTJDJTIwbXklMjBjaGlja2VuJTJDJTIwbXklMjBidXJnZXJzJTJDJTIwbXklMjBob3QlMjBkb2dzJTJDJTIwbXklMjBzYW5kd2ljaGVzJTJDJTIwbXklMjBzYWxhZHMlMkMlMjBteSUyMHAnJTVE",highlighted:`batch_size, seq_length = inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].shape
<span class="hljs-keyword">with</span> torch.no_grad():
    past_key_values = StaticCache(
        config=model.config, max_batch_size=<span class="hljs-number">2</span>, max_cache_len=<span class="hljs-number">4096</span>, device=torch_device, dtype=model.dtype
    )
    cache_position = torch.arange(seq_length, device=torch_device)
    generated_ids = torch.zeros(
        batch_size, seq_length + NUM_TOKENS_TO_GENERATE + <span class="hljs-number">1</span>, dtype=torch.<span class="hljs-built_in">int</span>, device=torch_device
    )
    generated_ids[:, cache_position] = inputs[<span class="hljs-string">&quot;input_ids&quot;</span>].to(torch_device).to(torch.<span class="hljs-built_in">int</span>)

    logits = model(
        **inputs, cache_position=cache_position, past_key_values=past_key_values,return_dict=<span class="hljs-literal">False</span>, use_cache=<span class="hljs-literal">True</span>
    )[<span class="hljs-number">0</span>]
    next_token = torch.argmax(logits[:, -<span class="hljs-number">1</span>], dim=-<span class="hljs-number">1</span>)[:, <span class="hljs-literal">None</span>]
    generated_ids[:, seq_length] = next_token[:, <span class="hljs-number">0</span>]

    decode_one_tokens = torch.<span class="hljs-built_in">compile</span>(decode_one_tokens, mode=<span class="hljs-string">&quot;reduce-overhead&quot;</span>, fullgraph=<span class="hljs-literal">True</span>)
    cache_position = torch.tensor([seq_length + <span class="hljs-number">1</span>], device=torch_device)
    <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">1</span>, NUM_TOKENS_TO_GENERATE):
        <span class="hljs-keyword">with</span> torch.backends.cuda.sdp_kernel(enable_flash=<span class="hljs-literal">False</span>, enable_mem_efficient=<span class="hljs-literal">False</span>, enable_math=<span class="hljs-literal">True</span>):
            next_token = decode_one_tokens(model, next_token.clone(), <span class="hljs-literal">None</span>, cache_position, past_key_values)
            generated_ids[:, cache_position] = next_token.<span class="hljs-built_in">int</span>()
        cache_position += <span class="hljs-number">1</span>

text = tokenizer.batch_decode(generated_ids, skip_special_tokens=<span class="hljs-literal">True</span>)
text
[<span class="hljs-string">&#x27;Simply put, the theory of relativity states that 1) the speed of light is constant, 2) the speed of light is the same for all observers, and 3) the laws of physics are the same for all observers.&#x27;</span>,
 <span class="hljs-string">&#x27;My favorite all time favorite condiment is ketchup. I love it on everything. I love it on my eggs, my fries, my chicken, my burgers, my hot dogs, my sandwiches, my salads, my p&#x27;</span>]`,wrap:!1}}),{c(){e=U("p"),e.innerHTML=i,t=c(),u(o.$$.fragment),p=c(),u(J.$$.fragment),T=c(),Z=U("p"),Z.innerHTML=$,C=c(),u(B.$$.fragment),I=c(),G=U("p"),G.innerHTML=Q,v=c(),R=U("ol"),R.innerHTML=F,_=c(),u(g.$$.fragment)},l(r){e=m(r,"P",{"data-svelte-h":!0}),y(e)!=="svelte-p6cg61"&&(e.innerHTML=i),t=M(r),h(o.$$.fragment,r),p=M(r),h(J.$$.fragment,r),T=M(r),Z=m(r,"P",{"data-svelte-h":!0}),y(Z)!=="svelte-10roleu"&&(Z.innerHTML=$),C=M(r),h(B.$$.fragment,r),I=M(r),G=m(r,"P",{"data-svelte-h":!0}),y(G)!=="svelte-1tznqst"&&(G.innerHTML=Q),v=M(r),R=m(r,"OL",{"data-svelte-h":!0}),y(R)!=="svelte-ghrmo1"&&(R.innerHTML=F),_=M(r),h(g.$$.fragment,r)},m(r,k){n(r,e,k),n(r,t,k),w(o,r,k),n(r,p,k),w(J,r,k),n(r,T,k),n(r,Z,k),n(r,C,k),w(B,r,k),n(r,I,k),n(r,G,k),n(r,v,k),n(r,R,k),n(r,_,k),w(g,r,k),d=!0},p(r,k){const E={};k&2&&(E.$$scope={dirty:k,ctx:r}),J.$set(E)},i(r){d||(f(o.$$.fragment,r),f(J.$$.fragment,r),f(B.$$.fragment,r),f(g.$$.fragment,r),d=!0)},o(r){b(o.$$.fragment,r),b(J.$$.fragment,r),b(B.$$.fragment,r),b(g.$$.fragment,r),d=!1},d(r){r&&(s(e),s(t),s(p),s(T),s(Z),s(C),s(I),s(G),s(v),s(R),s(_)),j(o,r),j(J,r),j(B,r),j(g,r)}}}function Mt(V){let e,i="전체 <code>generate</code> 함수를 컴파일하는 것은 코드 측면에서 기본 사용법보다 더 간단합니다. <code>generate</code> 함수에 대해 <code>torch.compile</code>을 호출하여 전체 함수를 컴파일하면 됩니다. 정적 캐시의 사용을 지정할 필요는 없습니다. 정적 캐시는 호환되지만, 벤치마크에서는 동적 캐시(기본 설정)가 더 빠른 것으로 나타났습니다.",t,o,p,J,T="이 방법을 통해 모델의 forward 패스뿐만 아니라, 입력 준비, logit 처리기 작업 등을 포함한 모든 것을 컴파일합니다. 기본 사용 예제에 비해 <code>generate</code> 호출이 약간 더 빠를 수 있으며, 컴파일된 그래프는 더 특이한 하드웨어 장치나 사용 사례에 적합할 수 있습니다. 그러나 이 접근 방식을 사용하는 데는 몇 가지 큰 단점이 있습니다:",Z,$,C="<li>컴파일 속도가 훨씬 느립니다;</li> <li><code>generate</code>의 모든 매개변수 설정은 <code>generation_config</code>를 통해서만 가능합니다;</li> <li>많은 경고와 예외가 억제됩니다. — 먼저 컴파일 되지 않은 형태로 테스트하는 것을 권장합니다;</li> <li>현재 작업 중이지만 기능 제한이 심합니다(예: 작성 시점에서는 EOS 토큰이 선택되어도 생성이 중단되지 않습니다).</li>",B;return o=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQWltcG9ydCUyMHRvcmNoJTBBaW1wb3J0JTIwb3MlMEFvcy5lbnZpcm9uJTVCJTIyVE9LRU5JWkVSU19QQVJBTExFTElTTSUyMiU1RCUyMCUzRCUyMCUyMmZhbHNlJTIyJTIwJTIwJTIzJTIwJUVBJUI4JUI0JTIwJUVBJUIyJUJEJUVBJUIzJUEwJTIwJUVCJUE5JTk0JUVDJThCJTlDJUVDJUE3JTgwJUVCJUE1JUJDJTIwJUVCJUIwJUE5JUVDJUE3JTgwJUVEJTk1JTk4JUVBJUI4JUIwJTIwJUVDJTlDJTg0JUVEJTk1JUI0JTIwJUVDJTg0JUE0JUVDJUEwJTk1JTIwJTNBKSUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZSUyRmdlbW1hLTJiJTIyKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMmdvb2dsZSUyRmdlbW1hLTJiJTIyJTJDJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIpJTBBJTBBbW9kZWwuZ2VuZXJhdGUlMjAlM0QlMjB0b3JjaC5jb21waWxlKG1vZGVsLmdlbmVyYXRlJTJDJTIwbW9kZSUzRCUyMnJlZHVjZS1vdmVyaGVhZCUyMiUyQyUyMGZ1bGxncmFwaCUzRFRydWUpJTBBaW5wdXRfdGV4dCUyMCUzRCUyMCUyMlRoZSUyMHRoZW9yeSUyMG9mJTIwc3BlY2lhbCUyMHJlbGF0aXZpdHklMjBzdGF0ZXMlMjAlMjIlMEFpbnB1dF9pZHMlMjAlM0QlMjB0b2tlbml6ZXIoaW5wdXRfdGV4dCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLnRvKCUyMmN1ZGElMjIpJTBBJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRfaWRzKSUwQXByaW50KHRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSklMEElNUInVGhlJTIwdGhlb3J5JTIwb2YlMjBzcGVjaWFsJTIwcmVsYXRpdml0eSUyMHN0YXRlcyUyMDEuJTIwVGhlJTIwc3BlZWQlMjBvZiUyMGxpZ2h0JTIwaXMlMjBjb25zdGFudCUyMGluJTIwYWxsJTIwaW5lcnRpYWwlMjByZWZlcmVuY2UnJTVE",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> os
os.environ[<span class="hljs-string">&quot;TOKENIZERS_PARALLELISM&quot;</span>] = <span class="hljs-string">&quot;false&quot;</span>  <span class="hljs-comment"># 긴 경고 메시지를 방지하기 위해 설정 :)</span>

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/gemma-2b&quot;</span>)
model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;google/gemma-2b&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>)

model.generate = torch.<span class="hljs-built_in">compile</span>(model.generate, mode=<span class="hljs-string">&quot;reduce-overhead&quot;</span>, fullgraph=<span class="hljs-literal">True</span>)
input_text = <span class="hljs-string">&quot;The theory of special relativity states &quot;</span>
input_ids = tokenizer(input_text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)

outputs = model.generate(**input_ids)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&#x27;The theory of special relativity states 1. The speed of light is constant in all inertial reference&#x27;</span>]`,wrap:!1}}),{c(){e=U("p"),e.innerHTML=i,t=c(),u(o.$$.fragment),p=c(),J=U("p"),J.innerHTML=T,Z=c(),$=U("ol"),$.innerHTML=C},l(I){e=m(I,"P",{"data-svelte-h":!0}),y(e)!=="svelte-gsicdl"&&(e.innerHTML=i),t=M(I),h(o.$$.fragment,I),p=M(I),J=m(I,"P",{"data-svelte-h":!0}),y(J)!=="svelte-q1zvmc"&&(J.innerHTML=T),Z=M(I),$=m(I,"OL",{"data-svelte-h":!0}),y($)!=="svelte-1h1n9r2"&&($.innerHTML=C)},m(I,G){n(I,e,G),n(I,t,G),w(o,I,G),n(I,p,G),n(I,J,G),n(I,Z,G),n(I,$,G),B=!0},p:W,i(I){B||(f(o.$$.fragment,I),B=!0)},o(I){b(o.$$.fragment,I),B=!1},d(I){I&&(s(e),s(t),s(p),s(J),s(Z),s($)),j(o,I)}}}function rt(V){let e,i,t,o,p,J;return e=new Gl({props:{id:"static-kv",option:"basic usage: generation_config",$$slots:{default:[Jt]},$$scope:{ctx:V}}}),t=new Gl({props:{id:"static-kv",option:"advanced usage: control Static Cache",$$slots:{default:[ct]},$$scope:{ctx:V}}}),p=new Gl({props:{id:"static-kv",option:"advanced usage: end-to-end generate compilation",$$slots:{default:[Mt]},$$scope:{ctx:V}}}),{c(){u(e.$$.fragment),i=c(),u(t.$$.fragment),o=c(),u(p.$$.fragment)},l(T){h(e.$$.fragment,T),i=M(T),h(t.$$.fragment,T),o=M(T),h(p.$$.fragment,T)},m(T,Z){w(e,T,Z),n(T,i,Z),w(t,T,Z),n(T,o,Z),w(p,T,Z),J=!0},p(T,Z){const $={};Z&2&&($.$$scope={dirty:Z,ctx:T}),e.$set($);const C={};Z&2&&(C.$$scope={dirty:Z,ctx:T}),t.$set(C);const B={};Z&2&&(B.$$scope={dirty:Z,ctx:T}),p.$set(B)},i(T){J||(f(e.$$.fragment,T),f(t.$$.fragment,T),f(p.$$.fragment,T),J=!0)},o(T){b(e.$$.fragment,T),b(t.$$.fragment,T),b(p.$$.fragment,T),J=!1},d(T){T&&(s(i),s(o)),j(e,T),j(t,T),j(p,T)}}}function Tt(V){let e,i='보다 심층적인 설명을 원한다면, <a href="https://hf.co/blog/assisted-generation" rel="nofollow">Assisted Generation: a new direction toward low-latency text generation</a> 블로그 게시물을 확인하십시오!';return{c(){e=U("p"),e.innerHTML=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-144tzha"&&(e.innerHTML=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function dt(V){let e,i="추정 디코딩은 탐욕 검색과 샘플링 디코딩 전략에서만 지원되며, 배치 입력을 지원하지 않습니다.";return{c(){e=U("p"),e.textContent=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-11g2hie"&&(e.textContent=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function Ut(V){let e,i;return e=new X({props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TIwb2YlMjBsaWdodCUyMGlzJTIwY29uc3RhbnQuJTIwJTIwJTIwJTIwJTIyJTVE",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-keyword">import</span> torch

device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>)
inputs = tokenizer(<span class="hljs-string">&quot;Einstein&#x27;s theory of relativity states&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device)

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>).to(device)
assistant_model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-125m&quot;</span>).to(device)
outputs = model.generate(**inputs, assistant_model=assistant_model)
tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)
[<span class="hljs-string">&quot;Einstein&#x27;s theory of relativity states that the speed of light is constant.    &quot;</span>]`,wrap:!1}}),{c(){u(e.$$.fragment)},l(t){h(e.$$.fragment,t)},m(t,o){w(e,t,o),i=!0},p:W,i(t){i||(f(e.$$.fragment,t),i=!0)},o(t){b(e.$$.fragment,t),i=!1},d(t){j(e,t)}}}function mt(V){let e,i="추정 샘플링 디코딩(speculative sampling decoding)을 위해, 보조 모델 외에도 <code>generate()</code> 메서드에 <code>do_sample</code> 및 <code>temperature</code> 매개변수를 추가하십시오.",t,o,p;return o=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQWltcG9ydCUyMHRvcmNoJTBBJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUyMGl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ljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-keyword">import</span> torch

device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>)
inputs = tokenizer(<span class="hljs-string">&quot;Einstein&#x27;s theory of relativity states&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device)

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>).to(device)
assistant_model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-125m&quot;</span>).to(device)
outputs = model.generate(**inputs, assistant_model=assistant_model, do_sample=<span class="hljs-literal">True</span>, temperature=<span class="hljs-number">0.7</span>)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&quot;Einstein&#x27;s theory of relativity states that motion in the universe is not a straight line.\\n&quot;</span>]`,wrap:!1}}),{c(){e=U("p"),e.innerHTML=i,t=c(),u(o.$$.fragment)},l(J){e=m(J,"P",{"data-svelte-h":!0}),y(e)!=="svelte-uh4ey6"&&(e.innerHTML=i),t=M(J),h(o.$$.fragment,J)},m(J,T){n(J,e,T),n(J,t,T),w(o,J,T),p=!0},p:W,i(J){p||(f(o.$$.fragment,J),p=!0)},o(J){b(o.$$.fragment,J),p=!1},d(J){J&&(s(e),s(t)),j(o,J)}}}function yt(V){let e,i,t,o;return e=new Gl({props:{id:"spec-decoding",option:"greedy search",$$slots:{default:[Ut]},$$scope:{ctx:V}}}),t=new Gl({props:{id:"spec-decoding",option:"sampling",$$slots:{default:[mt]},$$scope:{ctx:V}}}),{c(){u(e.$$.fragment),i=c(),u(t.$$.fragment)},l(p){h(e.$$.fragment,p),i=M(p),h(t.$$.fragment,p)},m(p,J){w(e,p,J),n(p,i,J),w(t,p,J),o=!0},p(p,J){const T={};J&2&&(T.$$scope={dirty:J,ctx:p}),e.$set(T);const Z={};J&2&&(Z.$$scope={dirty:J,ctx:p}),t.$set(Z)},i(p){o||(f(e.$$.fragment,p),f(t.$$.fragment,p),o=!0)},o(p){b(e.$$.fragment,p),b(t.$$.fragment,p),o=!1},d(p){p&&s(i),j(e,p),j(t,p)}}}function ut(V){let e,i;return e=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQWltcG9ydCUyMHRvcmNoJTBBJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUyMGlmJTIwdG9yY2guY3VkYS5pc19hdmFpbGFibGUoKSUyMGVsc2UlMjAlMjJjcHUlMjIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm9wdC0xLjNiJTIyKSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplciglMjJUaGUlMjBzZWNvbmQlMjBsYXclMjBvZiUyMHRoZXJtb2R5bmFtaWNzJTIwc3RhdGVzJTIyJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMikudG8oZGV2aWNlKSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMmZhY2Vib29rJTJGb3B0LTEuM2IlMjIpLnRvKGRldmljZSklMEFhc3Npc3RhbnRfbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIyZmFjZWJvb2slMkZvcHQtMTI1bSUyMikudG8oZGV2aWNlKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyUyQyUyMHByb21wdF9sb29rdXBfbnVtX3Rva2VucyUzRDMpJTBBcHJpbnQodG9rZW5pemVyLmJhdGNoX2RlY29kZShvdXRwdXRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpKSUwQSU1QidUaGUlMjBzZWNvbmQlMjBsYXclMjBvZiUyMHRoZXJtb2R5bmFtaWNzJTIwc3RhdGVzJTIwdGhhdCUyMGVudHJvcHklMjBpbmNyZWFzZXMlMjB3aXRoJTIwdGVtcGVyYXR1cmUuJTIwJTIwJTIwJTIwJTIwJTIwJyU1RA==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-keyword">import</span> torch

device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>)
inputs = tokenizer(<span class="hljs-string">&quot;The second law of thermodynamics states&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device)

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>).to(device)
assistant_model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-125m&quot;</span>).to(device)
outputs = model.generate(**inputs, prompt_lookup_num_tokens=<span class="hljs-number">3</span>)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&#x27;The second law of thermodynamics states that entropy increases with temperature.      &#x27;</span>]`,wrap:!1}}),{c(){u(e.$$.fragment)},l(t){h(e.$$.fragment,t)},m(t,o){w(e,t,o),i=!0},p:W,i(t){i||(f(e.$$.fragment,t),i=!0)},o(t){b(e.$$.fragment,t),i=!1},d(t){j(e,t)}}}function ht(V){let e,i="샘플링과 함께 프롬프트 조회 디코딩을 사용하려면, <code>generate()</code> 메서드에 <code>do_sample</code> 및 <code>temperature</code> 매개변수를 추가하십시오.",t,o,p;return o=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQWltcG9ydCUyMHRvcmNoJTBBJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUyMGlmJTIwdG9yY2guY3VkYS5pc19hdmFpbGFibGUoKSUyMGVsc2UlMjAlMjJjcHUlMjIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm9wdC0xLjNiJTIyKSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplciglMjJUaGUlMjBzZWNvbmQlMjBsYXclMjBvZiUyMHRoZXJtb2R5bmFtaWNzJTIwc3RhdGVzJTIyJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMikudG8oZGV2aWNlKSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMmZhY2Vib29rJTJGb3B0LTEuM2IlMjIpLnRvKGRldmljZSklMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoKippbnB1dHMlMkMlMjBwcm9tcHRfbG9va3VwX251bV90b2tlbnMlM0QzJTJDJTIwZG9fc2FtcGxlJTNEVHJ1ZSUyQyUyMHRlbXBlcmF0dXJlJTNEMC43KSUwQXByaW50KHRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSklMEElNUIlMjJUaGUlMjBzZWNvbmQlMjBsYXclMjBvZiUyMHRoZXJtb2R5bmFtaWNzJTIwc3RhdGVzJTIwdGhhdCUyMGVuZXJneSUyMGNhbm5vdCUyMGJlJTIwY3JlYXRlZCUyMG5vciUyMGRlc3Ryb3llZC4lMjBJdCdzJTIwbm90JTIwYSUyMiU1RA==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer
<span class="hljs-keyword">import</span> torch

device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>)
inputs = tokenizer(<span class="hljs-string">&quot;The second law of thermodynamics states&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device)

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;facebook/opt-1.3b&quot;</span>).to(device)
outputs = model.generate(**inputs, prompt_lookup_num_tokens=<span class="hljs-number">3</span>, do_sample=<span class="hljs-literal">True</span>, temperature=<span class="hljs-number">0.7</span>)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&quot;The second law of thermodynamics states that energy cannot be created nor destroyed. It&#x27;s not a&quot;</span>]`,wrap:!1}}),{c(){e=U("p"),e.innerHTML=i,t=c(),u(o.$$.fragment)},l(J){e=m(J,"P",{"data-svelte-h":!0}),y(e)!=="svelte-pyqekq"&&(e.innerHTML=i),t=M(J),h(o.$$.fragment,J)},m(J,T){n(J,e,T),n(J,t,T),w(o,J,T),p=!0},p:W,i(J){p||(f(o.$$.fragment,J),p=!0)},o(J){b(o.$$.fragment,J),p=!1},d(J){J&&(s(e),s(t)),j(o,J)}}}function wt(V){let e,i,t,o;return e=new Gl({props:{id:"pld",option:"greedy decoding",$$slots:{default:[ut]},$$scope:{ctx:V}}}),t=new Gl({props:{id:"pld",option:"sampling",$$slots:{default:[ht]},$$scope:{ctx:V}}}),{c(){u(e.$$.fragment),i=c(),u(t.$$.fragment)},l(p){h(e.$$.fragment,p),i=M(p),h(t.$$.fragment,p)},m(p,J){w(e,p,J),n(p,i,J),w(t,p,J),o=!0},p(p,J){const T={};J&2&&(T.$$scope={dirty:J,ctx:p}),e.$set(T);const Z={};J&2&&(Z.$$scope={dirty:J,ctx:p}),t.$set(Z)},i(p){o||(f(e.$$.fragment,p),f(t.$$.fragment,p),o=!0)},o(p){b(e.$$.fragment,p),b(t.$$.fragment,p),o=!1},d(p){p&&s(i),j(e,p),j(t,p)}}}function ft(V){let e,i="SDPA는 최신 PyTorch 버전이 설치되어 있으면 FlashAttention-2도 지원합니다.";return{c(){e=U("p"),e.textContent=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-1yx0a1x"&&(e.textContent=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function bt(V){let e,i='다양한 양자화 라이브러리(자세한 내용은 <a href="./quantization">Quantization</a> 가이드를 참조하십시오)가 있습니다. 여기에는 Quanto, AQLM, AWQ 및 AutoGPTQ가 포함됩니다. 사용 사례에 가장 잘 맞는 라이브러리를 사용해 보십시오. 또한 AutoGPTQ와 bitsandbytes를 비교하는 <a href="https://hf.co/blog/overview-quantization-transformers" rel="nofollow">Overview of natively supported quantization schemes in 🤗 Transformers</a> 블로그 게시물을 읽어보는 것을 추천합니다.';return{c(){e=U("p"),e.innerHTML=i},l(t){e=m(t,"P",{"data-svelte-h":!0}),y(e)!=="svelte-i3ictq"&&(e.innerHTML=i)},m(t,o){n(t,e,o)},p:W,d(t){t&&s(e)}}}function jt(V){let e,i,t,o,p,J,T,Z="대규모 언어 모델(LLM)은 채팅 및 코드 완성 모델과 같은 텍스트 생성 응용 프로그램을 한 단계 끌어올리며, 높은 수준의 이해력과 유창함을 보여주는 텍스트를 생성합니다. 그러나 LLM을 강력하게 만드는 요소인 그들의 크기는 동시에 추론 과정에서 도전 과제가 되기도 합니다.",$,C,B="기본적인 추론은 느립니다, 왜냐하면 LLM이 다음 토큰을 생성하기 위해 반복적으로 호출되어야 하기 때문입니다. 생성이 진행됨에 따라 입력 시퀀스가 길어져 처리 시간이 점점 길어집니다. 또한, LLM은 수십억 개의 매개변수를 가지고 있어 모든 가중치를 메모리에 저장하고 처리하는 데 어려움이 있습니다.",I,G,Q="이 가이드는 LLM 추론을 가속하기 위해 Transformers에서 사용할 수 있는 최적화 기술을 사용하는 방법을 보여줍니다.",v,R,F,_,g,d,r="디코딩 중에 LLM은 각 입력 토큰에 대한 key-value(kv) 값을 계산합니다. LLM은 자기회귀(autoregressive)이기 때문에 생성된 출력이 현재 입력의 일부가 되어 매번 동일한 kv 값을 계산합니다. 이는 매번 동일한 kv 값을 다시 계산하기 때문에 효율적이지 않습니다.",k,E,we='이를 최적화하기 위해, 이전 키(key)와 값(value)을 재계산하지 않고 저장하는 kv-cache를 사용할 수 있습니다. 그러나 kv-cache는 각 생성 단계에서 증가하며 동적이기 때문에 PyTorch 코드를 빠르고 최적화된 커널로 통합하는 강력한 최적화 도구인 <a href="./perf_torch_compile"><code>torch.compile</code></a>을 사용하는 데 제약이 있습니다.',Bl,O,fe="<em>정적 kv-cache</em>는 최댓값을 미리 할당하여 이 문제를 해결하여 <code>torch.compile</code>과 결합할 수 있게 합니다. 이를 통해 최대 4배의 속도 향상이 가능합니다. 속도 향상은 모델 크기(더 큰 모델은 속도 향상이 적음)와 하드웨어에 따라 다를 수 있습니다.",_l,H,Rl,ll,be="작업의 복잡성에 따라 세 가지 방식의 정적 kv-cache 사용 방법이 있습니다:",vl,el,je="<li>기본 사용법: <code>generation_config</code>에서 플래그를 설정하기만 하면 됩니다(권장);</li> <li>고급 사용법: 여러 번의 생성이나 맞춤형 생성 루프를 위해 캐시 객체를 처리합니다;</li> <li>고급 사용법: 단일 그래프가 필요한 경우, 전체 <code>generate</code> 함수를 하나의 그래프로 컴파일합니다.</li>",gl,tl,Ve="올바른 탭을 선택하여 각 방법에 대한 추가 지침을 확인하세요.",Wl,Y,Xl,S,Fl,sl,Ql,x,El,al,Ie="자기 회귀의 또 다른 문제는 각 입력 토큰에 대해 순전파 중에 모델 가중치를 매번 로드해야 한다는 점입니다. 이는 수십억 개의 매개변수를 가진 LLM에는 느리고 번거롭습니다. 추정 디코딩(speculative decoding)은 더 작고 빠른 보조 모델을 사용하여 후보 토큰을 생성하고, 이를 큰 LLM이 단일 순전파에서 검증하여 이 속도 저하를 완화합니다. 검증된 토큰이 정확하다면, LLM은 본래 자체적으로 생성하는 것처럼 토큰을 얻을 수 있습니다. 전방 패스가 동일한 출력을 보장하기 때문에 정확도 저하가 없습니다.",zl,nl,Ze="가장 큰 속도 향상을 얻기 위해, 보조 모델은 빠르게 토큰을 생성할 수 있도록 LLM보다 훨씬 작아야 합니다. 보조 모델과 LLM 모델은 토큰을 다시 인코딩하고 디코딩하지 않도록 동일한 토크나이저를 공유해야 합니다.",Nl,L,Hl,ol,Ce="보조 모델을 로드하고 이를 <code>generate()</code> 메서드에 전달하여 추정 디코딩을 활성화하십시오.",Yl,A,Sl,pl,xl,Jl,Ge="프롬프트 조회 디코딩은 탐욕 검색과 샘플링과도 호환되는 추정 디코딩의 변형입니다. 프롬프트 조회는 요약과 같은 입력 기반 작업에 특히 잘 작동합니다. 여기서는 프롬프트와 출력 간에 종종 겹치는 단어가 있습니다. 이러한 겹치는 n-그램이 LLM 후보 토큰으로 사용됩니다.",Ll,il,ke="프롬프트 조회 디코딩을 활성화하려면 <code>prompt_lookup_num_tokens</code> 매개변수에 겹치는 토큰 수를 지정하십시오. 그런 다음 이 매개변수를 <code>generate()</code> 메서드에 전달할 수 있습니다.",Al,q,ql,cl,Dl,Ml,$e="트랜스포머 모델의 알려진 문제는 셀프 어텐션 메커니즘이 입력 토큰 수와 함께 계산 및 메모리가 제곱으로 증가한다는 것입니다. 이 제한은 훨씬 더 긴 시퀀스를 처리하는 LLM에서는 더욱 커집니다. 이를 해결하기 위해 FlashAttention2 또는 PyTorch의 스케일된 점곱 어텐션을 사용해 보십시오. 이들은 더 메모리 효율적인 어텐션 구현으로 추론을 가속화할 수 있습니다.",Kl,rl,Pl,Tl,Be='FlashAttention과 <a href="./perf_infer_gpu_one#flashattention-2">FlashAttention-2</a>는 어텐션 계산을 더 작은 청크로 나누고 중간 읽기/쓰기 작업을 줄여 추론 속도를 높입니다. FlashAttention-2는 원래 FlashAttention 알고리즘을 개선하여 시퀀스 길이 차원에서도 병렬 처리를 수행하고 하드웨어에서 작업을 더 잘 분할하여 동기화 및 통신 오버헤드를 줄입니다.',Ol,dl,_e="FlashAttention-2를 사용하려면 <code>from_pretrained()</code> 메서드에서 <code>attn_implementation=&quot;flash_attention_2&quot;</code>를 설정하십시오.",le,Ul,ee,ml,te,yl,Re="스케일된 점곱 어텐션(SDPA)는 PyTorch 2.0에서 자동으로 활성화되며, FlashAttention, xFormers, PyTorch의 C++ 구현을 지원합니다. SDPA는 CUDA 백엔드를 사용하는 경우 가장 성능이 좋은 어텐션 알고리즘을 선택합니다. 다른 백엔드에서는 SDPA가 PyTorch C++ 구현으로 기본 설정됩니다.",se,D,ae,ul,ve='세 가지 어텐션 알고리즘 중 하나를 명시적으로 활성화하거나 비활성화하려면 <a href="https://pytorch.org/docs/master/generated/torch.nn.functional.scaled_dot_product_attention.html" rel="nofollow">torch.backends.cuda.sdp_kernel</a> 컨텍스트 관리자를 사용하십시오. 예를 들어 FlashAttention을 활성화하려면 <code>enable_flash=True</code>로 설정하십시오.',ne,hl,oe,wl,pe,fl,ge="양자화는 LLM 가중치를 더 낮은 정밀도로 저장하여 크기를 줄입니다. 이는 메모리 사용량을 줄이며 GPU 메모리에 제약이 있는 경우 추론을 위해 LLM을 로드하는 것을 더 용이하게 합니다. GPU가 충분하다면, 모델을 양자화할 필요는 없습니다. 추가적인 양자화 및 양자화 해제 단계로 인해 약간의 지연이 발생할 수 있기 때문입니다(AWQ 및 융합 AWQ 모듈 제외).",Je,K,ie,bl,We='아래의 모델 메모리 계산기를 사용하여 모델을 로드하는 데 필요한 메모리를 추정하고 비교해 보십시오. 예를 들어 <a href="https://huggingface.co/mistralai/Mistral-7B-v0.1" rel="nofollow">Mistral-7B-v0.1</a>를 로드하는 데 필요한 메모리를 추정해 보십시오.',ce,z,Xe,Me,jl,Fe="Mistral-7B-v0.1을 반정밀도로 로드하려면 <code>from_pretrained()</code> 메서드에서 <code>torch_dtype</code> 매개변수를 <code>torch.bfloat16</code>으로 설정하십시오. 이 경우 13.74GB의 메모리가 필요합니다.",re,Vl,Te,Il,Qe='추론을 위해 양자화된 모델(8비트 또는 4비트)을 로드하려면 <a href="https://hf.co/docs/bitsandbytes" rel="nofollow">bitsandbytes</a>를 사용하고 <code>load_in_4bit</code> 또는 <code>load_in_8bit</code> 매개변수를 <code>True</code>로 설정하십시오. 모델을 8비트로 로드하는 데는 6.87GB의 메모리만 필요합니다.',de,Zl,Ue,Cl,me,$l,ye;return p=new P({props:{title:"LLM 추론 최적화",local:"llm-inference-optimization",headingTag:"h1"}}),R=new N({props:{warning:!1,$$slots:{default:[at]},$$scope:{ctx:V}}}),_=new P({props:{title:"정적 kv-cache와 torch.compile",local:"static-kv-cache-and-torchcompile",headingTag:"h2"}}),H=new N({props:{warning:!0,$$slots:{default:[nt]},$$scope:{ctx:V}}}),Y=new N({props:{warning:!1,$$slots:{default:[ot]},$$scope:{ctx:V}}}),S=new he({props:{id:"static-kv",options:["basic usage: generation_config","advanced usage: control Static Cache","advanced usage: end-to-end generate compilation"],$$slots:{default:[rt]},$$scope:{ctx:V}}}),sl=new P({props:{title:"추정 디코딩",local:"speculative-decoding",headingTag:"h2"}}),x=new N({props:{warning:!1,$$slots:{default:[Tt]},$$scope:{ctx:V}}}),L=new N({props:{warning:!0,$$slots:{default:[dt]},$$scope:{ctx:V}}}),A=new he({props:{id:"spec-decoding",options:["greedy search","sampling"],$$slots:{default:[yt]},$$scope:{ctx:V}}}),pl=new P({props:{title:"프롬프트 조회 디코딩",local:"prompt-lookup-decoding",headingTag:"h3"}}),q=new he({props:{id:"pld",options:["greedy decoding","sampling"],$$slots:{default:[wt]},$$scope:{ctx:V}}}),cl=new P({props:{title:"어텐션 최적화",local:"attention-optimizations",headingTag:"h2"}}),rl=new P({props:{title:"FlashAttention-2",local:"flashattention-2",headingTag:"h3"}}),Ul=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQml0c0FuZEJ5dGVzQ29uZmlnJTBBJTBBcXVhbnRfY29uZmlnJTIwJTNEJTIwQml0c0FuZEJ5dGVzQ29uZmlnKGxvYWRfaW5fOGJpdCUzRFRydWUpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyZ29vZ2xlJTJGZ2VtbWEtMmIlMjIlMkMlMEElMjAlMjAlMjAlMjBxdWFudGl6YXRpb25fY29uZmlnJTNEcXVhbnRfY29uZmlnJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSUyMCUyMCUyMCUyMGF0dG5faW1wbGVtZW50YXRpb24lM0QlMjJmbGFzaF9hdHRlbnRpb25fMiUyMiUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, BitsAndBytesConfig

quant_config = BitsAndBytesConfig(load_in_8bit=<span class="hljs-literal">True</span>)
model = AutoModelForCausalLM.from_pretrained(
    <span class="hljs-string">&quot;google/gemma-2b&quot;</span>,
    quantization_config=quant_config,
    torch_dtype=torch.bfloat16,
    attn_implementation=<span class="hljs-string">&quot;flash_attention_2&quot;</span>,
)`,wrap:!1}}),ml=new P({props:{title:"PyTorch 스케일된 점곱 어텐션(scaled dot product attention)",local:"pytorch-scaled-dot-product-attention",headingTag:"h3"}}),D=new N({props:{warning:!1,$$slots:{default:[ft]},$$scope:{ctx:V}}}),hl=new X({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJnb29nbGUlMkZnZW1tYS0yYiUyMiUyQyUwQSUyMCUyMCUyMCUyMHRvcmNoX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMEEpJTBBJTBBd2l0aCUyMHRvcmNoLmJhY2tlbmRzLmN1ZGEuc2RwX2tlcm5lbChlbmFibGVfZmxhc2glM0RUcnVlJTJDJTIwZW5hYmxlX21hdGglM0RGYWxzZSUyQyUyMGVuYWJsZV9tZW1fZWZmaWNpZW50JTNERmFsc2UpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRzKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(
    <span class="hljs-string">&quot;google/gemma-2b&quot;</span>,
    torch_dtype=torch.bfloat16,
)

<span class="hljs-keyword">with</span> torch.backends.cuda.sdp_kernel(enable_flash=<span class="hljs-literal">True</span>, enable_math=<span class="hljs-literal">False</span>, enable_mem_efficient=<span class="hljs-literal">False</span>):
    outputs = model.generate(**inputs)`,wrap:!1}}),wl=new P({props:{title:"양자화",local:"quantization",headingTag:"h2"}}),K=new N({props:{warning:!1,$$slots:{default:[bt]},$$scope:{ctx:V}}}),Vl=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQWltcG9ydCUyMHRvcmNoJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIybWlzdHJhbGFpJTJGTWlzdHJhbC03Qi12MC4xJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUyMGRldmljZV9tYXAlM0QlMjJhdXRvJTIyJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM
<span class="hljs-keyword">import</span> torch

model = AutoModelForCausalLM.from_pretrained(
    <span class="hljs-string">&quot;mistralai/Mistral-7B-v0.1&quot;</span>, torch_dtype=torch.bfloat16, device_map=<span class="hljs-string">&quot;auto&quot;</span>,
)`,wrap:!1}}),Zl=new X({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUyQyUyMEJpdHNBbmRCeXRlc0NvbmZpZyUwQWltcG9ydCUyMHRvcmNoJTBBJTBBcXVhbnRfY29uZmlnJTIwJTNEJTIwQml0c0FuZEJ5dGVzQ29uZmlnKGxvYWRfaW5fOGJpdCUzRFRydWUpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIybWlzdHJhbGFpJTJGTWlzdHJhbC03Qi12MC4xJTIyJTJDJTIwcXVhbnRpemF0aW9uX2NvbmZpZyUzRHF1YW50X2NvbmZpZyUyQyUyMGRldmljZV9tYXAlM0QlMjJhdXRvJTIyJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
<span class="hljs-keyword">import</span> torch

quant_config = BitsAndBytesConfig(load_in_8bit=<span class="hljs-literal">True</span>)
model = AutoModelForCausalLM.from_pretrained(
    <span class="hljs-string">&quot;mistralai/Mistral-7B-v0.1&quot;</span>, quantization_config=quant_config, device_map=<span class="hljs-string">&quot;auto&quot;</span>
)`,wrap:!1}}),Cl=new st({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ko/llm_optims.md"}}),{c(){e=U("meta"),i=c(),t=U("p"),o=c(),u(p.$$.fragment),J=c(),T=U("p"),T.textContent=Z,$=c(),C=U("p"),C.textContent=B,I=c(),G=U("p"),G.textContent=Q,v=c(),u(R.$$.fragment),F=c(),u(_.$$.fragment),g=c(),d=U("p"),d.textContent=r,k=c(),E=U("p"),E.innerHTML=we,Bl=c(),O=U("p"),O.innerHTML=fe,_l=c(),u(H.$$.fragment),Rl=c(),ll=U("p"),ll.textContent=be,vl=c(),el=U("ol"),el.innerHTML=je,gl=c(),tl=U("p"),tl.textContent=Ve,Wl=c(),u(Y.$$.fragment),Xl=c(),u(S.$$.fragment),Fl=c(),u(sl.$$.fragment),Ql=c(),u(x.$$.fragment),El=c(),al=U("p"),al.textContent=Ie,zl=c(),nl=U("p"),nl.textContent=Ze,Nl=c(),u(L.$$.fragment),Hl=c(),ol=U("p"),ol.innerHTML=Ce,Yl=c(),u(A.$$.fragment),Sl=c(),u(pl.$$.fragment),xl=c(),Jl=U("p"),Jl.textContent=Ge,Ll=c(),il=U("p"),il.innerHTML=ke,Al=c(),u(q.$$.fragment),ql=c(),u(cl.$$.fragment),Dl=c(),Ml=U("p"),Ml.textContent=$e,Kl=c(),u(rl.$$.fragment),Pl=c(),Tl=U("p"),Tl.innerHTML=Be,Ol=c(),dl=U("p"),dl.innerHTML=_e,le=c(),u(Ul.$$.fragment),ee=c(),u(ml.$$.fragment),te=c(),yl=U("p"),yl.textContent=Re,se=c(),u(D.$$.fragment),ae=c(),ul=U("p"),ul.innerHTML=ve,ne=c(),u(hl.$$.fragment),oe=c(),u(wl.$$.fragment),pe=c(),fl=U("p"),fl.textContent=ge,Je=c(),u(K.$$.fragment),ie=c(),bl=U("p"),bl.innerHTML=We,ce=c(),z=U("iframe"),Me=c(),jl=U("p"),jl.innerHTML=Fe,re=c(),u(Vl.$$.fragment),Te=c(),Il=U("p"),Il.innerHTML=Qe,de=c(),u(Zl.$$.fragment),Ue=c(),u(Cl.$$.fragment),me=c(),$l=U("p"),this.h()},l(l){const a=et("svelte-u9bgzb",document.head);e=m(a,"META",{name:!0,content:!0}),a.forEach(s),i=M(l),t=m(l,"P",{}),ue(t).forEach(s),o=M(l),h(p.$$.fragment,l),J=M(l),T=m(l,"P",{"data-svelte-h":!0}),y(T)!=="svelte-ikijop"&&(T.textContent=Z),$=M(l),C=m(l,"P",{"data-svelte-h":!0}),y(C)!=="svelte-lgr6n0"&&(C.textContent=B),I=M(l),G=m(l,"P",{"data-svelte-h":!0}),y(G)!=="svelte-18buelc"&&(G.textContent=Q),v=M(l),h(R.$$.fragment,l),F=M(l),h(_.$$.fragment,l),g=M(l),d=m(l,"P",{"data-svelte-h":!0}),y(d)!=="svelte-1fmnpkw"&&(d.textContent=r),k=M(l),E=m(l,"P",{"data-svelte-h":!0}),y(E)!=="svelte-14rruly"&&(E.innerHTML=we),Bl=M(l),O=m(l,"P",{"data-svelte-h":!0}),y(O)!=="svelte-1s0aiak"&&(O.innerHTML=fe),_l=M(l),h(H.$$.fragment,l),Rl=M(l),ll=m(l,"P",{"data-svelte-h":!0}),y(ll)!=="svelte-608bjv"&&(ll.textContent=be),vl=M(l),el=m(l,"OL",{"data-svelte-h":!0}),y(el)!=="svelte-1jphkc4"&&(el.innerHTML=je),gl=M(l),tl=m(l,"P",{"data-svelte-h":!0}),y(tl)!=="svelte-alzl50"&&(tl.textContent=Ve),Wl=M(l),h(Y.$$.fragment,l),Xl=M(l),h(S.$$.fragment,l),Fl=M(l),h(sl.$$.fragment,l),Ql=M(l),h(x.$$.fragment,l),El=M(l),al=m(l,"P",{"data-svelte-h":!0}),y(al)!=="svelte-xfh61h"&&(al.textContent=Ie),zl=M(l),nl=m(l,"P",{"data-svelte-h":!0}),y(nl)!=="svelte-q0jd9k"&&(nl.textContent=Ze),Nl=M(l),h(L.$$.fragment,l),Hl=M(l),ol=m(l,"P",{"data-svelte-h":!0}),y(ol)!=="svelte-1no510f"&&(ol.innerHTML=Ce),Yl=M(l),h(A.$$.fragment,l),Sl=M(l),h(pl.$$.fragment,l),xl=M(l),Jl=m(l,"P",{"data-svelte-h":!0}),y(Jl)!=="svelte-2e74to"&&(Jl.textContent=Ge),Ll=M(l),il=m(l,"P",{"data-svelte-h":!0}),y(il)!=="svelte-474jlr"&&(il.innerHTML=ke),Al=M(l),h(q.$$.fragment,l),ql=M(l),h(cl.$$.fragment,l),Dl=M(l),Ml=m(l,"P",{"data-svelte-h":!0}),y(Ml)!=="svelte-dg6lyb"&&(Ml.textContent=$e),Kl=M(l),h(rl.$$.fragment,l),Pl=M(l),Tl=m(l,"P",{"data-svelte-h":!0}),y(Tl)!=="svelte-1wj8lzh"&&(Tl.innerHTML=Be),Ol=M(l),dl=m(l,"P",{"data-svelte-h":!0}),y(dl)!=="svelte-2wsrvp"&&(dl.innerHTML=_e),le=M(l),h(Ul.$$.fragment,l),ee=M(l),h(ml.$$.fragment,l),te=M(l),yl=m(l,"P",{"data-svelte-h":!0}),y(yl)!=="svelte-1pkp4tn"&&(yl.textContent=Re),se=M(l),h(D.$$.fragment,l),ae=M(l),ul=m(l,"P",{"data-svelte-h":!0}),y(ul)!=="svelte-1m2wes8"&&(ul.innerHTML=ve),ne=M(l),h(hl.$$.fragment,l),oe=M(l),h(wl.$$.fragment,l),pe=M(l),fl=m(l,"P",{"data-svelte-h":!0}),y(fl)!=="svelte-1nlhjc4"&&(fl.textContent=ge),Je=M(l),h(K.$$.fragment,l),ie=M(l),bl=m(l,"P",{"data-svelte-h":!0}),y(bl)!=="svelte-hdeqf"&&(bl.innerHTML=We),ce=M(l),z=m(l,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),ue(z).forEach(s),Me=M(l),jl=m(l,"P",{"data-svelte-h":!0}),y(jl)!=="svelte-duadc6"&&(jl.innerHTML=Fe),re=M(l),h(Vl.$$.fragment,l),Te=M(l),Il=m(l,"P",{"data-svelte-h":!0}),y(Il)!=="svelte-11tku4g"&&(Il.innerHTML=Qe),de=M(l),h(Zl.$$.fragment,l),Ue=M(l),h(Cl.$$.fragment,l),me=M(l),$l=m(l,"P",{}),ue($l).forEach(s),this.h()},h(){kl(e,"name","hf:doc:metadata"),kl(e,"content",Vt),Ke(z.src,Xe="https://hf-accelerate-model-memory-usage.hf.space")||kl(z,"src",Xe),kl(z,"frameborder","0"),kl(z,"width","850"),kl(z,"height","450")},m(l,a){tt(document.head,e),n(l,i,a),n(l,t,a),n(l,o,a),w(p,l,a),n(l,J,a),n(l,T,a),n(l,$,a),n(l,C,a),n(l,I,a),n(l,G,a),n(l,v,a),w(R,l,a),n(l,F,a),w(_,l,a),n(l,g,a),n(l,d,a),n(l,k,a),n(l,E,a),n(l,Bl,a),n(l,O,a),n(l,_l,a),w(H,l,a),n(l,Rl,a),n(l,ll,a),n(l,vl,a),n(l,el,a),n(l,gl,a),n(l,tl,a),n(l,Wl,a),w(Y,l,a),n(l,Xl,a),w(S,l,a),n(l,Fl,a),w(sl,l,a),n(l,Ql,a),w(x,l,a),n(l,El,a),n(l,al,a),n(l,zl,a),n(l,nl,a),n(l,Nl,a),w(L,l,a),n(l,Hl,a),n(l,ol,a),n(l,Yl,a),w(A,l,a),n(l,Sl,a),w(pl,l,a),n(l,xl,a),n(l,Jl,a),n(l,Ll,a),n(l,il,a),n(l,Al,a),w(q,l,a),n(l,ql,a),w(cl,l,a),n(l,Dl,a),n(l,Ml,a),n(l,Kl,a),w(rl,l,a),n(l,Pl,a),n(l,Tl,a),n(l,Ol,a),n(l,dl,a),n(l,le,a),w(Ul,l,a),n(l,ee,a),w(ml,l,a),n(l,te,a),n(l,yl,a),n(l,se,a),w(D,l,a),n(l,ae,a),n(l,ul,a),n(l,ne,a),w(hl,l,a),n(l,oe,a),w(wl,l,a),n(l,pe,a),n(l,fl,a),n(l,Je,a),w(K,l,a),n(l,ie,a),n(l,bl,a),n(l,ce,a),n(l,z,a),n(l,Me,a),n(l,jl,a),n(l,re,a),w(Vl,l,a),n(l,Te,a),n(l,Il,a),n(l,de,a),w(Zl,l,a),n(l,Ue,a),w(Cl,l,a),n(l,me,a),n(l,$l,a),ye=!0},p(l,[a]){const Ee={};a&2&&(Ee.$$scope={dirty:a,ctx:l}),R.$set(Ee);const ze={};a&2&&(ze.$$scope={dirty:a,ctx:l}),H.$set(ze);const Ne={};a&2&&(Ne.$$scope={dirty:a,ctx:l}),Y.$set(Ne);const He={};a&2&&(He.$$scope={dirty:a,ctx:l}),S.$set(He);const Ye={};a&2&&(Ye.$$scope={dirty:a,ctx:l}),x.$set(Ye);const Se={};a&2&&(Se.$$scope={dirty:a,ctx:l}),L.$set(Se);const xe={};a&2&&(xe.$$scope={dirty:a,ctx:l}),A.$set(xe);const Le={};a&2&&(Le.$$scope={dirty:a,ctx:l}),q.$set(Le);const Ae={};a&2&&(Ae.$$scope={dirty:a,ctx:l}),D.$set(Ae);const qe={};a&2&&(qe.$$scope={dirty:a,ctx:l}),K.$set(qe)},i(l){ye||(f(p.$$.fragment,l),f(R.$$.fragment,l),f(_.$$.fragment,l),f(H.$$.fragment,l),f(Y.$$.fragment,l),f(S.$$.fragment,l),f(sl.$$.fragment,l),f(x.$$.fragment,l),f(L.$$.fragment,l),f(A.$$.fragment,l),f(pl.$$.fragment,l),f(q.$$.fragment,l),f(cl.$$.fragment,l),f(rl.$$.fragment,l),f(Ul.$$.fragment,l),f(ml.$$.fragment,l),f(D.$$.fragment,l),f(hl.$$.fragment,l),f(wl.$$.fragment,l),f(K.$$.fragment,l),f(Vl.$$.fragment,l),f(Zl.$$.fragment,l),f(Cl.$$.fragment,l),ye=!0)},o(l){b(p.$$.fragment,l),b(R.$$.fragment,l),b(_.$$.fragment,l),b(H.$$.fragment,l),b(Y.$$.fragment,l),b(S.$$.fragment,l),b(sl.$$.fragment,l),b(x.$$.fragment,l),b(L.$$.fragment,l),b(A.$$.fragment,l),b(pl.$$.fragment,l),b(q.$$.fragment,l),b(cl.$$.fragment,l),b(rl.$$.fragment,l),b(Ul.$$.fragment,l),b(ml.$$.fragment,l),b(D.$$.fragment,l),b(hl.$$.fragment,l),b(wl.$$.fragment,l),b(K.$$.fragment,l),b(Vl.$$.fragment,l),b(Zl.$$.fragment,l),b(Cl.$$.fragment,l),ye=!1},d(l){l&&(s(i),s(t),s(o),s(J),s(T),s($),s(C),s(I),s(G),s(v),s(F),s(g),s(d),s(k),s(E),s(Bl),s(O),s(_l),s(Rl),s(ll),s(vl),s(el),s(gl),s(tl),s(Wl),s(Xl),s(Fl),s(Ql),s(El),s(al),s(zl),s(nl),s(Nl),s(Hl),s(ol),s(Yl),s(Sl),s(xl),s(Jl),s(Ll),s(il),s(Al),s(ql),s(Dl),s(Ml),s(Kl),s(Pl),s(Tl),s(Ol),s(dl),s(le),s(ee),s(te),s(yl),s(se),s(ae),s(ul),s(ne),s(oe),s(pe),s(fl),s(Je),s(ie),s(bl),s(ce),s(z),s(Me),s(jl),s(re),s(Te),s(Il),s(de),s(Ue),s(me),s($l)),s(e),j(p,l),j(R,l),j(_,l),j(H,l),j(Y,l),j(S,l),j(sl,l),j(x,l),j(L,l),j(A,l),j(pl,l),j(q,l),j(cl,l),j(rl,l),j(Ul,l),j(ml,l),j(D,l),j(hl,l),j(wl,l),j(K,l),j(Vl,l),j(Zl,l),j(Cl,l)}}}const Vt='{"title":"LLM 추론 최적화","local":"llm-inference-optimization","sections":[{"title":"정적 kv-cache와 torch.compile","local":"static-kv-cache-and-torchcompile","sections":[],"depth":2},{"title":"추정 디코딩","local":"speculative-decoding","sections":[{"title":"프롬프트 조회 디코딩","local":"prompt-lookup-decoding","sections":[],"depth":3}],"depth":2},{"title":"어텐션 최적화","local":"attention-optimizations","sections":[{"title":"FlashAttention-2","local":"flashattention-2","sections":[],"depth":3},{"title":"PyTorch 스케일된 점곱 어텐션(scaled dot product attention)","local":"pytorch-scaled-dot-product-attention","sections":[],"depth":3}],"depth":2},{"title":"양자화","local":"quantization","sections":[],"depth":2}],"depth":1}';function It(V){return Pe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class _t extends Oe{constructor(e){super(),lt(this,e,It,jt,De,{})}}export{_t as component};
