aiinfra-tools 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,12 @@
25
25
  const mla = s.attn === 'mla';
26
26
  const lat = s.mlaLatent || 512, rope = s.mlaRope == null ? 64 : s.mlaRope, nope = s.mlaNope == null ? 128 : s.mlaNope, vh = s.mlaV || 128;
27
27
  const swaLayers = s.swaWindow > 0 ? Math.round(s.layers * (s.swaFrac || 0)) : 0;
28
+ // linear-attention layers (Kimi Delta Attention, Gated DeltaNet): a fixed recurrent state per sequence, no KV per token
29
+ const linLayers = s.linFrac > 0 ? Math.min(s.layers - swaLayers, Math.round(s.layers * s.linFrac)) : 0;
30
+ const linState = linLayers * (s.linStateMB || 0) * 1e6;
31
+ // compressed attention keeps the KV of a share of the tokens (DeepSeek V4: 1/4 or 1/128 per layer); sparse attention
32
+ // (DSA, CSA, MSA) attends a fixed number of selected tokens per query instead of all of them
33
+ const keep = s.kvKeep > 0 && s.kvKeep < 1 ? s.kvKeep : 1, topK = s.sparseTopK > 0 ? s.sparseTopK : 0;
28
34
  // tensor-core rate for the weight precision; fall back when the GPU lacks that precision
29
35
  const tf = { bf16: s.tfBf16, fp8: s.tfFp8 || s.tfBf16, fp4: s.tfFp4 || s.tfFp8 || s.tfBf16 }[s.wprec] || s.tfBf16;
30
36
  const computeFallback = (s.wprec === 'fp4' && !s.tfFp4) ? (s.tfFp8 ? 'fp8' : 'bf16') : (s.wprec === 'fp8' && !s.tfFp8) ? 'bf16' : null;
@@ -33,7 +39,9 @@
33
39
  Wd: dense * 1e9 * bpp, We: Eall * 1e9 * bpp,
34
40
  denseP: dense * 1e9, activeP: (isMoE ? s.active : s.total) * 1e9,
35
41
  kvTokLayer: mla ? (lat + rope) * kvb : 2 * s.kvHeads * s.headDim * kvb,
36
- swaLayers, fullLayers: s.layers - swaLayers, win: s.swaWindow || 0,
42
+ swaLayers, linLayers, fullLayers: s.layers - swaLayers - linLayers, win: s.swaWindow || 0, keep, topK, linState,
43
+ // FLOPs per token per linear-attention layer: read and update the state (fp32, 4 bytes an element), ~4 FLOPs an element
44
+ Alin: (s.linStateMB || 0) * 1e6,
37
45
  // attention FLOPs per (query token, context token) per layer
38
46
  Apre: mla ? s.qHeads * (2 * (nope + rope) + 2 * vh) : 4 * s.qHeads * s.headDim,
39
47
  Adec: mla ? s.qHeads * (2 * (lat + rope) + 2 * lat) : 4 * s.qHeads * s.headDim,
@@ -44,17 +52,26 @@
44
52
  };
45
53
  }
46
54
 
55
+ // KV bytes one sequence of L tokens holds: full-attention layers keep (a share of) every token, sliding-window layers
56
+ // the last W, linear-attention layers a fixed state
47
57
  function kvBytes(md, L) {
48
- const w = md.win || L;
49
- return md.kvTokLayer * (md.fullLayers * L + md.swaLayers * Math.min(L, w));
58
+ const w = md.win || L, keep = md.keep || 1;
59
+ return md.kvTokLayer * (md.fullLayers * L * keep + md.swaLayers * Math.min(L, w)) + (md.linState || 0);
60
+ }
61
+ // context tokens one query attends in a full-attention layer, and its integral over query positions 0..x
62
+ const attended = (md, L) => { const n = L * (md.keep || 1); return md.topK ? Math.min(n, md.topK) : n; };
63
+ function attendedSum(md, x) {
64
+ const k = md.keep || 1;
65
+ if (!md.topK) return k * x * x / 2;
66
+ const t = md.topK / k;
67
+ return x <= t ? k * x * x / 2 : k * t * t / 2 + md.topK * (x - t);
50
68
  }
