Buckets:
| import{s as eo,o as to,n as ze}from"../chunks/scheduler.31fdf58d.js";import{S as oo,i as no,e as c,s as r,c as g,h as so,a as m,d as o,b as i,f as _e,j as h,g as _,k as P,w as ao,l as f,m as s,n as b,t as y,o as v,p as M}from"../chunks/index.2f76fdf0.js";import{T as Yt}from"../chunks/Tip.8d349121.js";import{C as ro}from"../chunks/CopyLLMTxtMenu.7f759a74.js";import{D as Fe}from"../chunks/Docstring.63c265aa.js";import{C as lt}from"../chunks/CodeBlock.e52df5d6.js";import{E as Kt}from"../chunks/ExampleCodeBlock.3b3321e8.js";import{H as N,E as io}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.75f9495b.js";import{H as lo,a as Ot}from"../chunks/HfOption.fb051768.js";function co(T){let n,u;return n=new lt({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjB0YXNrJTNEJTIydGV4dC1nZW5lcmF0aW9uJTIyJTJDJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0QlMjJhcmNlZS1haSUyRlRyaW5pdHktTWluaSUyMiUyQyUwQSUyMCUyMCUyMCUyMGRldmljZSUzRDAlMEEpJTBBJTBBb3V0cHV0JTIwJTNEJTIwcGlwZWxpbmUoJTIyVGhlJTIwa2V5JTIwaW5ub3ZhdGlvbiUyMGluJTIwbWl4dHVyZSUyMG9mJTIwZXhwZXJ0cyUyMGlzJTIyKSUwQXByaW50KG91dHB1dCU1QjAlNUQlNUIlMjJnZW5lcmF0ZWRfdGV4dCUyMiU1RCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline | |
| pipeline = pipeline( | |
| task=<span class="hljs-string">"text-generation"</span>, | |
| model=<span class="hljs-string">"arcee-ai/Trinity-Mini"</span>, | |
| device=<span class="hljs-number">0</span> | |
| ) | |
| output = pipeline(<span class="hljs-string">"The key innovation in mixture of experts is"</span>) | |
| <span class="hljs-built_in">print</span>(output[<span class="hljs-number">0</span>][<span class="hljs-string">"generated_text"</span>])`,lang:"python",wrap:!1}}),{c(){g(n.$$.fragment)},l(a){_(n.$$.fragment,a)},m(a,p){b(n,a,p),u=!0},p:ze,i(a){u||(y(n.$$.fragment,a),u=!0)},o(a){v(n.$$.fragment,a),u=!1},d(a){M(n,a)}}}function mo(T){let n,u;return n=new lt({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQWZtb2VGb3JDYXVzYWxMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMEElMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJhcmNlZS1haSUyRlRyaW5pdHktTWluaSUyMiklMEFtb2RlbCUyMCUzRCUyMEFmbW9lRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmFyY2VlLWFpJTJGVHJpbml0eS1NaW5pJTIyJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMEEpJTBBJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMlRoZSUyMGtleSUyMGlubm92YXRpb24lMjBpbiUyMG1peHR1cmUlMjBvZiUyMGV4cGVydHMlMjBpcyUyMiUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLnRvKG1vZGVsLmRldmljZSklMEF3aXRoJTIwdG9yY2gubm9fZ3JhZCgpJTNBJTBBJTIwJTIwJTIwJTIwb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRzJTJDJTIwbWF4X25ld190b2tlbnMlM0Q1MCklMEElMEFwcmludCh0b2tlbml6ZXIuZGVjb2RlKG91dHB1dHMlNUIwJTVEJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpKQ==",highlighted:`<span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AfmoeForCausalLM, AutoTokenizer | |
| tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">"arcee-ai/Trinity-Mini"</span>) | |
| model = AfmoeForCausalLM.from_pretrained( | |
| <span class="hljs-string">"arcee-ai/Trinity-Mini"</span>, | |
| device_map=<span class="hljs-string">"auto"</span> | |
| ) | |
| inputs = tokenizer(<span class="hljs-string">"The key innovation in mixture of experts is"</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device) | |
| <span class="hljs-keyword">with</span> torch.no_grad(): | |
| outputs = model.generate(**inputs, max_new_tokens=<span class="hljs-number">50</span>) | |
| <span class="hljs-built_in">print</span>(tokenizer.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>))`,lang:"python",wrap:!1}}),{c(){g(n.$$.fragment)},l(a){_(n.$$.fragment,a)},m(a,p){b(n,a,p),u=!0},p:ze,i(a){u||(y(n.$$.fragment,a),u=!0)},o(a){v(n.$$.fragment,a),u=!1},d(a){M(n,a)}}}function po(T){let n,u,a,p;return n=new Ot({props:{id:"usage",option:"Pipeline",$$slots:{default:[co]},$$scope:{ctx:T}}}),a=new Ot({props:{id:"usage",option:"AutoModel",$$slots:{default:[mo]},$$scope:{ctx:T}}}),{c(){g(n.$$.fragment),u=r(),g(a.$$.fragment)},l(d){_(n.$$.fragment,d),u=i(d),_(a.$$.fragment,d)},m(d,l){b(n,d,l),s(d,u,l),b(a,d,l),p=!0},p(d,l){const w={};l&2&&(w.$$scope={dirty:l,ctx:d}),n.$set(w);const j={};l&2&&(j.$$scope={dirty:l,ctx:d}),a.$set(j)},i(d){p||(y(n.$$.fragment,d),y(a.$$.fragment,d),p=!0)},o(d){v(n.$$.fragment,d),v(a.$$.fragment,d),p=!1},d(d){d&&o(u),M(n,d),M(a,d)}}}function uo(T){let n,u="Example:",a,p,d;return p=new lt({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEFmbW9lTW9kZWwlMkMlMjBBZm1vZUNvbmZpZyUwQSUwQSUyMyUyMEluaXRpYWxpemluZyUyMGFuJTIwQUZNb0UlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyMEFmbW9lQ29uZmlnKCklMEElMEElMjMlMjBJbml0aWFsaXppbmclMjBhJTIwbW9kZWwlMjBmcm9tJTIwdGhlJTIwYWZtb2Utc21hbGwtc2Z0LXYxJTIwc3R5bGUlMjBjb25maWd1cmF0aW9uJTBBbW9kZWwlMjAlM0QlMjBBZm1vZU1vZGVsKGNvbmZpZ3VyYXRpb24pJTBBJTBBJTIzJTIwQWNjZXNzaW5nJTIwdGhlJTIwbW9kZWwlMjBjb25maWd1cmF0aW9uJTBBY29uZmlndXJhdGlvbiUyMCUzRCUyMG1vZGVsLmNvbmZpZw==",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AfmoeModel, AfmoeConfig | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing an AFMoE configuration</span> | |
| <span class="hljs-meta">>>> </span>configuration = AfmoeConfig() | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing a model from the afmoe-small-sft-v1 style configuration</span> | |
| <span class="hljs-meta">>>> </span>model = AfmoeModel(configuration) | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Accessing the model configuration</span> | |
| <span class="hljs-meta">>>> </span>configuration = model.config`,lang:"python",wrap:!1}}),{c(){n=c("p"),n.textContent=u,a=r(),g(p.$$.fragment)},l(l){n=m(l,"P",{"data-svelte-h":!0}),h(n)!=="svelte-11lpom8"&&(n.textContent=u),a=i(l),_(p.$$.fragment,l)},m(l,w){s(l,n,w),s(l,a,w),b(p,l,w),d=!0},p:ze,i(l){d||(y(p.$$.fragment,l),d=!0)},o(l){v(p.$$.fragment,l),d=!1},d(l){l&&(o(n),o(a)),M(p,l)}}}function fo(T){let n,u=`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=c("p"),n.innerHTML=u},l(a){n=m(a,"P",{"data-svelte-h":!0}),h(n)!=="svelte-fincs2"&&(n.innerHTML=u)},m(a,p){s(a,n,p)},p:ze,d(a){a&&o(n)}}}function ho(T){let n,u=`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=c("p"),n.innerHTML=u},l(a){n=m(a,"P",{"data-svelte-h":!0}),h(n)!=="svelte-fincs2"&&(n.innerHTML=u)},m(a,p){s(a,n,p)},p:ze,d(a){a&&o(n)}}}function go(T){let n,u="Example:",a,p,d;return p=new lt({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBZm1vZUZvckNhdXNhbExNJTBBJTBBbW9kZWwlMjAlM0QlMjBBZm1vZUZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMjJtZXRhLWFmbW9lJTJGQWZtb2UtMi03Yi1oZiUyMiklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJtZXRhLWFmbW9lJTJGQWZtb2UtMi03Yi1oZiUyMiklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJIZXklMkMlMjBhcmUlMjB5b3UlMjBjb25zY2lvdXMlM0YlMjBDYW4lMjB5b3UlMjB0YWxrJTIwdG8lMjBtZSUzRiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihwcm9tcHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQSUyMyUyMEdlbmVyYXRlJTBBZ2VuZXJhdGVfaWRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoaW5wdXRzLmlucHV0X2lkcyUyQyUyMG1heF9sZW5ndGglM0QzMCklMEF0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKGdlbmVyYXRlX2lkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlJTJDJTIwY2xlYW5fdXBfdG9rZW5pemF0aW9uX3NwYWNlcyUzREZhbHNlKSU1QjAlNUQ=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AfmoeForCausalLM | |
| <span class="hljs-meta">>>> </span>model = AfmoeForCausalLM.from_pretrained(<span class="hljs-string">"meta-afmoe/Afmoe-2-7b-hf"</span>) | |
| <span class="hljs-meta">>>> </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">"meta-afmoe/Afmoe-2-7b-hf"</span>) | |
| <span class="hljs-meta">>>> </span>prompt = <span class="hljs-string">"Hey, are you conscious? Can you talk to me?"</span> | |
| <span class="hljs-meta">>>> </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">"pt"</span>) | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Generate</span> | |
| <span class="hljs-meta">>>> </span>generate_ids = model.generate(inputs.input_ids, max_length=<span class="hljs-number">30</span>) | |
| <span class="hljs-meta">>>> </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">"Hey, are you conscious? Can you talk to me?\\nI'm not conscious, but I can talk to you."</span>`,lang:"python",wrap:!1}}),{c(){n=c("p"),n.textContent=u,a=r(),g(p.$$.fragment)},l(l){n=m(l,"P",{"data-svelte-h":!0}),h(n)!=="svelte-11lpom8"&&(n.textContent=u),a=i(l),_(p.$$.fragment,l)},m(l,w){s(l,n,w),s(l,a,w),b(p,l,w),d=!0},p:ze,i(l){d||(y(p.$$.fragment,l),d=!0)},o(l){v(p.$$.fragment,l),d=!1},d(l){l&&(o(n),o(a)),M(p,l)}}}function _o(T){let n,u,a,p,d,l="<em>This model was contributed to Hugging Face Transformers on 2025-11-29.</em>",w,j,Je,W,xt='<div class="flex flex-wrap space-x-1"><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&logo=pytorch&logoColor=white"/></div>',je,G,Le,R,Ct="AFMoE (Arcee Foundational Mixture of Experts) is a decoder-only transformer model that extends the Llama architecture with a sparse Mixture of Experts (MoE) approach. The model combines token-choice routing with shared experts and employs several architectural innovations for efficient inference and improved performance.",Ne,V,We,X,At="AFMoE introduces several key modifications to the standard transformer architecture:",Ee,S,zt="<li><strong>Mixture of Experts with Shared Experts</strong>: Combines routed experts (activated per-token via learned routing) with always-active shared experts for stable base computation</li> <li><strong>Token-Choice Routing</strong>: Uses sigmoid or softmax-based routing with normalization and scaling for expert selection</li> <li><strong>Q/K Normalization and Gating</strong>: Applies RMSNorm to query and key projections and uses sigmoid gating on attention outputs for improved stability</li> <li><strong>Hybrid Attention Patterns</strong>: Alternates between sliding window attention and full attention across layers for efficiency with long contexts</li> <li><strong>Dual Normalization</strong>: Uses pre- and post-normalization around both attention and MLP blocks for training stability</li> <li><strong>Configurable Dense Layers</strong>: Allows initial layers to use dense MLPs before transitioning to sparse MoE layers</li>",Ie,Q,Ut="The model supports extended context lengths with RoPE embeddings and includes all standard Transformers features including Flash Attention 2, SDPA, gradient checkpointing, and quantization support.",Ze,E,Ft="<p>AFMoE is particularly well-suited for scenarios requiring efficient scaling through sparsity while maintaining strong performance. The shared experts provide a stable computation baseline while routed experts enable model capacity scaling.</p>",Be,D,Jt='The example below demonstrates how to generate text with AFMoE using <a href="/docs/transformers/pr_40546/en/main_classes/pipelines#transformers.Pipeline">Pipeline</a> or the <a href="/docs/transformers/pr_40546/en/model_doc/auto#transformers.AutoModel">AutoModel</a>.',qe,I,He,Y,Pe,K,Ge,O,jt="AFMoE uses token-choice routing where each token independently selects top-k experts based on router logits. The routing mechanism includes:",Re,ee,Lt="<li>Configurable scoring function (sigmoid or softmax)</li> <li>Optional route normalization for balanced expert utilization</li> <li>Route scaling to control expert contribution strength</li> <li>Bias correction for expert selection</li>",Ve,te,Xe,oe,Nt="Unlike standard MoE models, AFMoE includes shared experts that are always activated for every token, providing:",Se,ne,Wt="<li>A stable computation baseline across all tokens</li> <li>Reduced variance in model outputs</li> <li>Better handling of out-of-distribution inputs</li>",Qe,se,De,ae,Et="The hybrid attention pattern alternates between:",Ye,re,It="<li><strong>Sliding Window Attention</strong>: For efficiency on long sequences, with configurable window size</li> <li><strong>Full Attention</strong>: Applied every N layers (configurable via <code>global_attn_every_n_layers</code>) for global context</li>",Ke,ie,Zt="All attention layers include Q/K normalization and output gating for improved training dynamics.",Oe,le,et,F,de,dt,be,Bt=`AFMoE is an Adaptive Feedforward MoE (Mixture of Experts) model with token-choice routing, shared experts, and a | |
| hybrid attention mechanism combining sliding window and full attention patterns.`,ct,Z,tt,ce,ot,$,me,mt,ye,qt="The bare Afmoe Model outputting raw hidden-states without any specific head on top.",pt,ve,Ht=`This model inherits from <a href="/docs/transformers/pr_40546/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.)`,ut,Me,Pt=`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.`,ft,U,pe,ht,Te,Gt='The <a href="/docs/transformers/pr_40546/en/model_doc/afmoe#transformers.AfmoeModel">AfmoeModel</a> forward method, overrides the <code>__call__</code> special method.',gt,B,_t,we,Rt=`<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>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/pr_40546/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 and optionally if | |
| <code>config.is_encoder_decoder=True</code> in the cross-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> <li><p><strong>router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_probs=True</code> and <code>config.add_router_probs=True</code> is passed or when <code>config.output_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p> <p>Raw router logtis (post-softmax) that are computed by MoE routers, these terms are used to compute the auxiliary | |
| loss for Mixture of Experts models.</p></li>`,nt,ue,st,k,fe,bt,$e,Vt="The Afmoe Model for causal language modeling.",yt,ke,Xt=`This model inherits from <a href="/docs/transformers/pr_40546/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.)`,vt,xe,St=`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.`,Mt,x,he,Tt,Ce,Qt='The <a href="/docs/transformers/pr_40546/en/model_doc/afmoe#transformers.AfmoeForCausalLM">AfmoeForCausalLM</a> forward method, overrides the <code>__call__</code> special method.',wt,q,$t,Ae,Dt=`<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>aux_loss</strong> (<code>torch.FloatTensor</code>, <em>optional</em>, returned when <code>labels</code> is provided) — aux_loss for the sparse modules.</p></li> <li><p><strong>router_logits</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_router_probs=True</code> and <code>config.add_router_probs=True</code> is passed or when <code>config.output_router_probs=True</code>) — Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p> <p>Raw router logtis (post-softmax) that are computed by MoE routers, these terms are used to compute the auxiliary | |
| loss for Mixture of Experts models.</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/pr_40546/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>`,kt,H,at,ge,rt,Ue,it;return j=new ro({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),G=new N({props:{title:"AFMoE",local:"afmoe",headingTag:"h1"}}),V=new N({props:{title:"Key Architecture Features",local:"key-architecture-features",headingTag:"h2"}}),I=new lo({props:{id:"usage",options:["Pipeline","AutoModel"],$$slots:{default:[po]},$$scope:{ctx:T}}}),Y=new N({props:{title:"Model Architecture Details",local:"model-architecture-details",headingTag:"h2"}}),K=new N({props:{title:"Expert Routing",local:"expert-routing",headingTag:"h3"}}),te=new N({props:{title:"Shared Experts",local:"shared-experts",headingTag:"h3"}}),se=new N({props:{title:"Attention Mechanism",local:"attention-mechanism",headingTag:"h3"}}),le=new N({props:{title:"AfmoeConfig",local:"transformers.AfmoeConfig",headingTag:"h2"}}),de=new Fe({props:{name:"class transformers.AfmoeConfig",anchor:"transformers.AfmoeConfig",parameters:[{name:"transformers_version",val:": str | None = None"},{name:"architectures",val:": list[str] | None = None"},{name:"output_hidden_states",val:": bool | None = False"},{name:"return_dict",val:": bool | None = True"},{name:"dtype",val:": typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None"},{name:"chunk_size_feed_forward",val:": int = 0"},{name:"is_encoder_decoder",val:": bool = False"},{name:"id2label",val:": dict[int, str] | dict[str, str] | None = None"},{name:"label2id",val:": dict[str, int] | dict[str, str] | None = None"},{name:"problem_type",val:": typing.Optional[typing.Literal['regression', 'single_label_classification', 'multi_label_classification']] = None"},{name:"vocab_size",val:": int = 200192"},{name:"hidden_size",val:": int = 2048"},{name:"intermediate_size",val:": int = 6144"},{name:"moe_intermediate_size",val:": int = 1408"},{name:"num_hidden_layers",val:": int = 32"},{name:"num_dense_layers",val:": int | None = 1"},{name:"num_attention_heads",val:": int = 16"},{name:"num_key_value_heads",val:": int | None = None"},{name:"head_dim",val:": int | None = 128"},{name:"hidden_act",val:": str = 'silu'"},{name:"max_position_embeddings",val:": int = 16384"},{name:"initializer_range",val:": float = 0.02"},{name:"rms_norm_eps",val:": float = 1e-05"},{name:"use_cache",val:": bool = True"},{name:"tie_word_embeddings",val:": bool = False"},{name:"rope_parameters",val:": transformers.modeling_rope_utils.RopeParameters | dict | None = None"},{name:"num_experts",val:": int | None = 64"},{name:"num_experts_per_tok",val:": int | None = 6"},{name:"num_shared_experts",val:": int | None = 2"},{name:"route_scale",val:": float | None = 1.0"},{name:"output_router_logits",val:": bool = False"},{name:"global_attn_every_n_layers",val:": int | None = 4"},{name:"sliding_window",val:": int | None = 1024"},{name:"layer_types",val:": list[str] | None = None"},{name:"attention_dropout",val:": float | int | None = 0.0"},{name:"mup_enabled",val:": bool | None = False"},{name:"eos_token_id",val:": int | list[int] | None = None"},{name:"pad_token_id",val:": int | None = None"},{name:"bos_token_id",val:": int | None = None"},{name:"attention_bias",val:": bool = False"}],parametersDescription:[{anchor:"transformers.AfmoeConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>200192</code>) — | |
| Vocabulary size of the model. Defines the number of different tokens that can be represented by the <code>input_ids</code>.`,name:"vocab_size"},{anchor:"transformers.AfmoeConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2048</code>) — | |
| Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.AfmoeConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>6144</code>) — | |
| Dimension of the MLP representations.`,name:"intermediate_size"},{anchor:"transformers.AfmoeConfig.moe_intermediate_size",description:`<strong>moe_intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1408</code>) — | |
| Intermediate size of the routed expert MLPs.`,name:"moe_intermediate_size"},{anchor:"transformers.AfmoeConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) — | |
| Number of hidden layers in the Transformer decoder.`,name:"num_hidden_layers"},{anchor:"transformers.AfmoeConfig.num_dense_layers",description:`<strong>num_dense_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) — | |
| Number of initial dense layers before MoE layers begin. Layers with index < num_dense_layers will use | |
| standard dense MLPs instead of MoE.`,name:"num_dense_layers"},{anchor:"transformers.AfmoeConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>16</code>) — | |
| Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_attention_heads"},{anchor:"transformers.AfmoeConfig.num_key_value_heads",description:`<strong>num_key_value_heads</strong> (<code>int</code>, <em>optional</em>) — | |
| 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, check out <a href="https://huggingface.co/papers/2305.13245" rel="nofollow">this | |
| paper</a>. If it is not specified, will default to | |
| <code>num_attention_heads</code>.`,name:"num_key_value_heads"},{anchor:"transformers.AfmoeConfig.head_dim",description:`<strong>head_dim</strong> (<code>int</code>, <em>optional</em>, defaults to <code>128</code>) — | |
| The attention head dimension. If None, it will default to hidden_size // num_attention_heads`,name:"head_dim"},{anchor:"transformers.AfmoeConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code>, <em>optional</em>, defaults to <code>silu</code>) — | |
| The non-linear activation function (function or string) in the decoder. For example, <code>"gelu"</code>, | |
| <code>"relu"</code>, <code>"silu"</code>, etc.`,name:"hidden_act"},{anchor:"transformers.AfmoeConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to <code>16384</code>) — | |
| The maximum sequence length that this model might ever be used with.`,name:"max_position_embeddings"},{anchor:"transformers.AfmoeConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.02</code>) — | |
| The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.AfmoeConfig.rms_norm_eps",description:`<strong>rms_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1e-05</code>) — | |
| The epsilon used by the rms normalization layers.`,name:"rms_norm_eps"},{anchor:"transformers.AfmoeConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| 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> or when the model is a decoder-only generative model.`,name:"use_cache"},{anchor:"transformers.AfmoeConfig.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to tie weight embeddings according to model’s <code>tied_weights_keys</code> mapping.`,name:"tie_word_embeddings"},{anchor:"transformers.AfmoeConfig.rope_parameters",description:`<strong>rope_parameters</strong> (<code>Union[~modeling_rope_utils.RopeParameters, dict]</code>, <em>optional</em>) — | |
| Dictionary containing the configuration parameters for the RoPE embeddings. The dictionary should contain | |
| a value for <code>rope_theta</code> and optionally parameters used for scaling in case you want to use RoPE | |
| with longer <code>max_position_embeddings</code>.`,name:"rope_parameters"},{anchor:"transformers.AfmoeConfig.num_experts",description:`<strong>num_experts</strong> (<code>int</code>, <em>optional</em>, defaults to <code>64</code>) — | |
| Number of routed experts in MoE layers.`,name:"num_experts"},{anchor:"transformers.AfmoeConfig.num_experts_per_tok",description:`<strong>num_experts_per_tok</strong> (<code>int</code>, <em>optional</em>, defaults to <code>6</code>) — | |
| Number of experts to route each token to. This is the top-k value for the token-choice routing.`,name:"num_experts_per_tok"},{anchor:"transformers.AfmoeConfig.num_shared_experts",description:`<strong>num_shared_experts</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2</code>) — | |
| Number of shared experts that are always activated for all tokens.`,name:"num_shared_experts"},{anchor:"transformers.AfmoeConfig.route_scale",description:`<strong>route_scale</strong> (<code>float</code>, <em>optional</em>, defaults to <code>1.0</code>) — | |
| Scaling factor or routed experts.`,name:"route_scale"},{anchor:"transformers.AfmoeConfig.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not the router logits should be returned by the model. Enabling this will also allow the model | |
| to output the auxiliary loss, including load balancing loss and router z-loss.`,name:"output_router_logits"},{anchor:"transformers.AfmoeConfig.global_attn_every_n_layers",description:`<strong>global_attn_every_n_layers</strong> (<code>int</code>, <em>optional</em>, defaults to 4) — | |
| The frequency of full attention layers. Every Nth layer will use full attention, while others use sliding | |
| window attention.`,name:"global_attn_every_n_layers"},{anchor:"transformers.AfmoeConfig.sliding_window",description:`<strong>sliding_window</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1024</code>) — | |
| Sliding window attention window size. If <code>None</code>, no sliding window is applied.`,name:"sliding_window"},{anchor:"transformers.AfmoeConfig.layer_types",description:`<strong>layer_types</strong> (<code>list[str]</code>, <em>optional</em>) — | |
| A list that explicitly maps each layer index with its layer type. If not provided, it will be automatically | |
| generated based on config values.`,name:"layer_types"},{anchor:"transformers.AfmoeConfig.attention_dropout",description:`<strong>attention_dropout</strong> (<code>Union[float, int]</code>, <em>optional</em>, defaults to <code>0.0</code>) — | |
| The dropout ratio for the attention probabilities.`,name:"attention_dropout"},{anchor:"transformers.AfmoeConfig.mup_enabled",description:`<strong>mup_enabled</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to enable muP (Maximal Update Parametrization) input scaling. When enabled, input embeddings | |
| are scaled by <code>sqrt(hidden_size)</code>.`,name:"mup_enabled"},{anchor:"transformers.AfmoeConfig.eos_token_id",description:`<strong>eos_token_id</strong> (<code>Union[int, list[int]]</code>, <em>optional</em>) — | |
| Token id used for end-of-stream in the vocabulary.`,name:"eos_token_id"},{anchor:"transformers.AfmoeConfig.pad_token_id",description:`<strong>pad_token_id</strong> (<code>int</code>, <em>optional</em>) — | |
| Token id used for padding in the vocabulary.`,name:"pad_token_id"},{anchor:"transformers.AfmoeConfig.bos_token_id",description:`<strong>bos_token_id</strong> (<code>int</code>, <em>optional</em>) — | |
| Token id used for beginning-of-stream in the vocabulary.`,name:"bos_token_id"},{anchor:"transformers.AfmoeConfig.attention_bias",description:`<strong>attention_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to use a bias in the query, key, value and output projection layers during self-attention.`,name:"attention_bias"}],source:"https://github.com/huggingface/transformers/blob/vr_40546/src/transformers/models/afmoe/configuration_afmoe.py#L31"}}),Z=new Kt({props:{anchor:"transformers.AfmoeConfig.example",$$slots:{default:[uo]},$$scope:{ctx:T}}}),ce=new N({props:{title:"AfmoeModel",local:"transformers.AfmoeModel",headingTag:"h2"}}),me=new Fe({props:{name:"class transformers.AfmoeModel",anchor:"transformers.AfmoeModel",parameters:[{name:"config",val:": AfmoeConfig"}],parametersDescription:[{anchor:"transformers.AfmoeModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_40546/en/model_doc/afmoe#transformers.AfmoeConfig">AfmoeConfig</a>) — | |
| 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_40546/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/vr_40546/src/transformers/models/afmoe/modeling_afmoe.py#L526"}}),pe=new Fe({props:{name:"forward",anchor:"transformers.AfmoeModel.forward",parameters:[{name:"input_ids",val:": torch.LongTensor | None = None"},{name:"attention_mask",val:": torch.Tensor | None = None"},{name:"inputs_embeds",val:": torch.FloatTensor | None = None"},{name:"position_ids",val:": torch.LongTensor | None = None"},{name:"past_key_values",val:": transformers.cache_utils.Cache | None = None"},{name:"use_cache",val:": bool | None = None"},{name:"**kwargs",val:": typing_extensions.Unpack[transformers.utils.generic.TransformersKwargs]"}],parametersDescription:[{anchor:"transformers.AfmoeModel.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| 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/pr_40546/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_40546/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and | |
| <a href="/docs/transformers/pr_40546/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.AfmoeModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| 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.AfmoeModel.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>) — | |
| 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’s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.AfmoeModel.forward.position_ids",description:`<strong>position_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| 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.AfmoeModel.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>~cache_utils.Cache</code>, <em>optional</em>) — | |
| 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>Only <a href="/docs/transformers/pr_40546/en/internal/generation_utils#transformers.Cache">Cache</a> instance is allowed as input, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>. | |
| If no <code>past_key_values</code> are passed, <a href="/docs/transformers/pr_40546/en/internal/generation_utils#transformers.DynamicCache">DynamicCache</a> will be initialized by default.</p> | |
| <p>The model will output the same cache format that is fed as input.</p> | |
| <p>If <code>past_key_values</code> are used, the user is expected to input only unprocessed <code>input_ids</code> (those that don’t | |
| have their past key value states given to this model) of shape <code>(batch_size, unprocessed_length)</code> instead of all <code>input_ids</code> | |
| of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.AfmoeModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) — | |
| 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"}],source:"https://github.com/huggingface/transformers/blob/vr_40546/src/transformers/models/afmoe/modeling_afmoe.py#L549",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <code>MoeModelOutputWithPast</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 (<code>None</code>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>MoeModelOutputWithPast</code> or <code>tuple(torch.FloatTensor)</code></p> | |
| `}}),B=new Yt({props:{$$slots:{default:[fo]},$$scope:{ctx:T}}}),ue=new N({props:{title:"AfmoeForCausalLM",local:"transformers.AfmoeForCausalLM",headingTag:"h2"}}),fe=new Fe({props:{name:"class transformers.AfmoeForCausalLM",anchor:"transformers.AfmoeForCausalLM",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.AfmoeForCausalLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_40546/en/model_doc/afmoe#transformers.AfmoeForCausalLM">AfmoeForCausalLM</a>) — | |
| 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_40546/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/vr_40546/src/transformers/models/afmoe/modeling_afmoe.py#L616"}}),he=new Fe({props:{name:"forward",anchor:"transformers.AfmoeForCausalLM.forward",parameters:[{name:"input_ids",val:": torch.LongTensor | None = None"},{name:"attention_mask",val:": torch.Tensor | None = None"},{name:"position_ids",val:": torch.LongTensor | None = None"},{name:"past_key_values",val:": transformers.cache_utils.Cache | None = None"},{name:"inputs_embeds",val:": torch.FloatTensor | None = None"},{name:"labels",val:": torch.LongTensor | None = None"},{name:"use_cache",val:": bool | None = None"},{name:"output_router_logits",val:": bool | None = None"},{name:"logits_to_keep",val:": int | torch.Tensor = 0"},{name:"**kwargs",val:": typing_extensions.Unpack[transformers.utils.generic.TransformersKwargs]"}],parametersDescription:[{anchor:"transformers.AfmoeForCausalLM.forward.input_ids",description:`<strong>input_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| 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/pr_40546/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_40546/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and | |
| <a href="/docs/transformers/pr_40546/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.AfmoeForCausalLM.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| 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.AfmoeForCausalLM.forward.position_ids",description:`<strong>position_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| 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.AfmoeForCausalLM.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>~cache_utils.Cache</code>, <em>optional</em>) — | |
| 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>Only <a href="/docs/transformers/pr_40546/en/internal/generation_utils#transformers.Cache">Cache</a> instance is allowed as input, see our <a href="https://huggingface.co/docs/transformers/en/kv_cache" rel="nofollow">kv cache guide</a>. | |
| If no <code>past_key_values</code> are passed, <a href="/docs/transformers/pr_40546/en/internal/generation_utils#transformers.DynamicCache">DynamicCache</a> will be initialized by default.</p> | |
| <p>The model will output the same cache format that is fed as input.</p> | |
| <p>If <code>past_key_values</code> are used, the user is expected to input only unprocessed <code>input_ids</code> (those that don’t | |
| have their past key value states given to this model) of shape <code>(batch_size, unprocessed_length)</code> instead of all <code>input_ids</code> | |
| of shape <code>(batch_size, sequence_length)</code>.`,name:"past_key_values"},{anchor:"transformers.AfmoeForCausalLM.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>) — | |
| 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’s internal embedding lookup matrix.`,name:"inputs_embeds"},{anchor:"transformers.AfmoeForCausalLM.forward.labels",description:`<strong>labels</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| 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.AfmoeForCausalLM.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) — | |
| 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.AfmoeForCausalLM.forward.output_router_logits",description:`<strong>output_router_logits</strong> (<code>bool</code>, <em>optional</em>) — | |
| 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.AfmoeForCausalLM.forward.logits_to_keep",description:`<strong>logits_to_keep</strong> (<code>Union[int, torch.Tensor]</code>, <em>optional</em>, defaults to <code>0</code>) — | |
| 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/vr_40546/src/transformers/models/afmoe/modeling_afmoe.py#L628",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>A <code>MoeCausalLMOutputWithPast</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_40546/en/model_doc/afmoe#transformers.AfmoeConfig" | |
| >AfmoeConfig</a>) and inputs.</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>MoeCausalLMOutputWithPast</code> or <code>tuple(torch.FloatTensor)</code></p> | |
| `}}),q=new Yt({props:{$$slots:{default:[ho]},$$scope:{ctx:T}}}),H=new Kt({props:{anchor:"transformers.AfmoeForCausalLM.forward.example",$$slots:{default:[go]},$$scope:{ctx:T}}}),ge=new io({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/afmoe.md"}}),{c(){n=c("meta"),u=r(),a=c("p"),p=r(),d=c("p"),d.innerHTML=l,w=r(),g(j.$$.fragment),Je=r(),W=c("div"),W.innerHTML=xt,je=r(),g(G.$$.fragment),Le=r(),R=c("p"),R.textContent=Ct,Ne=r(),g(V.$$.fragment),We=r(),X=c("p"),X.textContent=At,Ee=r(),S=c("ul"),S.innerHTML=zt,Ie=r(),Q=c("p"),Q.textContent=Ut,Ze=r(),E=c("blockquote"),E.innerHTML=Ft,Be=r(),D=c("p"),D.innerHTML=Jt,qe=r(),g(I.$$.fragment),He=r(),g(Y.$$.fragment),Pe=r(),g(K.$$.fragment),Ge=r(),O=c("p"),O.textContent=jt,Re=r(),ee=c("ul"),ee.innerHTML=Lt,Ve=r(),g(te.$$.fragment),Xe=r(),oe=c("p"),oe.textContent=Nt,Se=r(),ne=c("ul"),ne.innerHTML=Wt,Qe=r(),g(se.$$.fragment),De=r(),ae=c("p"),ae.textContent=Et,Ye=r(),re=c("ul"),re.innerHTML=It,Ke=r(),ie=c("p"),ie.textContent=Zt,Oe=r(),g(le.$$.fragment),et=r(),F=c("div"),g(de.$$.fragment),dt=r(),be=c("p"),be.textContent=Bt,ct=r(),g(Z.$$.fragment),tt=r(),g(ce.$$.fragment),ot=r(),$=c("div"),g(me.$$.fragment),mt=r(),ye=c("p"),ye.textContent=qt,pt=r(),ve=c("p"),ve.innerHTML=Ht,ut=r(),Me=c("p"),Me.innerHTML=Pt,ft=r(),U=c("div"),g(pe.$$.fragment),ht=r(),Te=c("p"),Te.innerHTML=Gt,gt=r(),g(B.$$.fragment),_t=r(),we=c("ul"),we.innerHTML=Rt,nt=r(),g(ue.$$.fragment),st=r(),k=c("div"),g(fe.$$.fragment),bt=r(),$e=c("p"),$e.textContent=Vt,yt=r(),ke=c("p"),ke.innerHTML=Xt,vt=r(),xe=c("p"),xe.innerHTML=St,Mt=r(),x=c("div"),g(he.$$.fragment),Tt=r(),Ce=c("p"),Ce.innerHTML=Qt,wt=r(),g(q.$$.fragment),$t=r(),Ae=c("ul"),Ae.innerHTML=Dt,kt=r(),g(H.$$.fragment),at=r(),g(ge.$$.fragment),rt=r(),Ue=c("p"),this.h()},l(e){const t=so("svelte-u9bgzb",document.head);n=m(t,"META",{name:!0,content:!0}),t.forEach(o),u=i(e),a=m(e,"P",{}),_e(a).forEach(o),p=i(e),d=m(e,"P",{"data-svelte-h":!0}),h(d)!=="svelte-9l34zu"&&(d.innerHTML=l),w=i(e),_(j.$$.fragment,e),Je=i(e),W=m(e,"DIV",{style:!0,"data-svelte-h":!0}),h(W)!=="svelte-8z1avl"&&(W.innerHTML=xt),je=i(e),_(G.$$.fragment,e),Le=i(e),R=m(e,"P",{"data-svelte-h":!0}),h(R)!=="svelte-tn969l"&&(R.textContent=Ct),Ne=i(e),_(V.$$.fragment,e),We=i(e),X=m(e,"P",{"data-svelte-h":!0}),h(X)!=="svelte-19y750v"&&(X.textContent=At),Ee=i(e),S=m(e,"UL",{"data-svelte-h":!0}),h(S)!=="svelte-15kwwly"&&(S.innerHTML=zt),Ie=i(e),Q=m(e,"P",{"data-svelte-h":!0}),h(Q)!=="svelte-em2ybk"&&(Q.textContent=Ut),Ze=i(e),E=m(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),h(E)!=="svelte-10cxnof"&&(E.innerHTML=Ft),Be=i(e),D=m(e,"P",{"data-svelte-h":!0}),h(D)!=="svelte-ue03j0"&&(D.innerHTML=Jt),qe=i(e),_(I.$$.fragment,e),He=i(e),_(Y.$$.fragment,e),Pe=i(e),_(K.$$.fragment,e),Ge=i(e),O=m(e,"P",{"data-svelte-h":!0}),h(O)!=="svelte-1oh8sos"&&(O.textContent=jt),Re=i(e),ee=m(e,"UL",{"data-svelte-h":!0}),h(ee)!=="svelte-1xfdq3u"&&(ee.innerHTML=Lt),Ve=i(e),_(te.$$.fragment,e),Xe=i(e),oe=m(e,"P",{"data-svelte-h":!0}),h(oe)!=="svelte-1ru8smn"&&(oe.textContent=Nt),Se=i(e),ne=m(e,"UL",{"data-svelte-h":!0}),h(ne)!=="svelte-133w6im"&&(ne.innerHTML=Wt),Qe=i(e),_(se.$$.fragment,e),De=i(e),ae=m(e,"P",{"data-svelte-h":!0}),h(ae)!=="svelte-o9qnb8"&&(ae.textContent=Et),Ye=i(e),re=m(e,"UL",{"data-svelte-h":!0}),h(re)!=="svelte-urui3p"&&(re.innerHTML=It),Ke=i(e),ie=m(e,"P",{"data-svelte-h":!0}),h(ie)!=="svelte-8xcpae"&&(ie.textContent=Zt),Oe=i(e),_(le.$$.fragment,e),et=i(e),F=m(e,"DIV",{class:!0});var L=_e(F);_(de.$$.fragment,L),dt=i(L),be=m(L,"P",{"data-svelte-h":!0}),h(be)!=="svelte-1tn2yc8"&&(be.textContent=Bt),ct=i(L),_(Z.$$.fragment,L),L.forEach(o),tt=i(e),_(ce.$$.fragment,e),ot=i(e),$=m(e,"DIV",{class:!0});var C=_e($);_(me.$$.fragment,C),mt=i(C),ye=m(C,"P",{"data-svelte-h":!0}),h(ye)!=="svelte-eormwo"&&(ye.textContent=qt),pt=i(C),ve=m(C,"P",{"data-svelte-h":!0}),h(ve)!=="svelte-zpgma5"&&(ve.innerHTML=Ht),ut=i(C),Me=m(C,"P",{"data-svelte-h":!0}),h(Me)!=="svelte-hswkmf"&&(Me.innerHTML=Pt),ft=i(C),U=m(C,"DIV",{class:!0});var J=_e(U);_(pe.$$.fragment,J),ht=i(J),Te=m(J,"P",{"data-svelte-h":!0}),h(Te)!=="svelte-1tbsll4"&&(Te.innerHTML=Gt),gt=i(J),_(B.$$.fragment,J),_t=i(J),we=m(J,"UL",{"data-svelte-h":!0}),h(we)!=="svelte-ese0q"&&(we.innerHTML=Rt),J.forEach(o),C.forEach(o),nt=i(e),_(ue.$$.fragment,e),st=i(e),k=m(e,"DIV",{class:!0});var A=_e(k);_(fe.$$.fragment,A),bt=i(A),$e=m(A,"P",{"data-svelte-h":!0}),h($e)!=="svelte-1r26bhx"&&($e.textContent=Vt),yt=i(A),ke=m(A,"P",{"data-svelte-h":!0}),h(ke)!=="svelte-zpgma5"&&(ke.innerHTML=Xt),vt=i(A),xe=m(A,"P",{"data-svelte-h":!0}),h(xe)!=="svelte-hswkmf"&&(xe.innerHTML=St),Mt=i(A),x=m(A,"DIV",{class:!0});var z=_e(x);_(he.$$.fragment,z),Tt=i(z),Ce=m(z,"P",{"data-svelte-h":!0}),h(Ce)!=="svelte-12dd81g"&&(Ce.innerHTML=Qt),wt=i(z),_(q.$$.fragment,z),$t=i(z),Ae=m(z,"UL",{"data-svelte-h":!0}),h(Ae)!=="svelte-ynlrd2"&&(Ae.innerHTML=Dt),kt=i(z),_(H.$$.fragment,z),z.forEach(o),A.forEach(o),at=i(e),_(ge.$$.fragment,e),rt=i(e),Ue=m(e,"P",{}),_e(Ue).forEach(o),this.h()},h(){P(n,"name","hf:doc:metadata"),P(n,"content",bo),ao(W,"float","right"),P(E,"class","tip"),P(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),P(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),P($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),P(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),P(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){f(document.head,n),s(e,u,t),s(e,a,t),s(e,p,t),s(e,d,t),s(e,w,t),b(j,e,t),s(e,Je,t),s(e,W,t),s(e,je,t),b(G,e,t),s(e,Le,t),s(e,R,t),s(e,Ne,t),b(V,e,t),s(e,We,t),s(e,X,t),s(e,Ee,t),s(e,S,t),s(e,Ie,t),s(e,Q,t),s(e,Ze,t),s(e,E,t),s(e,Be,t),s(e,D,t),s(e,qe,t),b(I,e,t),s(e,He,t),b(Y,e,t),s(e,Pe,t),b(K,e,t),s(e,Ge,t),s(e,O,t),s(e,Re,t),s(e,ee,t),s(e,Ve,t),b(te,e,t),s(e,Xe,t),s(e,oe,t),s(e,Se,t),s(e,ne,t),s(e,Qe,t),b(se,e,t),s(e,De,t),s(e,ae,t),s(e,Ye,t),s(e,re,t),s(e,Ke,t),s(e,ie,t),s(e,Oe,t),b(le,e,t),s(e,et,t),s(e,F,t),b(de,F,null),f(F,dt),f(F,be),f(F,ct),b(Z,F,null),s(e,tt,t),b(ce,e,t),s(e,ot,t),s(e,$,t),b(me,$,null),f($,mt),f($,ye),f($,pt),f($,ve),f($,ut),f($,Me),f($,ft),f($,U),b(pe,U,null),f(U,ht),f(U,Te),f(U,gt),b(B,U,null),f(U,_t),f(U,we),s(e,nt,t),b(ue,e,t),s(e,st,t),s(e,k,t),b(fe,k,null),f(k,bt),f(k,$e),f(k,yt),f(k,ke),f(k,vt),f(k,xe),f(k,Mt),f(k,x),b(he,x,null),f(x,Tt),f(x,Ce),f(x,wt),b(q,x,null),f(x,$t),f(x,Ae),f(x,kt),b(H,x,null),s(e,at,t),b(ge,e,t),s(e,rt,t),s(e,Ue,t),it=!0},p(e,[t]){const L={};t&2&&(L.$$scope={dirty:t,ctx:e}),I.$set(L);const C={};t&2&&(C.$$scope={dirty:t,ctx:e}),Z.$set(C);const J={};t&2&&(J.$$scope={dirty:t,ctx:e}),B.$set(J);const A={};t&2&&(A.$$scope={dirty:t,ctx:e}),q.$set(A);const z={};t&2&&(z.$$scope={dirty:t,ctx:e}),H.$set(z)},i(e){it||(y(j.$$.fragment,e),y(G.$$.fragment,e),y(V.$$.fragment,e),y(I.$$.fragment,e),y(Y.$$.fragment,e),y(K.$$.fragment,e),y(te.$$.fragment,e),y(se.$$.fragment,e),y(le.$$.fragment,e),y(de.$$.fragment,e),y(Z.$$.fragment,e),y(ce.$$.fragment,e),y(me.$$.fragment,e),y(pe.$$.fragment,e),y(B.$$.fragment,e),y(ue.$$.fragment,e),y(fe.$$.fragment,e),y(he.$$.fragment,e),y(q.$$.fragment,e),y(H.$$.fragment,e),y(ge.$$.fragment,e),it=!0)},o(e){v(j.$$.fragment,e),v(G.$$.fragment,e),v(V.$$.fragment,e),v(I.$$.fragment,e),v(Y.$$.fragment,e),v(K.$$.fragment,e),v(te.$$.fragment,e),v(se.$$.fragment,e),v(le.$$.fragment,e),v(de.$$.fragment,e),v(Z.$$.fragment,e),v(ce.$$.fragment,e),v(me.$$.fragment,e),v(pe.$$.fragment,e),v(B.$$.fragment,e),v(ue.$$.fragment,e),v(fe.$$.fragment,e),v(he.$$.fragment,e),v(q.$$.fragment,e),v(H.$$.fragment,e),v(ge.$$.fragment,e),it=!1},d(e){e&&(o(u),o(a),o(p),o(d),o(w),o(Je),o(W),o(je),o(Le),o(R),o(Ne),o(We),o(X),o(Ee),o(S),o(Ie),o(Q),o(Ze),o(E),o(Be),o(D),o(qe),o(He),o(Pe),o(Ge),o(O),o(Re),o(ee),o(Ve),o(Xe),o(oe),o(Se),o(ne),o(Qe),o(De),o(ae),o(Ye),o(re),o(Ke),o(ie),o(Oe),o(et),o(F),o(tt),o(ot),o($),o(nt),o(st),o(k),o(at),o(rt),o(Ue)),o(n),M(j,e),M(G,e),M(V,e),M(I,e),M(Y,e),M(K,e),M(te,e),M(se,e),M(le,e),M(de),M(Z),M(ce,e),M(me),M(pe),M(B),M(ue,e),M(fe),M(he),M(q),M(H),M(ge,e)}}}const bo='{"title":"AFMoE","local":"afmoe","sections":[{"title":"Key Architecture Features","local":"key-architecture-features","sections":[],"depth":2},{"title":"Model Architecture Details","local":"model-architecture-details","sections":[{"title":"Expert Routing","local":"expert-routing","sections":[],"depth":3},{"title":"Shared Experts","local":"shared-experts","sections":[],"depth":3},{"title":"Attention Mechanism","local":"attention-mechanism","sections":[],"depth":3}],"depth":2},{"title":"AfmoeConfig","local":"transformers.AfmoeConfig","sections":[],"depth":2},{"title":"AfmoeModel","local":"transformers.AfmoeModel","sections":[],"depth":2},{"title":"AfmoeForCausalLM","local":"transformers.AfmoeForCausalLM","sections":[],"depth":2}],"depth":1}';function yo(T){return to(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zo extends oo{constructor(n){super(),no(this,n,yo,_o,eo,{})}}export{zo as component}; | |
Xet Storage Details
- Size:
- 57.3 kB
- Xet hash:
- cc8c080961261d6c87c67f8d3ea6d7ff4ddb7abad238f8d726c9cda81c1d3245
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.