import{s as Ze,o as Ne,n as qe}from"../chunks/scheduler.18a86fab.js";import{S as Pe,i as Ve,g as i,s as a,r as v,A as Re,h as l,f as n,c as s,j as K,u as T,x as u,k as O,y as m,a as o,v as k,d as M,t as w,w as C}from"../chunks/index.98837b22.js";import{T as Ee}from"../chunks/Tip.77304350.js";import{D as we}from"../chunks/Docstring.6758ea23.js";import{C as We}from"../chunks/CodeBlock.8d0c2e8a.js";import{E as Ge}from"../chunks/ExampleCodeBlock.0c42463f.js";import{H as pe}from"../chunks/Heading.7e7e0c5b.js";import{E as Xe}from"../chunks/index.499f366c.js";function Ae(R){let r,x=`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(){r=i("p"),r.innerHTML=x},l(c){r=l(c,"P",{"data-svelte-h":!0}),u(r)!=="svelte-fincs2"&&(r.innerHTML=x)},m(c,p){o(c,r,p)},p:qe,d(c){c&&n(r)}}}function De(R){let r,x="Example:",c,p,_;return p=new We({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(){r=i("p"),r.textContent=x,c=a(),v(p.$$.fragment)},l(d){r=l(d,"P",{"data-svelte-h":!0}),u(r)!=="svelte-11lpom8"&&(r.textContent=x),c=s(d),T(p.$$.fragment,d)},m(d,b){o(d,r,b),o(d,c,b),k(p,d,b),_=!0},p:qe,i(d){_||(M(p.$$.fragment,d),_=!0)},o(d){w(p.$$.fragment,d),_=!1},d(d){d&&(n(r),n(c)),C(p,d)}}}function Qe(R){let r,x,c,p,_,d,b,Ce='<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"/>',ee,F,te,J,Be='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.',ne,U,xe='Checkout all Bamba-9B model checkpoints <a href="https://github.com/foundation-model-stack/bamba" rel="nofollow">here</a>.',oe,j,ae,I,$e="<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>",se,f,H,ue,E,ze=`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>.`,fe,G,Le=`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.`,ge,X,Fe=`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.`,re,q,ie,W,le,h,Z,_e,A,Je="The Bamba Model for causal language modeling.",be,D,Ue=`This model inherits from <a href="/docs/transformers/main/en/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.)`,ye,Q,je=`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.`,ve,y,N,Te,S,Ie='The <a href="/docs/transformers/main/en/model_doc/bamba#transformers.BambaForCausalLM">BambaForCausalLM</a> forward method, overrides the <code>__call__</code> special method.',ke,$,Me,z,de,P,He='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>.',me,V,ce,Y,he;return _=new pe({props:{title:"Bamba",local:"bamba",headingTag:"h1"}}),F=new pe({props:{title:"Overview",local:"overview",headingTag:"h2"}}),j=new pe({props:{title:"BambaConfig",local:"transformers.BambaConfig",headingTag:"h2"}}),H=new we({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 an 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 embedding 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"}}),q=new pe({props:{title:"BambaForCausalLM",local:"transformers.BambaForCausalLM",headingTag:"h2"}}),W=new We({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}}),Z=new we({props:{name:"class transformers.BambaForCausalLM",anchor:"transformers.BambaForCausalLM",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.BambaForCausalLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/main/en/model_doc/bamba#transformers.BambaForCausalLM">BambaForCausalLM</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/main/en/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/main/src/transformers/models/bamba/modeling_bamba.py#L1306"}}),N=new we({props:{name:"forward",anchor:"transformers.BambaForCausalLM.forward",parameters:[{name:"input_ids",val:": typing.Optional[torch.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:"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>, <em>optional</em>) &#x2014;
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default.</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>`,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>~models.bamba.modeling_bamba.HybridMambaAttentionDynamicCache</code>, <em>optional</em>) &#x2014;
Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
blocks) that can be used to speed up sequential decoding. This typically consists in the <code>past_key_values</code>
returned by the model at a previous stage of decoding, when <code>use_cache=True</code> or <code>config.use_cache=True</code>.</p>
<p>Two formats are allowed:</p>
<ul>
<li>a <a href="/docs/transformers/main/en/internal/generation_utils#transformers.Cache">Cache</a> instance, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>;</li>
<li>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>). This is also known as the legacy
cache format.</li>
</ul>
<p>The model will output the same cache format that is fed as input. If no <code>past_key_values</code> are passed, the
legacy cache format will be returned.</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.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.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.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.logits_to_keep",description:`<strong>logits_to_keep</strong> (<code>Union[int, torch.Tensor]</code>, defaults to <code>0</code>) &#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#L1339",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>Cache</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) — It is a <a
  href="/docs/transformers/main/en/internal/generation_utils#transformers.Cache"
>Cache</a> instance. For more details, see our <a
  href="https://huggingface.co/docs/transformers/en/kv_cache"
  rel="nofollow"
>kv cache guide</a>.</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>
`}}),$=new Ee({props:{$$slots:{default:[Ae]},$$scope:{ctx:R}}}),z=new Ge({props:{anchor:"transformers.BambaForCausalLM.forward.example",$$slots:{default:[De]},$$scope:{ctx:R}}}),V=new Xe({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/bamba.md"}}),{c(){r=i("meta"),x=a(),c=i("p"),p=a(),v(_.$$.fragment),d=a(),b=i("div"),b.innerHTML=Ce,ee=a(),v(F.$$.fragment),te=a(),J=i("p"),J.innerHTML=Be,ne=a(),U=i("p"),U.innerHTML=xe,oe=a(),v(j.$$.fragment),ae=a(),I=i("table"),I.innerHTML=$e,se=a(),f=i("div"),v(H.$$.fragment),ue=a(),E=i("p"),E.innerHTML=ze,fe=a(),G=i("p"),G.innerHTML=Le,ge=a(),X=i("p"),X.innerHTML=Fe,re=a(),v(q.$$.fragment),ie=a(),v(W.$$.fragment),le=a(),h=i("div"),v(Z.$$.fragment),_e=a(),A=i("p"),A.textContent=Je,be=a(),D=i("p"),D.innerHTML=Ue,ye=a(),Q=i("p"),Q.innerHTML=je,ve=a(),y=i("div"),v(N.$$.fragment),Te=a(),S=i("p"),S.innerHTML=Ie,ke=a(),v($.$$.fragment),Me=a(),v(z.$$.fragment),de=a(),P=i("p"),P.innerHTML=He,me=a(),v(V.$$.fragment),ce=a(),Y=i("p"),this.h()},l(e){const t=Re("svelte-u9bgzb",document.head);r=l(t,"META",{name:!0,content:!0}),t.forEach(n),x=s(e),c=l(e,"P",{}),K(c).forEach(n),p=s(e),T(_.$$.fragment,e),d=s(e),b=l(e,"DIV",{class:!0,"data-svelte-h":!0}),u(b)!=="svelte-b95w5j"&&(b.innerHTML=Ce),ee=s(e),T(F.$$.fragment,e),te=s(e),J=l(e,"P",{"data-svelte-h":!0}),u(J)!=="svelte-1y13t4e"&&(J.innerHTML=Be),ne=s(e),U=l(e,"P",{"data-svelte-h":!0}),u(U)!=="svelte-1ego9ix"&&(U.innerHTML=xe),oe=s(e),T(j.$$.fragment,e),ae=s(e),I=l(e,"TABLE",{"data-svelte-h":!0}),u(I)!=="svelte-1rch88z"&&(I.innerHTML=$e),se=s(e),f=l(e,"DIV",{class:!0});var B=K(f);T(H.$$.fragment,B),ue=s(B),E=l(B,"P",{"data-svelte-h":!0}),u(E)!=="svelte-sna0j2"&&(E.innerHTML=ze),fe=s(B),G=l(B,"P",{"data-svelte-h":!0}),u(G)!=="svelte-5k5of"&&(G.innerHTML=Le),ge=s(B),X=l(B,"P",{"data-svelte-h":!0}),u(X)!=="svelte-o55m63"&&(X.innerHTML=Fe),B.forEach(n),re=s(e),T(q.$$.fragment,e),ie=s(e),T(W.$$.fragment,e),le=s(e),h=l(e,"DIV",{class:!0});var g=K(h);T(Z.$$.fragment,g),_e=s(g),A=l(g,"P",{"data-svelte-h":!0}),u(A)!=="svelte-eixqf6"&&(A.textContent=Je),be=s(g),D=l(g,"P",{"data-svelte-h":!0}),u(D)!=="svelte-6pahdo"&&(D.innerHTML=Ue),ye=s(g),Q=l(g,"P",{"data-svelte-h":!0}),u(Q)!=="svelte-hswkmf"&&(Q.innerHTML=je),ve=s(g),y=l(g,"DIV",{class:!0});var L=K(y);T(N.$$.fragment,L),Te=s(L),S=l(L,"P",{"data-svelte-h":!0}),u(S)!=="svelte-lvhhjq"&&(S.innerHTML=Ie),ke=s(L),T($.$$.fragment,L),Me=s(L),T(z.$$.fragment,L),L.forEach(n),g.forEach(n),de=s(e),P=l(e,"P",{"data-svelte-h":!0}),u(P)!=="svelte-14g2lxt"&&(P.innerHTML=He),me=s(e),T(V.$$.fragment,e),ce=s(e),Y=l(e,"P",{}),K(Y).forEach(n),this.h()},h(){O(r,"name","hf:doc:metadata"),O(r,"content",Se),O(b,"class","flex flex-wrap space-x-1"),O(f,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),O(h,"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){m(document.head,r),o(e,x,t),o(e,c,t),o(e,p,t),k(_,e,t),o(e,d,t),o(e,b,t),o(e,ee,t),k(F,e,t),o(e,te,t),o(e,J,t),o(e,ne,t),o(e,U,t),o(e,oe,t),k(j,e,t),o(e,ae,t),o(e,I,t),o(e,se,t),o(e,f,t),k(H,f,null),m(f,ue),m(f,E),m(f,fe),m(f,G),m(f,ge),m(f,X),o(e,re,t),k(q,e,t),o(e,ie,t),k(W,e,t),o(e,le,t),o(e,h,t),k(Z,h,null),m(h,_e),m(h,A),m(h,be),m(h,D),m(h,ye),m(h,Q),m(h,ve),m(h,y),k(N,y,null),m(y,Te),m(y,S),m(y,ke),k($,y,null),m(y,Me),k(z,y,null),o(e,de,t),o(e,P,t),o(e,me,t),k(V,e,t),o(e,ce,t),o(e,Y,t),he=!0},p(e,[t]){const B={};t&2&&(B.$$scope={dirty:t,ctx:e}),$.$set(B);const g={};t&2&&(g.$$scope={dirty:t,ctx:e}),z.$set(g)},i(e){he||(M(_.$$.fragment,e),M(F.$$.fragment,e),M(j.$$.fragment,e),M(H.$$.fragment,e),M(q.$$.fragment,e),M(W.$$.fragment,e),M(Z.$$.fragment,e),M(N.$$.fragment,e),M($.$$.fragment,e),M(z.$$.fragment,e),M(V.$$.fragment,e),he=!0)},o(e){w(_.$$.fragment,e),w(F.$$.fragment,e),w(j.$$.fragment,e),w(H.$$.fragment,e),w(q.$$.fragment,e),w(W.$$.fragment,e),w(Z.$$.fragment,e),w(N.$$.fragment,e),w($.$$.fragment,e),w(z.$$.fragment,e),w(V.$$.fragment,e),he=!1},d(e){e&&(n(x),n(c),n(p),n(d),n(b),n(ee),n(te),n(J),n(ne),n(U),n(oe),n(ae),n(I),n(se),n(f),n(re),n(ie),n(le),n(h),n(de),n(P),n(me),n(ce),n(Y)),n(r),C(_,e),C(F,e),C(j,e),C(H),C(q,e),C(W,e),C(Z),C(N),C($),C(z),C(V,e)}}}const Se='{"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 Oe(R){return Ne(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class rt extends Pe{constructor(r){super(),Ve(this,r,Oe,Qe,Ze,{})}}export{rt as component};