51
69
  function attnPre(md, Lc, L) {
52
70
  const W = md.win;
53
- const f = x => x * x / 2;
54
71
  const g = x => x <= W ? x * x / 2 : W * W / 2 + W * (x - W);
55
- return md.Apre * (md.fullLayers * (f(L) - f(Lc)) + md.swaLayers * (g(L) - g(Lc)));
72
+ return md.Apre * (md.fullLayers * (attendedSum(md, L) - attendedSum(md, Lc)) + md.swaLayers * (g(L) - g(Lc))) + (md.linLayers || 0) * (md.Alin || 0) * (L - Lc);
56
73
  }
57
- function attnDec(md, L) { return md.Adec * (md.fullLayers * L + md.swaLayers * Math.min(L, md.win || L)); }
74
+ function attnDec(md, L) { return md.Adec * (md.fullLayers * attended(md, L) + md.swaLayers * Math.min(L, md.win || L)) + (md.linLayers || 0) * (md.Alin || 0); }
58
75
 
59
76
  // ---------- parallel layouts ----------
60
77
  // Instances of g GPUs. Inside one scale-up domain (D GPUs): TP, or TP+EP for MoE, or DP-attention+EP for MLA.
@@ -376,6 +393,6 @@
376
393
  return res;
377
394
  }
378
395
 
379
- const api = { SETTINGS, plan, derive, kvBytes, decodeStep, memInfo, prefillStats, prefillTime, configs, computeLoad, decodeLabel, prefillLabel, decodeCap, packNodes, operatingPoint };
396
+ const api = { SETTINGS, plan, derive, kvBytes, attnPre, attnDec, decodeStep, memInfo, prefillStats, prefillTime, configs, computeLoad, decodeLabel, prefillLabel, decodeCap, packNodes, operatingPoint };
380
397
  if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.SizerModel = api;
381
398
  })(this);
