After decoding, look at the representation computation that precedes logits. Follow a position through attention, feed-forward transformations and expert routing. Weight residency and KV storage are covered next, so architectural structure and deployment capacity can be reasoned about separately.
How a Decoder Layer Updates Representations
This article uses the common structure of an autoregressive Transformer decoder as an example. Token IDs are first mapped into vectors; the model also needs to represent positional information. Positional information can be introduced via positional embeddings or position-related transformations on vectors in attention, and not all models simply add the two embeddings together.
A layer typically contains attention, a feed-forward network (FFN), residual connections, and normalization. The diagram below illustrates the pre-norm form for ease of understanding; original Transformers and subsequent models differ in normalization placement, activation functions, and positional mechanisms. Attention Is All You Need
Input Representation x One vector per position u = x + Attention(Norm(x)) Causal attention mixes allowed positions y = u + FFN(Norm(u)) A Simplified pre-norm Decoder Layer FFN transforms per position; MoE can replace this After repeating multiple layers, logits are obtained via output projection; normalization positions and specific FFN forms vary by architecture.
Attention: How Current Representations Leverage Other Positions
For the input matrix X, linear projections yield Q=XWQ, K=XWK, V=XWV. The query at a specific position performs a dot product with keys from allowed positions, followed by scaling, masking, and softmax to obtain weights, which are then used to compute a weighted sum of values. A single head is often written as:
Attention(Q,K,V) = softmax(QKᵀ/√dₖ + M)V
The causal mask M prevents future positions from participating in the current position's attention, typically allowing access to the current position and all preceding positions . The representation at position i is used to predict subsequent tokens, so including the current position does not constitute peeking at unknown future information. Multi-head attention divides this computation into multiple groups and then merges the results; one cannot conclude that a specific head is responsible for fixed semantics or fully explain the model's judgment based on a single attention map.
Consider a masking example with three positions: if the original scores for the second position against all three positions are zero, the third position becomes inaccessible after masking, and the first two positions each receive a weight of 1/2. If the corresponding values are [2,0], [0,4], and [99,99], the result is [1,2], preventing large numbers from future positions from interfering. Only the third position is qualified to combine information from the first three positions.
FFN, Residuals, and Layer Depth
The FFN typically performs a linear transformation on the vector at each position, applies non-linear activation, and projects back to the model dimension; modern implementations often use gating mechanisms. "Per position" here means this sub-layer does not directly mix information across positions, but the input already carries information aggregated by previous attention layers. Attention and FFN jointly constitute representation computation across multiple layers; it is an oversimplification to divide them into "attention only looks, FFN only thinks."
Residual connections add the sub-layer's increment back to the original representation, providing direct paths for information and gradients; normalization helps control numerical scales. Increasing the number of layers changes the depth of sequential transformations, while increasing the number of experts primarily changes the set of selectable parameters; these two types of "scaling up" are not equivalent. The number of activated parameters is also not a measure of the number of inference steps within the model.
How does masking change the weighted result?
Dot products and scaling produce relative scores, masking determines eligibility, and softmax allocates weight. Keep q at zero to isolate causality, then change q to inspect contributions. Highlighted weights do not constitute a complete explanation of a model.
α i = softmax i ( q K ⊤ / d k + M ) , o = i ∑ α i v i
Preparing the visual Try again
How does masking change the weighted result? Masked positions have zero weight; softmax distributes mass among accessible positions before weighting values.
{"id":"ai-attention-mask","title":"How does masking change the weighted result?","summary":"Masked positions have zero weight; softmax distributes mass among accessible positions before weighting values.","height":1000,"html":"<h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p><div class=\"control\"><label for=\"pos\" data-i18n=\"pos\"></label><output for=\"pos\" id=\"pos-value\"></output><input id=\"pos\" type=\"range\" min=\"1\" max=\"3\" value=\"2\" step=\"1\"></div><div class=\"control\"><label for=\"qx\" data-i18n=\"qx\"></label><output for=\"qx\" id=\"qx-value\"></output><input id=\"qx\" type=\"range\" min=\"-2\" max=\"2\" value=\"0\" step=\"0.25\"></div><div class=\"control\"><label for=\"qy\" data-i18n=\"qy\"></label><output for=\"qy\" id=\"qy-value\"></output><input id=\"qy\" type=\"range\" min=\"-2\" max=\"2\" value=\"0\" step=\"0.25\"></div><label class=\"check\"><input type=\"checkbox\" id=\"future\"><span data-i18n=\"future\"></span></label><section class=\"panel\"><h3 data-i18n=\"weights\"></h3><div id=\"matrix\"></div></section><div class=\"metrics\"><div><span data-i18n=\"output\"></span><strong id=\"output\"></strong></div><div><span data-i18n=\"mass\"></span><strong id=\"mass\"></strong></div></div><div id=\"math\" class=\"formula\"></div><div class=\"copy\"><p id=\"explanation\" role=\"status\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"explain\"></p></div><details class=\"scope\"><summary data-i18n=\"scopeLabel\"></summary><p data-i18n=\"scope\"></p></details>","css":".intro{margin:8px 0 18px;color:var(--muted);font-size:14px}.control{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:6px 12px;align-items:center;margin:14px 0;font-size:13px}.control output{color:var(--accent);text-align:right;font-variant-numeric:tabular-nums;min-width:4em}.control input{grid-column:1/-1;width:100%;margin:0}.presets{display:flex;gap:4px;align-items:stretch}.presets button{flex:1;min-width:0;overflow-wrap:anywhere;font-size:13px;min-height:44px}.actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:16px 0}.actions button{min-width:0;min-height:44px;font-size:13px;overflow-wrap:anywhere}.copy{display:grid;font-size:14px;margin:16px 0}.copy>*{grid-area:1/1;margin:0;overflow-wrap:anywhere}.reserve{visibility:hidden}.scope{margin-top:14px;color:var(--muted);font-size:12px}.scope summary{padding:8px 0;cursor:pointer}.scope p{margin-top:10px;overflow-wrap:anywhere}.metrics{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;margin:18px 0}.metrics>div{border-left:2px solid var(--accent);padding:0 6px 0 10px;min-width:0}.metrics span{display:block;min-height:3.6em;color:var(--muted);font-size:12px;overflow-wrap:anywhere}.metrics strong{font-size:21px;display:block;min-height:2em;font-weight:550;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.check{display:flex;align-items:center;gap:9px;font-size:13px;margin:14px 0}.check input{width:18px;height:18px;flex-shrink:0;accent-color:var(--accent)}select,input[type=text],input[type=number]{background:var(--paper);color:var(--ink);font:inherit;font-size:14px;padding:10px;border:1px solid var(--rule);border-radius:7px;max-width:100%;min-width:0}select{width:100%;min-height:44px}.panel{padding:14px;border:1px solid var(--rule);border-radius:9px;margin:16px 0;min-width:0}.panel>header{font-size:13px;font-weight:600;margin-bottom:12px;color:var(--muted)}.panel>div{overflow-wrap:anywhere}.track-row{margin:16px 0}.track-row>span{display:block;font-size:12px;color:var(--muted);margin-bottom:8px}.track{display:flex;gap:5px;min-width:0}.cell{flex:1;min-width:0;min-height:56px;border:1px solid var(--rule);border-radius:5px;background:var(--surface);display:flex;align-items:center;justify-content:center;text-align:center;padding:6px 3px;font-size:12px;overflow-wrap:anywhere}.cell.on{background:var(--accent-soft);border-color:var(--accent)}.cell.gold{background:var(--second-soft);border-color:var(--second)}.cell.empty{border-style:dashed;color:var(--muted)}.cell.error{border-color:var(--second);text-decoration:line-through}.table{display:grid;gap:5px;font-size:12px}.tr{display:grid;gap:5px}.tr>div{background:var(--surface);border-radius:4px;padding:9px 6px;min-width:0;min-height:5em;overflow-wrap:anywhere;display:flex;align-items:center}.tr>.gold{background:var(--second-soft)}.tr>.on{background:var(--accent-soft)}.formula,.source{font:13px/1.8 ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere;margin:16px 0}.formula{border-top:1px solid var(--rule);padding-top:12px;min-height:7.2em}.source{min-height:8em;background:var(--surface);padding:12px;border-radius:8px}.intervals{margin:16px 0}.interval{position:relative;height:38px;background:var(--surface);margin:6px 0;border-radius:4px;overflow:hidden}.interval i{position:absolute;height:100%;background:var(--accent-soft);border-left:2px solid var(--accent)}.interval i.gold{background:var(--second-soft);border-color:var(--second)}.interval span{position:relative;z-index:1;font:12px/38px ui-monospace,monospace;padding-left:7px}.bars{display:grid;gap:10px;margin:16px 0}.bar-row{display:grid;grid-template-columns:44px minmax(0,1fr) 62px;gap:8px;align-items:center;font:12px ui-monospace,monospace}.bar-track{height:24px;background:var(--surface);border-radius:4px;overflow:hidden}.bar-track i{display:block;height:100%;background:var(--accent);transition:width .2s}.bar-track i.gold{background:var(--second)}.bar-track i.empty{opacity:.2}.bar-row output{text-align:right}.diagram{display:block;width:100%;height:auto;margin:18px 0}.diagram text{font:13px ui-monospace,monospace;fill:var(--ink)}.node{fill:var(--surface);stroke:var(--rule)}.node.on{fill:var(--accent-soft);stroke:var(--accent)}.node.gold{fill:var(--second-soft);stroke:var(--second)}.edge{stroke:var(--rule);stroke-width:2;fill:none}.edge.on{stroke:var(--accent)}.matrix{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin:16px 0}.matrix button{min-width:0;min-height:44px;font:13px ui-monospace,monospace}.matrix button[aria-pressed=true]{background:var(--accent-soft);border-color:var(--accent)}.matrix button.masked{opacity:.35}.legend{font-size:12px;color:var(--muted);min-height:3.6em;overflow-wrap:anywhere}.numeric{font-variant-numeric:tabular-nums}.scope p{line-break:strict}@media(max-width:480px){.presets button,.actions button{font-size:12px}.panel{padding:12px}.metrics{gap:10px}.metrics strong{font-size:19px}.bar-row{grid-template-columns:34px minmax(0,1fr) 58px;gap:6px}}@media(prefers-reduced-motion:reduce){*,*::before,*::after{transition:none!important;animation:none!important}}\n\n.panel>h3{font-size:13px;font-weight:600;margin:0 0 12px;color:var(--muted)}\n\n.bar-row{grid-template-columns:44px minmax(0,1fr) 82px}.bar-row output{white-space:nowrap}@media(max-width:480px){.bar-row{grid-template-columns:34px minmax(0,1fr) 76px}}\n\n.metrics strong{font-size:17px;min-height:3.6em}","js":"const $=s=>document.querySelector(s);const set=(id,v)=>$('#'+id).textContent=v;const t=k=>viz.t(k);function cells(id,values){$('#'+id).replaceChildren(...values.map(v=>{const e=document.createElement('div');e.className='cell '+(v.cls||'');e.textContent=v.text;e.title=v.title||v.text;return e;}));}function pressed(mode){document.querySelectorAll('[data-mode]').forEach(e=>e.setAttribute('aria-pressed',String(e.dataset.mode===mode)));}const esc=s=>String(s).replace(/[&<>\"']/g,c=>({'&':'&','<':'<','>':'>','\"':'"',\"'\":'''}[c]));const fmt=s=>'{'+[...s].sort().join(', ')+'}';function graph(id,nodes,edges){const el=$('#'+id);el.setAttribute('viewBox','0 0 360 200');el.innerHTML='<defs><marker id=\"arrow-'+id+'\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"5\" markerHeight=\"5\" orient=\"auto-start-reverse\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"var(--muted)\"/></marker></defs>'+edges.map(e=>{const a=nodes[e[0]],b=nodes[e[1]],dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy)||1;if(edges.some(r=>r[0]===e[1]&&r[1]===e[0])){const nx=-dy/d,ny=dx/d;return '<path class=\"edge '+(e[2]?'on':'')+'\" d=\"M '+(a.x+dx/d*22+nx*12)+' '+(a.y+dy/d*22+ny*12)+' Q '+((a.x+b.x)/2+nx*38)+' '+((a.y+b.y)/2+ny*38)+' '+(b.x-dx/d*25+nx*12)+' '+(b.y-dy/d*25+ny*12)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}return '<line class=\"edge '+(e[2]?'on':'')+'\" x1=\"'+(a.x+dx/d*25)+'\" y1=\"'+(a.y+dy/d*25)+'\" x2=\"'+(b.x-dx/d*28)+'\" y2=\"'+(b.y-dy/d*28)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}).join('')+nodes.map(n=>'<g><circle class=\"node '+(n.cls||'')+'\" cx=\"'+n.x+'\" cy=\"'+n.y+'\" r=\"25\"/><text x=\"'+n.x+'\" y=\"'+(n.y+4)+'\" text-anchor=\"middle\">'+esc(n.name)+'</text>'+(n.sub?'<text x=\"'+n.x+'\" y=\"'+(n.y+43)+'\" text-anchor=\"middle\">'+esc(n.sub)+'</text>':'')+'</g>').join('');}function table(id,rows){$('#'+id).classList.add('table');$('#'+id).replaceChildren(...rows.map(r=>{const row=document.createElement('div');row.className='tr';row.style.gridTemplateColumns='repeat('+r.length+',minmax(0,1fr))';r.forEach(x=>{const c=document.createElement('div');if(typeof x==='object'){c.textContent=x.text;c.className=x.cls||'';}else c.textContent=x;row.append(c)});return row;}));}function band(id,parts,total){$('#'+id).replaceChildren(...parts.map((p,i)=>{const e=document.createElement('i');e.style.width=(100*p.value/total)+'%';e.className=i%2?'gold':'on';e.title=p.name+': '+p.value;return e}));}function intervals(id,items,total){$('#'+id).replaceChildren(...items.map(p=>{const row=document.createElement('div');row.className='interval';const bar=document.createElement('i');bar.style.left=(100*p.start/total)+'%';bar.style.width=(100*(p.end-p.start)/total)+'%';bar.className=p.cls||'';const label=document.createElement('span');label.textContent=p.label;row.append(bar,label);return row;}));}function plot(id,series,xr,yr,opts={}){const e=$('#'+id),X=x=>42+(x-xr[0])/(xr[1]-xr[0])*298,Y=y=>175-(y-yr[0])/(yr[1]-yr[0])*148;let out='<defs><clipPath id=\"clip-'+id+'\"><rect x=\"42\" y=\"27\" width=\"298\" height=\"148\"/></clipPath></defs>';for(let i=0;i<3;i++){let x=xr[0]+i*(xr[1]-xr[0])/2,y=yr[0]+i*(yr[1]-yr[0])/2;out+='<path class=\"gridline\" d=\"M '+X(x)+' 27V175M42 '+Y(y)+'H340\"/><text x=\"'+X(x)+'\" y=\"194\" text-anchor=\"middle\">'+esc(opts.xfmt?opts.xfmt(x):Number(x.toFixed(2)))+'</text><text x=\"36\" y=\"'+(Y(y)+4)+'\" text-anchor=\"end\">'+esc(opts.yfmt?opts.yfmt(y):Number(y.toFixed(2)))+'</text>';}out+='<g clip-path=\"url(#clip-'+id+')\">';for(const s of series){out+='<path fill=\"none\" stroke=\"'+(s.color||'var(--accent)')+'\" stroke-width=\"2.5\" '+(s.dash?'stroke-dasharray=\"5 4\"':'')+' d=\"'+s.pts.map((p,i)=>(i?'L':'M')+X(p[0]).toFixed(2)+','+Y(p[1]).toFixed(2)).join(' ')+'\"/>';}for(const p of opts.points||[])out+='<circle cx=\"'+X(p[0])+'\" cy=\"'+Y(p[1])+'\" r=\"4\" fill=\"var(--second)\" stroke=\"var(--paper)\" stroke-width=\"1.5\"/>';if(opts.cursor!==undefined)out+='<path d=\"M'+X(opts.cursor)+' 27V175\" stroke=\"var(--muted)\" stroke-dasharray=\"3 3\"/>';e.innerHTML=out+'</g>';e.dataset.curves=JSON.stringify(series.map(s=>s.pts));}const curve=(fn,lo,hi,n=120)=>Array.from({length:n+1},(_,i)=>{const x=lo+(hi-lo)*i/n;return[x,fn(x)]});function inputs(draw){document.querySelectorAll('input,select').forEach(e=>{e.addEventListener('input',draw);e.addEventListener('change',draw)});draw()}const n=id=>+$('#'+id).value;const show=(id,v,d=3)=>set(id,Number(v.toFixed(d)));function bars(id,values,max=1){$('#'+id).className='bars';$('#'+id).innerHTML=values.map(v=>'<div class=\"bar-row\"><span>'+esc(v.label)+'</span><div class=\"bar-track\"><i class=\"'+(v.cls||'')+'\" style=\"width:'+Math.max(0,Math.min(100,v.value/max*100))+'%\"></i></div><output>'+esc(v.text??(v.value*100).toFixed(1)+'%')+'</output></div>').join('')}function softmax(z,T=1){let max=Math.max(...z),w=z.map(x=>Math.exp((x-max)/T)),sum=w.reduce((a,b)=>a+b,0);return w.map(x=>x/sum)}function draw(){let p=n('pos'),q=[n('qx'),n('qy')],z=[q[0],q[1],q[0]+q[1]].map(x=>x/Math.sqrt(2)),w=softmax(z.slice(0,p));while(w.length<3)w.push(0);let f=$('#future').checked?0:99,V=[[2,0],[0,4],[f,f]],o=[0,1].map(j=>w.reduce((a,b,i)=>a+b*V[i][j],0));table('matrix',[['i','q·k / √2','α'],...w.map((v,i)=>[''+(i+1),i<p?z[i].toFixed(3):'−∞',{text:v.toFixed(4),cls:i<p?'on':''}])]);['pos','qx','qy'].forEach(x=>set(x+'-value',n(x)));set('output','('+o.map(x=>x.toFixed(2)).join(', ')+')');set('mass',w.reduce((a,b)=>a+b,0).toFixed(2));set('math',w.map((a,i)=>a.toFixed(3)+' × ('+V[i].join(',')+')').join('\\n+ '));set('explanation',t('explain'));document.body.dataset.weights=JSON.stringify(w);document.body.dataset.output=JSON.stringify(o);}inputs(draw);","audio":false,"strings":{"explain":"At position 2 with q=(0,0), each visible position gets half the mass, yielding (1,2). Changing future V has no effect.","future":"Set position 3 value to 0","heading":"How does masking change the weighted result?","intro":"Choose a query position and change q; inspect scores, weights and value contributions.","mass":"Weight sum","output":"Weighted output","pos":"Query position","qx":"q dimension 1","qy":"q dimension 2","reset":"Reset","scope":"One head, three positions, dₖ=2; fixed K=[(1,0),(0,1),(1,1)], V=[(2,0),(0,4),(99,99)]. q is a teaching input, not a trained representation.","scopeLabel":"Model scope and assumptions","weights":"Attention weights"}}
From Dense FFN to Sparse Experts
In a dense FFN layer, all positions use the same set of feed-forward weights. In a sparse MoE layer, multiple expert networks are prepared, and a router selects a subset based on the current position's representation. Other components, such as attention, still perform their own computations; the model is not simply cut into several mutually exclusive sub-models.
Suppose the router assigns weights [0.6, 0.3, 0.1] to three experts. If the layer selects the top-2 and normalizes within the selected set, the weights become [2/3, 1/3]. If the two selected experts output [3,0] and [0,6] respectively, the merged result is [2,2]. The third expert did not participate in the expert computation for this position, but it can be selected for the next position or a lower layer.
Position vector h Gate: .6 / .3 / .1 Expert 1 E₁(h) = [3, 0] Expert 2 E₂(h) = [0, 6] Expert 3 Not Selected for This Position Weighted Result [2, 2] Weights Re-normalized: 2/3, 1/3 Example Routing: Each Position Selects Experts, Then Merges Outputs This is a teaching example for top-2 with re-normalization; gating and shared expert designs in different MoE architectures may vary.
This is just one form of gating: top-k selection, weight normalization methods, capacity control, and which layers use MoE all depend on specific designs. Switch Transformers demonstrated top-1 sparse routing; Mixtral's publicly available architecture selects two feed-forward experts per token per layer. Switch Transformers , Mixtral of Experts
Experts Do Not Automatically Become Manually Defined Disciplines
"Expert" is simply the name of a sub-network; it does not imply that the system is pre-configured with math experts, legal experts, and code experts. Training may produce certain specializations, but actual routing is also influenced by representations, positions, and optimization objectives; one cannot treat a single selection as a reliable topic classification result.
Load imbalance during training can cause a few experts to receive a large number of tokens, while other experts are under-trained; hotspots and waiting times may also form during serving. Designs can use auxiliary losses, routing constraints, and other methods to improve this, but "absolute uniformity per batch" does not necessarily align with task requirements. Some architectures introduce always-active shared experts to handle common knowledge and reduce redundancy; this is a specific architectural choice, not a mandatory component for all MoE models. DeepSeekMoE
A Parameter Account: Separating Capacity from Computation
Assume the non-expert part of the model has 1B parameters, and all MoE layers collectively have 2B parameters per expert path, with 8 paths in total, selecting 2 paths per position. Then the total parameters are 1 + 8×2 = 17B. According to this simplified metric, the parameters involved per token are approximately 1 + 2×2 = 5B. If the number of paths increases to 16 while still selecting 2, the total becomes 33B, but the activated metric remains approximately 5B.
This example illustrates that candidate capacity can be increased without proportionally increasing expert computation, but it does not prove that computation remains completely unchanged: router overhead, communication, and load balancing will all change. Actual model parameter statistics also involve metrics for embeddings, output heads, and shared experts; one should read the model report rather than guessing the total using "number of experts × size of a certain dense model."
Selection and weighting are separate
Router scores are not final mixture coefficients: select top-k, then normalize the selected values. Raising E1 changes the mixture; increasing k also changes executed expert count. Fixed expert outputs isolate routing from expert computation.
Preparing the visual Try again
Selection and weighting are separate Normalize within selected experts, then combine outputs; unselected experts still have stored weights.
{"id":"ai-moe-routing","title":"Selection and weighting are separate","summary":"Normalize within selected experts, then combine outputs; unselected experts still have stored weights.","height":1000,"html":"<h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p><div class=\"control\"><label for=\"a\" data-i18n=\"a\"></label><output for=\"a\" id=\"a-value\"></output><input id=\"a\" type=\"range\" min=\"1\" max=\"9\" value=\"6\" step=\"1\"></div><div class=\"control\"><label for=\"k\" data-i18n=\"k\"></label><output for=\"k\" id=\"k-value\"></output><input id=\"k\" type=\"range\" min=\"1\" max=\"3\" value=\"2\" step=\"1\"></div><div id=\"routing\"></div><div class=\"metrics\"><div><span data-i18n=\"output\"></span><strong id=\"output\"></strong></div><div><span data-i18n=\"active\"></span><strong id=\"active\"></strong></div></div><div id=\"math\" class=\"formula\"></div><div class=\"copy\"><p id=\"explanation\" role=\"status\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"explain\"></p></div><details class=\"scope\"><summary data-i18n=\"scopeLabel\"></summary><p data-i18n=\"scope\"></p></details>","css":".intro{margin:8px 0 18px;color:var(--muted);font-size:14px}.control{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:6px 12px;align-items:center;margin:14px 0;font-size:13px}.control output{color:var(--accent);text-align:right;font-variant-numeric:tabular-nums;min-width:4em}.control input{grid-column:1/-1;width:100%;margin:0}.presets{display:flex;gap:4px;align-items:stretch}.presets button{flex:1;min-width:0;overflow-wrap:anywhere;font-size:13px;min-height:44px}.actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:16px 0}.actions button{min-width:0;min-height:44px;font-size:13px;overflow-wrap:anywhere}.copy{display:grid;font-size:14px;margin:16px 0}.copy>*{grid-area:1/1;margin:0;overflow-wrap:anywhere}.reserve{visibility:hidden}.scope{margin-top:14px;color:var(--muted);font-size:12px}.scope summary{padding:8px 0;cursor:pointer}.scope p{margin-top:10px;overflow-wrap:anywhere}.metrics{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px;margin:18px 0}.metrics>div{border-left:2px solid var(--accent);padding:0 6px 0 10px;min-width:0}.metrics span{display:block;min-height:3.6em;color:var(--muted);font-size:12px;overflow-wrap:anywhere}.metrics strong{font-size:21px;display:block;min-height:2em;font-weight:550;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.check{display:flex;align-items:center;gap:9px;font-size:13px;margin:14px 0}.check input{width:18px;height:18px;flex-shrink:0;accent-color:var(--accent)}select,input[type=text],input[type=number]{background:var(--paper);color:var(--ink);font:inherit;font-size:14px;padding:10px;border:1px solid var(--rule);border-radius:7px;max-width:100%;min-width:0}select{width:100%;min-height:44px}.panel{padding:14px;border:1px solid var(--rule);border-radius:9px;margin:16px 0;min-width:0}.panel>header{font-size:13px;font-weight:600;margin-bottom:12px;color:var(--muted)}.panel>div{overflow-wrap:anywhere}.track-row{margin:16px 0}.track-row>span{display:block;font-size:12px;color:var(--muted);margin-bottom:8px}.track{display:flex;gap:5px;min-width:0}.cell{flex:1;min-width:0;min-height:56px;border:1px solid var(--rule);border-radius:5px;background:var(--surface);display:flex;align-items:center;justify-content:center;text-align:center;padding:6px 3px;font-size:12px;overflow-wrap:anywhere}.cell.on{background:var(--accent-soft);border-color:var(--accent)}.cell.gold{background:var(--second-soft);border-color:var(--second)}.cell.empty{border-style:dashed;color:var(--muted)}.cell.error{border-color:var(--second);text-decoration:line-through}.table{display:grid;gap:5px;font-size:12px}.tr{display:grid;gap:5px}.tr>div{background:var(--surface);border-radius:4px;padding:9px 6px;min-width:0;min-height:5em;overflow-wrap:anywhere;display:flex;align-items:center}.tr>.gold{background:var(--second-soft)}.tr>.on{background:var(--accent-soft)}.formula,.source{font:13px/1.8 ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere;margin:16px 0}.formula{border-top:1px solid var(--rule);padding-top:12px;min-height:7.2em}.source{min-height:8em;background:var(--surface);padding:12px;border-radius:8px}.intervals{margin:16px 0}.interval{position:relative;height:38px;background:var(--surface);margin:6px 0;border-radius:4px;overflow:hidden}.interval i{position:absolute;height:100%;background:var(--accent-soft);border-left:2px solid var(--accent)}.interval i.gold{background:var(--second-soft);border-color:var(--second)}.interval span{position:relative;z-index:1;font:12px/38px ui-monospace,monospace;padding-left:7px}.bars{display:grid;gap:10px;margin:16px 0}.bar-row{display:grid;grid-template-columns:44px minmax(0,1fr) 62px;gap:8px;align-items:center;font:12px ui-monospace,monospace}.bar-track{height:24px;background:var(--surface);border-radius:4px;overflow:hidden}.bar-track i{display:block;height:100%;background:var(--accent);transition:width .2s}.bar-track i.gold{background:var(--second)}.bar-track i.empty{opacity:.2}.bar-row output{text-align:right}.diagram{display:block;width:100%;height:auto;margin:18px 0}.diagram text{font:13px ui-monospace,monospace;fill:var(--ink)}.node{fill:var(--surface);stroke:var(--rule)}.node.on{fill:var(--accent-soft);stroke:var(--accent)}.node.gold{fill:var(--second-soft);stroke:var(--second)}.edge{stroke:var(--rule);stroke-width:2;fill:none}.edge.on{stroke:var(--accent)}.matrix{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin:16px 0}.matrix button{min-width:0;min-height:44px;font:13px ui-monospace,monospace}.matrix button[aria-pressed=true]{background:var(--accent-soft);border-color:var(--accent)}.matrix button.masked{opacity:.35}.legend{font-size:12px;color:var(--muted);min-height:3.6em;overflow-wrap:anywhere}.numeric{font-variant-numeric:tabular-nums}.scope p{line-break:strict}@media(max-width:480px){.presets button,.actions button{font-size:12px}.panel{padding:12px}.metrics{gap:10px}.metrics strong{font-size:19px}.bar-row{grid-template-columns:34px minmax(0,1fr) 58px;gap:6px}}@media(prefers-reduced-motion:reduce){*,*::before,*::after{transition:none!important;animation:none!important}}\n\n.panel>h3{font-size:13px;font-weight:600;margin:0 0 12px;color:var(--muted)}\n\n.bar-row{grid-template-columns:44px minmax(0,1fr) 82px}.bar-row output{white-space:nowrap}@media(max-width:480px){.bar-row{grid-template-columns:34px minmax(0,1fr) 76px}}\n\n.metrics strong{font-size:18px;min-height:3.6em}","js":"const $=s=>document.querySelector(s);const set=(id,v)=>$('#'+id).textContent=v;const t=k=>viz.t(k);function cells(id,values){$('#'+id).replaceChildren(...values.map(v=>{const e=document.createElement('div');e.className='cell '+(v.cls||'');e.textContent=v.text;e.title=v.title||v.text;return e;}));}function pressed(mode){document.querySelectorAll('[data-mode]').forEach(e=>e.setAttribute('aria-pressed',String(e.dataset.mode===mode)));}const esc=s=>String(s).replace(/[&<>\"']/g,c=>({'&':'&','<':'<','>':'>','\"':'"',\"'\":'''}[c]));const fmt=s=>'{'+[...s].sort().join(', ')+'}';function graph(id,nodes,edges){const el=$('#'+id);el.setAttribute('viewBox','0 0 360 200');el.innerHTML='<defs><marker id=\"arrow-'+id+'\" viewBox=\"0 0 10 10\" refX=\"8\" refY=\"5\" markerWidth=\"5\" markerHeight=\"5\" orient=\"auto-start-reverse\"><path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"var(--muted)\"/></marker></defs>'+edges.map(e=>{const a=nodes[e[0]],b=nodes[e[1]],dx=b.x-a.x,dy=b.y-a.y,d=Math.hypot(dx,dy)||1;if(edges.some(r=>r[0]===e[1]&&r[1]===e[0])){const nx=-dy/d,ny=dx/d;return '<path class=\"edge '+(e[2]?'on':'')+'\" d=\"M '+(a.x+dx/d*22+nx*12)+' '+(a.y+dy/d*22+ny*12)+' Q '+((a.x+b.x)/2+nx*38)+' '+((a.y+b.y)/2+ny*38)+' '+(b.x-dx/d*25+nx*12)+' '+(b.y-dy/d*25+ny*12)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}return '<line class=\"edge '+(e[2]?'on':'')+'\" x1=\"'+(a.x+dx/d*25)+'\" y1=\"'+(a.y+dy/d*25)+'\" x2=\"'+(b.x-dx/d*28)+'\" y2=\"'+(b.y-dy/d*28)+'\" marker-end=\"url(#arrow-'+id+')\"/>';}).join('')+nodes.map(n=>'<g><circle class=\"node '+(n.cls||'')+'\" cx=\"'+n.x+'\" cy=\"'+n.y+'\" r=\"25\"/><text x=\"'+n.x+'\" y=\"'+(n.y+4)+'\" text-anchor=\"middle\">'+esc(n.name)+'</text>'+(n.sub?'<text x=\"'+n.x+'\" y=\"'+(n.y+43)+'\" text-anchor=\"middle\">'+esc(n.sub)+'</text>':'')+'</g>').join('');}function table(id,rows){$('#'+id).classList.add('table');$('#'+id).replaceChildren(...rows.map(r=>{const row=document.createElement('div');row.className='tr';row.style.gridTemplateColumns='repeat('+r.length+',minmax(0,1fr))';r.forEach(x=>{const c=document.createElement('div');if(typeof x==='object'){c.textContent=x.text;c.className=x.cls||'';}else c.textContent=x;row.append(c)});return row;}));}function band(id,parts,total){$('#'+id).replaceChildren(...parts.map((p,i)=>{const e=document.createElement('i');e.style.width=(100*p.value/total)+'%';e.className=i%2?'gold':'on';e.title=p.name+': '+p.value;return e}));}function intervals(id,items,total){$('#'+id).replaceChildren(...items.map(p=>{const row=document.createElement('div');row.className='interval';const bar=document.createElement('i');bar.style.left=(100*p.start/total)+'%';bar.style.width=(100*(p.end-p.start)/total)+'%';bar.className=p.cls||'';const label=document.createElement('span');label.textContent=p.label;row.append(bar,label);return row;}));}function plot(id,series,xr,yr,opts={}){const e=$('#'+id),X=x=>42+(x-xr[0])/(xr[1]-xr[0])*298,Y=y=>175-(y-yr[0])/(yr[1]-yr[0])*148;let out='<defs><clipPath id=\"clip-'+id+'\"><rect x=\"42\" y=\"27\" width=\"298\" height=\"148\"/></clipPath></defs>';for(let i=0;i<3;i++){let x=xr[0]+i*(xr[1]-xr[0])/2,y=yr[0]+i*(yr[1]-yr[0])/2;out+='<path class=\"gridline\" d=\"M '+X(x)+' 27V175M42 '+Y(y)+'H340\"/><text x=\"'+X(x)+'\" y=\"194\" text-anchor=\"middle\">'+esc(opts.xfmt?opts.xfmt(x):Number(x.toFixed(2)))+'</text><text x=\"36\" y=\"'+(Y(y)+4)+'\" text-anchor=\"end\">'+esc(opts.yfmt?opts.yfmt(y):Number(y.toFixed(2)))+'</text>';}out+='<g clip-path=\"url(#clip-'+id+')\">';for(const s of series){out+='<path fill=\"none\" stroke=\"'+(s.color||'var(--accent)')+'\" stroke-width=\"2.5\" '+(s.dash?'stroke-dasharray=\"5 4\"':'')+' d=\"'+s.pts.map((p,i)=>(i?'L':'M')+X(p[0]).toFixed(2)+','+Y(p[1]).toFixed(2)).join(' ')+'\"/>';}for(const p of opts.points||[])out+='<circle cx=\"'+X(p[0])+'\" cy=\"'+Y(p[1])+'\" r=\"4\" fill=\"var(--second)\" stroke=\"var(--paper)\" stroke-width=\"1.5\"/>';if(opts.cursor!==undefined)out+='<path d=\"M'+X(opts.cursor)+' 27V175\" stroke=\"var(--muted)\" stroke-dasharray=\"3 3\"/>';e.innerHTML=out+'</g>';e.dataset.curves=JSON.stringify(series.map(s=>s.pts));}const curve=(fn,lo,hi,n=120)=>Array.from({length:n+1},(_,i)=>{const x=lo+(hi-lo)*i/n;return[x,fn(x)]});function inputs(draw){document.querySelectorAll('input,select').forEach(e=>{e.addEventListener('input',draw);e.addEventListener('change',draw)});draw()}const n=id=>+$('#'+id).value;const show=(id,v,d=3)=>set(id,Number(v.toFixed(d)));function bars(id,values,max=1){$('#'+id).className='bars';$('#'+id).innerHTML=values.map(v=>'<div class=\"bar-row\"><span>'+esc(v.label)+'</span><div class=\"bar-track\"><i class=\"'+(v.cls||'')+'\" style=\"width:'+Math.max(0,Math.min(100,v.value/max*100))+'%\"></i></div><output>'+esc(v.text??(v.value*100).toFixed(1)+'%')+'</output></div>').join('')}function softmax(z,T=1){let max=Math.max(...z),w=z.map(x=>Math.exp((x-max)/T)),sum=w.reduce((a,b)=>a+b,0);return w.map(x=>x/sum)}function draw(){let a=[n('a'),3,1],k=n('k'),ids=[0,1,2].sort((i,j)=>a[j]-a[i]||i-j).slice(0,k),sum=ids.reduce((s,i)=>s+a[i],0),w=a.map((x,i)=>ids.includes(i)?x/sum:0),V=[[3,0],[0,6],[9,9]],o=[0,1].map(j=>w.reduce((s,x,i)=>s+x*V[i][j],0));set('a-value',a[0]+' : 3 : 1');set('k-value',k);bars('routing',w.map((value,i)=>({label:'E'+(i+1),value,cls:ids.includes(i)?'':'empty'})));set('output','('+o.map(x=>x.toFixed(2)).join(', ')+')');set('active',k+' / 3');set('math',w.map((v,i)=>v.toFixed(3)+' × ('+V[i].join(',')+')').join('\\n+ '));set('explanation',t('explain'));document.body.dataset.output=JSON.stringify(o);document.body.dataset.weights=JSON.stringify(w);}inputs(draw);","audio":false,"strings":{"a":"E1 routing weight","active":"Experts executed","explain":"Default 6:3:1 with top-2 gives weights 2/3 and 1/3, combining (3,0) and (0,6) into (2,2).","heading":"Selection and weighting are separate","intro":"Change routing weights and top-k; inspect executed experts and the combined vector.","k":"Experts per position","output":"Combined output","reset":"Reset","routing":"Selected weights","scope":"Fixed expert outputs (3,0),(0,6),(9,9); positive routing weights, omitting router training, capacity limits and communication.","scopeLabel":"Model scope and assumptions"}}
Tool-calling failures should first distinguish between model output, chat template, tool protocol parsing, missing context, and tool execution exceptions. The presence of function names in text form, without a valid calling structure, is insufficient evidence that MoE activated parameters are too few; the model may not have been trained on the corresponding protocol, or the inference engine may not be using the correct template.
There is no universal activation parameter threshold where "7B can stably perform single-step and 2B can stably perform multi-step." Training data, post-training methods, context, decoding configuration, task difficulty, and tool feedback all affect results. Using parameter scale as a filtering criterion is acceptable, but treating it as a guarantee of success lacks evidence.
Continue with:Inference, KV cache and memory 。