import{s as Ft,o as Rt,n as ve}from"../chunks/scheduler.bdbef820.js";import{S as Vt,i as Et,g as i,s as r,r as u,A as Qt,h as d,f as o,c as l,j as de,u as f,x as h,k as me,y as p,a,v as g,d as b,t as _,w as M}from"../chunks/index.33f81d56.js";import{T as Bt}from"../chunks/Tip.34194030.js";import{D as we}from"../chunks/Docstring.64554317.js";import{C as ke}from"../chunks/CodeBlock.362b34a4.js";import{E as ht}from"../chunks/ExampleCodeBlock.4f2252c6.js";import{H as ce,E as Xt}from"../chunks/EditOnGithub.a9246e21.js";function Lt($){let n,J="Example:",m,c,T;return c=new ke({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME1hbWJhMkNvbmZpZyUyQyUyME1hbWJhMk1vZGVsJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyME1hbWJhMiUyMGNvbmZpZ3VyYXRpb24lMEFjb25maWd1cmF0aW9uJTIwJTNEJTIwTWFtYmEyQ29uZmlnKCklMEElMEElMjMlMjBJbml0aWFsaXppbmclMjBhJTIwbW9kZWwlMjAod2l0aCUyMHJhbmRvbSUyMHdlaWdodHMpJTIwZnJvbSUyMHRoZSUyMGNvbmZpZ3VyYXRpb24lMEFtb2RlbCUyMCUzRCUyME1hbWJhMk1vZGVsKGNvbmZpZ3VyYXRpb24pJTBBJTBBJTIzJTIwQWNjZXNzaW5nJTIwdGhlJTIwbW9kZWwlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyMG1vZGVsLmNvbmZpZw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Mamba2Config, Mamba2Model

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a Mamba2 configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = Mamba2Config()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model (with random weights) from the configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = Mamba2Model(configuration)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config`,wrap:!1}}),{c(){n=i("p"),n.textContent=J,m=r(),u(c.$$.fragment)},l(s){n=d(s,"P",{"data-svelte-h":!0}),h(n)!=="svelte-11lpom8"&&(n.textContent=J),m=l(s),f(c.$$.fragment,s)},m(s,y){a(s,n,y),a(s,m,y),g(c,s,y),T=!0},p:ve,i(s){T||(b(c.$$.fragment,s),T=!0)},o(s){_(c.$$.fragment,s),T=!1},d(s){s&&(o(n),o(m)),M(c,s)}}}function Nt($){let n,J=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){n=i("p"),n.innerHTML=J},l(m){n=d(m,"P",{"data-svelte-h":!0}),h(n)!=="svelte-fincs2"&&(n.innerHTML=J)},m(m,c){a(m,n,c)},p:ve,d(m){m&&o(n)}}}function Ht($){let n,J="Example:",m,c,T;return c=new ke({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBNYW1iYTJNb2RlbCUwQWltcG9ydCUyMHRvcmNoJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIybWlzdHJhbGFpJTJGbWFtYmEtY29kZXN0cmFsLTdCLXYwLjElMjIpJTBBbW9kZWwlMjAlM0QlMjBNYW1iYTJNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIybWlzdHJhbGFpJTJGbWFtYmEtY29kZXN0cmFsLTdCLXYwLjElMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMkhlbGxvJTJDJTIwbXklMjBkb2clMjBpcyUyMGN1dGUlMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyklMEElMEFsYXN0X2hpZGRlbl9zdGF0ZXMlMjAlM0QlMjBvdXRwdXRzLmxhc3RfaGlkZGVuX3N0YXRl",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, Mamba2Model
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mistralai/mamba-codestral-7B-v0.1&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = Mamba2Model.from_pretrained(<span class="hljs-string">&quot;mistralai/mamba-codestral-7B-v0.1&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;Hello, my dog is cute&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs)

<span class="hljs-meta">&gt;&gt;&gt; </span>last_hidden_states = outputs.last_hidden_state`,wrap:!1}}),{c(){n=i("p"),n.textContent=J,m=r(),u(c.$$.fragment)},l(s){n=d(s,"P",{"data-svelte-h":!0}),h(n)!=="svelte-11lpom8"&&(n.textContent=J),m=l(s),f(c.$$.fragment,s)},m(s,y){a(s,n,y),a(s,m,y),g(c,s,y),T=!0},p:ve,i(s){T||(b(c.$$.fragment,s),T=!0)},o(s){_(c.$$.fragment,s),T=!1},d(s){s&&(o(n),o(m)),M(c,s)}}}function Gt($){let n,J=`Although the recipe for forward pass needs to be defined within this function, one should call the <code>Module</code>
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`;return{c(){n=i("p"),n.innerHTML=J},l(m){n=d(m,"P",{"data-svelte-h":!0}),h(n)!=="svelte-fincs2"&&(n.innerHTML=J)},m(m,c){a(m,n,c)},p:ve,d(m){m&&o(n)}}}function qt($){let n,J="Example:",m,c,T;return c=new ke({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyME1hbWJhMkZvckNhdXNhbExNJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIybWlzdHJhbGFpJTJGbWFtYmEtY29kZXN0cmFsLTdCLXYwLjElMjIpJTBBbW9kZWwlMjAlM0QlMjBNYW1iYTJGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIybWlzdHJhbGFpJTJGbWFtYmEtY29kZXN0cmFsLTdCLXYwLjElMjIpJTBBJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMkhlbGxvJTJDJTIwbXklMjBkb2clMjBpcyUyMGN1dGUlMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmlucHV0cyUyQyUyMGxhYmVscyUzRGlucHV0cyU1QiUyMmlucHV0X2lkcyUyMiU1RCklMEFsb3NzJTIwJTNEJTIwb3V0cHV0cy5sb3NzJTBBbG9naXRzJTIwJTNEJTIwb3V0cHV0cy5sb2dpdHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, Mamba2ForCausalLM

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;mistralai/mamba-codestral-7B-v0.1&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = Mamba2ForCausalLM.from_pretrained(<span class="hljs-string">&quot;mistralai/mamba-codestral-7B-v0.1&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;Hello, my dog is cute&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(**inputs, labels=inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>loss = outputs.loss
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = outputs.logits`,wrap:!1}}),{c(){n=i("p"),n.textContent=J,m=r(),u(c.$$.fragment)},l(s){n=d(s,"P",{"data-svelte-h":!0}),h(n)!=="svelte-11lpom8"&&(n.textContent=J),m=l(s),f(c.$$.fragment,s)},m(s,y){a(s,n,y),a(s,m,y),g(c,s,y),T=!0},p:ve,i(s){T||(b(c.$$.fragment,s),T=!0)},o(s){_(c.$$.fragment,s),T=!1},d(s){s&&(o(n),o(m)),M(c,s)}}}function At($){let n,J,m,c,T,s,y,Ce,E,ut='맘바2 모델은 Tri Dao, Albert Gu가 제안한 <a href="https://arxiv.org/abs/2405.21060" rel="nofollow">트랜스포머는 SSM이다: 구조화된 상태 공간 이중성을 통한 일반화된 모델과 효율적인 알고리즘</a>라는 논문에서 소개되었습니다. 맘바2는 맘바1과 유사한 상태 공간 모델로, 단순화된 아키텍처에서 더 나은 성능을 보입니다.',Ue,Q,ft="해당 논문의 초록입니다:",$e,X,gt="<em>트랜스포머는 언어 모델링에서 딥러닝 성공의 주요 아키텍처였지만, 맘바와 같은 상태 공간 모델(SSM)이 최근 소규모 혹은 중간 규모에서 트랜스포머와 대등하거나 더 나은 성능을 보이는 것으로 나타났습니다. 우리는 이러한 모델 계열들이 실제로 매우 밀접하게 연관되어 있음을 파악했습니다. 그리고 구조화된 준분리(semiseparable) 행렬 중 연구가 잘 이루어진 클래스의 다양한 분해를 통해 연결된 SSM과 어텐션 변형 사이의 풍부한 이론적 연결 프레임워크를 개발했습니다. 상태 공간 이중성(SSD) 프레임워크를 통해 맘바1의 선택적 SSM을 개선한 새로운 아키텍처를 설계할 수 있었고, 트랜스포머와 경쟁력을 유지하면서도 속도는 2~8배 더 빠른 성능을 냅니다.</em>",Ie,L,bt="팁:",xe,N,_t='이 버전은 맘바2 구현을 지원해야 하며, 특히 Mistral AI의 <a href="https://huggingface.co/mistralai/Mamba-Codestral-7B-v0.1" rel="nofollow">Mamba-2 codestral</a>을 지원합니다. 특히, mamba 2 codestral은 8개의 <code>groups</code>로 출시되었는데, 이는 어텐션 기반 모델의 KV 헤드 수와 유사하다고 판단 가능합니다.',je,H,Mt='이 모델은 <code>torch_forward</code>와 <code>cuda_kernels_forward</code>라는 두 가지 다른 전방 패스를 가집니다. <code>cuda_kernels_forward</code>는 환경에서 cuda 커널을 찾으면 이를 사용하며, prefill에서는 더 느립니다. 즉, 높은 CPU 오버헤드로 인해 “웜업 실행”이 필요하기 때문입니다. 관련 내용은 <a href="https://github.com/state-spaces/mamba/issues/389#issuecomment-2171755306" rel="nofollow">이곳</a>과 <a href="https://github.com/state-spaces/mamba/issues/355#issuecomment-2147597457" rel="nofollow">이곳</a>을 참고하세요.',ze,G,Tt='컴파일 없이는 <code>torch_forward</code> 구현이 3~4배 빠릅니다. 또한, 이 모델에는 위치 임베딩이 없지만 <code>attention_mask</code>와 배치 생성의 경우 두 곳에서 은닉 상태(hidden state)를 마스킹하는 특정 로직이 있습니다. 관련 내용은 <a href="https://github.com/state-spaces/mamba/issues/66#issuecomment-1863563829" rel="nofollow">이곳</a>을 참고하세요.',We,q,Jt="이로인해 맘바2 커널의 재구현과 함께 배치 생성 및 캐시된 생성에서 약간의 차이가 예상됩니다. 또한 cuda 커널 또는 torch forward가 제공하는 결과가 약간 다를 것으로 예상됩니다. SSM 알고리즘은 텐서 수축에 크게 의존하는데, 이는 matmul과 동등하지만 연산 순서가 약간 다르며, 이로 인해 더 작은 정밀도에서 차이가 더 커집니다.",Ze,A,yt="또 다른 참고사항으로, 패딩 토큰에 해당하는 은닉 상태(hidden state)의 종료는 두 곳에서 이루어지며 주로 왼쪽 패딩으로 테스트되었습니다. 오른쪽 패딩은 노이즈를 전파하므로 만족스러운 결과를 보장하지 않습니다. <code>tokenizer.padding_side = &quot;left&quot;</code>를 사용하면 올바른 패딩 방향을 사용할 수 있습니다.",Be,D,wt=`이 모델은 <a href="https://huggingface.co/Molbap" rel="nofollow">Molbap</a>이 기여했으며, <a href="https://github.com/vasqu" rel="nofollow">Anton Vlasjuk</a>의 큰 도움을 받았습니다.
원본 코드는 <a href="https://github.com/state-spaces/mamba" rel="nofollow">이곳</a>에서 확인할 수 있습니다.`,Fe,S,Re,P,Ve,Y,Ee,O,kt="이곳은 미세조정을 위한 초안 스크립트입니다:",Qe,K,Xe,ee,Le,v,te,Pe,pe,vt=`This is the configuration class to store the configuration of a <a href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2Model">Mamba2Model</a>. It is used to instantiate a MAMBA2
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the MAMBA2
<a href="https://huggingface.co/state-spaces/mamba2-2.8b" rel="nofollow">state-spaces/mamba2-2.8b</a> architecture.`,Ye,he,Ct=`Configuration objects inherit from <a href="/docs/transformers/pr_22105/ko/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/pr_22105/ko/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> for more information.`,Oe,Z,Ne,oe,He,w,ae,Ke,ue,Ut="The bare MAMBA2 Model transformer outputting raw hidden-states without any specific head on top.",et,fe,$t=`This model inherits from <a href="/docs/transformers/pr_22105/ko/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`,tt,ge,It=`This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`,ot,I,ne,at,be,xt='The <a href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2Model">Mamba2Model</a> forward method, overrides the <code>__call__</code> special method.',nt,B,st,F,Ge,se,qe,k,re,rt,_e,jt=`The MAMBA2 Model transformer with a language modeling head on top (linear layer with weights not tied to the input
embeddings).`,lt,Me,zt=`This model inherits from <a href="/docs/transformers/pr_22105/ko/main_classes/model#transformers.PreTrainedModel">PreTrainedModel</a>. Check the superclass documentation for the generic methods the
library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
etc.)`,it,Te,Wt=`This model is also a PyTorch <a href="https://pytorch.org/docs/stable/nn.html#torch.nn.Module" rel="nofollow">torch.nn.Module</a> subclass.
Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
and behavior.`,dt,x,le,mt,Je,Zt='The <a href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2ForCausalLM">Mamba2ForCausalLM</a> forward method, overrides the <code>__call__</code> special method.',ct,R,pt,V,Ae,ie,De,ye,Se;return T=new ce({props:{title:"맘바2",local:"mamba-2",headingTag:"h1"}}),y=new ce({props:{title:"개요",local:"overview",headingTag:"h2"}}),S=new ce({props:{title:"사용",local:"사용",headingTag:"h1"}}),P=new ce({props:{title:"간단한 생성 예:",local:"간단한-생성-예",headingTag:"h3"}}),Y=new ke({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME1hbWJhMkNvbmZpZyUyQyUyME1hbWJhMkZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQWltcG9ydCUyMHRvcmNoJTBBbW9kZWxfaWQlMjAlM0QlMjAnbWlzdHJhbGFpJTJGTWFtYmEtQ29kZXN0cmFsLTdCLXYwLjEnJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjByZXZpc2lvbiUzRCdyZWZzJTJGcHIlMkY5JyUyQyUyMGZyb21fc2xvdyUzRFRydWUlMkMlMjBsZWdhY3klM0RGYWxzZSklMEFtb2RlbCUyMCUzRCUyME1hbWJhMkZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHJldmlzaW9uJTNEJ3JlZnMlMkZwciUyRjknKSUwQWlucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplciglMjJIZXklMjBob3clMjBhcmUlMjB5b3UlMjBkb2luZyUzRiUyMiUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIwJTIycHQlMjIpJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTBBJTBBb3V0JTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoaW5wdXRfaWRzJTJDJTIwbWF4X25ld190b2tlbnMlM0QxMCklMEFwcmludCh0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKG91dCkp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Mamba2Config, Mamba2ForCausalLM, AutoTokenizer
<span class="hljs-keyword">import</span> torch
model_id = <span class="hljs-string">&#x27;mistralai/Mamba-Codestral-7B-v0.1&#x27;</span>
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=<span class="hljs-string">&#x27;refs/pr/9&#x27;</span>, from_slow=<span class="hljs-literal">True</span>, legacy=<span class="hljs-literal">False</span>)
model = Mamba2ForCausalLM.from_pretrained(model_id, revision=<span class="hljs-string">&#x27;refs/pr/9&#x27;</span>)
input_ids = tokenizer(<span class="hljs-string">&quot;Hey how are you doing?&quot;</span>, return_tensors= <span class="hljs-string">&quot;pt&quot;</span>)[<span class="hljs-string">&quot;input_ids&quot;</span>]

out = model.generate(input_ids, max_new_tokens=<span class="hljs-number">10</span>)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(out))`,wrap:!1}}),K=new ke({props:{code:"ZnJvbSUyMHRybCUyMGltcG9ydCUyMFNGVFRyYWluZXIlMEFmcm9tJTIwcGVmdCUyMGltcG9ydCUyMExvcmFDb25maWclMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyME1hbWJhMkZvckNhdXNhbExNJTJDJTIwVHJhaW5pbmdBcmd1bWVudHMlMEFtb2RlbF9pZCUyMCUzRCUyMCdtaXN0cmFsYWklMkZNYW1iYS1Db2Rlc3RyYWwtN0ItdjAuMSclMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHJldmlzaW9uJTNEJ3JlZnMlMkZwciUyRjknJTJDJTIwZnJvbV9zbG93JTNEVHJ1ZSUyQyUyMGxlZ2FjeSUzREZhbHNlKSUwQXRva2VuaXplci5wYWRfdG9rZW4lMjAlM0QlMjB0b2tlbml6ZXIuZW9zX3Rva2VuJTBBdG9rZW5pemVyLnBhZGRpbmdfc2lkZSUyMCUzRCUyMCUyMmxlZnQlMjIlMjAlMjMlRUMlOTklQkMlRUMlQUElQkQlMjAlRUQlOEMlQTglRUIlOTQlQTklRUMlOUMlQkMlRUIlQTElOUMlMjAlRUMlODQlQTQlRUMlQTAlOTUlMEElMEFtb2RlbCUyMCUzRCUyME1hbWJhMkZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHJldmlzaW9uJTNEJ3JlZnMlMkZwciUyRjknKSUwQWRhdGFzZXQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyQWJpcmF0ZSUyRmVuZ2xpc2hfcXVvdGVzJTIyJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiklMEElMjMlMjBDVURBJTIwJUVDJUJCJUE0JUVCJTg0JTkwJUVDJTk3JTg2JUVDJTlEJUI0JUVCJThBJTk0JTJDJTIwJUVCJUIwJUIwJUVDJUI5JTk4JUVEJTgxJUFDJUVBJUI4JUIwJTIwMiVFQSVCMCU4MCUyMDgwR0IlMjAlRUMlOUUlQTUlRUMlQjklOTglRUIlQTUlQkMlMjAlRUQlOTUlOTglRUIlODIlOTglMjAlRUMlQjAlQTglRUMlQTclODAlRUQlOTUlQTklRUIlOEIlODglRUIlOEIlQTQuJTBBJTIzJTIwJUVEJTk1JTk4JUVDJUE3JTgwJUVCJUE3JThDJTIwJUVDJUEwJTk1JUVEJTk5JTk1JUVCJThGJTg0JUVCJThBJTk0JTIwJUVBJUIwJTkwJUVDJTg2JThDJUVEJTk1JUE5JUVCJThCJTg4JUVCJThCJUE0LiUwQSUyMyUyMCVFQyU4QiVBNCVFRCU5NyU5OCVFQSVCMyVCQyUyMCVFQyU4QiU5QyVFQiU4RiU4NCVFQiVBNSVCQyUyMCVFRCU5OSU5OCVFQyU5OCU4MSVFRCU5NSVBOSVFQiU4QiU4OCVFQiU4QiVBNCElMEF0cmFpbmluZ19hcmdzJTIwJTNEJTIwVHJhaW5pbmdBcmd1bWVudHMoJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMi4lMkZyZXN1bHRzJTIyJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX2Vwb2NocyUzRDMlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QyJTJDJTBBJTIwJTIwJTIwJTIwbG9nZ2luZ19kaXIlM0QnLiUyRmxvZ3MnJTJDJTBBJTIwJTIwJTIwJTIwbG9nZ2luZ19zdGVwcyUzRDEwJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTMlMEEpJTBBbG9yYV9jb25maWclMjAlM0QlMjAlMjBMb3JhQ29uZmlnKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHIlM0Q4JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGFyZ2V0X21vZHVsZXMlM0QlNUIlMjJlbWJlZGRpbmdzJTIyJTJDJTIwJTIyaW5fcHJvaiUyMiUyQyUyMCUyMm91dF9wcm9qJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGFza190eXBlJTNEJTIyQ0FVU0FMX0xNJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYmlhcyUzRCUyMm5vbmUlMjIlMEEpJTBBdHJhaW5lciUyMCUzRCUyMFNGVFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwcGVmdF9jb25maWclM0Rsb3JhX2NvbmZpZyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0RkYXRhc2V0JTJDJTBBJTIwJTIwJTIwJTIwZGF0YXNldF90ZXh0X2ZpZWxkJTNEJTIycXVvdGUlMjIlMkMlMEEpJTBBdHJhaW5lci50cmFpbigp",highlighted:`<span class="hljs-keyword">from</span> trl <span class="hljs-keyword">import</span> SFTTrainer
<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> LoraConfig
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, Mamba2ForCausalLM, TrainingArguments
model_id = <span class="hljs-string">&#x27;mistralai/Mamba-Codestral-7B-v0.1&#x27;</span>
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=<span class="hljs-string">&#x27;refs/pr/9&#x27;</span>, from_slow=<span class="hljs-literal">True</span>, legacy=<span class="hljs-literal">False</span>)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = <span class="hljs-string">&quot;left&quot;</span> <span class="hljs-comment">#왼쪽 패딩으로 설정</span>

model = Mamba2ForCausalLM.from_pretrained(model_id, revision=<span class="hljs-string">&#x27;refs/pr/9&#x27;</span>)
dataset = load_dataset(<span class="hljs-string">&quot;Abirate/english_quotes&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
<span class="hljs-comment"># CUDA 커널없이는, 배치크기 2가 80GB 장치를 하나 차지합니다.</span>
<span class="hljs-comment"># 하지만 정확도는 감소합니다.</span>
<span class="hljs-comment"># 실험과 시도를 환영합니다!</span>
training_args = TrainingArguments(
    output_dir=<span class="hljs-string">&quot;./results&quot;</span>,
    num_train_epochs=<span class="hljs-number">3</span>,
    per_device_train_batch_size=<span class="hljs-number">2</span>,
    logging_dir=<span class="hljs-string">&#x27;./logs&#x27;</span>,
    logging_steps=<span class="hljs-number">10</span>,
    learning_rate=<span class="hljs-number">2e-3</span>
)
lora_config =  LoraConfig(
        r=<span class="hljs-number">8</span>,
        target_modules=[<span class="hljs-string">&quot;embeddings&quot;</span>, <span class="hljs-string">&quot;in_proj&quot;</span>, <span class="hljs-string">&quot;out_proj&quot;</span>],
        task_type=<span class="hljs-string">&quot;CAUSAL_LM&quot;</span>,
        bias=<span class="hljs-string">&quot;none&quot;</span>
)
trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    args=training_args,
    peft_config=lora_config,
    train_dataset=dataset,
    dataset_text_field=<span class="hljs-string">&quot;quote&quot;</span>,
)
trainer.train()`,wrap:!1}}),ee=new ce({props:{title:"Mamba2Config",local:"transformers.Mamba2Config",headingTag:"h2"}}),te=new we({props:{name:"class transformers.Mamba2Config",anchor:"transformers.Mamba2Config",parameters:[{name:"num_heads",val:" = 128"},{name:"head_dim",val:" = 64"},{name:"vocab_size",val:" = 32768"},{name:"hidden_size",val:" = 4096"},{name:"state_size",val:" = 128"},{name:"num_hidden_layers",val:" = 64"},{name:"layer_norm_epsilon",val:" = 1e-05"},{name:"pad_token_id",val:" = 1"},{name:"bos_token_id",val:" = 0"},{name:"eos_token_id",val:" = 2"},{name:"expand",val:" = 2"},{name:"conv_kernel",val:" = 4"},{name:"n_groups",val:" = 8"},{name:"use_bias",val:" = False"},{name:"use_conv_bias",val:" = True"},{name:"hidden_act",val:" = 'silu'"},{name:"initializer_range",val:" = 0.1"},{name:"residual_in_fp32",val:" = True"},{name:"time_step_rank",val:" = 'auto'"},{name:"time_step_min",val:" = 0.001"},{name:"time_step_max",val:" = 0.1"},{name:"time_step_floor",val:" = 0.0001"},{name:"time_step_limit",val:" = (0.0, inf)"},{name:"rescale_prenorm_residual",val:" = False"},{name:"use_cache",val:" = True"},{name:"rms_norm",val:" = True"},{name:"chunk_size",val:" = 256"},{name:"tie_word_embeddings",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.Mamba2Config.num_heads",description:`<strong>num_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
Number of heads for the evolution matrices of mamba 2.`,name:"num_heads"},{anchor:"transformers.Mamba2Config.head_dim",description:`<strong>head_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
Dimension of each head.`,name:"head_dim"},{anchor:"transformers.Mamba2Config.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 32768) &#x2014;
Vocabulary size of the MAMBA2 model. Defines the number of different tokens that can be represented by the
<code>inputs_ids</code> passed when calling <a href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2Model">Mamba2Model</a>.`,name:"vocab_size"},{anchor:"transformers.Mamba2Config.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 4096) &#x2014;
Dimensionality of the embeddings and hidden states.`,name:"hidden_size"},{anchor:"transformers.Mamba2Config.state_size",description:"<strong>state_size</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014; shape of the state space latents.",name:"state_size"},{anchor:"transformers.Mamba2Config.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 64) &#x2014;
Number of hidden layers in the model.`,name:"num_hidden_layers"},{anchor:"transformers.Mamba2Config.layer_norm_epsilon",description:`<strong>layer_norm_epsilon</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-05) &#x2014;
The epsilon to use in the layer normalization layers.`,name:"layer_norm_epsilon"},{anchor:"transformers.Mamba2Config.pad_token_id",description:`<strong>pad_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
Padding token id.`,name:"pad_token_id"},{anchor:"transformers.Mamba2Config.bos_token_id",description:`<strong>bos_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014;
The id of the beginning of sentence token in the vocabulary.`,name:"bos_token_id"},{anchor:"transformers.Mamba2Config.eos_token_id",description:`<strong>eos_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The id of the end of sentence token in the vocabulary.`,name:"eos_token_id"},{anchor:"transformers.Mamba2Config.expand",description:"<strong>expand</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014; Expanding factor used to determine the intermediate size.",name:"expand"},{anchor:"transformers.Mamba2Config.conv_kernel",description:"<strong>conv_kernel</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014; Size of the convolution kernel.",name:"conv_kernel"},{anchor:"transformers.Mamba2Config.n_groups",description:`<strong>n_groups</strong> (<code>int</code>, <em>optional</em>, defaults to 8) &#x2014;
Number of groups for the evolution matrices of mamba 2.`,name:"n_groups"},{anchor:"transformers.Mamba2Config.use_bias",description:`<strong>use_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to use bias in [&#x201C;in_proj&#x201D;, &#x201C;out_proj&#x201D;] of the mixer block`,name:"use_bias"},{anchor:"transformers.Mamba2Config.use_conv_bias",description:`<strong>use_conv_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to use bias in the convolution layer of the mixer block.`,name:"use_conv_bias"},{anchor:"transformers.Mamba2Config.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;silu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the decoder.`,name:"hidden_act"},{anchor:"transformers.Mamba2Config.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.Mamba2Config.residual_in_fp32",description:`<strong>residual_in_fp32</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not residuals should be in <code>float32</code>. If set to <code>False</code> residuals will keep the same <code>dtype</code> as the rest of the model`,name:"residual_in_fp32"},{anchor:"transformers.Mamba2Config.time_step_rank",description:`<strong>time_step_rank</strong> (<code>Union[int,str]</code>, <em>optional</em>, defaults to <code>&quot;auto&quot;</code>) &#x2014;
Rank of the discretization projection matrix. <code>&quot;auto&quot;</code> means that it will default to <code>math.ceil(self.hidden_size / 16)</code>`,name:"time_step_rank"},{anchor:"transformers.Mamba2Config.time_step_min",description:`<strong>time_step_min</strong> (<code>float</code>, <em>optional</em>, defaults to 0.001) &#x2014;
Minimum <code>time_step</code> used to bound <code>dt_proj.bias</code>.`,name:"time_step_min"},{anchor:"transformers.Mamba2Config.time_step_max",description:`<strong>time_step_max</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
Maximum <code>time_step</code> used to bound <code>dt_proj.bias</code>.`,name:"time_step_max"},{anchor:"transformers.Mamba2Config.time_step_floor",description:`<strong>time_step_floor</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0001) &#x2014;
Minimum clamping value of the <code>dt_proj.bias</code> layer initialization.`,name:"time_step_floor"},{anchor:"transformers.Mamba2Config.time_step_limit",description:`<strong>time_step_limit</strong> (<code>tuple</code>, <em>optional</em>, defaults to <code>(0.0, inf)</code>) &#x2014;
Accepted range of time step values.`,name:"time_step_limit"},{anchor:"transformers.Mamba2Config.rescale_prenorm_residual",description:`<strong>rescale_prenorm_residual</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether or not to rescale <code>out_proj</code> weights when initializing.`,name:"rescale_prenorm_residual"},{anchor:"transformers.Mamba2Config.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not the cache should be used.`,name:"use_cache"},{anchor:"transformers.Mamba2Config.rms_norm",description:`<strong>rms_norm</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to use RMS norm or not.`,name:"rms_norm"},{anchor:"transformers.Mamba2Config.chunk_size",description:`<strong>chunk_size</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
Size of the chunks that will comprise the sequence.`,name:"chunk_size"},{anchor:"transformers.Mamba2Config.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to tie word embeddings or not.`,name:"tie_word_embeddings"}],source:"https://github.com/huggingface/transformers/blob/vr_22105/src/transformers/models/mamba2/configuration_mamba2.py#L26"}}),Z=new ht({props:{anchor:"transformers.Mamba2Config.example",$$slots:{default:[Lt]},$$scope:{ctx:$}}}),oe=new ce({props:{title:"Mamba2Model",local:"transformers.Mamba2Model",headingTag:"h2"}}),ae=new we({props:{name:"class transformers.Mamba2Model",anchor:"transformers.Mamba2Model",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.Mamba2Model.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2Config">Mamba2Config</a>) &#x2014; Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/pr_22105/ko/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/vr_22105/src/transformers/models/mamba2/modeling_mamba2.py#L821"}}),ne=new we({props:{name:"forward",anchor:"transformers.Mamba2Model.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.LongTensor] = None"},{name:"cache_params",val:": typing.Optional[transformers.models.mamba2.modeling_mamba2.Mamba2Cache] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"},{name:"cache_position",val:": typing.Optional[torch.LongTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.Mamba2Model.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, input_ids_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>If <code>cache_params.seqlen_offset&gt;0</code>, only <code>input_ids</code> that do not have their past calculated should be passed as
<code>input_ids</code>.</p>
<p>Indices can be obtained using <a href="/docs/transformers/pr_22105/ko/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_22105/ko/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/pr_22105/ko/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.Mamba2Model.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.Mamba2Model.forward.cache_params",description:`<strong>cache_params</strong> (<code>Mamba2Cache</code>, <em>optional</em>) &#x2014;
If passed along, the model uses the previous state in all the blocks (which will give the output for the
<code>input_ids</code> provided as if the model add <code>state_input_ids + input_ids</code> as context).`,name:"cache_params"},{anchor:"transformers.Mamba2Model.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, the <code>cache_params</code> is returned and can be used to quickly generate the next logits.`,name:"use_cache"},{anchor:"transformers.Mamba2Model.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.Mamba2Model.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/pr_22105/ko/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.Mamba2Model.forward.cache_position",description:`<strong>cache_position</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
The position of the current input in the cache. This is used to ensure that the cache is correctly updated.
If <code>cache_params</code> is passed, <code>cache_position</code> should also be passed.`,name:"cache_position"},{anchor:"transformers.Mamba2Model.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"}],source:"https://github.com/huggingface/transformers/blob/vr_22105/src/transformers/models/mamba2/modeling_mamba2.py#L850",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <code>transformers.models.mamba2.modeling_mamba2.Mamba2Output</code> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2Config"
>Mamba2Config</a>) and inputs.</p>
<ul>
<li>
<p><strong>last_hidden_state</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p>
</li>
<li>
<p><strong>cache_params</strong> (<code>Mamba2Cache</code>) — The state of the model at the last time step. Can be used in a forward method with the next <code>input_ids</code> to
avoid providing the old <code>input_ids</code>.</p>
<p>Includes both the State space model state matrices after the selective scan, and the Convolutional states</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
</ul>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>transformers.models.mamba2.modeling_mamba2.Mamba2Output</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),B=new Bt({props:{$$slots:{default:[Nt]},$$scope:{ctx:$}}}),F=new ht({props:{anchor:"transformers.Mamba2Model.forward.example",$$slots:{default:[Ht]},$$scope:{ctx:$}}}),se=new ce({props:{title:"Mamba2LMHeadModel",local:"transformers.Mamba2ForCausalLM",headingTag:"h2"}}),re=new we({props:{name:"class transformers.Mamba2ForCausalLM",anchor:"transformers.Mamba2ForCausalLM",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.Mamba2ForCausalLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2Config">Mamba2Config</a>) &#x2014; Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/pr_22105/ko/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/vr_22105/src/transformers/models/mamba2/modeling_mamba2.py#L937"}}),le=new we({props:{name:"forward",anchor:"transformers.Mamba2ForCausalLM.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cache_params",val:": typing.Optional[transformers.models.mamba2.modeling_mamba2.Mamba2Cache] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"cache_position",val:": typing.Optional[torch.Tensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.Mamba2ForCausalLM.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, input_ids_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary.</p>
<p>If <code>cache_params.seqlen_offset&gt;0</code>, only <code>input_ids</code> that do not have their past calculated should be passed as
<code>input_ids</code>.</p>
<p>Indices can be obtained using <a href="/docs/transformers/pr_22105/ko/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_22105/ko/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/pr_22105/ko/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p><a href="../glossary#input-ids">What are input IDs?</a>`,name:"input_ids"},{anchor:"transformers.Mamba2ForCausalLM.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>, <em>optional</em>) &#x2014;
Optionally, instead of passing <code>input_ids</code> you can choose to directly pass an embedded representation. This
is useful if you want more control over how to convert <code>input_ids</code> indices into associated vectors than the
model&#x2019;s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.Mamba2ForCausalLM.forward.cache_params",description:`<strong>cache_params</strong> (<code>Mamba2Cache</code>, <em>optional</em>) &#x2014;
If passed along, the model uses the previous state in all the blocks (which will give the output for the
<code>input_ids</code> provided as if the model add <code>state_input_ids + input_ids</code> as context).`,name:"cache_params"},{anchor:"transformers.Mamba2ForCausalLM.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, the <code>cache_params</code> is returned and can be used to quickly generate the next logits.`,name:"use_cache"},{anchor:"transformers.Mamba2ForCausalLM.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.Mamba2ForCausalLM.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/pr_22105/ko/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.Mamba2ForCausalLM.forward.cache_position",description:`<strong>cache_position</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size,)</code>, <em>optional</em>) &#x2014;
The position of the current input in the cache. This is used to ensure that the cache is correctly updated.
If <code>cache_params</code> is passed, <code>cache_position</code> should also be passed.`,name:"cache_position"},{anchor:"transformers.Mamba2ForCausalLM.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.Mamba2ForCausalLM.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for language modeling. Note that the labels <strong>are shifted</strong> inside the model, i.e. you can set
<code>labels = input_ids</code> Indices are selected in <code>[-100, 0, ..., config.vocab_size]</code> All labels set to <code>-100</code>
are ignored (masked), the loss is only computed for labels in <code>[0, ..., config.vocab_size]</code>`,name:"labels"}],source:"https://github.com/huggingface/transformers/blob/vr_22105/src/transformers/models/mamba2/modeling_mamba2.py#L1032",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <code>transformers.models.mamba2.modeling_mamba2.Mamba2CausalLMOutput</code> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/pr_22105/ko/model_doc/mamba2#transformers.Mamba2Config"
>Mamba2Config</a>) and inputs.</p>
<ul>
<li>
<p><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) — Language modeling loss (for next-token prediction).</p>
</li>
<li>
<p><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) — Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</p>
</li>
<li>
<p><strong>cache_params</strong> (<code>Mamba2Cache</code>) — The state of the model at the last time step. Can be used in a forward method with the next <code>input_ids</code> to
avoid providing the old <code>input_ids</code>.</p>
<p>Includes both the State space model state matrices after the selective scan, and the Convolutional states</p>
</li>
<li>
<p><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings, if the model has an embedding layer, +
one for the output of each layer) of shape <code>(batch_size, sequence_length, hidden_size)</code>.</p>
<p>Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.</p>
</li>
</ul>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>transformers.models.mamba2.modeling_mamba2.Mamba2CausalLMOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),R=new Bt({props:{$$slots:{default:[Gt]},$$scope:{ctx:$}}}),V=new ht({props:{anchor:"transformers.Mamba2ForCausalLM.forward.example",$$slots:{default:[qt]},$$scope:{ctx:$}}}),ie=new Xt({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/ko/model_doc/mamba2.md"}}),{c(){n=i("meta"),J=r(),m=i("p"),c=r(),u(T.$$.fragment),s=r(),u(y.$$.fragment),Ce=r(),E=i("p"),E.innerHTML=ut,Ue=r(),Q=i("p"),Q.textContent=ft,$e=r(),X=i("p"),X.innerHTML=gt,Ie=r(),L=i("p"),L.textContent=bt,xe=r(),N=i("p"),N.innerHTML=_t,je=r(),H=i("p"),H.innerHTML=Mt,ze=r(),G=i("p"),G.innerHTML=Tt,We=r(),q=i("p"),q.textContent=Jt,Ze=r(),A=i("p"),A.innerHTML=yt,Be=r(),D=i("p"),D.innerHTML=wt,Fe=r(),u(S.$$.fragment),Re=r(),u(P.$$.fragment),Ve=r(),u(Y.$$.fragment),Ee=r(),O=i("p"),O.textContent=kt,Qe=r(),u(K.$$.fragment),Xe=r(),u(ee.$$.fragment),Le=r(),v=i("div"),u(te.$$.fragment),Pe=r(),pe=i("p"),pe.innerHTML=vt,Ye=r(),he=i("p"),he.innerHTML=Ct,Oe=r(),u(Z.$$.fragment),Ne=r(),u(oe.$$.fragment),He=r(),w=i("div"),u(ae.$$.fragment),Ke=r(),ue=i("p"),ue.textContent=Ut,et=r(),fe=i("p"),fe.innerHTML=$t,tt=r(),ge=i("p"),ge.innerHTML=It,ot=r(),I=i("div"),u(ne.$$.fragment),at=r(),be=i("p"),be.innerHTML=xt,nt=r(),u(B.$$.fragment),st=r(),u(F.$$.fragment),Ge=r(),u(se.$$.fragment),qe=r(),k=i("div"),u(re.$$.fragment),rt=r(),_e=i("p"),_e.textContent=jt,lt=r(),Me=i("p"),Me.innerHTML=zt,it=r(),Te=i("p"),Te.innerHTML=Wt,dt=r(),x=i("div"),u(le.$$.fragment),mt=r(),Je=i("p"),Je.innerHTML=Zt,ct=r(),u(R.$$.fragment),pt=r(),u(V.$$.fragment),Ae=r(),u(ie.$$.fragment),De=r(),ye=i("p"),this.h()},l(e){const t=Qt("svelte-u9bgzb",document.head);n=d(t,"META",{name:!0,content:!0}),t.forEach(o),J=l(e),m=d(e,"P",{}),de(m).forEach(o),c=l(e),f(T.$$.fragment,e),s=l(e),f(y.$$.fragment,e),Ce=l(e),E=d(e,"P",{"data-svelte-h":!0}),h(E)!=="svelte-13sb336"&&(E.innerHTML=ut),Ue=l(e),Q=d(e,"P",{"data-svelte-h":!0}),h(Q)!=="svelte-un5jih"&&(Q.textContent=ft),$e=l(e),X=d(e,"P",{"data-svelte-h":!0}),h(X)!=="svelte-tmp2gx"&&(X.innerHTML=gt),Ie=l(e),L=d(e,"P",{"data-svelte-h":!0}),h(L)!=="svelte-k6v9m1"&&(L.textContent=bt),xe=l(e),N=d(e,"P",{"data-svelte-h":!0}),h(N)!=="svelte-fhnyac"&&(N.innerHTML=_t),je=l(e),H=d(e,"P",{"data-svelte-h":!0}),h(H)!=="svelte-k5mues"&&(H.innerHTML=Mt),ze=l(e),G=d(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-1cm0lmb"&&(G.innerHTML=Tt),We=l(e),q=d(e,"P",{"data-svelte-h":!0}),h(q)!=="svelte-1sogc1t"&&(q.textContent=Jt),Ze=l(e),A=d(e,"P",{"data-svelte-h":!0}),h(A)!=="svelte-c8fxzm"&&(A.innerHTML=yt),Be=l(e),D=d(e,"P",{"data-svelte-h":!0}),h(D)!=="svelte-75idyi"&&(D.innerHTML=wt),Fe=l(e),f(S.$$.fragment,e),Re=l(e),f(P.$$.fragment,e),Ve=l(e),f(Y.$$.fragment,e),Ee=l(e),O=d(e,"P",{"data-svelte-h":!0}),h(O)!=="svelte-4nej7c"&&(O.textContent=kt),Qe=l(e),f(K.$$.fragment,e),Xe=l(e),f(ee.$$.fragment,e),Le=l(e),v=d(e,"DIV",{class:!0});var j=de(v);f(te.$$.fragment,j),Pe=l(j),pe=d(j,"P",{"data-svelte-h":!0}),h(pe)!=="svelte-1f2q1ui"&&(pe.innerHTML=vt),Ye=l(j),he=d(j,"P",{"data-svelte-h":!0}),h(he)!=="svelte-3joicb"&&(he.innerHTML=Ct),Oe=l(j),f(Z.$$.fragment,j),j.forEach(o),Ne=l(e),f(oe.$$.fragment,e),He=l(e),w=d(e,"DIV",{class:!0});var C=de(w);f(ae.$$.fragment,C),Ke=l(C),ue=d(C,"P",{"data-svelte-h":!0}),h(ue)!=="svelte-1rstypp"&&(ue.textContent=Ut),et=l(C),fe=d(C,"P",{"data-svelte-h":!0}),h(fe)!=="svelte-c0a1if"&&(fe.innerHTML=$t),tt=l(C),ge=d(C,"P",{"data-svelte-h":!0}),h(ge)!=="svelte-hswkmf"&&(ge.innerHTML=It),ot=l(C),I=d(C,"DIV",{class:!0});var z=de(I);f(ne.$$.fragment,z),at=l(z),be=d(z,"P",{"data-svelte-h":!0}),h(be)!=="svelte-3mmrdo"&&(be.innerHTML=xt),nt=l(z),f(B.$$.fragment,z),st=l(z),f(F.$$.fragment,z),z.forEach(o),C.forEach(o),Ge=l(e),f(se.$$.fragment,e),qe=l(e),k=d(e,"DIV",{class:!0});var U=de(k);f(re.$$.fragment,U),rt=l(U),_e=d(U,"P",{"data-svelte-h":!0}),h(_e)!=="svelte-14gyjie"&&(_e.textContent=jt),lt=l(U),Me=d(U,"P",{"data-svelte-h":!0}),h(Me)!=="svelte-c0a1if"&&(Me.innerHTML=zt),it=l(U),Te=d(U,"P",{"data-svelte-h":!0}),h(Te)!=="svelte-hswkmf"&&(Te.innerHTML=Wt),dt=l(U),x=d(U,"DIV",{class:!0});var W=de(x);f(le.$$.fragment,W),mt=l(W),Je=d(W,"P",{"data-svelte-h":!0}),h(Je)!=="svelte-wy1620"&&(Je.innerHTML=Zt),ct=l(W),f(R.$$.fragment,W),pt=l(W),f(V.$$.fragment,W),W.forEach(o),U.forEach(o),Ae=l(e),f(ie.$$.fragment,e),De=l(e),ye=d(e,"P",{}),de(ye).forEach(o),this.h()},h(){me(n,"name","hf:doc:metadata"),me(n,"content",Dt),me(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),me(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),me(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),me(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),me(k,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){p(document.head,n),a(e,J,t),a(e,m,t),a(e,c,t),g(T,e,t),a(e,s,t),g(y,e,t),a(e,Ce,t),a(e,E,t),a(e,Ue,t),a(e,Q,t),a(e,$e,t),a(e,X,t),a(e,Ie,t),a(e,L,t),a(e,xe,t),a(e,N,t),a(e,je,t),a(e,H,t),a(e,ze,t),a(e,G,t),a(e,We,t),a(e,q,t),a(e,Ze,t),a(e,A,t),a(e,Be,t),a(e,D,t),a(e,Fe,t),g(S,e,t),a(e,Re,t),g(P,e,t),a(e,Ve,t),g(Y,e,t),a(e,Ee,t),a(e,O,t),a(e,Qe,t),g(K,e,t),a(e,Xe,t),g(ee,e,t),a(e,Le,t),a(e,v,t),g(te,v,null),p(v,Pe),p(v,pe),p(v,Ye),p(v,he),p(v,Oe),g(Z,v,null),a(e,Ne,t),g(oe,e,t),a(e,He,t),a(e,w,t),g(ae,w,null),p(w,Ke),p(w,ue),p(w,et),p(w,fe),p(w,tt),p(w,ge),p(w,ot),p(w,I),g(ne,I,null),p(I,at),p(I,be),p(I,nt),g(B,I,null),p(I,st),g(F,I,null),a(e,Ge,t),g(se,e,t),a(e,qe,t),a(e,k,t),g(re,k,null),p(k,rt),p(k,_e),p(k,lt),p(k,Me),p(k,it),p(k,Te),p(k,dt),p(k,x),g(le,x,null),p(x,mt),p(x,Je),p(x,ct),g(R,x,null),p(x,pt),g(V,x,null),a(e,Ae,t),g(ie,e,t),a(e,De,t),a(e,ye,t),Se=!0},p(e,[t]){const j={};t&2&&(j.$$scope={dirty:t,ctx:e}),Z.$set(j);const C={};t&2&&(C.$$scope={dirty:t,ctx:e}),B.$set(C);const z={};t&2&&(z.$$scope={dirty:t,ctx:e}),F.$set(z);const U={};t&2&&(U.$$scope={dirty:t,ctx:e}),R.$set(U);const W={};t&2&&(W.$$scope={dirty:t,ctx:e}),V.$set(W)},i(e){Se||(b(T.$$.fragment,e),b(y.$$.fragment,e),b(S.$$.fragment,e),b(P.$$.fragment,e),b(Y.$$.fragment,e),b(K.$$.fragment,e),b(ee.$$.fragment,e),b(te.$$.fragment,e),b(Z.$$.fragment,e),b(oe.$$.fragment,e),b(ae.$$.fragment,e),b(ne.$$.fragment,e),b(B.$$.fragment,e),b(F.$$.fragment,e),b(se.$$.fragment,e),b(re.$$.fragment,e),b(le.$$.fragment,e),b(R.$$.fragment,e),b(V.$$.fragment,e),b(ie.$$.fragment,e),Se=!0)},o(e){_(T.$$.fragment,e),_(y.$$.fragment,e),_(S.$$.fragment,e),_(P.$$.fragment,e),_(Y.$$.fragment,e),_(K.$$.fragment,e),_(ee.$$.fragment,e),_(te.$$.fragment,e),_(Z.$$.fragment,e),_(oe.$$.fragment,e),_(ae.$$.fragment,e),_(ne.$$.fragment,e),_(B.$$.fragment,e),_(F.$$.fragment,e),_(se.$$.fragment,e),_(re.$$.fragment,e),_(le.$$.fragment,e),_(R.$$.fragment,e),_(V.$$.fragment,e),_(ie.$$.fragment,e),Se=!1},d(e){e&&(o(J),o(m),o(c),o(s),o(Ce),o(E),o(Ue),o(Q),o($e),o(X),o(Ie),o(L),o(xe),o(N),o(je),o(H),o(ze),o(G),o(We),o(q),o(Ze),o(A),o(Be),o(D),o(Fe),o(Re),o(Ve),o(Ee),o(O),o(Qe),o(Xe),o(Le),o(v),o(Ne),o(He),o(w),o(Ge),o(qe),o(k),o(Ae),o(De),o(ye)),o(n),M(T,e),M(y,e),M(S,e),M(P,e),M(Y,e),M(K,e),M(ee,e),M(te),M(Z),M(oe,e),M(ae),M(ne),M(B),M(F),M(se,e),M(re),M(le),M(R),M(V),M(ie,e)}}}const Dt='{"title":"맘바2","local":"mamba-2","sections":[{"title":"개요","local":"overview","sections":[],"depth":2}],"depth":1}';function St($){return Rt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ao extends Vt{constructor(n){super(),Et(this,n,St,At,Ft,{})}}export{ao as component};
