Buckets:
| import"../chunks/DsnmJJEf.js";import{i as K,h as $,C as ee,H as o,a as r,D as i,E as oe,s as ne}from"../chunks/CN3cOuQA.js";import{p as te,o as se,s as e,f as g,a,b as ae,c as l,d as c,r as d,n as F}from"../chunks/DdiSzEty.js";import{T as V}from"../chunks/Biyddybe.js";import{E as q}from"../chunks/BpTh2jDR.js";const re='{"title":"EXAONE MoE","local":"exaone-moe","sections":[{"title":"Overview","local":"overview","sections":[{"title":"Key Features","local":"key-features","sections":[],"depth":3}],"depth":2},{"title":"Model Details","local":"model-details","sections":[{"title":"Model Configuration of K-EXAONE","local":"model-configuration-of-k-exaone","sections":[],"depth":3}],"depth":2},{"title":"Usage Tips","local":"usage-tips","sections":[{"title":"Reasoning mode","local":"reasoning-mode","sections":[],"depth":3},{"title":"Non-reasoning mode","local":"non-reasoning-mode","sections":[],"depth":3},{"title":"Agentic tool use","local":"agentic-tool-use","sections":[],"depth":3}],"depth":2},{"title":"ExaoneMoeConfig","local":"transformers.ExaoneMoeConfig","sections":[],"depth":2},{"title":"ExaoneMoeModel","local":"transformers.ExaoneMoeModel","sections":[],"depth":2},{"title":"ExaoneMoeForCausalLM","local":"transformers.ExaoneMoeForCausalLM","sections":[],"depth":2}],"depth":1}';var ie=c('<meta name="hf:doc:metadata"/>'),Q=c("<p>Example:</p> <!>",1),S=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>`),le=c(`<p></p> <p><em>This model was contributed to Hugging Face Transformers on 2026-02-04.</em></p> <!> <!> <!> <p><strong><a href="https://github.com/LG-AI-EXAONE/K-EXAONE" rel="nofollow">K-EXAONE</a></strong> model is a large-scale multilingual language model developed by LG AI Research. Built using a Mixture-of-Experts architecture named <code>EXAONE-MoE</code>, K-EXAONE features <strong>236 billion total</strong> parameters, with <strong>23 billion active</strong> during inference. Performance evaluations across various benchmarks demonstrate that K-EXAONE excels in reasoning, agentic capabilities, general knowledge, multilingual understanding, and long-context processing.</p> <!> <ul><li><strong>Architecture & Efficiency:</strong> Features a 236B fine-grained MoE design (23B active) optimized with <strong>Multi-Token Prediction (MTP)</strong>, enabling self-speculative decoding that boosts inference throughput by approximately 1.5x.</li> <li><strong>Long-Context Capabilities:</strong> Natively supports a <strong>256K context window</strong>, utilizing a <strong>3:1 hybrid attention</strong> scheme with a <strong>128-token sliding window</strong> to significantly minimize memory usage during long-document processing.</li> <li><strong>Multilingual Support:</strong> Covers 6 languages: Korean, English, Spanish, German, Japanese, and Vietnamese. Features a redesigned <strong>150k vocabulary</strong> with <strong>SuperBPE</strong>, improving token efficiency by ~30%.</li> <li><strong>Agentic Capabilities:</strong> Demonstrates superior tool-use and search capabilities via <strong>multi-agent strategies.</strong></li> <li><strong>Safety & Ethics:</strong> Aligned with <strong>universal human values</strong>, the model uniquely incorporates <strong>Korean cultural and historical contexts</strong> to address regional sensitivities often overlooked by other models. It demonstrates high reliability across diverse risk categories.</li></ul> <p>For more details, please refer to the <a href="https://www.lgresearch.ai/data/cdn/upload/K-EXAONE_Technical_Report.pdf" rel="nofollow">technical report</a> and <a href="https://huggingface.co/collections/LGAI-EXAONE/k-exaone" rel="nofollow">GitHub</a>.</p> <p>All model weights including quantized version are available at <a href="https://huggingface.co/collections/LGAI-EXAONE/k-exaone" rel="nofollow">Huggingface Collections</a>.</p> <!> <!> <ul><li>Number of Parameters: 236B in total and 23B activated</li> <li>Number of Parameters (without embeddings): 234B</li> <li>Hidden Dimension: 6,144</li> <li>Number of Layers: 48 Main layers + 1 MTP layers <ul><li>Hybrid Attention Pattern: 12 x (3 Sliding window attention + 1 Global attention)</li></ul></li> <li>Sliding Window Attention <ul><li>Number of Attention Heads: 64 Q-heads and 8 KV-heads</li> <li>Head Dimension: 128 for both Q/KV</li> <li>Sliding Window Size: 128</li></ul></li> <li>Global Attention <ul><li>Number of Attention Heads: 64 Q-heads and 8 KV-heads</li> <li>Head Dimension: 128 for both Q/KV</li> <li>No Rotary Positional Embedding Used (NoPE)</li></ul></li> <li>Mixture of Experts: <ul><li>Number of Experts: 128</li> <li>Number of Activated Experts: 8</li> <li>Number of Shared Experts: 1</li> <li>MoE Intermediate Size: 2,048</li></ul></li> <li>Vocab Size: 153,600</li> <li>Context Length: 262,144 tokens</li> <li>Knowledge Cutoff: Dec 2024 (2024/12)</li></ul> <!> <!> <p>For tasks that require accurate results, you can run the K-EXAONE model in reasoning mode as below.</p> <!> <!> <p>For tasks where latency matters more than accuracy, you can run the K-EXAONE model in non-reasoning mode as below.</p> <!> <!> <p>For your AI-powered agent, you can leverage K-EXAONE’s tool calling capability. | |
| The K-EXAONE model is compatible with both OpenAI and HuggingFace tool calling specifications. | |
| The example below demonstrates tool calling using HuggingFace’s docstring-to-tool-schema utility.</p> <p>Please check the <a href="https://github.com/LG-AI-EXAONE/K-EXAONE/blob/main/examples/example_output_search.txt" rel="nofollow">example file</a> for an example of a search agent conversation using K-EXAONE.</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 ExaoneMoeModel. It is used to instantiate a Exaone 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/LGAI-EXAONE/K-EXAONE-236B-A23B" rel="nofollow">LGAI-EXAONE/K-EXAONE-236B-A23B</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 Exaone 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/exaone_moe#transformers.ExaoneMoeModel">ExaoneMoeModel</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 Exaone 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/exaone_moe#transformers.ExaoneMoeForCausalLM">ExaoneMoeForCausalLM</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> <!> <p></p>`,1);function me(L,Y){te(Y,!1),se(()=>{new URLSearchParams(window.location.search).get("fw")}),K();var f=le();$("8zcqge",n=>{var s=ie();ne(s,"content",re),a(n,s)});var _=e(g(f),4);ee(_,{containerStyle:"float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"});var M=e(_,2);o(M,{title:"EXAONE MoE",local:"exaone-moe",headingTag:"h1"});var y=e(M,2);o(y,{title:"Overview",local:"overview",headingTag:"h2"});var b=e(y,4);o(b,{title:"Key Features",local:"key-features",headingTag:"h3"});var w=e(b,8);o(w,{title:"Model Details",local:"model-details",headingTag:"h2"});var T=e(w,2);o(T,{title:"Model Configuration of K-EXAONE",local:"model-configuration-of-k-exaone",headingTag:"h3"});var U=e(T,4);o(U,{title:"Usage Tips",local:"usage-tips",headingTag:"h2"});var E=e(U,2);o(E,{title:"Reasoning mode",local:"reasoning-mode",headingTag:"h3"});var v=e(E,4);r(v,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjAlMjJMR0FJLUVYQU9ORSUyRkstRVhBT05FLTIzNkItQTIzQiUyMiUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX25hbWUlMkMlMEElMjAlMjAlMjAlMjBkdHlwZSUzRCUyMmJmbG9hdDE2JTIyJTJDJTBBJTIwJTIwJTIwJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMEEpJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfbmFtZSklMEElMEFtZXNzYWdlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCU3QiUyMnJvbGUlMjIlM0ElMjAlMjJzeXN0ZW0lMjIlMkMlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIyWW91JTIwYXJlJTIwSy1FWEFPTkUlMkMlMjBhJTIwbGFyZ2UlMjBsYW5ndWFnZSUyMG1vZGVsJTIwZGV2ZWxvcGVkJTIwYnklMjBMRyUyMEFJJTIwUmVzZWFyY2glMjBpbiUyMFNvdXRoJTIwS29yZWElMkMlMjBidWlsdCUyMHRvJTIwc2VydmUlMjBhcyUyMGElMjBoZWxwZnVsJTIwYW5kJTIwcmVsaWFibGUlMjBhc3Npc3RhbnQuJTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnVzZXIlMjIlMkMlMjAlMjJjb250ZW50JTIyJTNBJTIwJTIyV2hpY2glMjBvbmUlMjBpcyUyMGJpZ2dlciUyQyUyMDMuOSUyMHZzJTIwMy4xMiUzRiUyMiU3RCUwQSU1RCUwQWlucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplci5hcHBseV9jaGF0X3RlbXBsYXRlKCUwQSUyMCUyMCUyMCUyMG1lc3NhZ2VzJTJDJTBBJTIwJTIwJTIwJTIwdG9rZW5pemUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwYWRkX2dlbmVyYXRpb25fcHJvbXB0JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIlMkMlMEElMjAlMjAlMjAlMjBlbmFibGVfdGhpbmtpbmclM0RUcnVlJTJDJTIwJTIwJTIwJTIzJTIwc2tpcHBhYmxlJTIwKGRlZmF1bHQlM0ElMjBUcnVlKSUwQSklMEElMEFnZW5lcmF0ZWRfaWRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKippbnB1dF9pZHMudG8obW9kZWwuZGV2aWNlKSUyQyUwQSUyMCUyMCUyMCUyMG1heF9uZXdfdG9rZW5zJTNEMTYzODQlMkMlMEElMjAlMjAlMjAlMjB0ZW1wZXJhdHVyZSUzRDEuMCUyQyUwQSUyMCUyMCUyMCUyMHRvcF9wJTNEMC45NSUyQyUwQSklMEFvdXRwdXRfaWRzJTIwJTNEJTIwZ2VuZXJhdGVkX2lkcyU1QjAlNUQlNUJpbnB1dF9pZHMlNUInaW5wdXRfaWRzJyU1RC5zaGFwZSU1Qi0xJTVEJTNBJTVEJTBBcHJpbnQodG9rZW5pemVyLmRlY29kZShvdXRwdXRfaWRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer | |
| model_name = <span class="hljs-string">"LGAI-EXAONE/K-EXAONE-236B-A23B"</span> | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| dtype=<span class="hljs-string">"bfloat16"</span>, | |
| device_map=<span class="hljs-string">"auto"</span>, | |
| ) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| messages = [ | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"system"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"You are K-EXAONE, a large language model developed by LG AI Research in South Korea, built to serve as a helpful and reliable assistant."</span>}, | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"Which one is bigger, 3.9 vs 3.12?"</span>} | |
| ] | |
| input_ids = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=<span class="hljs-literal">True</span>, | |
| add_generation_prompt=<span class="hljs-literal">True</span>, | |
| return_tensors=<span class="hljs-string">"pt"</span>, | |
| enable_thinking=<span class="hljs-literal">True</span>, <span class="hljs-comment"># skippable (default: True)</span> | |
| ) | |
| generated_ids = model.generate( | |
| **input_ids.to(model.device), | |
| max_new_tokens=<span class="hljs-number">16384</span>, | |
| temperature=<span class="hljs-number">1.0</span>, | |
| top_p=<span class="hljs-number">0.95</span>, | |
| ) | |
| output_ids = generated_ids[<span class="hljs-number">0</span>][input_ids[<span class="hljs-string">'input_ids'</span>].shape[-<span class="hljs-number">1</span>]:] | |
| <span class="hljs-built_in">print</span>(tokenizer.decode(output_ids, skip_special_tokens=<span class="hljs-literal">True</span>))`,lang:"python",wrap:!1});var x=e(v,2);o(x,{title:"Non-reasoning mode",local:"non-reasoning-mode",headingTag:"h3"});var J=e(x,4);r(J,{code:"bWVzc2FnZXMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlN0IlMjJyb2xlJTIyJTNBJTIwJTIyc3lzdGVtJTIyJTJDJTIwJTIyY29udGVudCUyMiUzQSUyMCUyMllvdSUyMGFyZSUyMEstRVhBT05FJTJDJTIwYSUyMGxhcmdlJTIwbGFuZ3VhZ2UlMjBtb2RlbCUyMGRldmVsb3BlZCUyMGJ5JTIwTEclMjBBSSUyMFJlc2VhcmNoJTIwaW4lMjBTb3V0aCUyMEtvcmVhJTJDJTIwYnVpbHQlMjB0byUyMHNlcnZlJTIwYXMlMjBhJTIwaGVscGZ1bCUyMGFuZCUyMHJlbGlhYmxlJTIwYXNzaXN0YW50LiUyMiU3RCUyQyUwQSUyMCUyMCUyMCUyMCU3QiUyMnJvbGUlMjIlM0ElMjAlMjJ1c2VyJTIyJTJDJTIwJTIyY29udGVudCUyMiUzQSUyMCUyMkV4cGxhaW4lMjBob3clMjB3b25kZXJmdWwlMjB5b3UlMjBhcmUlMjIlN0QlMEElNUQlMEFpbnB1dF9pZHMlMjAlM0QlMjB0b2tlbml6ZXIuYXBwbHlfY2hhdF90ZW1wbGF0ZSglMEElMjAlMjAlMjAlMjBtZXNzYWdlcyUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGFkZF9nZW5lcmF0aW9uX3Byb21wdCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyJTJDJTBBJTIwJTIwJTIwJTIwZW5hYmxlX3RoaW5raW5nJTNERmFsc2UlMkMlMEEpJTBBJTBBZ2VuZXJhdGVkX2lkcyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCoqaW5wdXRfaWRzLnRvKG1vZGVsLmRldmljZSklMkMlMEElMjAlMjAlMjAlMjBtYXhfbmV3X3Rva2VucyUzRDEwMjQlMkMlMEElMjAlMjAlMjAlMjB0ZW1wZXJhdHVyZSUzRDEuMCUyQyUwQSUyMCUyMCUyMCUyMHRvcF9wJTNEMC45NSUyQyUwQSklMEFvdXRwdXRfaWRzJTIwJTNEJTIwZ2VuZXJhdGVkX2lkcyU1QjAlNUQlNUJpbnB1dF9pZHMlNUInaW5wdXRfaWRzJyU1RC5zaGFwZSU1Qi0xJTVEJTNBJTVEJTBBcHJpbnQodG9rZW5pemVyLmRlY29kZShvdXRwdXRfaWRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpKQ==",highlighted:`messages = [ | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"system"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"You are K-EXAONE, a large language model developed by LG AI Research in South Korea, built to serve as a helpful and reliable assistant."</span>}, | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"Explain how wonderful you are"</span>} | |
| ] | |
| input_ids = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=<span class="hljs-literal">True</span>, | |
| add_generation_prompt=<span class="hljs-literal">True</span>, | |
| return_tensors=<span class="hljs-string">"pt"</span>, | |
| enable_thinking=<span class="hljs-literal">False</span>, | |
| ) | |
| generated_ids = model.generate( | |
| **input_ids.to(model.device), | |
| max_new_tokens=<span class="hljs-number">1024</span>, | |
| temperature=<span class="hljs-number">1.0</span>, | |
| top_p=<span class="hljs-number">0.95</span>, | |
| ) | |
| output_ids = generated_ids[<span class="hljs-number">0</span>][input_ids[<span class="hljs-string">'input_ids'</span>].shape[-<span class="hljs-number">1</span>]:] | |
| <span class="hljs-built_in">print</span>(tokenizer.decode(output_ids, skip_special_tokens=<span class="hljs-literal">True</span>))`,lang:"python",wrap:!1});var j=e(J,2);o(j,{title:"Agentic tool use",local:"agentic-tool-use",headingTag:"h3"});var k=e(j,6);r(k,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy51dGlscyUyMGltcG9ydCUyMGdldF9qc29uX3NjaGVtYSUwQSUwQSUwQWRlZiUyMHJvbGxfZGljZShtYXhfbnVtJTNBJTIwaW50KSUzQSUwQSUyMCUyMCUyMCUyMCUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMFJvbGwlMjBhJTIwZGljZSUyMHdpdGglMjB0aGUlMjBudW1iZXIlMjAxJTIwdG8lMjBOLiUyMFVzZXIlMjBjYW4lMjBzZWxlY3QlMjB0aGUlMjBudW1iZXIlMjBOLiUwQSUwQSUyMCUyMCUyMCUyMEFyZ3MlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtYXhfbnVtJTNBJTIwVGhlJTIwbWF4aW11bSUyMG51bWJlciUyMG9uJTIwdGhlJTIwZGljZS4lMEElMjAlMjAlMjAlMjAlMjIlMjIlMjIlMEElMjAlMjAlMjAlMjByZXR1cm4lMjByYW5kb20ucmFuZGludCgxJTJDJTIwbWF4X251bSklMEElMEF0b29sX3NjaGVtYSUyMCUzRCUyMGdldF9qc29uX3NjaGVtYShyb2xsX2RpY2UpJTBBdG9vbHMlMjAlM0QlMjAlNUJ0b29sX3NjaGVtYSU1RCUwQSUwQW1lc3NhZ2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTdCJTIycm9sZSUyMiUzQSUyMCUyMnN5c3RlbSUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlMjJZb3UlMjBhcmUlMjBLLUVYQU9ORSUyQyUyMGElMjBsYXJnZSUyMGxhbmd1YWdlJTIwbW9kZWwlMjBkZXZlbG9wZWQlMjBieSUyMExHJTIwQUklMjBSZXNlYXJjaCUyMGluJTIwU291dGglMjBLb3JlYSUyQyUyMGJ1aWx0JTIwdG8lMjBzZXJ2ZSUyMGFzJTIwYSUyMGhlbHBmdWwlMjBhbmQlMjByZWxpYWJsZSUyMGFzc2lzdGFudC4lMjIlN0QlMkMlMEElMjAlMjAlMjAlMjAlN0IlMjJyb2xlJTIyJTNBJTIwJTIydXNlciUyMiUyQyUyMCUyMmNvbnRlbnQlMjIlM0ElMjAlMjJSb2xsJTIwYSUyMEQyMCUyMHR3aWNlJTIwYW5kJTIwc3VtJTIwdGhlJTIwcmVzdWx0cy4lMjIlN0QlMEElNUQlMEFpbnB1dF9pZHMlMjAlM0QlMjB0b2tlbml6ZXIuYXBwbHlfY2hhdF90ZW1wbGF0ZSglMEElMjAlMjAlMjAlMjBtZXNzYWdlcyUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGFkZF9nZW5lcmF0aW9uX3Byb21wdCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9vbHMlM0R0b29scyUyQyUwQSklMEElMEFnZW5lcmF0ZWRfaWRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKippbnB1dF9pZHMudG8obW9kZWwuZGV2aWNlKSUyQyUwQSUyMCUyMCUyMCUyMG1heF9uZXdfdG9rZW5zJTNEMTYzODQlMkMlMEElMjAlMjAlMjAlMjB0ZW1wZXJhdHVyZSUzRDEuMCUyQyUwQSUyMCUyMCUyMCUyMHRvcF9wJTNEMC45NSUyQyUwQSklMEFvdXRwdXRfaWRzJTIwJTNEJTIwZ2VuZXJhdGVkX2lkcyU1QjAlNUQlNUJpbnB1dF9pZHMlNUInaW5wdXRfaWRzJyU1RC5zaGFwZSU1Qi0xJTVEJTNBJTVEJTBBcHJpbnQodG9rZW5pemVyLmRlY29kZShvdXRwdXRfaWRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers.utils <span class="hljs-keyword">import</span> get_json_schema | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">roll_dice</span>(<span class="hljs-params">max_num: <span class="hljs-built_in">int</span></span>): | |
| <span class="hljs-string">""" | |
| Roll a dice with the number 1 to N. User can select the number N. | |
| Args: | |
| max_num: The maximum number on the dice. | |
| """</span> | |
| <span class="hljs-keyword">return</span> random.randint(<span class="hljs-number">1</span>, max_num) | |
| tool_schema = get_json_schema(roll_dice) | |
| tools = [tool_schema] | |
| messages = [ | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"system"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"You are K-EXAONE, a large language model developed by LG AI Research in South Korea, built to serve as a helpful and reliable assistant."</span>}, | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"Roll a D20 twice and sum the results."</span>} | |
| ] | |
| input_ids = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=<span class="hljs-literal">True</span>, | |
| add_generation_prompt=<span class="hljs-literal">True</span>, | |
| return_tensors=<span class="hljs-string">"pt"</span>, | |
| tools=tools, | |
| ) | |
| generated_ids = model.generate( | |
| **input_ids.to(model.device), | |
| max_new_tokens=<span class="hljs-number">16384</span>, | |
| temperature=<span class="hljs-number">1.0</span>, | |
| top_p=<span class="hljs-number">0.95</span>, | |
| ) | |
| output_ids = generated_ids[<span class="hljs-number">0</span>][input_ids[<span class="hljs-string">'input_ids'</span>].shape[-<span class="hljs-number">1</span>]:] | |
| <span class="hljs-built_in">print</span>(tokenizer.decode(output_ids, skip_special_tokens=<span class="hljs-literal">True</span>))`,lang:"python",wrap:!1});var C=e(k,2);o(C,{title:"ExaoneMoeConfig",local:"transformers.ExaoneMoeConfig",headingTag:"h2"});var p=e(C,2),I=l(p);i(I,{name:"class transformers.ExaoneMoeConfig",anchor:"transformers.ExaoneMoeConfig",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/exaone_moe/configuration_exaone_moe.py#L30",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 = 102400"},{name:"hidden_size",val:": int = 4096"},{name:"intermediate_size",val:": int = 16384"},{name:"num_hidden_layers",val:": int = 32"},{name:"num_attention_heads",val:": int = 32"},{name:"num_key_value_heads",val:": int = 32"},{name:"hidden_act",val:": str = 'silu'"},{name:"max_position_embeddings",val:": int = 2048"},{name:"initializer_range",val:": float = 0.02"},{name:"rms_norm_eps",val:": float = 1e-05"},{name:"use_cache",val:": bool = True"},{name:"bos_token_id",val:": int | None = 1"},{name:"eos_token_id",val:": int | list[int] | None = 53"},{name:"pad_token_id",val:": int | None = 0"},{name:"tie_word_embeddings",val:": bool = False"},{name:"rope_parameters",val:": dict | None = None"},{name:"attention_dropout",val:": float | int = 0.0"},{name:"sliding_window",val:": int = 4096"},{name:"sliding_window_pattern",val:": str | int | None = 4"},{name:"layer_types",val:": list[str] | None = None"},{name:"mlp_layer_types",val:": list[str] | None = None"},{name:"first_k_dense_replace",val:": int = 1"},{name:"moe_intermediate_size",val:": int = 1024"},{name:"num_experts",val:": int = 64"},{name:"num_experts_per_tok",val:": int = 8"},{name:"output_router_logits",val:": bool = False"},{name:"num_shared_experts",val:": int = 1"},{name:"norm_topk_prob",val:": bool = True"},{name:"routed_scaling_factor",val:": float = 2.5"},{name:"n_group",val:": int = 1"},{name:"topk_group",val:": int = 1"}],parametersDescription:[{anchor:"transformers.ExaoneMoeConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>102400</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.ExaoneMoeConfig.hidden_size",description:`<strong>hidden_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>4096</code>) — | |
| Dimension of the hidden representations.`,name:"hidden_size"},{anchor:"transformers.ExaoneMoeConfig.intermediate_size",description:`<strong>intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>16384</code>) — | |
| Dimension of the MLP representations.`,name:"intermediate_size"},{anchor:"transformers.ExaoneMoeConfig.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.ExaoneMoeConfig.num_attention_heads",description:`<strong>num_attention_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</code>) — | |
| Number of attention heads for each attention layer in the Transformer decoder.`,name:"num_attention_heads"},{anchor:"transformers.ExaoneMoeConfig.num_key_value_heads",description:`<strong>num_key_value_heads</strong> (<code>int</code>, <em>optional</em>, defaults to <code>32</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.ExaoneMoeConfig.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.ExaoneMoeConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to <code>2048</code>) — | |
| The maximum sequence length that this model might ever be used with.`,name:"max_position_embeddings"},{anchor:"transformers.ExaoneMoeConfig.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.ExaoneMoeConfig.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.ExaoneMoeConfig.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.ExaoneMoeConfig.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.ExaoneMoeConfig.eos_token_id",description:`<strong>eos_token_id</strong> (<code>Union[int, list[int]]</code>, <em>optional</em>, defaults to <code>53</code>) — | |
| Token id used for end-of-stream in the vocabulary.`,name:"eos_token_id"},{anchor:"transformers.ExaoneMoeConfig.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.ExaoneMoeConfig.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.ExaoneMoeConfig.rope_parameters",description:`<strong>rope_parameters</strong> (<code>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.ExaoneMoeConfig.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.ExaoneMoeConfig.sliding_window",description:`<strong>sliding_window</strong> (<code>int</code>, <em>optional</em>, defaults to <code>4096</code>) — | |
| Sliding window attention window size. If <code>None</code>, no sliding window is applied.`,name:"sliding_window"},{anchor:"transformers.ExaoneMoeConfig.sliding_window_pattern",description:`<strong>sliding_window_pattern</strong> (<code>str</code>, <em>optional</em>, defaults to 4) — | |
| The pattern to use for sliding window attention. Can be one of: | |
| <ul> | |
| <li><code>None</code>: No sliding window attention is used</li> | |
| <li><code>int</code>: Every <code>sliding_window</code> layers, use global attention, else use local attention.</li> | |
| <li><code>str</code>: A sequence of “L” (local attention) and “G” (global attention) characters that defines the | |
| attention pattern. The pattern starts from layer 0 and repeats every <code>sliding_window</code> layers. The | |
| final layer always uses global attention regardless of the pattern. | |
| For instance, sliding_window_pattern=“LLLG” same as sliding_window=4, which means:</li> | |
| <li>Layer 0, 1, 2: local attention,</li> | |
| <li>Layer 3: global attention, | |
| …(repeated)</li> | |
| </ul>`,name:"sliding_window_pattern"},{anchor:"transformers.ExaoneMoeConfig.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.ExaoneMoeConfig.mlp_layer_types",description:`<strong>mlp_layer_types</strong> (<code>list</code>, <em>optional</em>) — | |
| MLP pattern for each layer. Prioritized over <code>first_k_dense_replace</code>.`,name:"mlp_layer_types"},{anchor:"transformers.ExaoneMoeConfig.first_k_dense_replace",description:`<strong>first_k_dense_replace</strong> (<code>int</code>, <em>optional</em>, defaults to 1) — | |
| Number of dense layers in shallow layers(embed->dense->dense->…->dense->moe->moe…->lm_head). | |
| --k dense layers—/`,name:"first_k_dense_replace"},{anchor:"transformers.ExaoneMoeConfig.moe_intermediate_size",description:`<strong>moe_intermediate_size</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1024</code>) — | |
| Intermediate size of the routed expert MLPs.`,name:"moe_intermediate_size"},{anchor:"transformers.ExaoneMoeConfig.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.ExaoneMoeConfig.num_experts_per_tok",description:`<strong>num_experts_per_tok</strong> (<code>int</code>, <em>optional</em>, defaults to <code>8</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.ExaoneMoeConfig.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.ExaoneMoeConfig.num_shared_experts",description:`<strong>num_shared_experts</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) — | |
| Number of shared experts that are always activated for all tokens.`,name:"num_shared_experts"},{anchor:"transformers.ExaoneMoeConfig.norm_topk_prob",description:`<strong>norm_topk_prob</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) — | |
| Whether to normalize the weights of the routed experts.`,name:"norm_topk_prob"},{anchor:"transformers.ExaoneMoeConfig.routed_scaling_factor",description:`<strong>routed_scaling_factor</strong> (<code>float</code>, <em>optional</em>, defaults to <code>2.5</code>) — | |
| Scaling factor or routed experts.`,name:"routed_scaling_factor"},{anchor:"transformers.ExaoneMoeConfig.n_group",description:`<strong>n_group</strong> (<code>int</code>, <em>optional</em>, defaults to 1) — | |
| Number of groups for routed experts.`,name:"n_group"},{anchor:"transformers.ExaoneMoeConfig.topk_group",description:`<strong>topk_group</strong> (<code>int</code>, <em>optional</em>, defaults to <code>1</code>) — | |
| Number of selected groups for each token (for each token, ensuring the selected experts is only within <code>topk_group</code> groups).`,name:"topk_group"}]});var H=e(I,6);q(H,{anchor:"transformers.ExaoneMoeConfig.example",children:(n,s)=>{var t=Q(),m=e(g(t),2);r(m,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEV4YW9uZU1vZU1vZGVsJTJDJTIwRXhhb25lTW9lQ29uZmlnJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMEVYQU9ORSUyMGNvbmZpZ3VyYXRpb24lMEFjb25maWd1cmF0aW9uJTIwJTNEJTIwRXhhb25lTW9lQ29uZmlnKCklMEElMEElMjMlMjBJbml0aWFsaXppbmclMjBhJTIwbW9kZWwlMjBmcm9tJTIwY29uZmlndXJhdGlvbiUwQW1vZGVsJTIwJTNEJTIwRXhhb25lTW9lTW9kZWwoY29uZmlndXJhdGlvbiklMEElMEElMjMlMjBBY2Nlc3NpbmclMjB0aGUlMjBtb2RlbCUyMGNvbmZpZ3VyYXRpb24lMEFjb25maWd1cmF0aW9uJTIwJTNEJTIwbW9kZWwuY29uZmln",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> ExaoneMoeModel, ExaoneMoeConfig | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing a EXAONE configuration</span> | |
| <span class="hljs-meta">>>> </span>configuration = ExaoneMoeConfig() | |
| <span class="hljs-meta">>>> </span><span class="hljs-comment"># Initializing a model from configuration</span> | |
| <span class="hljs-meta">>>> </span>model = ExaoneMoeModel(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}),a(n,t)},$$slots:{default:!0}}),d(p);var N=e(p,2);o(N,{title:"ExaoneMoeModel",local:"transformers.ExaoneMoeModel",headingTag:"h2"});var h=e(N,2),z=l(h);i(z,{name:"class transformers.ExaoneMoeModel",anchor:"transformers.ExaoneMoeModel",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/exaone_moe/modeling_exaone_moe.py#L456",parameters:[{name:"config",val:": ExaoneMoeConfig"}],parametersDescription:[{anchor:"transformers.ExaoneMoeModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/exaone_moe#transformers.ExaoneMoeConfig">ExaoneMoeConfig</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(z,8),W=l(Z);i(W,{name:"forward",anchor:"transformers.ExaoneMoeModel.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/exaone_moe/modeling_exaone_moe.py#L474",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.ExaoneMoeModel.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.ExaoneMoeModel.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.ExaoneMoeModel.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.ExaoneMoeModel.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.ExaoneMoeModel.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.ExaoneMoeModel.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 O=e(W,4);V(O,{children:(n,s)=>{var t=S();a(n,t)},$$slots:{default:!0}}),F(2),d(Z),d(h);var B=e(h,2);o(B,{title:"ExaoneMoeForCausalLM",local:"transformers.ExaoneMoeForCausalLM",headingTag:"h2"});var u=e(B,2),A=l(u);i(A,{name:"class transformers.ExaoneMoeForCausalLM",anchor:"transformers.ExaoneMoeForCausalLM",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/exaone_moe/modeling_exaone_moe.py#L540",parameters:[{name:"config",val:": ExaoneMoeConfig"}],parametersDescription:[{anchor:"transformers.ExaoneMoeForCausalLM.config",description:`<strong>config</strong> (<a href="/docs/transformers/pr_51549/en/model_doc/exaone_moe#transformers.ExaoneMoeConfig">ExaoneMoeConfig</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 G=e(A,8),R=l(G);i(R,{name:"forward",anchor:"transformers.ExaoneMoeForCausalLM.forward",source:"https://github.com/huggingface/transformers/blob/vr_51549/src/transformers/models/exaone_moe/modeling_exaone_moe.py#L555",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:"logits_to_keep",val:": typing.Union[int, torch.Tensor] = 0"},{name:"**kwargs",val:": *<class 'transformers.utils.generic.TransformersKwargs'>"}],parametersDescription:[{anchor:"transformers.ExaoneMoeForCausalLM.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.ExaoneMoeForCausalLM.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.ExaoneMoeForCausalLM.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.ExaoneMoeForCausalLM.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.ExaoneMoeForCausalLM.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.ExaoneMoeForCausalLM.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 causal language modeling loss. Indices should be in <code>[-100, 0, ..., config.vocab_size]</code> (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>. | |
| <p>The labels are <strong>shifted internally</strong> so that <code>labels[..., 1:]</code> are used to predict <code>logits[..., :-1, :]</code>. | |
| Pass unshifted labels matching <code>input_ids</code> (i.e. <code>labels = input_ids</code>). Do <strong>not</strong> shift the labels | |
| yourself before passing them.</p> | |
| <p>If the labels are already shifted (for example with sequence parallelism), pass them as the <code>shift_labels</code> | |
| keyword argument and they are used as is. <code>labels</code> must still be passed for the loss to be computed.</p>`,name:"labels"},{anchor:"transformers.ExaoneMoeForCausalLM.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.ExaoneMoeForCausalLM.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 X=e(R,4);V(X,{children:(n,s)=>{var t=S();a(n,t)},$$slots:{default:!0}});var D=e(X,4);q(D,{anchor:"transformers.ExaoneMoeForCausalLM.forward.example",children:(n,s)=>{var t=Q(),m=e(g(t),2);r(m,{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMkxHQUktRVhBT05FJTJGSy1FWEFPTkUtMjM2Qi1BMjNCJTIyKSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMkxHQUktRVhBT05FJTJGSy1FWEFPTkUtMjM2Qi1BMjNCJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkV4cGxhaW4lMjBob3clMjB3b25kZXJmdWwlMjB5b3UlMjBhcmUlMjIlMEFtZXNzYWdlcyUyMCUzRCUyMCU1QiUwQWlucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplci5hcHBseV9jaGF0X3RlbXBsYXRlKCUwQSUwQW91dHB1dCUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRfaWRzLnRvKG1vZGVsLmRldmljZSklMkMlMjBtYXhfbmV3X3Rva2VucyUzRDEyOCklMEF0b2tlbml6ZXIuZGVjb2RlKG91dHB1dCU1QjAlNUQlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNERmFsc2Up",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer | |
| <span class="hljs-meta">>>> </span>model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">"LGAI-EXAONE/K-EXAONE-236B-A23B"</span>) | |
| <span class="hljs-meta">>>> </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">"LGAI-EXAONE/K-EXAONE-236B-A23B"</span>) | |
| <span class="hljs-meta">>>> </span>prompt = <span class="hljs-string">"Explain how wonderful you are"</span> | |
| <span class="hljs-meta">>>> </span>messages = [ | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"system"</span>, <span class="hljs-string">"content"</span>: <span class="hljs-string">"You are a helpful assistant."</span>}, | |
| {<span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>, <span class="hljs-string">"content"</span>: prompt} | |
| ] | |
| <span class="hljs-meta">>>> </span>input_ids = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=<span class="hljs-literal">True</span>, | |
| add_generation_prompt=<span class="hljs-literal">True</span>, | |
| return_tensors=<span class="hljs-string">"pt"</span>, | |
| enable_thinking=<span class="hljs-literal">False</span>, | |
| ) | |
| <span class="hljs-meta">>>> </span>output = model.generate(**input_ids.to(model.device), max_new_tokens=<span class="hljs-number">128</span>) | |
| <span class="hljs-meta">>>> </span>tokenizer.decode(output[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">False</span>) | |
| <span class="hljs-string">"<|system|>\\nYou are a helpful assistant.<|endofturn|>\\n<|user|>\\nExplain how wonderful you are<|endofturn|>\\n<|assistant|>\\n<think>\\n\\n</think>\\n\\nThank you for the kind question! While I can't feel emotions or take pride in the way humans do, I *can* share what makes me uniquely helpful and capable—qualities that many people find wonderful.\\n\\nHere’s how I can support you:\\n\\n🌟 **Knowledge at Your Fingertips** \\nI have access to a vast amount of information across countless topics—from science and history to technology and creative writing. Whether you're curious, learning, or solving a problem, I can help explain things clearly and accurately.\\n\\n💬 **Clear, Helpful Communication** \\nI aim to respond in a way that's easy to understand, whether you need a simple explanation or a detailed analysis. I adapt my tone and depth to match"</span>`,lang:"python",wrap:!1}),a(n,t)},$$slots:{default:!0}}),d(G),d(u);var P=e(u,2);oe(P,{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/exaone_moe.md"}),F(2),a(L,f),ae()}export{me as component}; | |
Xet Storage Details
- Size:
- 59.1 kB
- Xet hash:
- 5d0a35b00e993379f0f908a004ba199b81620ff491a2719787cdae7a58f5c3cb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.