Buckets:
| import"../chunks/DsnmJJEf.js";import{i as O,h as K,C as $,H as n,a as d,D as s,E as ee,s as oe}from"../chunks/CN3cOuQA.js";import{p as ne,o as te,s as e,f as X,a as r,b as ae,c as i,d as c,r as l,n as p}from"../chunks/DdiSzEty.js";import{T as g}from"../chunks/Biyddybe.js";import{E as se}from"../chunks/BpTh2jDR.js";const re='{"title":"Ernie 4.5 Moe","local":"ernie-45-moe","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Usage Tips","local":"usage-tips","sections":[{"title":"Generate text","local":"generate-text","sections":[],"depth":3},{"title":"Distributed Generation with Tensor Parallelism","local":"distributed-generation-with-tensor-parallelism","sections":[],"depth":3},{"title":"Quantization with Bitsandbytes","local":"quantization-with-bitsandbytes","sections":[],"depth":3},{"title":"Speculative decoding with multi-token prediction","local":"speculative-decoding-with-multi-token-prediction","sections":[],"depth":3}],"depth":2},{"title":"Ernie4_5_MoeConfig","local":"transformers.Ernie4_5_MoeConfig","sections":[],"depth":2},{"title":"Ernie4_5_MoeModel","local":"transformers.Ernie4_5_MoeModel","sections":[],"depth":2},{"title":"Ernie4_5_MoeForCausalLM","local":"transformers.Ernie4_5_MoeForCausalLM","sections":[],"depth":2}],"depth":1}';var ie=c('<meta name="hf:doc:metadata"/>'),le=c("<p>Example:</p> <!>",1),Q=c(`<p>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.</p>`),de=c(`<p>Most generation-controlling parameters are set in <code>generation_config</code> which, if not passed, will be set to the | |
| model’s default generation configuration. You can override any <code>generation_config</code> by passing the corresponding | |
| parameters to generate(), e.g. <code>.generate(inputs, num_beams=4, do_sample=True)</code>.</p> <p>For an overview of generation strategies and code examples, check out the <a href="../generation_strategies">following | |
| guide</a>.</p>`,1),ce=c(`<p></p> <p><em>This model was contributed to Hugging Face Transformers on 2025-07-21.</em></p> <!> <div style="float: right;"><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"/> <img alt="Tensor parallelism" src="https://img.shields.io/badge/Tensor%20parallelism-06b6d4?style=flat&logoColor=white"/></div></div> <!> <!> <p>The Ernie 4.5 Moe model was released in the <a href="https://ernie.baidu.com/blog/posts/ernie4.5/" rel="nofollow">Ernie 4.5 Model Family</a> release by baidu. | |
| This family of models contains multiple different architectures and model sizes. This model in specific targets the base text | |
| model with mixture of experts (moe) - one with 21B total, 3B active parameters and another one with 300B total, 47B active parameters. | |
| It uses the standard <a href="./llama">Llama</a> at its core combined with a specialized MoE based on <a href="./mixtral">Mixtral</a> with additional shared | |
| experts.</p> <p>Other models from the family can be found at <a href="./ernie4_5">Ernie 4.5</a> and <a href="./ernie4_5_vl_moe">Ernie 4.5 VL MoE</a>.</p> <div class="flex justify-center"><img src="https://ernie.baidu.com/blog/posts/ernie4.5/overview.png"/></div> <!> <!> <!> <!> <!> <!> <!> <!> <p>The ERNIE 4.5 MoE checkpoints ship a multi-token prediction (MTP) layer, which <a href="/docs/transformers/pr_51549/en/main_classes/text_generation#transformers.GenerationMixin.generate">generate()</a> can use as a draft model for speculative decoding.</p> <!> <p>This model was contributed by <a href="https://huggingface.co/AntonV" rel="nofollow">Anton Vlasjuk</a>. | |
| The original code can be found <a href="https://github.com/PaddlePaddle/ERNIE" rel="nofollow">here</a>.</p> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>This is the configuration class to store the configuration of a Ernie4_5_MoeModel. It is used to instantiate a Ernie4 5 Moe | |
| model according to the specified arguments, defining the model architecture. Instantiating a configuration with the | |
| defaults will yield a similar configuration to that of the <a href="https://huggingface.co/baidu/ERNIE-4.5-21B-A3B-PT" rel="nofollow">baidu/ERNIE-4.5-21B-A3B-PT</a></p> <p>Configuration objects inherit from <a href="/docs/transformers/pr_51549/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/pr_51549/en/main_classes/configuration#transformers.PreTrainedConfig">PreTrainedConfig</a> for more information.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The bare Ernie4 5 Moe Model outputting raw hidden-states without any specific head on top.</p> <p>This model inherits from <a href="/docs/transformers/pr_51549/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.)</p> <p>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.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_51549/en/model_doc/ernie4_5_moe#transformers.Ernie4_5_MoeModel">Ernie4_5_MoeModel</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>last_hidden_state</strong> (<code>torch.Tensor</code> of shape <code>(batch_size, sequence_length, hidden_size)</code>) — Sequence of hidden-states at the output of the last layer of the model.</p></li> <li><p><strong>cache</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_51549/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>cache</code> input) to speed up sequential decoding.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.Tensor)</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.Tensor</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.Tensor)</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.Tensor</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.Tensor)</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.Tensor</code> (one for each layer) of shape <code>(batch_size, sequence_length, num_experts)</code>.</p> <p>Raw router logits (post-softmax) that are computed by MoE routers, these terms are used to compute the auxiliary | |
| loss for Mixture of Experts models.</p></li></ul></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The Ernie4 5 Moe Model for causal language modeling.</p> <p>This model inherits from <a href="/docs/transformers/pr_51549/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.)</p> <p>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.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>The <a href="/docs/transformers/pr_51549/en/model_doc/ernie4_5_moe#transformers.Ernie4_5_MoeForCausalLM">Ernie4_5_MoeForCausalLM</a> forward method, overrides the <code>__call__</code> special method.</p> <!> <ul><li><p><strong>loss</strong> (<code>torch.Tensor</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.Tensor</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.Tensor</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.output_router_logits=True</code>, and the model trains its router with a load-balancing loss) — Load-balancing auxiliary loss for the sparse modules. Models that balance their experts with a router bias | |
| instead (DeepSeek-V3 and the architectures derived from it) return <code>None</code> here while still returning <code>router_logits</code>.</p></li> <li><p><strong>router_logits</strong> (<code>tuple(torch.Tensor)</code>, <em>optional</em>, returned when <code>output_router_logits=True</code> is passed or when <code>config.output_router_logits=True</code>) — Tuple of <code>torch.Tensor</code> (one for each sparse layer) of shape <code>(batch_size * sequence_length, num_experts)</code>.</p> <p>Raw router logits computed by the MoE routers. They can be used to compute a load-balancing loss or to | |
| inspect how tokens are dispatched to experts.</p></li> <li><p><strong>cache</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_51549/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>cache</code> input) to speed up sequential decoding.</p></li> <li><p><strong>hidden_states</strong> (<code>tuple(torch.Tensor)</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.Tensor</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.Tensor)</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.Tensor</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></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Generates sequences of token ids for models with a language modeling head.</p> <!></div></div> <!> <p></p>`,1);function ge(A,S){ne(S,!1),te(()=>{new URLSearchParams(window.location.search).get("fw")}),O();var f=ce();K("4h70dj",o=>{var a=ie();oe(a,"content",re),r(o,a)});var M=e(X(f),4);$(M,{containerStyle:"float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"});var y=e(M,4);n(y,{title:"Ernie 4.5 Moe",local:"ernie-45-moe",headingTag:"h1"});var b=e(y,2);n(b,{title:"Overview",local:"overview",headingTag:"h2"});var T=e(b,8);n(T,{title:"Usage Tips",local:"usage-tips",headingTag:"h2"});var w=e(T,2);n(w,{title:"Generate text",local:"generate-text",headingTag:"h3"});var v=e(w,2);d(v,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjAlMjJiYWlkdSUyRkVSTklFLTQuNS0yMUItQTNCLVBUJTIyJTBBJTBBJTIzJTIwbG9hZCUyMHRoZSUyMHRva2VuaXplciUyMGFuZCUyMHRoZSUyMG1vZGVsJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfbmFtZSklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9uYW1lJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMEEpJTBBJTBBJTIzJTIwcHJlcGFyZSUyMHRoZSUyMG1vZGVsJTIwaW5wdXQlMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoJTIySGV5JTJDJTIwYXJlJTIweW91JTIwY29uc2Npb3VzJTNGJTIwQ2FuJTIweW91JTIwdGFsayUyMHRvJTIwbWUlM0YlMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byhtb2RlbC5kZXZpY2UpJTBBcHJvbXB0JTIwJTNEJTIwJTIySGV5JTJDJTIwYXJlJTIweW91JTIwY29uc2Npb3VzJTNGJTIwQ2FuJTIweW91JTIwdGFsayUyMHRvJTIwbWUlM0YlMjIlMEFtZXNzYWdlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU3QiUyMnJvbGUlMjIlM0ElMjAlMjJ1c2VyJTIyJTJDJTIwJTIyY29udGVudCUyMiUzQSUyMHByb21wdCU3RCUwQSU1RCUwQXRleHQlMjAlM0QlMjB0b2tlbml6ZXIuYXBwbHlfY2hhdF90ZW1wbGF0ZSglMEElMjAlMjAlMjAlMjBtZXNzYWdlcyUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBhZGRfZ2VuZXJhdGlvbl9wcm9tcHQlM0RUcnVlJTBBKSUwQW1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplciglNUJ0ZXh0JTVEJTJDJTIwYWRkX3NwZWNpYWxfdG9rZW5zJTNERmFsc2UlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byhtb2RlbC5kZXZpY2UpJTBBJTBBJTIzJTIwY29uZHVjdCUyMHRleHQlMjBjb21wbGV0aW9uJTBBZ2VuZXJhdGVkX2lkcyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCoqbW9kZWxfaW5wdXRzJTJDJTBBJTIwJTIwJTIwJTIwbWF4X25ld190b2tlbnMlM0QzMiUyQyUwQSklMEFvdXRwdXRfaWRzJTIwJTNEJTIwZ2VuZXJhdGVkX2lkcyU1QjAlNUQlNUJsZW4obW9kZWxfaW5wdXRzLmlucHV0X2lkcyU1QjAlNUQpJTNBJTVELnRvbGlzdCgpJTBBJTBBJTIzJTIwZGVjb2RlJTIwdGhlJTIwZ2VuZXJhdGVkJTIwaWRzJTBBZ2VuZXJhdGVfdGV4dCUyMCUzRCUyMHRva2VuaXplci5kZWNvZGUob3V0cHV0X2lkcyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer | |
| model_name = <span class="hljs-string">"baidu/ERNIE-4.5-21B-A3B-PT"</span> | |
| <span class="hljs-comment"># load the tokenizer and the model</span> | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| device_map=<span class="hljs-string">"auto"</span>, | |
| ) | |
| <span class="hljs-comment"># prepare the model input</span> | |
| inputs = tokenizer(<span class="hljs-string">"Hey, are you conscious? Can you talk to me?"</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device) | |
| prompt = <span class="hljs-string">"Hey, are you conscious? Can you talk to me?"</span> | |
| messages = [ | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: prompt} | |
| ] | |
| text = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=<span class="hljs-literal">False</span>, | |
| add_generation_prompt=<span class="hljs-literal">True</span> | |
| ) | |
| model_inputs = tokenizer([text], add_special_tokens=<span class="hljs-literal">False</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device) | |
| <span class="hljs-comment"># conduct text completion</span> | |
| generated_ids = model.generate( | |
| **model_inputs, | |
| max_new_tokens=<span class="hljs-number">32</span>, | |
| ) | |
| output_ids = generated_ids[<span class="hljs-number">0</span>][<span class="hljs-built_in">len</span>(model_inputs.input_ids[<span class="hljs-number">0</span>]):].tolist() | |
| <span class="hljs-comment"># decode the generated ids</span> | |
| generate_text = tokenizer.decode(output_ids, skip_special_tokens=<span class="hljs-literal">True</span>)`,lang:"python",wrap:!1});var k=e(v,2);n(k,{title:"Distributed Generation with Tensor Parallelism",local:"distributed-generation-with-tensor-parallelism",headingTag:"h3"});var J=e(k,2);d(J,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjAlMjJiYWlkdSUyRkVSTklFLTQuNS0yMUItQTNCLVBUJTIyJTBBJTBBJTIzJTIwbG9hZCUyMHRoZSUyMHRva2VuaXplciUyMGFuZCUyMHRoZSUyMG1vZGVsJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfbmFtZSklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9uYW1lJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjB0cF9wbGFuJTNEJTIyYXV0byUyMiUyQyUwQSklMEElMEElMjMlMjBwcmVwYXJlJTIwdGhlJTIwbW9kZWwlMjBpbnB1dCUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplciglMjJIZXklMkMlMjBhcmUlMjB5b3UlMjBjb25zY2lvdXMlM0YlMjBDYW4lMjB5b3UlMjB0YWxrJTIwdG8lMjBtZSUzRiUyMiUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLnRvKG1vZGVsLmRldmljZSklMEFwcm9tcHQlMjAlM0QlMjAlMjJIZXklMkMlMjBhcmUlMjB5b3UlMjBjb25zY2lvdXMlM0YlMjBDYW4lMjB5b3UlMjB0YWxrJTIwdG8lMjBtZSUzRiUyMiUwQW1lc3NhZ2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMjAlMjJjb250ZW50JTIyJTNBJTIwcHJvbXB0JTdEJTBBJTVEJTBBdGV4dCUyMCUzRCUyMHRva2VuaXplci5hcHBseV9jaGF0X3RlbXBsYXRlKCUwQSUyMCUyMCUyMCUyMG1lc3NhZ2VzJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemUlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGFkZF9nZW5lcmF0aW9uX3Byb21wdCUzRFRydWUlMEEpJTBBbW9kZWxfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCU1QnRleHQlNUQlMkMlMjBhZGRfc3BlY2lhbF90b2tlbnMlM0RGYWxzZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLnRvKG1vZGVsLmRldmljZSklMEElMEElMjMlMjBjb25kdWN0JTIwdGV4dCUyMGNvbXBsZXRpb24lMEFnZW5lcmF0ZWRfaWRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKiptb2RlbF9pbnB1dHMlMkMlMEElMjAlMjAlMjAlMjBtYXhfbmV3X3Rva2VucyUzRDMyJTJDJTBBKSUwQW91dHB1dF9pZHMlMjAlM0QlMjBnZW5lcmF0ZWRfaWRzJTVCMCU1RCU1Qmxlbihtb2RlbF9pbnB1dHMuaW5wdXRfaWRzJTVCMCU1RCklM0ElNUQudG9saXN0KCklMEElMEElMjMlMjBkZWNvZGUlMjB0aGUlMjBnZW5lcmF0ZWQlMjBpZHMlMEFnZW5lcmF0ZV90ZXh0JTIwJTNEJTIwdG9rZW5pemVyLmRlY29kZShvdXRwdXRfaWRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer | |
| model_name = <span class="hljs-string">"baidu/ERNIE-4.5-21B-A3B-PT"</span> | |
| <span class="hljs-comment"># load the tokenizer and the model</span> | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| device_map=<span class="hljs-string">"auto"</span>, | |
| tp_plan=<span class="hljs-string">"auto"</span>, | |
| ) | |
| <span class="hljs-comment"># prepare the model input</span> | |
| inputs = tokenizer(<span class="hljs-string">"Hey, are you conscious? Can you talk to me?"</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device) | |
| prompt = <span class="hljs-string">"Hey, are you conscious? Can you talk to me?"</span> | |
| messages = [ | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: prompt} | |
| ] | |
| text = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=<span class="hljs-literal">False</span>, | |
| add_generation_prompt=<span class="hljs-literal">True</span> | |
| ) | |
| model_inputs = tokenizer([text], add_special_tokens=<span class="hljs-literal">False</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device) | |
| <span class="hljs-comment"># conduct text completion</span> | |
| generated_ids = model.generate( | |
| **model_inputs, | |
| max_new_tokens=<span class="hljs-number">32</span>, | |
| ) | |
| output_ids = generated_ids[<span class="hljs-number">0</span>][<span class="hljs-built_in">len</span>(model_inputs.input_ids[<span class="hljs-number">0</span>]):].tolist() | |
| <span class="hljs-comment"># decode the generated ids</span> | |
| generate_text = tokenizer.decode(output_ids, skip_special_tokens=<span class="hljs-literal">True</span>)`,lang:"python",wrap:!1});var U=e(J,2);n(U,{title:"Quantization with Bitsandbytes",local:"quantization-with-bitsandbytes",headingTag:"h3"});var E=e(U,2);d(E,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUyQyUyMEJpdHNBbmRCeXRlc0NvbmZpZyUwQSUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjAlMjJiYWlkdSUyRkVSTklFLTQuNS0yMUItQTNCLVBUJTIyJTBBJTBBJTIzJTIwbG9hZCUyMHRoZSUyMHRva2VuaXplciUyMGFuZCUyMHRoZSUyMG1vZGVsJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfbmFtZSklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9uYW1lJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMEElMjAlMjAlMjAlMjBxdWFudGl6YXRpb25fY29uZmlnJTNEQml0c0FuZEJ5dGVzQ29uZmlnKGxvYWRfaW5fNGJpdCUzRFRydWUpJTJDJTBBKSUwQSUwQSUyMyUyMHByZXBhcmUlMjB0aGUlMjBtb2RlbCUyMGlucHV0JTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMkhleSUyQyUyMGFyZSUyMHlvdSUyMGNvbnNjaW91cyUzRiUyMENhbiUyMHlvdSUyMHRhbGslMjB0byUyMG1lJTNGJTIyJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMikudG8obW9kZWwuZGV2aWNlKSUwQXByb21wdCUyMCUzRCUyMCUyMkhleSUyQyUyMGFyZSUyMHlvdSUyMGNvbnNjaW91cyUzRiUyMENhbiUyMHlvdSUyMHRhbGslMjB0byUyMG1lJTNGJTIyJTBBbWVzc2FnZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlN0IlMjJyb2xlJTIyJTNBJTIwJTIydXNlciUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjBwcm9tcHQlN0QlMEElNUQlMEF0ZXh0JTIwJTNEJTIwdG9rZW5pemVyLmFwcGx5X2NoYXRfdGVtcGxhdGUoJTBBJTIwJTIwJTIwJTIwbWVzc2FnZXMlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYWRkX2dlbmVyYXRpb25fcHJvbXB0JTNEVHJ1ZSUwQSklMEFtb2RlbF9pbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIoJTVCdGV4dCU1RCUyQyUyMGFkZF9zcGVjaWFsX3Rva2VucyUzREZhbHNlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMikudG8obW9kZWwuZGV2aWNlKSUwQSUwQSUyMyUyMGNvbmR1Y3QlMjB0ZXh0JTIwY29tcGxldGlvbiUwQWdlbmVyYXRlZF9pZHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSglMEElMjAlMjAlMjAlMjAqKm1vZGVsX2lucHV0cyUyQyUwQSUyMCUyMCUyMCUyMG1heF9uZXdfdG9rZW5zJTNEMzIlMkMlMEEpJTBBb3V0cHV0X2lkcyUyMCUzRCUyMGdlbmVyYXRlZF9pZHMlNUIwJTVEJTVCbGVuKG1vZGVsX2lucHV0cy5pbnB1dF9pZHMlNUIwJTVEKSUzQSU1RC50b2xpc3QoKSUwQSUwQSUyMyUyMGRlY29kZSUyMHRoZSUyMGdlbmVyYXRlZCUyMGlkcyUwQWdlbmVyYXRlX3RleHQlMjAlM0QlMjB0b2tlbml6ZXIuZGVjb2RlKG91dHB1dF9pZHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig | |
| model_name = <span class="hljs-string">"baidu/ERNIE-4.5-21B-A3B-PT"</span> | |
| <span class="hljs-comment"># load the tokenizer and the model</span> | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| device_map=<span class="hljs-string">"auto"</span>, | |
| quantization_config=BitsAndBytesConfig(load_in_4bit=<span class="hljs-literal">True</span>), | |
| ) | |
| <span class="hljs-comment"># prepare the model input</span> | |
| inputs = tokenizer(<span class="hljs-string">"Hey, are you conscious? Can you talk to me?"</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device) | |
| prompt = <span class="hljs-string">"Hey, are you conscious? Can you talk to me?"</span> | |
| messages = [ | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: prompt} | |
| ] | |
| text = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=<span class="hljs-literal">False</span>, | |
| add_generation_prompt=<span class="hljs-literal">True</span> | |
| ) | |
| model_inputs = tokenizer([text], add_special_tokens=<span class="hljs-literal">False</span>, return_tensors=<span class="hljs-string">"pt"</span>).to(model.device) | |
| <span class="hljs-comment"># conduct text completion</span> | |
| generated_ids = model.generate( | |
| **model_inputs, | |
| max_new_tokens=<span class="hljs-number">32</span>, | |
| ) | |
| output_ids = generated_ids[<span class="hljs-number">0</span>][<span class="hljs-built_in">len</span>(model_inputs.input_ids[<span class="hljs-number">0</span>]):].tolist() | |
| <span class="hljs-comment"># decode the generated ids</span> | |
| generate_text = tokenizer.decode(output_ids, skip_special_tokens=<span class="hljs-literal">True</span>)`,lang:"python",wrap:!1});var C=e(E,2);n(C,{title:"Speculative decoding with multi-token prediction",local:"speculative-decoding-with-multi-token-prediction",headingTag:"h3"});var j=e(C,4);d(j,{code:"Z2VuZXJhdGVkX2lkcyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqbW9kZWxfaW5wdXRzJTJDJTIwbWF4X25ld190b2tlbnMlM0QzMiUyQyUyMHVzZV9tdHAlM0RUcnVlKQ==",highlighted:'generated_ids = model.generate(**model_inputs, max_new_tokens=<span class="hljs-number">32</span>, use_mtp=<span class="hljs-literal">True</span>)',lang:"python",wrap:!1});var x=e(j,4);n(x,{title:"Ernie4_5_MoeConfig",local:"transformers.Ernie4_5_MoeConfig",headingTag:"h2"});var m=e(x,2),z=i(m);s(z,{name:"class transformers.Ernie4_5_MoeConfig",anchor:"transformers.Ernie4_5_MoeConfig",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/ernie4_5_moe/configuration_ernie4_5_moe.py#L25",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:": str | torch.dtype | None = 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:": Literal['regression', 'single_label_classification', 'multi_label_classification'] | None = None"},{name:"vocab_size",val:": int = 103424"},{name:"pad_token_id",val:": int | None = 0"},{name:"bos_token_id",val:": int | None = 1"},{name:"eos_token_id",val:": int | list[int] | None = 2"},{name:"hidden_size",val:": int = 2560"},{name:"intermediate_size",val:": int = 12288"},{name:"num_hidden_layers",val:": int = 28"},{name:"num_attention_heads",val:": int = 20"},{name:"num_key_value_heads",val:": int | None = 4"},{name:"hidden_act",val:": str = 'silu'"},{name:"max_position_embeddings",val:": int = 131072"},{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 = True"},{name:"rope_parameters",val:": transformers.modeling_rope_utils.RopeParameters | dict | None = None"},{name:"use_bias",val:": bool | None = False"},{name:"moe_intermediate_size",val:": int = 1536"},{name:"moe_k",val:": int | None = 6"},{name:"moe_num_experts",val:": int | None = 64"},{name:"moe_num_shared_experts",val:": int | None = 2"},{name:"moe_layer_start_index",val:": int | None = 1"},{name:"moe_layer_end_index",val:": int | None = -1"},{name:"moe_layer_interval",val:": int | None = 1"},{name:"moe_norm_min",val:": float | None = 1e-12"},{name:"output_router_logits",val:": bool | None = False"},{name:"router_aux_loss_coef",val:": float | None = 0.001"},{name:"num_mtp_layers",val:": int | None = None"}],parametersDescription:[{anchor:"transformers.Ernie4_5_MoeConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>103424</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.Ernie4_5_MoeConfig.pad_token_id",description:`<strong>pad_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to <code>0</code>) — | |
| Token id used for padding in the vocabulary.`,name:"pad_token_id"},{anchor:"transformers.Ernie4_5_MoeConfig.bos_token_id",description:`<strong>bos_token_id</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) — | |
| Token id used for beginning-of-stream in the vocabulary.`,name:"bos_token_id"},{anchor:"transformers.Ernie4_5_MoeConfig.eos_token_id",description:`<strong>eos_token_id</strong> (<code>Union[int, list[int]]</code>, <em>optional</em>, defaults to <code>2</code>) — | |
| Token id used for end-of-stream in the vocabulary.`,name:"eos_token_id"},{anchor:"transformers.Ernie4_5_MoeConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2560</code>) — | |
| Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.Ernie4_5_MoeConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>12288</code>) — | |
| Dimension of the MLP representations.`,name:"intermediate_size"},{anchor:"transformers.Ernie4_5_MoeConfig.num_hidden_layers",description:`<strong>num_hidden_layers</strong> (<code>int</code>, <em>optional</em>, defaults to <code>28</code>) — | |
| Number of hidden layers in the Transformer decoder.`,name:"num_hidden_layers"},{anchor:"transformers.Ernie4_5_MoeConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>20</code>) — | |
| Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_attention_heads"},{anchor:"transformers.Ernie4_5_MoeConfig.num_key_value_heads",description:`<strong>num_key_value_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>4</code>) — | |
| 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.Ernie4_5_MoeConfig.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.Ernie4_5_MoeConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to <code>131072</code>) — | |
| The maximum sequence length that this model might ever be used with.`,name:"max_position_embeddings"},{anchor:"transformers.Ernie4_5_MoeConfig.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.Ernie4_5_MoeConfig.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.Ernie4_5_MoeConfig.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.Ernie4_5_MoeConfig.tie_word_embeddings",description:`<strong>tie_word_embeddings</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to tie weight embeddings according to model’s <code>tied_weights_keys</code> mapping.`,name:"tie_word_embeddings"},{anchor:"transformers.Ernie4_5_MoeConfig.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.Ernie4_5_MoeConfig.use_bias",description:`<strong>use_bias</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to use a bias in any of the projections including mlp and attention for example.`,name:"use_bias"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_intermediate_size",description:`<strong>moe_intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1536</code>) — | |
| Intermediate size of the routed expert MLPs.`,name:"moe_intermediate_size"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_k",description:`<strong>moe_k</strong> (<code>int</code>, <em>optional</em>, defaults to 6) — | |
| Number of selected experts.`,name:"moe_k"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_num_experts",description:`<strong>moe_num_experts</strong> (<code>int</code>, <em>optional</em>, defaults to 64) — | |
| Number of routed experts.`,name:"moe_num_experts"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_num_shared_experts",description:`<strong>moe_num_shared_experts</strong> (<code>int</code>, <em>optional</em>, defaults to 2) — | |
| The number of experts that are shared for all MoE forwards.`,name:"moe_num_shared_experts"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_layer_start_index",description:`<strong>moe_layer_start_index</strong> (<code>int</code>, <em>optional</em>, defaults to 1) — | |
| The first index at which MoE layers start to appear.`,name:"moe_layer_start_index"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_layer_end_index",description:`<strong>moe_layer_end_index</strong> (<code>int</code>, <em>optional</em>, defaults to -1) — | |
| The last possible index for a MoE layer.`,name:"moe_layer_end_index"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_layer_interval",description:`<strong>moe_layer_interval</strong> (<code>int</code>, <em>optional</em>, defaults to 1) — | |
| The intervals between MoE layers to appear.`,name:"moe_layer_interval"},{anchor:"transformers.Ernie4_5_MoeConfig.moe_norm_min",description:`<strong>moe_norm_min</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-12) — | |
| Minimum division value during routing normalization.`,name:"moe_norm_min"},{anchor:"transformers.Ernie4_5_MoeConfig.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.Ernie4_5_MoeConfig.router_aux_loss_coef",description:`<strong>router_aux_loss_coef</strong> (<code>float</code>, <em>optional</em>, defaults to <code>0.001</code>) — | |
| Auxiliary load balancing loss coefficient. Used to penalize uneven expert routing in MoE models.`,name:"router_aux_loss_coef"},{anchor:"transformers.Ernie4_5_MoeConfig.num_mtp_layers",description:`<strong>num_mtp_layers</strong> (<code>int</code>, <em>optional</em>) — | |
| Number of multi-token prediction (MTP) layers stored after the base model in the checkpoint, used for | |
| speculative decoding with <code>generate(..., use_mtp=True)</code>. At most one is supported.`,name:"num_mtp_layers"}]});var q=e(z,6);se(q,{anchor:"transformers.Ernie4_5_MoeConfig.example",children:(o,a)=>{var t=le(),D=e(X(t),2);d(D,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEVybmllNF81X01vZU1vZGVsJTJDJTIwRXJuaWU0XzVfTW9FQ29uZmlnJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMEVybmllNF81X01vRSUyMHN0eWxlJTIwY29uZmlndXJhdGlvbiUwQWNvbmZpZ3VyYXRpb24lMjAlM0QlMjBFcm5pZTRfNV9Nb0VDb25maWcoKSUwQSUwQSUyMyUyMEluaXRpYWxpemluZyUyMGElMjBtb2RlbCUyMGZyb20lMjB0aGUlMjBFUk5JRS00LjUtMjFCLUEzQiUyMHN0eWxlJTIwY29uZmlndXJhdGlvbiUwQW1vZGVsJTIwJTNEJTIwRXJuaWU0XzVfTW9lTW9kZWwoY29uZmlndXJhdGlvbiklMEElMEElMjMlMjBBY2Nlc3NpbmclMjB0aGUlMjBtb2RlbCUyMGNvbmZpZ3VyYXRpb24lMEFjb25maWd1cmF0aW9uJTIwJTNEJTIwbW9kZWwuY29uZmln",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Ernie4_5_MoeModel, Ernie4_5_MoEConfig | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing a Ernie4_5_MoE style configuration</span> | |
| <span class="hljs-meta">>>> </span>configuration = Ernie4_5_MoEConfig() | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing a model from the ERNIE-4.5-21B-A3B style configuration</span> | |
| <span class="hljs-meta">>>> </span>model = Ernie4_5_MoeModel(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}),r(o,t)},$$slots:{default:!0}}),l(m);var I=e(m,2);n(I,{title:"Ernie4_5_MoeModel",local:"transformers.Ernie4_5_MoeModel",headingTag:"h2"});var h=e(I,2),N=i(h);s(N,{name:"class transformers.Ernie4_5_MoeModel",anchor:"transformers.Ernie4_5_MoeModel",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/ernie4_5_moe/modeling_ernie4_5_moe.py#L476",parameters:[{name:"config",val:": Ernie4_5_MoeConfig"}],parametersDescription:[{anchor:"transformers.Ernie4_5_MoeModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/ernie4_5_moe#transformers.Ernie4_5_MoeConfig">Ernie4_5_MoeConfig</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_51549/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var Z=e(N,8),B=i(Z);s(B,{name:"forward",anchor:"transformers.Ernie4_5_MoeModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/ernie4_5_moe/modeling_ernie4_5_moe.py#L493",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:"cache",val:": transformers.cache_utils.Cache | None = None"},{name:"inputs_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"use_cache",val:": bool | None = None"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.Ernie4_5_MoeModel.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>Indices can be obtained using <a href="/docs/transformers/pr_51549/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_51549/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and | |
| <a href="/docs/transformers/pr_51549/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></p>`,name:"input_ids"},{anchor:"transformers.Ernie4_5_MoeModel.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>: | |
| <ul> | |
| <li>1 for tokens that are <strong>not masked</strong>,</li> | |
| <li>0 for tokens that are <strong>masked</strong>.</li> | |
| </ul> | |
| <p><a href="../glossary#attention-mask">What are attention masks?</a></p>`,name:"attention_mask"},{anchor:"transformers.Ernie4_5_MoeModel.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><a href="../glossary#position-ids">What are position IDs?</a></p>`,name:"position_ids"},{anchor:"transformers.Ernie4_5_MoeModel.forward.cache",description:`<strong>cache</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>cache</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>Only <a href="/docs/transformers/pr_51549/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>cache</code> are passed, <a href="/docs/transformers/pr_51549/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>cache</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>.</p>`,name:"cache"},{anchor:"transformers.Ernie4_5_MoeModel.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.Tensor</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.Ernie4_5_MoeModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) — | |
| If set to <code>True</code>, <code>cache</code> key value states are returned and can be used to speed up decoding (see | |
| <code>cache</code>).`,name:"use_cache"}],returnDescription:` | |
| <p>A <code>MoeModelOutputWithPast</code> or a tuple of | |
| <code>torch.Tensor</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:` | |
| <p><code>MoeModelOutputWithPast</code> or <code>tuple(torch.Tensor)</code></p> | |
| `});var H=e(B,4);g(H,{children:(o,a)=>{var t=Q();r(o,t)},$$slots:{default:!0}}),p(2),l(Z),l(h);var R=e(h,2);n(R,{title:"Ernie4_5_MoeForCausalLM",local:"transformers.Ernie4_5_MoeForCausalLM",headingTag:"h2"});var u=e(R,2),G=i(u);s(G,{name:"class transformers.Ernie4_5_MoeForCausalLM",anchor:"transformers.Ernie4_5_MoeForCausalLM",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/ernie4_5_moe/modeling_ernie4_5_moe.py#L626",parameters:[{name:"config",val:": Ernie4_5_MoeConfig"}],parametersDescription:[{anchor:"transformers.Ernie4_5_MoeForCausalLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/ernie4_5_moe#transformers.Ernie4_5_MoeConfig">Ernie4_5_MoeConfig</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_51549/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}]});var _=e(G,8),W=i(_);s(W,{name:"forward",anchor:"transformers.Ernie4_5_MoeForCausalLM.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/ernie4_5_moe/modeling_ernie4_5_moe.py#L645",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:"cache",val:": transformers.cache_utils.Cache | None = None"},{name:"inputs_embeds",val:": typing.Optional[torch.Tensor] = None"},{name:"labels",val:": typing.Optional[torch.LongTensor] = None"},{name:"use_cache",val:": bool | None = None"},{name:"output_router_logits",val:": bool | None = None"},{name:"logits_to_keep",val:": typing.Union[int, torch.Tensor] = 0"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.Ernie4_5_MoeForCausalLM.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>Indices can be obtained using <a href="/docs/transformers/pr_51549/en/model_doc/auto#transformers.AutoTokenizer">AutoTokenizer</a>. See <a href="/docs/transformers/pr_51549/en/internal/tokenization_utils#transformers.PreTrainedTokenizerBase.encode">PreTrainedTokenizer.encode()</a> and | |
| <a href="/docs/transformers/pr_51549/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></p>`,name:"input_ids"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.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>: | |
| <ul> | |
| <li>1 for tokens that are <strong>not masked</strong>,</li> | |
| <li>0 for tokens that are <strong>masked</strong>.</li> | |
| </ul> | |
| <p><a href="../glossary#attention-mask">What are attention masks?</a></p>`,name:"attention_mask"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.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><a href="../glossary#position-ids">What are position IDs?</a></p>`,name:"position_ids"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.forward.cache",description:`<strong>cache</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>cache</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>Only <a href="/docs/transformers/pr_51549/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>cache</code> are passed, <a href="/docs/transformers/pr_51549/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>cache</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>.</p>`,name:"cache"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.forward.inputs_embeds",description:`<strong>inputs_embeds</strong> (<code>torch.Tensor</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.Ernie4_5_MoeForCausalLM.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.Ernie4_5_MoeForCausalLM.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) — | |
| If set to <code>True</code>, <code>cache</code> key value states are returned and can be used to speed up decoding (see | |
| <code>cache</code>).`,name:"use_cache"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.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.Ernie4_5_MoeForCausalLM.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"}],returnDescription:` | |
| <p>A <code>MoeCausalLMOutputWithPast</code> or a tuple of | |
| <code>torch.Tensor</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:` | |
| <p><code>MoeCausalLMOutputWithPast</code> or <code>tuple(torch.Tensor)</code></p> | |
| `});var L=e(W,4);g(L,{children:(o,a)=>{var t=Q();r(o,t)},$$slots:{default:!0}}),p(2),l(_);var F=e(_,2),V=i(F);s(V,{name:"generate",anchor:"transformers.Ernie4_5_MoeForCausalLM.generate",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/generation/utils.py#L2584",parameters:[{name:"inputs",val:": typing.Optional[torch.Tensor] = None"},{name:"generation_config",val:": transformers.generation.configuration_utils.GenerationConfig | None = None"},{name:"logits_processor",val:": transformers.generation.logits_process.LogitsProcessorList | None = None"},{name:"stopping_criteria",val:": transformers.generation.stopping_criteria.StoppingCriteriaList | None = None"},{name:"prefix_allowed_tokens_fn",val:": collections.abc.Callable[[int, torch.Tensor], list[int]] | None = None"},{name:"synced_gpus",val:": bool | None = None"},{name:"assistant_model",val:": typing.Optional[ForwardRef('PreTrainedModel')] = None"},{name:"streamer",val:": typing.Optional[ForwardRef('BaseStreamer')] = None"},{name:"negative_prompt_ids",val:": typing.Optional[torch.Tensor] = None"},{name:"negative_prompt_attention_mask",val:": typing.Optional[torch.Tensor] = None"},{name:"custom_generate",val:": str | collections.abc.Callable | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.inputs",description:`<strong>inputs</strong> (<code>torch.Tensor</code> of varying shape depending on the modality, <em>optional</em>) — | |
| The sequence used as a prompt for the generation or as model inputs to the encoder. If <code>None</code> the | |
| method initializes it with <code>bos_token_id</code> and a batch size of 1. For decoder-only models <code>inputs</code> | |
| should be in the format of <code>input_ids</code>. For encoder-decoder models <em>inputs</em> can represent any of | |
| <code>input_ids</code>, <code>input_values</code>, <code>input_features</code>, or <code>pixel_values</code>.`,name:"inputs"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.generation_config",description:`<strong>generation_config</strong> (<a href="/docs/transformers/pr_51549/en/main_classes/text_generation#transformers.GenerationConfig">GenerationConfig</a>, <em>optional</em>) — | |
| The generation configuration to be used as base parametrization for the generation call. <code>**kwargs</code> | |
| passed to generate matching the attributes of <code>generation_config</code> will override them. If | |
| <code>generation_config</code> is not provided, the default will be used, which has the following loading | |
| priority: 1) from the <code>generation_config.json</code> model file, if it exists; 2) from the model | |
| configuration. Please note that unspecified parameters will inherit <a href="/docs/transformers/pr_51549/en/main_classes/text_generation#transformers.GenerationConfig">GenerationConfig</a>’s | |
| default values, whose documentation should be checked to parameterize generation.`,name:"generation_config"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.logits_processor",description:`<strong>logits_processor</strong> (<code>LogitsProcessorList</code>, <em>optional</em>) — | |
| Custom logits processors that complement the default logits processors built from arguments and | |
| generation config. If a logit processor is passed that is already created with the arguments or a | |
| generation config an error is thrown. This feature is intended for advanced users.`,name:"logits_processor"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.stopping_criteria",description:`<strong>stopping_criteria</strong> (<code>StoppingCriteriaList</code>, <em>optional</em>) — | |
| Custom stopping criteria that complements the default stopping criteria built from arguments and a | |
| generation config. If a stopping criteria is passed that is already created with the arguments or a | |
| generation config an error is thrown. If your stopping criteria depends on the <code>scores</code> input, make | |
| sure you pass <code>return_dict_in_generate=True, output_scores=True</code> to <code>generate</code>. This feature is | |
| intended for advanced users.`,name:"stopping_criteria"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.prefix_allowed_tokens_fn",description:`<strong>prefix_allowed_tokens_fn</strong> (<code>Callable[[int, torch.Tensor], list[int]]</code>, <em>optional</em>) — | |
| If provided, this function constraints the beam search to allowed tokens only at each step. If not | |
| provided no constraint is applied. This function takes 2 arguments: the batch ID <code>batch_id</code> and | |
| <code>input_ids</code>. It has to return a list with the allowed tokens for the next generation step conditioned | |
| on the batch ID <code>batch_id</code> and the previously generated tokens <code>inputs_ids</code>. This argument is useful | |
| for constrained generation conditioned on the prefix, as described in <a href="https://huggingface.co/papers/2010.00904" rel="nofollow">Autoregressive Entity | |
| Retrieval</a>.`,name:"prefix_allowed_tokens_fn"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.synced_gpus",description:`<strong>synced_gpus</strong> (<code>bool</code>, <em>optional</em>) — | |
| Whether to continue running the while loop until max_length. Unless overridden, this flag will be set | |
| to <code>True</code> if using <code>FullyShardedDataParallel</code> or DeepSpeed ZeRO Stage 3 with multiple GPUs to avoid | |
| deadlocking if one GPU finishes generating before other GPUs. Otherwise, defaults to <code>False</code>.`,name:"synced_gpus"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.assistant_model",description:`<strong>assistant_model</strong> (<code>PreTrainedModel</code>, <em>optional</em>) — | |
| An assistant model that can be used to accelerate generation. The assistant model must have the exact | |
| same tokenizer. The acceleration is achieved when forecasting candidate tokens with the assistant model | |
| is much faster than running generation with the model you’re calling generate from. As such, the | |
| assistant model should be much smaller.`,name:"assistant_model"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.streamer",description:`<strong>streamer</strong> (<code>BaseStreamer</code>, <em>optional</em>) — | |
| Streamer object that will be used to stream the generated sequences. Generated tokens are passed | |
| through <code>streamer.put(token_ids)</code> and the streamer is responsible for any further processing.`,name:"streamer"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.negative_prompt_ids",description:`<strong>negative_prompt_ids</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| The negative prompt needed for some processors such as CFG. The batch size must match the input batch | |
| size. This is an experimental feature, subject to breaking API changes in future versions.`,name:"negative_prompt_ids"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.negative_prompt_attention_mask",description:`<strong>negative_prompt_attention_mask</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) — | |
| Attention_mask for <code>negative_prompt_ids</code>.`,name:"negative_prompt_attention_mask"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.custom_generate",description:`<strong>custom_generate</strong> (<code>str</code> or <code>Callable</code>, <em>optional</em>) — | |
| One of the following: | |
| <ul> | |
| <li><code>str</code> (Hugging Face Hub repository name): runs the custom <code>generate</code> function defined at | |
| <code>custom_generate/generate.py</code> in that repository instead of the standard <code>generate</code> method. The | |
| repository fully replaces the generation logic, and the return type may differ.</li> | |
| <li><code>str</code> (local repository path): same as above but from a local path. Local directories also | |
| require <code>trust_remote_code=True</code> because the local <code>custom_generate/generate.py</code> is executed.</li> | |
| <li><code>Callable</code>: <code>generate</code> will perform the usual input preparation steps, then call the provided callable to | |
| run the decoding loop. | |
| For more information, see <a href="../../generation_strategies#custom-generation-methods">the docs</a>.</li> | |
| </ul>`,name:"custom_generate"},{anchor:"transformers.Ernie4_5_MoeForCausalLM.generate.kwargs",description:`<strong>kwargs</strong> (<code>dict[str, Any]</code>, <em>optional</em>) — | |
| Ad hoc parametrization of <code>generation_config</code> and/or additional model-specific kwargs that will be | |
| forwarded to the <code>forward</code> function of the model. If the model is an encoder-decoder model, encoder | |
| specific kwargs should not be prefixed and decoder specific kwargs should be prefixed with <em>decoder_</em>.`,name:"kwargs"}],returnDescription:` | |
| <p>A <a | |
| href="/docs/transformers/pr_51549/en/main_classes/output#transformers.utils.ModelOutput" | |
| >ModelOutput</a> (if <code>return_dict_in_generate=True</code> | |
| or when <code>config.return_dict_in_generate=True</code>) or a <code>torch.LongTensor</code>.</p> | |
| <p>If the model is <em>not</em> an encoder-decoder model (<code>model.config.is_encoder_decoder=False</code>), the possible | |
| <a | |
| href="/docs/transformers/pr_51549/en/main_classes/output#transformers.utils.ModelOutput" | |
| >ModelOutput</a> types are:</p> | |
| <ul> | |
| <li><a | |
| href="/docs/transformers/pr_51549/en/internal/generation_utils#transformers.generation.GenerateDecoderOnlyOutput" | |
| >GenerateDecoderOnlyOutput</a>,</li> | |
| <li><a | |
| href="/docs/transformers/pr_51549/en/internal/generation_utils#transformers.generation.GenerateBeamDecoderOnlyOutput" | |
| >GenerateBeamDecoderOnlyOutput</a></li> | |
| </ul> | |
| <p>If the model is an encoder-decoder model (<code>model.config.is_encoder_decoder=True</code>), the possible | |
| <a | |
| href="/docs/transformers/pr_51549/en/main_classes/output#transformers.utils.ModelOutput" | |
| >ModelOutput</a> types are:</p> | |
| <ul> | |
| <li><a | |
| href="/docs/transformers/pr_51549/en/internal/generation_utils#transformers.generation.GenerateEncoderDecoderOutput" | |
| >GenerateEncoderDecoderOutput</a>,</li> | |
| <li><a | |
| href="/docs/transformers/pr_51549/en/internal/generation_utils#transformers.generation.GenerateBeamEncoderDecoderOutput" | |
| >GenerateBeamEncoderDecoderOutput</a></li> | |
| </ul> | |
| `,returnType:` | |
| <p><a | |
| href="/docs/transformers/pr_51549/en/main_classes/output#transformers.utils.ModelOutput" | |
| >ModelOutput</a> or <code>torch.LongTensor</code></p> | |
| `});var Y=e(V,4);g(Y,{warning:!0,children:(o,a)=>{var t=de();p(2),r(o,t)},$$slots:{default:!0}}),l(F),l(u);var P=e(u,2);ee(P,{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/ernie4_5_moe.md"}),p(2),r(A,f),ae()}export{ge as component}; | |
Xet Storage Details
- Size:
- 63.9 kB
- Xet hash:
- 1cd2c010fe5f8e0770ad8c72c361027417160da5578a0bcb818d40905a3ed54a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.