import{s as Fe,o as Le,n as $e}from"../chunks/scheduler.01eeda35.js";import{S as Je,i as je,g as d,s,r as _,A as Ue,h as l,f as n,c as r,j as S,u as b,x as w,k as D,y as u,a as o,v as y,d as v,t as T,w as k}from"../chunks/index.6dd51b66.js";import{T as Ie}from"../chunks/Tip.de9bae2b.js";import{D as be}from"../chunks/Docstring.76e6b3cf.js";import{C as ze}from"../chunks/CodeBlock.864da1b0.js";import{E as He}from"../chunks/ExampleCodeBlock.6a36fb6b.js";import{H as me,E as qe}from"../chunks/EditOnGithub.7faefd25.js";function We(R){let a,C=`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(){a=d("p"),a.innerHTML=C},l(m){a=l(m,"P",{"data-svelte-h":!0}),w(a)!=="svelte-fincs2"&&(a.innerHTML=C)},m(m,c){o(m,a,c)},p:$e,d(m){m&&n(a)}}}function Ne(R){let a,C="Example:",m,c,h;return c=new ze({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBCYW1iYUZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBCYW1iYUZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMjIuLi4lMjIpJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIyLi4uJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkhleSUyQyUyMGFyZSUyMHlvdSUyMGNvbnNjaW91cyUzRiUyMENhbiUyMHlvdSUyMHRhbGslMjB0byUyMG1lJTNGJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHByb21wdCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTBBJTIzJTIwR2VuZXJhdGUlMEFnZW5lcmF0ZV9pZHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZShpbnB1dHMuaW5wdXRfaWRzJTJDJTIwbWF4X2xlbmd0aCUzRDMwKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUoZ2VuZXJhdGVfaWRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUlMkMlMjBjbGVhbl91cF90b2tlbml6YXRpb25fc3BhY2VzJTNERmFsc2UpJTVCMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, BambaForCausalLM

<span class="hljs-meta">&gt;&gt;&gt; </span>model = BambaForCausalLM.from_pretrained(<span class="hljs-string">&quot;...&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;...&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;Hey, are you conscious? Can you talk to me?&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Generate</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generate_ids = model.generate(inputs.input_ids, max_length=<span class="hljs-number">30</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(generate_ids, skip_special_tokens=<span class="hljs-literal">True</span>, clean_up_tokenization_spaces=<span class="hljs-literal">False</span>)[<span class="hljs-number">0</span>]
<span class="hljs-string">&quot;Hey, are you conscious? Can you talk to me?\\nI&#x27;m not conscious, but I can talk to you.&quot;</span>`,wrap:!1}}),{c(){a=d("p"),a.textContent=C,m=s(),_(c.$$.fragment)},l(i){a=l(i,"P",{"data-svelte-h":!0}),w(a)!=="svelte-11lpom8"&&(a.textContent=C),m=r(i),b(c.$$.fragment,i)},m(i,f){o(i,a,f),o(i,m,f),y(c,i,f),h=!0},p:$e,i(i){h||(v(c.$$.fragment,i),h=!0)},o(i){T(c.$$.fragment,i),h=!1},d(i){i&&(n(a),n(m)),k(c,i)}}}function Ze(R){let a,C,m,c,h,i,f,ye='<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&amp;logo=pytorch&amp;logoColor=white"/> <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"/> <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&amp;logo=pytorch&amp;logoColor=white"/>',O,F,Y,L,ve='Bamba-9B is a decoder-only language model based on the <a href="https://github.com/state-spaces/mamba" rel="nofollow">Mamba-2</a> architecture and is designed to handle a wide range of text generation tasks. It is trained from scratch using a two-stage training approach. In the first stage, the model is trained on 2 trillion tokens from the Dolma v1.7 dataset. In the second stage, it undergoes additional training on 200 billion tokens, leveraging a carefully curated blend of high-quality data to further refine its performance and enhance output quality.',K,J,Te='Checkout all Bamba-9B model checkpoints <a href="https://github.com/foundation-model-stack/bamba" rel="nofollow">here</a>.',ee,j,te,U,ke="<thead><tr><th>Model</th> <th>Params</th> <th># Layers</th> <th>Hidden Dim.</th> <th>Attention Heads</th> <th>GQA</th> <th>KV Heads</th> <th>Context Length</th> <th>Tied Embeddings</th></tr></thead> <tbody><tr><td>Bamba</td> <td>9B (9.78B)</td> <td>32</td> <td>4096</td> <td>32</td> <td>Yes</td> <td>8</td> <td>4096</td> <td>True</td></tr></tbody>",ne,p,I,ce,P,Me=`This is the configuration class to store the configuration of a <a href="/docs/transformers/main/en/model_doc/bamba#transformers.BambaModel">BambaModel</a>. It is used to instantiate a
BambaModel model according to the specified arguments, defining the model architecture. Instantiating a configuration
with defaults taken from <a href="https://huggingface.co/ibm-fms/Bamba-9.8b-2.2T-hf" rel="nofollow">ibm-fms/Bamba-9.8b-2.2T-hf</a>.`,pe,E,we=`The BambaModel is a hybrid <a href="https://github.com/state-spaces/mamba" rel="nofollow">mamba2</a> architecture with SwiGLU.
The checkpoints are  jointly trained by IBM, Princeton, and UIUC.`,ue,G,Ce=`Configuration objects inherit from <a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> and can be used to control the model outputs. Read the
documentation from <a href="/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig">PretrainedConfig</a> for more information.`,oe,H,ae,q,se,B,W,he,g,N,fe,X,Be='The <a href="/docs/transformers/main/en/model_doc/bamba#transformers.BambaForCausalLM">BambaForCausalLM</a> forward method, overrides the <code>__call__</code> special method.',ge,x,_e,$,re,Z,xe='This HF implementation is contributed by <a href="https://github.com/ani300" rel="nofollow">ani300</a> and <a href="https://github.com/fabianlim" rel="nofollow">fabianlim</a>.',ie,V,de,Q,le;return h=new me({props:{title:"Bamba",local:"bamba",headingTag:"h1"}}),F=new me({props:{title:"Overview",local:"overview",headingTag:"h2"}}),j=new me({props:{title:"BambaConfig",local:"transformers.BambaConfig",headingTag:"h2"}}),I=new be({props:{name:"class transformers.BambaConfig",anchor:"transformers.BambaConfig",parameters:[{name:"vocab_size",val:" = 128000"},{name:"tie_word_embeddings",val:" = False"},{name:"hidden_size",val:" = 4096"},{name:"intermediate_size",val:" = 14336"},{name:"num_hidden_layers",val:" = 32"},{name:"num_attention_heads",val:" = 32"},{name:"num_key_value_heads",val:" = 8"},{name:"hidden_act",val:" = 'silu'"},{name:"initializer_range",val:" = 0.02"},{name:"rms_norm_eps",val:" = 1e-05"},{name:"use_cache",val:" = True"},{name:"num_logits_to_keep",val:" = 1"},{name:"pad_token_id",val:" = 0"},{name:"bos_token_id",val:" = 1"},{name:"eos_token_id",val:" = 2"},{name:"max_position_embeddings",val:" = 262144"},{name:"attention_dropout",val:" = 0.0"},{name:"attn_layer_indices",val:" = None"},{name:"mamba_n_heads",val:" = 128"},{name:"mamba_d_head",val:" = 'auto'"},{name:"mamba_n_groups",val:" = 1"},{name:"mamba_d_state",val:" = 256"},{name:"mamba_d_conv",val:" = 4"},{name:"mamba_expand",val:" = 2"},{name:"mamba_chunk_size",val:" = 256"},{name:"mamba_conv_bias",val:" = True"},{name:"mamba_proj_bias",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.BambaConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 128000) &#x2014;
Vocabulary size of the Bamba model. Defines the number of different tokens that can be represented by the
<code>inputs_ids</code> passed when calling <a href="/docs/transformers/main/en/model_doc/bamba#transformers.BambaModel">BambaModel</a>`,name:"vocab_size"},{anchor:"transformers.BambaConfig.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether the model&#x2019;s input and output word embeddings should be tied. Note that this is only relevant if the
model has a output word embedding layer.`,name:"tie_word_embeddings"},{anchor:"transformers.BambaConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to 4096) &#x2014;
Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.BambaConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to 14336) &#x2014;
Dimension of the MLP representations.`,name:"intermediate_size"},{anchor:"transformers.BambaConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 32) &#x2014;
Number of hidden layers in the Transformer encoder.`,name:"num_hidden_layers"},{anchor:"transformers.BambaConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 32) &#x2014;
Number of attention heads for each attention layer in the Transformer encoder.`,name:"num_attention_heads"},{anchor:"transformers.BambaConfig.num_key_value_heads",description:`<strong>num_key_value_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 8) &#x2014;
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
<code>num_key_value_heads=num_attention_heads</code>, the model will use Multi Head Attention (MHA), if
<code>num_key_value_heads=1</code> the model will use Multi Query Attention (MQA) otherwise GQA is used. When
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
by meanpooling all the original heads within that group. For more details checkout <a href="https://arxiv.org/pdf/2305.13245.pdf" rel="nofollow">this
paper</a>. If it is not specified, will default to <code>8</code>.`,name:"num_key_value_heads"},{anchor:"transformers.BambaConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code> or <code>function</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.BambaConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.BambaConfig.rms_norm_eps",description:`<strong>rms_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-05) &#x2014;
The epsilon used by the rms normalization layers.`,name:"rms_norm_eps"},{anchor:"transformers.BambaConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not the model should return the last key/values attentions (not used by all models). Only
relevant if <code>config.is_decoder=True</code>.`,name:"use_cache"},{anchor:"transformers.BambaConfig.num_logits_to_keep",description:`<strong>num_logits_to_keep</strong> (<code>int</code> or <code>None</code>, <em>optional</em>, defaults to 1) &#x2014;
Number of prompt logits to calculate during generation. If <code>None</code>, all logits will be calculated. If an
integer value, only last <code>num_logits_to_keep</code> logits will be calculated. Default is 1 because only the
logits of the last prompt token are needed for generation. For long sequences, the logits for the entire
sequence may use a lot of memory so, setting <code>num_logits_to_keep=1</code> will reduce memory footprint
significantly.`,name:"num_logits_to_keep"},{anchor:"transformers.BambaConfig.pad_token_id",description:`<strong>pad_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to 0) &#x2014;
The id of the padding token.`,name:"pad_token_id"},{anchor:"transformers.BambaConfig.bos_token_id",description:`<strong>bos_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The id of the &#x201C;beginning-of-sequence&#x201D; token.`,name:"bos_token_id"},{anchor:"transformers.BambaConfig.eos_token_id",description:`<strong>eos_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
The id of the &#x201C;end-of-sequence&#x201D; token.`,name:"eos_token_id"},{anchor:"transformers.BambaConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to 262144) &#x2014;
Max cached sequence length for the model`,name:"max_position_embeddings"},{anchor:"transformers.BambaConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.BambaConfig.attn_layer_indices",description:`<strong>attn_layer_indices</strong> (<code>list</code>, <em>optional</em>) &#x2014;
Specifies the layer indices that will have full attention. Must contain values at most num_hidden_layers.`,name:"attn_layer_indices"},{anchor:"transformers.BambaConfig.mamba_n_heads",description:`<strong>mamba_n_heads</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
The number of mamba heads used in the v2 implementation.`,name:"mamba_n_heads"},{anchor:"transformers.BambaConfig.mamba_d_head",description:`<strong>mamba_d_head</strong> (<code>int</code>, <em>optional</em>, defaults to <code>&quot;auto&quot;</code>) &#x2014;
Head embeddding dimension size`,name:"mamba_d_head"},{anchor:"transformers.BambaConfig.mamba_n_groups",description:`<strong>mamba_n_groups</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of the mamba groups used in the v2 implementation.`,name:"mamba_n_groups"},{anchor:"transformers.BambaConfig.mamba_d_state",description:`<strong>mamba_d_state</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The dimension the mamba state space latents`,name:"mamba_d_state"},{anchor:"transformers.BambaConfig.mamba_d_conv",description:`<strong>mamba_d_conv</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
The size of the mamba convolution kernel`,name:"mamba_d_conv"},{anchor:"transformers.BambaConfig.mamba_expand",description:`<strong>mamba_expand</strong> (<code>int</code>, <em>optional</em>, defaults to 2) &#x2014;
Expanding factor (relative to hidden_size) used to determine the mamba intermediate size`,name:"mamba_expand"},{anchor:"transformers.BambaConfig.mamba_chunk_size",description:`<strong>mamba_chunk_size</strong> (<code>int</code>, <em>optional</em>, defaults to 256) &#x2014;
The chunks in which to break the sequence when doing prefill/training`,name:"mamba_chunk_size"},{anchor:"transformers.BambaConfig.mamba_conv_bias",description:`<strong>mamba_conv_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Flag indicating whether or not to use bias in the convolution layer of the mamba mixer block.`,name:"mamba_conv_bias"},{anchor:"transformers.BambaConfig.mamba_proj_bias",description:`<strong>mamba_proj_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Flag indicating whether or not to use bias in the input and output projections ([&#x201C;in_proj&#x201D;, &#x201C;out_proj&#x201D;]) of the mamba mixer block`,name:"mamba_proj_bias"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/bamba/configuration_bamba.py#L24"}}),H=new me({props:{title:"BambaForCausalLM",local:"transformers.BambaForCausalLM",headingTag:"h2"}}),q=new ze({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMmlibS1mbXMlMkZCYW1iYS05QiUyMiklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJpYm0tZm1zJTJGQmFtYmEtOUIlMjIpJTBBJTBBbWVzc2FnZSUyMCUzRCUyMCU1QiUyMk1hbWJhJTIwaXMlMjBhJTIwc25ha2UlMjB3aXRoJTIwZm9sbG93aW5nJTIwcHJvcGVydGllcyUyMCUyMCUyMiU1RCUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihtZXNzYWdlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QncHQnJTJDJTIwcmV0dXJuX3Rva2VuX3R5cGVfaWRzJTNERmFsc2UpJTBBcmVzcG9uc2UlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyUyQyUyMG1heF9uZXdfdG9rZW5zJTNENjQpJTBBcHJpbnQodG9rZW5pemVyLmJhdGNoX2RlY29kZShyZXNwb25zZSUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;ibm-fms/Bamba-9B&quot;</span>)
tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;ibm-fms/Bamba-9B&quot;</span>)

message = [<span class="hljs-string">&quot;Mamba is a snake with following properties  &quot;</span>]
inputs = tokenizer(message, return_tensors=<span class="hljs-string">&#x27;pt&#x27;</span>, return_token_type_ids=<span class="hljs-literal">False</span>)
response = model.generate(**inputs, max_new_tokens=<span class="hljs-number">64</span>)
<span class="hljs-built_in">print</span>(tokenizer.batch_decode(response, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>])`,wrap:!1}}),W=new be({props:{name:"class transformers.BambaForCausalLM",anchor:"transformers.BambaForCausalLM",parameters:[{name:"config",val:""}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/bamba/modeling_bamba.py#L1445"}}),N=new be({props:{name:"forward",anchor:"transformers.BambaForCausalLM.forward",parameters:[{name:"input_ids",val:": LongTensor = None"},{name:"attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"position_ids",val:": typing.Optional[torch.LongTensor] = None"},{name:"past_key_values",val:": typing.Optional[transformers.models.bamba.modeling_bamba.HybridMambaAttentionDynamicCache] = None"},{name:"inputs_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",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:"logits_to_keep",val:": typing.Union[int, torch.Tensor] = 0"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.BambaForCausalLM.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
it.</p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/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.BambaForCausalLM.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</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></p>
<p>Indices can be obtained using <a href="/docs/transformers/main/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and
<a href="/docs/transformers/main/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.__call__">PreTrainedTokenizer.<strong>call</strong>()</a> for details.</p>
<p>If <code>past_key_values</code> is used, optionally only the last <code>input_ids</code> have to be input (see
<code>past_key_values</code>).</p>
<p>If you want to change padding behavior, you should read <code>modeling_opt._prepare_decoder_attention_mask</code>
and modify to your needs. See diagram 1 in <a href="https://arxiv.org/abs/1910.13461" rel="nofollow">the paper</a> for more
information on the default strategy.</p>
<ul>
<li>1 indicates the head is <strong>not masked</strong>,</li>
<li>0 indicates the head is <strong>masked</strong>.</li>
</ul>`,name:"attention_mask"},{anchor:"transformers.BambaForCausalLM.forward.position_ids",description:`<strong>position_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Indices of positions of each input sequence tokens in the position embeddings. Selected in the range <code>[0, config.n_positions - 1]</code>.</p>
<p><a href="../glossary#position-ids">What are position IDs?</a>`,name:"position_ids"},{anchor:"transformers.BambaForCausalLM.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>HybridMambaAttentionDynamicCache</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) &#x2014;
A HybridMambaAttentionDynamicCache object containing pre-computed hidden-states (keys and values in the
self-attention blocks and convolution and ssm states in the mamba blocks) that can be used (see
<code>past_key_values</code> input) to speed up sequential decoding.
Key and value cache tensors have shape <code>(batch_size, num_heads, seq_len, head_dim)</code>.
Convolution and ssm states tensors have shape <code>(batch_size, d_inner, d_conv)</code> and
<code>(batch_size, d_inner, d_state)</code> respectively.
See the <code>HybridMambaAttentionDynamicCache</code> class for more details.</p>
<p>If <code>past_key_values</code> are used, the user can optionally input only the last <code>input_ids</code> (those that
don&#x2019;t have their past key value states given to this model) of shape <code>(batch_size, 1)</code> instead of all
<code>input_ids</code> of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.BambaForCausalLM.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.BambaForCausalLM.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.BambaForCausalLM.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.BambaForCausalLM.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.BambaForCausalLM.forward.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
should not be returned during inference.`,name:"output_router_logits"},{anchor:"transformers.BambaForCausalLM.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/main/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"},{anchor:"transformers.BambaForCausalLM.forward.cache_position",description:`<strong>cache_position</strong> (<code>torch.LongTensor</code> of shape <code>(sequence_length)</code>, <em>optional</em>) &#x2014;
Indices depicting the position of the input sequence tokens in the sequence. Contrarily to <code>position_ids</code>,
this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
the complete sequence length.`,name:"cache_position"},{anchor:"transformers.BambaForCausalLM.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Labels for computing the masked language modeling loss. Indices should either be in <code>[0, ..., config.vocab_size]</code> or -100 (see <code>input_ids</code> docstring). Tokens with indices set to <code>-100</code> are ignored
(masked), the loss is only computed for the tokens with labels in <code>[0, ..., config.vocab_size]</code>.`,name:"labels"},{anchor:"transformers.BambaForCausalLM.forward.logits_to_keep",description:`<strong>logits_to_keep</strong> (<code>int</code> or <code>torch.Tensor</code>, <em>optional</em>) &#x2014;
If an <code>int</code>, compute logits for the last <code>logits_to_keep</code> tokens. If <code>0</code>, calculate logits for all
<code>input_ids</code> (special case). Only last token logits are needed for generation, and calculating them only for that
token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
If a <code>torch.Tensor</code>, must be 1D corresponding to the indices to keep in the sequence length dimension.
This is useful when using packed tensor format (single dimension for batch and sequence length).`,name:"logits_to_keep"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/bamba/modeling_bamba.py#L1477",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.CausalLMOutputWithPast"
>transformers.modeling_outputs.CausalLMOutputWithPast</a> 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/main/en/model_doc/bamba#transformers.BambaConfig"
>BambaConfig</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>past_key_values</strong> (<code>tuple(tuple(torch.FloatTensor))</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) — Tuple of <code>tuple(torch.FloatTensor)</code> of length <code>config.n_layers</code>, with each tuple having 2 tensors of shape
<code>(batch_size, num_heads, sequence_length, embed_size_per_head)</code>)</p>
<p>Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
<code>past_key_values</code> input) to speed up sequential decoding.</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>
<li>
<p><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>.</p>
<p>Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
heads.</p>
</li>
</ul>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><a
  href="/docs/transformers/main/en/main_classes/output#transformers.modeling_outputs.CausalLMOutputWithPast"
>transformers.modeling_outputs.CausalLMOutputWithPast</a> or <code>tuple(torch.FloatTensor)</code></p>
`}}),x=new Ie({props:{$$slots:{default:[We]},$$scope:{ctx:R}}}),$=new He({props:{anchor:"transformers.BambaForCausalLM.forward.example",$$slots:{default:[Ne]},$$scope:{ctx:R}}}),V=new qe({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/bamba.md"}}),{c(){a=d("meta"),C=s(),m=d("p"),c=s(),_(h.$$.fragment),i=s(),f=d("div"),f.innerHTML=ye,O=s(),_(F.$$.fragment),Y=s(),L=d("p"),L.innerHTML=ve,K=s(),J=d("p"),J.innerHTML=Te,ee=s(),_(j.$$.fragment),te=s(),U=d("table"),U.innerHTML=ke,ne=s(),p=d("div"),_(I.$$.fragment),ce=s(),P=d("p"),P.innerHTML=Me,pe=s(),E=d("p"),E.innerHTML=we,ue=s(),G=d("p"),G.innerHTML=Ce,oe=s(),_(H.$$.fragment),ae=s(),_(q.$$.fragment),se=s(),B=d("div"),_(W.$$.fragment),he=s(),g=d("div"),_(N.$$.fragment),fe=s(),X=d("p"),X.innerHTML=Be,ge=s(),_(x.$$.fragment),_e=s(),_($.$$.fragment),re=s(),Z=d("p"),Z.innerHTML=xe,ie=s(),_(V.$$.fragment),de=s(),Q=d("p"),this.h()},l(e){const t=Ue("svelte-u9bgzb",document.head);a=l(t,"META",{name:!0,content:!0}),t.forEach(n),C=r(e),m=l(e,"P",{}),S(m).forEach(n),c=r(e),b(h.$$.fragment,e),i=r(e),f=l(e,"DIV",{class:!0,"data-svelte-h":!0}),w(f)!=="svelte-b95w5j"&&(f.innerHTML=ye),O=r(e),b(F.$$.fragment,e),Y=r(e),L=l(e,"P",{"data-svelte-h":!0}),w(L)!=="svelte-1y13t4e"&&(L.innerHTML=ve),K=r(e),J=l(e,"P",{"data-svelte-h":!0}),w(J)!=="svelte-1ego9ix"&&(J.innerHTML=Te),ee=r(e),b(j.$$.fragment,e),te=r(e),U=l(e,"TABLE",{"data-svelte-h":!0}),w(U)!=="svelte-1rch88z"&&(U.innerHTML=ke),ne=r(e),p=l(e,"DIV",{class:!0});var M=S(p);b(I.$$.fragment,M),ce=r(M),P=l(M,"P",{"data-svelte-h":!0}),w(P)!=="svelte-sna0j2"&&(P.innerHTML=Me),pe=r(M),E=l(M,"P",{"data-svelte-h":!0}),w(E)!=="svelte-5k5of"&&(E.innerHTML=we),ue=r(M),G=l(M,"P",{"data-svelte-h":!0}),w(G)!=="svelte-o55m63"&&(G.innerHTML=Ce),M.forEach(n),oe=r(e),b(H.$$.fragment,e),ae=r(e),b(q.$$.fragment,e),se=r(e),B=l(e,"DIV",{class:!0});var A=S(B);b(W.$$.fragment,A),he=r(A),g=l(A,"DIV",{class:!0});var z=S(g);b(N.$$.fragment,z),fe=r(z),X=l(z,"P",{"data-svelte-h":!0}),w(X)!=="svelte-lvhhjq"&&(X.innerHTML=Be),ge=r(z),b(x.$$.fragment,z),_e=r(z),b($.$$.fragment,z),z.forEach(n),A.forEach(n),re=r(e),Z=l(e,"P",{"data-svelte-h":!0}),w(Z)!=="svelte-14g2lxt"&&(Z.innerHTML=xe),ie=r(e),b(V.$$.fragment,e),de=r(e),Q=l(e,"P",{}),S(Q).forEach(n),this.h()},h(){D(a,"name","hf:doc:metadata"),D(a,"content",Ve),D(f,"class","flex flex-wrap space-x-1"),D(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),D(g,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),D(B,"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){u(document.head,a),o(e,C,t),o(e,m,t),o(e,c,t),y(h,e,t),o(e,i,t),o(e,f,t),o(e,O,t),y(F,e,t),o(e,Y,t),o(e,L,t),o(e,K,t),o(e,J,t),o(e,ee,t),y(j,e,t),o(e,te,t),o(e,U,t),o(e,ne,t),o(e,p,t),y(I,p,null),u(p,ce),u(p,P),u(p,pe),u(p,E),u(p,ue),u(p,G),o(e,oe,t),y(H,e,t),o(e,ae,t),y(q,e,t),o(e,se,t),o(e,B,t),y(W,B,null),u(B,he),u(B,g),y(N,g,null),u(g,fe),u(g,X),u(g,ge),y(x,g,null),u(g,_e),y($,g,null),o(e,re,t),o(e,Z,t),o(e,ie,t),y(V,e,t),o(e,de,t),o(e,Q,t),le=!0},p(e,[t]){const M={};t&2&&(M.$$scope={dirty:t,ctx:e}),x.$set(M);const A={};t&2&&(A.$$scope={dirty:t,ctx:e}),$.$set(A)},i(e){le||(v(h.$$.fragment,e),v(F.$$.fragment,e),v(j.$$.fragment,e),v(I.$$.fragment,e),v(H.$$.fragment,e),v(q.$$.fragment,e),v(W.$$.fragment,e),v(N.$$.fragment,e),v(x.$$.fragment,e),v($.$$.fragment,e),v(V.$$.fragment,e),le=!0)},o(e){T(h.$$.fragment,e),T(F.$$.fragment,e),T(j.$$.fragment,e),T(I.$$.fragment,e),T(H.$$.fragment,e),T(q.$$.fragment,e),T(W.$$.fragment,e),T(N.$$.fragment,e),T(x.$$.fragment,e),T($.$$.fragment,e),T(V.$$.fragment,e),le=!1},d(e){e&&(n(C),n(m),n(c),n(i),n(f),n(O),n(Y),n(L),n(K),n(J),n(ee),n(te),n(U),n(ne),n(p),n(oe),n(ae),n(se),n(B),n(re),n(Z),n(ie),n(de),n(Q)),n(a),k(h,e),k(F,e),k(j,e),k(I),k(H,e),k(q,e),k(W),k(N),k(x),k($),k(V,e)}}}const Ve='{"title":"Bamba","local":"bamba","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"BambaConfig","local":"transformers.BambaConfig","sections":[],"depth":2},{"title":"BambaForCausalLM","local":"transformers.BambaForCausalLM","sections":[],"depth":2}],"depth":1}';function Ae(R){return Le(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends Je{constructor(a){super(),je(this,a,Ae,Ze,Fe,{})}}export{Se as component};