@@ -467,7 +467,7 @@ function memoryHTML(r) {
467
467
  <div class="membar">${parts.map(p => `<div style="width:${Math.max(0, 100 * p[1] / hbm).toFixed(2)}%;background:${p[2]}" title="${p[0]}"></div>`).join('')}</div>
468
468
  <div class="memlegend">${parts.map(p => `<i style="background:${p[2]}"></i><span>${p[0]}</span><span class="mono">${fGB(p[1])}</span>`).join('')}</div>
469
469
  <dl class="kv" style="margin-top:14px">
470
- <dt>KV per token (all layers)</dt><dd>${fGB(md.kvTokLayer * s.layers)}</dd>
470
+ <dt>KV per token (all layers, averaged over a full context)</dt><dd>${fGB(M.kvBytes(md, s.ctx) / s.ctx)}</dd>
471
471
  <dt>KV for one ${fCtx(s.ctx)} full-context request</dt><dd>${fGB(mi.ctxBytes)}</dd>
472
472
  <dt>KV for an average request (${fInt(s.avgIn + s.avgOut)} tokens)</dt><dd>${fGB(M.kvBytes(md, Math.min(s.ctx, s.avgIn + s.avgOut)))}</dd>
473
473
  <dt>KV capacity per instance</dt><dd>${fGB(mi.cap)}</dd>
@@ -21,13 +21,19 @@ import { GPU, summary } from './validate-inferencex.mjs';
21
21
  const require = createRequire(import.meta.url);
22
22
  const C = require('../src/catalog.js'), M = require('../src/model.js');
23
23
 
24
- export const MODELS = { dsr1: 'deepseek-v3', dsv3: 'deepseek-v3', 'kimi-k2': 'kimi-k2', 'qwen3-235b': 'qwen3-235b', 'qwen3-coder': 'qwen3-coder-480b', 'gpt-oss-120b': 'gpt-oss-120b', llama4: 'llama4-maverick' };
24
+ // InferenceX's model prefixes (infmax_model_prefix, as its recipes name them) → sizer catalog ids. The longest
25
+ // matching prefix wins, so dsv41flash is not read as dsv4. null: a model the sizer can't size yet (counted as skipped).
26
+ // A prefix not here: --models map.json.
27
+ export const MODELS = { dsr1: 'deepseek-v3', dsv3: 'deepseek-v3', dsv4: 'deepseek-v4-pro', dsv41flash: null,
28
+ kimik3: 'kimi-k3', 'kimik3.1': 'kimi-k3', 'kimi-k2': 'kimi-k2', 'glm5.2': 'glm-5.3', 'glm5.3': 'glm-5.3', 'glm5.3flash': null,
29
+ minimaxm3: 'minimax-m3', minimaxm31flash: 'minimax-m3', musespark: 'muse-spark-open', 'qwen3.5': 'qwen35-397b', 'qwen3.8next': null, h3: null,
30
+ gptoss: 'gpt-oss-120b', 'gpt-oss-120b': 'gpt-oss-120b', 'qwen3-235b': 'qwen3-235b', 'qwen3-coder': 'qwen3-coder-480b', llama4: 'llama4-maverick' };
25
31
  const get = (o, p) => p.split('.').reduce((a, k) => (a == null ? undefined : a[k]), o);
26
32
  const firstNum = (o, ps) => { for (const p of ps) { const v = get(o, p); const n = typeof v === 'object' && v ? (v.mean ?? v.avg ?? v.median ?? v.p50) : v; if (Number.isFinite(+n) && n !== null && n !== '') return +n; } return null; };
27
33
 
28
34
  // One AgentX result → the fields the sizer needs (null when the result can't be scored)
29
35
  export function normalize(r, models = MODELS, catalog = C.MODELS) {
30
- const hw = String(r.hw || r.hardware || '').toLowerCase().replace(/-(nv|sxm|oam).*$/, '');
36
+ const hw0 = String(r.hw || r.hardware || '').toLowerCase().replace(/-(nv|sxm|oam).*$/, ''), hw = GPU[hw0] ? hw0 : hw0.split('-')[0]; // b200-nscale: a B200 at a cloud
31
37
  const prefix = String(r.infmax_model_prefix || r.model || '').toLowerCase();
32
38
  const key = Object.keys(models).sort((a, b) => b.length - a.length).find(k => prefix.startsWith(k.toLowerCase()));
33
39
  const model = key && catalog.find(m => m.id === models[key]), gpu = C.GPUS.find(g => g.id === GPU[hw]);
@@ -27,7 +27,7 @@ export const SOURCE = {
27
27
  repo: 'https://github.com/SemiAnalysisAI/InferenceX-app', commit: '187628924b6ec899b1f3f771617655dd4cd61d8c',
28
28
  path: 'packages/app/cypress/fixtures/api/benchmarks.json', sha256: 'f46823a76cb63248705329f327e1494df02b4dfa4df0898b7ee084c75c20bd52',
29
29
  };
30
- export const GPU = { b200: 'B200', b300: 'B300', h200: 'H200', h100: 'H100', mi300x: 'MI300X', mi325x: 'MI325X', mi355x: 'MI355X', gb200: 'GB200-NVL72', gb300: 'GB300-NVL72' };
30
+ export const GPU = { a100: 'A100', b200: 'B200', b300: 'B300', h200: 'H200', h100: 'H100', mi300x: 'MI300X', mi325x: 'MI325X', mi355x: 'MI355X', gb200: 'GB200-NVL72', gb300: 'GB300-NVL72', vr200: 'VR200-NVL72', mi455x: 'MI455X-Helios' };
31
31
  const MODEL = { dsr1: 'deepseek-v3' }; // DeepSeek-R1 has DeepSeek-V3's architecture
32
32
 
33
33
  export function fetchData(cache = path.join(os.homedir(), '.cache', 'aiinfra-tools', 'inferencex', SOURCE.commit.slice(0, 12))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiinfra-tools",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Open tools for running GPU fleets: size inference, simulate capacity, find root causes, cap power, deploy on llm-d, and charge back GPU-hours. No dependencies.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -74,7 +74,6 @@
74
74
  "test:all": "for t in fleetops gpu-health fleetscope inference-sizer hybrid-tracing gpu-ledger harness-ledger; do (cd $t && npm test) || exit 1; done"
75
75
  },
76
76
  "publishConfig": {
77
- "access": "public",
78
- "provenance": true
77
+ "access": "public"
79
78
  }
80
79
  }