aiinfra-tools 0.2.0 → 0.3.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.
- package/CHANGELOG.md +210 -0
- package/README.md +14 -3
- package/bin/aiinfra.mjs +5 -2
- package/bin/report.mjs +177 -0
- package/fleetops/README.md +33 -1
- package/fleetops/deploy/shadow-gate/argo-analysistemplate.yaml +34 -0
- package/fleetops/deploy/shadow-gate/argo-rollout-example.yaml +38 -0
- package/fleetops/deploy/shadow-gate/flagger-canary.yaml +34 -0
- package/fleetops/deploy/shadow-gate/judge.yaml +51 -0
- package/fleetops/deploy/shadow-gate/llmd-canary-example.yaml +35 -0
- package/fleetops/deploy/shadow-gate/podmonitor-vllm.yaml +20 -0
- package/fleetops/deploy/shadow-live/README.md +33 -0
- package/fleetops/deploy/shadow-live/kit.yaml +121 -0
- package/fleetops/deploy/shadow-live/load-canary.yaml +26 -0
- package/fleetops/deploy/shadow-live/run.sh +48 -0
- package/fleetops/docs/ADMISSION.md +9 -9
- package/fleetops/docs/FABRIC-STORAGE.md +1 -1
- package/fleetops/docs/SERVING.md +11 -1
- package/fleetops/docs/SHADOW.md +250 -0
- package/fleetops/docs/SIGNALS.md +5 -2
- package/fleetops/docs/WORKLOADS.md +1 -1
- package/fleetops/package.json +7 -4
- package/fleetops/src/adapters/fabric.mjs +19 -7
- package/fleetops/src/adapters/live.mjs +38 -5
- package/fleetops/src/adapters/logs.mjs +10 -7
- package/fleetops/src/adapters/nvsentinel.mjs +95 -0
- package/fleetops/src/adapters/topology.mjs +53 -1
- package/fleetops/src/admission.mjs +26 -18
- package/fleetops/src/api.mjs +2 -1
- package/fleetops/src/bundle.mjs +3 -0
- package/fleetops/src/calibrate.mjs +1 -1
- package/fleetops/src/detect.mjs +1 -1
- package/fleetops/src/export.mjs +5 -1
- package/fleetops/src/goodput.mjs +0 -2
- package/fleetops/src/incidents.mjs +1 -2
- package/fleetops/src/ingest.mjs +1 -1
- package/fleetops/src/inject.mjs +2 -2
- package/fleetops/src/live.mjs +2 -1
- package/fleetops/src/llmd.mjs +7 -3
- package/fleetops/src/optimize.mjs +1 -1
- package/fleetops/src/power.mjs +7 -7
- package/fleetops/src/procure.mjs +67 -0
- package/fleetops/src/rca.mjs +1 -1
- package/fleetops/src/rollout.mjs +1 -1
- package/fleetops/src/schema.mjs +3 -2
- package/fleetops/src/security.mjs +1 -1
- package/fleetops/src/serving.mjs +21 -9
- package/fleetops/src/shadow-canary.mjs +74 -0
- package/fleetops/src/shadow-gate.mjs +49 -0
- package/fleetops/src/shadow-prom.mjs +205 -0
- package/fleetops/src/shadow-replay.mjs +147 -0
- package/fleetops/src/shadow.mjs +291 -0
- package/fleetops/src/stats.mjs +14 -0
- package/fleetops/src/traces.mjs +0 -5
- package/fleetops/tests/fixtures/real/README.md +5 -0
- package/fleetops/tools/admit-node.sh +51 -16
- package/fleetops/tools/amd-admit.py +111 -0
- package/fleetops/tools/cmd/calibrate.mjs +61 -0
- package/fleetops/tools/cmd/capacity.mjs +116 -0
- package/fleetops/tools/cmd/common.mjs +32 -0
- package/fleetops/tools/cmd/data.mjs +343 -0
- package/fleetops/tools/cmd/help.mjs +243 -0
- package/fleetops/tools/cmd/incidents.mjs +216 -0
- package/fleetops/tools/cmd/rollout.mjs +122 -0
- package/fleetops/tools/cmd/server.mjs +122 -0
- package/fleetops/tools/cmd/serving.mjs +95 -0
- package/fleetops/tools/cmd/shadow.mjs +204 -0
- package/fleetops/tools/cmd/training.mjs +79 -0
- package/fleetops/tools/collect.sh +6 -1
- package/fleetops/tools/fleetops.mjs +18 -1308
- package/fleetops/tools/loop-demo.mjs +1 -1
- package/fleetops/tools/workload-profile.mjs +0 -1
- package/fleetscope/README.md +5 -1
- package/fleetscope/build.mjs +1 -0
- package/fleetscope/dist/index.html +295 -26
- package/fleetscope/docs/AGENTIC.md +89 -0
- package/fleetscope/docs/PLANNING.md +4 -2
- package/fleetscope/docs/VALIDATION-AGENTIC.md +37 -0
- package/fleetscope/package.json +4 -3
- package/fleetscope/src/agentic.js +288 -0
- package/fleetscope/src/ask.js +0 -1
- package/fleetscope/src/cluster-ui.js +1 -0
- package/fleetscope/src/engine.js +10 -11
- package/fleetscope/src/index.src.html +9 -5
- package/fleetscope/src/inference-ui.js +1 -0
- package/fleetscope/src/ingest.js +89 -3
- package/fleetscope/src/optimize.js +11 -5
- package/fleetscope/src/plan.js +1 -1
- package/fleetscope/src/training-ui.js +1 -0
- package/fleetscope/tools/agentic.mjs +148 -0
- package/fleetscope/tools/tracelab-data.mjs +27 -0
- package/gpu-health/README.md +13 -2
- package/gpu-health/docs/CONFIG.md +29 -1
- package/gpu-health/package.json +7 -4
- package/gpu-health/src/actions.mjs +16 -3
- package/gpu-health/src/analyze.mjs +3 -0
- package/gpu-health/src/config.mjs +3 -0
- package/gpu-health/src/executors.mjs +9 -4
- package/gpu-health/src/health.mjs +1 -1
- package/gpu-health/src/ingest.mjs +27 -3
- package/gpu-health/src/platforms.mjs +109 -0
- package/gpu-health/src/vendors.mjs +12 -5
- package/gpu-health/tools/gpu-health.mjs +6 -4
- package/gpu-ledger/README.md +3 -1
- package/gpu-ledger/package.json +12 -4
- package/gpu-ledger/src/adapters.mjs +3 -2
- package/gpu-ledger/src/cloud.mjs +104 -0
- package/gpu-ledger/src/core.mjs +12 -10
- package/gpu-ledger/tools/ledger.mjs +8 -2
- package/harness-ledger/README.md +152 -0
- package/harness-ledger/docs/FORMATS.md +114 -0
- package/harness-ledger/docs/METHOD.md +133 -0
- package/harness-ledger/docs/VALIDATION-ECONOMICS.md +59 -0
- package/harness-ledger/docs/VALIDATION-SWEBENCH.md +26 -0
- package/harness-ledger/docs/VALIDATION-TRACELAB.md +56 -0
- package/harness-ledger/package.json +19 -0
- package/harness-ledger/src/demo.mjs +115 -0
- package/harness-ledger/src/economics.mjs +184 -0
- package/harness-ledger/src/gpu.mjs +80 -0
- package/harness-ledger/src/html.mjs +63 -0
- package/harness-ledger/src/importers.mjs +247 -0
- package/harness-ledger/src/ledger.mjs +128 -0
- package/harness-ledger/src/opencost.mjs +55 -0
- package/harness-ledger/src/outcomes.mjs +67 -0
- package/harness-ledger/src/prices.mjs +75 -0
- package/harness-ledger/src/record.mjs +52 -0
- package/harness-ledger/src/waste.mjs +136 -0
- package/harness-ledger/tools/harness-ledger.mjs +199 -0
- package/harness-ledger/tools/validate-economics.mjs +69 -0
- package/harness-ledger/tools/validate-swebench.mjs +57 -0
- package/harness-ledger/tools/validate-tracelab.mjs +74 -0
- package/hybrid-tracing/package.json +4 -3
- package/hybrid-tracing/tools/fix-skew.mjs +1 -1
- package/inference-sizer/README.md +5 -1
- package/inference-sizer/build.mjs +1 -0
- package/inference-sizer/dist/index.html +205 -22
- package/inference-sizer/docs/ACCELERATORS.md +62 -0
- package/inference-sizer/docs/VALIDATION-INFERENCEX.md +37 -0
- package/inference-sizer/package.json +4 -3
- package/inference-sizer/src/accelerators.js +172 -0
- package/inference-sizer/src/catalog.js +7 -20
- package/inference-sizer/src/fit-ui.js +1 -1
- package/inference-sizer/src/index.src.html +3 -0
- package/inference-sizer/src/model.js +22 -1
- package/inference-sizer/tools/validate-agentx.mjs +110 -0
- package/inference-sizer/tools/validate-inferencex.mjs +132 -0
- package/mcp/README.md +6 -1
- package/mcp/server.mjs +34 -0
- package/package.json +9 -4
- package/schemas/README.md +3 -0
- package/schemas/aiinfra.report.schema.json +474 -0
- package/schemas/commands.mjs +14 -0
- package/schemas/fleetops.shadow.canary.schema.json +96 -0
- package/schemas/fleetops.shadow.compare.schema.json +266 -0
- package/schemas/fleetops.shadow.prom.schema.json +354 -0
- package/schemas/harness-ledger.economics.schema.json +567 -0
- package/schemas/sizer.list.schema.json +15 -2
|
@@ -12,9 +12,6 @@ import { VENDORS } from './vendors.mjs';
|
|
|
12
12
|
// Fields a vendor doesn't report are simply absent; the checks that need them don't run (see coverage in vendors.mjs).
|
|
13
13
|
// Jobs are joined later by (node, gpu); exporters that carry pod labels can set `job` directly.
|
|
14
14
|
|
|
15
|
-
export const NUM_FIELDS = ['tensor', 'sm', 'dram', 'memUsedGB', 'memTotalGB', 'frameworkPeakGB', 'clockMHz', 'maxClockMHz', 'throttle', 'tempC', 'memTempC', 'powerW', 'powerLimitW', 'powerBrake',
|
|
16
|
-
'eccSbeTotal', 'eccDbeTotal', 'remapPending', 'remapFailed', 'remapUsed', 'remapSpare', 'pcieWidth', 'pcieWidthMax', 'pcieGen', 'pcieGenMax', 'linkErrTotal', 'linkUeTotal', 'faultCountTotal', 'cpuWait'];
|
|
17
|
-
|
|
18
15
|
// NVML clock event (throttle) reason bits, as exported in DCGM_FI_DEV_CLOCKS_EVENT_REASONS
|
|
19
16
|
export const CLOCK_REASON = { swPowerCap: 0x4, hwSlowdown: 0x8, swThermal: 0x20, hwThermal: 0x40, hwPowerBrake: 0x80 };
|
|
20
17
|
|
|
@@ -87,6 +84,33 @@ export function samplesFromExporter(text, opts = {}) {
|
|
|
87
84
|
}
|
|
88
85
|
|
|
89
86
|
// JSON lines of samples (already normalized) -> array; validates the essentials.
|
|
87
|
+
// Google Cloud Monitoring timeSeries.list JSON (projects.timeSeries.list, or `gcloud monitoring time-series list
|
|
88
|
+
// --format=json`) → samples, for GKE node accelerators (kubernetes.io/node/accelerator/*, resource k8s_node) and TPU
|
|
89
|
+
// VMs (…/accelerator/* on tpu_worker or gce_instance). Duty cycle stands in for SM activity, TensorCore utilization for
|
|
90
|
+
// tensor activity, memory bandwidth utilization for HBM activity; values in % become fractions, bytes become GB.
|
|
91
|
+
// make = nvidia → vendor nvidia, kind gpu; otherwise (a TPU model or a TPU resource) vendor tpu, kind tpu.
|
|
92
|
+
const CM_FIELDS = { duty_cycle: ['sm', 100], tensorcore_utilization: ['tensor', 100], memory_bandwidth_utilization: ['dram', 100], memory_used: ['memUsedGB', 1e9], memory_total: ['memTotalGB', 1e9] }; // [field, divisor]
|
|
93
|
+
export function samplesFromCloudMonitoring(json, { site } = {}) {
|
|
94
|
+
const j = typeof json === 'string' ? JSON.parse(json) : json, list = Array.isArray(j) ? j : (j.timeSeries || []), by = new Map();
|
|
95
|
+
for (const ts of list) {
|
|
96
|
+
const type = (ts.metric || {}).type || '', f = CM_FIELDS[(type.match(/accelerator\/(\w+)$/) || [])[1]];
|
|
97
|
+
if (!f) continue;
|
|
98
|
+
const ml = (ts.metric || {}).labels || {}, rl = (ts.resource || {}).labels || {}, rtype = (ts.resource || {}).type || '';
|
|
99
|
+
const node = rl.node_name || ml.instance_name || rl.instance_name || (rl.node_id ? `${rl.node_id}${rl.worker_id != null ? '-w' + rl.worker_id : ''}` : rl.instance_id);
|
|
100
|
+
if (!node) continue;
|
|
101
|
+
const make = String(ml.make || '').toLowerCase(), model = ml.model || '', tpu = make ? make !== 'nvidia' : /tpu/i.test(rtype + ' ' + model);
|
|
102
|
+
for (const pt of ts.points || []) {
|
|
103
|
+
const t = Math.floor(Date.parse((pt.interval || {}).endTime) / 1000), v = pt.value || {};
|
|
104
|
+
const x = v.doubleValue != null ? +v.doubleValue : v.int64Value != null ? +v.int64Value : null;
|
|
105
|
+
if (!Number.isFinite(t) || x == null || !Number.isFinite(x)) continue;
|
|
106
|
+
const k = `${node}|${ml.accelerator_id ?? 0}|${t}`;
|
|
107
|
+
if (!by.has(k)) by.set(k, { t, ...(site ? { site } : {}), node, gpu: String(ml.accelerator_id ?? 0), vendor: tpu ? 'tpu' : 'nvidia', kind: tpu ? 'tpu' : 'gpu', sku: model || (tpu ? 'TPU' : ''), ...(ml.tpu_topology ? { topology: ml.tpu_topology } : {}) });
|
|
108
|
+
by.get(k)[f[0]] = x / f[1];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return [...by.values()].sort((a, b) => a.t - b.t || a.node.localeCompare(b.node));
|
|
112
|
+
}
|
|
113
|
+
|
|
90
114
|
export function readSamples(text) {
|
|
91
115
|
const out = [];
|
|
92
116
|
String(text).split(/\r?\n/).forEach((l, i) => {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Platforms: where a node runs, which changes what can be done about it. The accelerator vendor (vendors.mjs) says
|
|
2
|
+
// how to read a device and reset it; the platform says who owns the hardware. On a cloud you can't reseat a card or
|
|
3
|
+
// align firmware, and rebooting or replacing a node means acting on the cloud's instance, not on the node name.
|
|
4
|
+
//
|
|
5
|
+
// A node's platform: cfg.nodes[node].platform, else the first cfg.platformByNode regex that matches, else cfg.platform.
|
|
6
|
+
// cfg.nodes[node] also carries the instance, zone and project the executors fill in ({instance}, {zone}, {project}).
|
|
7
|
+
// cfg.nodesFrom: a `kubectl get nodes -o json` file whose spec.providerID fills cfg.nodes (loadPlatformNodes).
|
|
8
|
+
//
|
|
9
|
+
// A profile has executors (they win over the vendor's and the global ones), unsupported action kinds, and
|
|
10
|
+
// autoRepair: when the cloud's own node repair is on (EKS node auto repair, GKE node auto-repair), reboot and replace
|
|
11
|
+
// are left to it: they become notes, so gpu-health and the cloud don't both act on one node.
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
|
|
14
|
+
const OWNED_BY_PROVIDER = ['reseat', 'firmware-align', 'facilities-check'];
|
|
15
|
+
export const PLATFORMS = {
|
|
16
|
+
aws: {
|
|
17
|
+
name: 'AWS EC2',
|
|
18
|
+
executors: {
|
|
19
|
+
'node-reboot': [['aws', 'ec2', 'reboot-instances', '--instance-ids', '{instance}']],
|
|
20
|
+
// marking the instance unhealthy makes its Auto Scaling group (EKS managed node groups use one) replace it
|
|
21
|
+
'rma': [['aws', 'autoscaling', 'set-instance-health', '--instance-id', '{instance}', '--health-status', 'Unhealthy', '--no-should-respect-grace-period']],
|
|
22
|
+
},
|
|
23
|
+
unsupported: OWNED_BY_PROVIDER,
|
|
24
|
+
autoRepairNote: 'EKS node auto repair reboots or replaces this node itself once the node monitoring agent sets AcceleratedHardwareReady=False (after about 10 minutes): check the node condition and events.',
|
|
25
|
+
},
|
|
26
|
+
// Compute Engine VMs (Slurm or VM-based clusters): reset the VM; report the host as faulty so Compute Engine repairs
|
|
27
|
+
// it (gcloud compute instances report-host-as-faulty: behaviors PERFORMANCE, SILENT_DATA_CORRUPTION,
|
|
28
|
+
// UNRECOVERABLE_GPU_ERROR, CHIP_ERROR for TPUs).
|
|
29
|
+
gcp: {
|
|
30
|
+
name: 'Google Compute Engine',
|
|
31
|
+
executors: {
|
|
32
|
+
'node-reboot': [['gcloud', 'compute', 'instances', 'reset', '{instance}', '--zone={zone}', '--project={project}']],
|
|
33
|
+
'rma': [['gcloud', 'compute', 'instances', 'report-host-as-faulty', '{instance}', '--zone={zone}', '--project={project}', '--disruption-schedule=IMMEDIATE', '--fault-reasons=behavior={behavior},description=gpu-health']],
|
|
34
|
+
},
|
|
35
|
+
behaviors: { sdc: 'SILENT_DATA_CORRUPTION', performance: 'PERFORMANCE', tpu: 'CHIP_ERROR', default: 'UNRECOVERABLE_GPU_ERROR' },
|
|
36
|
+
unsupported: OWNED_BY_PROVIDER,
|
|
37
|
+
},
|
|
38
|
+
// GKE: label the node with the fault and GKE drains it, reports the host and brings it back repaired
|
|
39
|
+
// (docs.cloud.google.com/ai-hypercomputer/docs/manage/manage-gke-clusters: PERFORMANCE, SDC, XID).
|
|
40
|
+
gke: {
|
|
41
|
+
name: 'Google Kubernetes Engine',
|
|
42
|
+
executors: {
|
|
43
|
+
'node-reboot': [['gcloud', 'compute', 'instances', 'reset', '{instance}', '--zone={zone}', '--project={project}']],
|
|
44
|
+
'rma': [['kubectl', 'label', 'node', '{node}', 'cloud.google.com/fault-behavior={behavior}', '--overwrite']],
|
|
45
|
+
},
|
|
46
|
+
behaviors: { sdc: 'SDC', performance: 'PERFORMANCE', default: 'XID' },
|
|
47
|
+
// GKE's faulty-host label is documented for GPU nodes; TPU slices keep the TPU profile's steps
|
|
48
|
+
skipKinds: ['tpu'],
|
|
49
|
+
unsupported: OWNED_BY_PROVIDER,
|
|
50
|
+
autoRepairNote: 'GKE node auto-repair recreates this node itself when it stays unhealthy (about 10 minutes); a multi-host TPU slice is recreated as a whole node pool.',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export function platformOf(cfg, node) {
|
|
55
|
+
if (!cfg) return null;
|
|
56
|
+
const n = (cfg.nodes || {})[node];
|
|
57
|
+
if (n && n.platform) return n.platform;
|
|
58
|
+
for (const [re, p] of Object.entries(cfg.platformByNode || {})) if (node != null && new RegExp(re).test(String(node))) return p;
|
|
59
|
+
return cfg.platform || null;
|
|
60
|
+
}
|
|
61
|
+
// the profile with any per-config overrides merged in ({ platforms: { aws: { autoRepair: true } } })
|
|
62
|
+
export function platformProfile(cfg, node) {
|
|
63
|
+
const k = platformOf(cfg, node); if (!k) return null;
|
|
64
|
+
const base = PLATFORMS[k] || {}, over = ((cfg && cfg.platforms) || {})[k] || {};
|
|
65
|
+
const p = Object.assign({ key: k }, base, over, { executors: Object.assign({}, base.executors, over.executors) });
|
|
66
|
+
if (p.autoRepair) for (const kind of ['node-reboot', 'rma']) p.executors[kind] = { webhook: p.autoRepairNote || `${p.name || k} repairs this node itself: check its repair status.` };
|
|
67
|
+
return p;
|
|
68
|
+
}
|
|
69
|
+
// spec.providerID → { provider, zone?, project?, instance }: aws:///us-east-1a/i-0abc…, gce://project/zone/name, azure:///…/name
|
|
70
|
+
export function cloudIdentity(providerID) {
|
|
71
|
+
const p = String(providerID || ''), m = p.match(/^(\w+):\/\/(.*)$/);
|
|
72
|
+
if (!m) return null;
|
|
73
|
+
const parts = m[2].split('/').filter(Boolean);
|
|
74
|
+
if (m[1] === 'aws') return { provider: 'aws', zone: parts.length > 1 ? parts[parts.length - 2] : undefined, instance: parts[parts.length - 1] };
|
|
75
|
+
if (m[1] === 'gce') return { provider: 'gcp', project: parts[0], zone: parts[1], instance: parts[2] };
|
|
76
|
+
if (m[1] === 'azure') return { provider: 'azure', instance: parts[parts.length - 1] };
|
|
77
|
+
return { provider: m[1], instance: parts[parts.length - 1] };
|
|
78
|
+
}
|
|
79
|
+
// `kubectl get nodes -o json` → { node: { platform, instance, zone, project } } for cfg.nodes
|
|
80
|
+
export function nodesFromK8s(json) {
|
|
81
|
+
const j = typeof json === 'string' ? JSON.parse(json) : json, out = {};
|
|
82
|
+
for (const n of j.items || []) {
|
|
83
|
+
const c = cloudIdentity((n.spec || {}).providerID); if (!c) continue;
|
|
84
|
+
const gke = c.provider === 'gcp' && Object.keys((n.metadata || {}).labels || {}).some(k => k.startsWith('cloud.google.com/gke-'));
|
|
85
|
+
const r = { platform: gke ? 'gke' : c.provider, instance: c.instance, zone: c.zone, project: c.project };
|
|
86
|
+
for (const k of Object.keys(r)) if (r[k] == null) delete r[k];
|
|
87
|
+
out[n.metadata.name] = r;
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
// cfg.nodesFrom (a file path) → cfg.nodes, with nodes already in the config winning
|
|
92
|
+
export function loadPlatformNodes(cfg, read = f => fs.readFileSync(f, 'utf8')) {
|
|
93
|
+
if (!cfg || !cfg.nodesFrom) return cfg;
|
|
94
|
+
const found = nodesFromK8s(read(cfg.nodesFrom)), nodes = Object.assign({}, found);
|
|
95
|
+
for (const [k, v] of Object.entries(cfg.nodes || {})) nodes[k] = Object.assign({}, found[k], v);
|
|
96
|
+
return Object.assign({}, cfg, { nodes });
|
|
97
|
+
}
|
|
98
|
+
// what executors may fill in for an action: the node's instance, zone and project on the cloud, and the fault
|
|
99
|
+
// behavior the cloud's repair API wants for the action's fault class
|
|
100
|
+
export function nodeVars(cfg, node, a = {}) {
|
|
101
|
+
const n = ((cfg && cfg.nodes) || {})[node] || {}, p = platformProfile(cfg, node);
|
|
102
|
+
const out = {};
|
|
103
|
+
for (const k of ['instance', 'zone', 'project']) if (n[k] != null) out[k] = n[k];
|
|
104
|
+
if (p && p.behaviors) {
|
|
105
|
+
const cls = String(a.faultClass || ''), b = p.behaviors;
|
|
106
|
+
out.behavior = /sdc|corrupt/i.test(cls) ? b.sdc : /perf|slow|straggl|throttl/i.test(cls) ? b.performance : a.kind === 'tpu' || a.devKind === 'tpu' || a.vendor === 'tpu' ? (b.tpu || b.default) : b.default;
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
// Metric names follow each vendor's published exporter. Check them against the versions you run and override any of
|
|
18
18
|
// them in the config file.
|
|
19
19
|
|
|
20
|
+
import { platformProfile } from './platforms.mjs';
|
|
21
|
+
|
|
20
22
|
export const VENDORS = {
|
|
21
23
|
nvidia: {
|
|
22
24
|
name: 'NVIDIA', kind: 'gpu',
|
|
@@ -147,17 +149,22 @@ export function faultDef(cfg, vendor, code) {
|
|
|
147
149
|
// What to call one device in messages.
|
|
148
150
|
export const noun = kind => ({ tpu: 'TPU chip', rdu: 'RDU' }[kind] || 'GPU');
|
|
149
151
|
|
|
150
|
-
|
|
152
|
+
// node (optional): the node's platform can rule out more (no reseat on a cloud instance)
|
|
153
|
+
export const supports = (cfg, vendor, kind, node) => !((vendorOf(cfg, vendor) || {}).unsupported || []).includes(kind)
|
|
154
|
+
&& !((platformProfile(cfg, node) || {}).unsupported || []).includes(kind);
|
|
151
155
|
|
|
152
156
|
// Repair ladder for a fault class on a vendor, with steps the platform can't do left out.
|
|
153
|
-
export function ladderFor(cfg, vendor, cls) {
|
|
157
|
+
export function ladderFor(cfg, vendor, cls, node) {
|
|
154
158
|
const v = vendorOf(cfg, vendor) || {}, vl = v.ladder || {};
|
|
155
|
-
const l = (vl[cls] || vl.default || cfg.ladder[cls] || cfg.ladder.default).filter(k => supports(cfg, vendor, k));
|
|
159
|
+
const l = (vl[cls] || vl.default || cfg.ladder[cls] || cfg.ladder.default).filter(k => supports(cfg, vendor, k, node));
|
|
156
160
|
return l.length ? l : ['rma'];
|
|
157
161
|
}
|
|
158
162
|
|
|
159
|
-
// Executor for an action: the
|
|
160
|
-
|
|
163
|
+
// Executor for an action: the node's platform's (reboot or replace a cloud instance), else the vendor's own, else the
|
|
164
|
+
// global one.
|
|
165
|
+
export function executorFor(cfg, vendor, kind, node) {
|
|
166
|
+
const p = platformProfile(cfg, node), v0 = vendorOf(cfg, vendor);
|
|
167
|
+
if (p && p.executors && p.executors[kind] != null && !(p.skipKinds || []).includes((v0 || {}).kind)) return p.executors[kind];
|
|
161
168
|
const v = vendorOf(cfg, vendor);
|
|
162
169
|
if (v && v.executors && v.executors[kind] != null) return v.executors[kind];
|
|
163
170
|
return cfg.executors[kind];
|
|
@@ -4,7 +4,8 @@ import fs from 'node:fs';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { loadConfig } from '../src/config.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { loadPlatformNodes } from '../src/platforms.mjs';
|
|
8
|
+
import { readSamples, samplesFromExporter, samplesFromCloudMonitoring } from '../src/ingest.mjs';
|
|
8
9
|
import { analyze } from '../src/analyze.mjs';
|
|
9
10
|
import { persistable } from '../src/health.mjs';
|
|
10
11
|
import { Store } from '../src/actions.mjs';
|
|
@@ -18,7 +19,7 @@ const HELP = `gpu-health — GPU health, efficiency and savings, with an approva
|
|
|
18
19
|
gpu-health demo [--out DIR] [--mixed] build a demo fleet with planted problems and analyze it
|
|
19
20
|
(--mixed: AMD, SambaNova and Cloud TPU nodes instead)
|
|
20
21
|
gpu-health analyze --samples F[,F] --jobs F analyze; writes STATE/analysis.json and updates the action queue
|
|
21
|
-
[--prom F[,F]] [--vendor nvidia|amd|sambanova] [--steps F] [--probes F] [--results F] [--cluster F] [--config F] [--days 7] [--now EPOCH]
|
|
22
|
+
[--prom F[,F]] [--cloud-monitoring F[,F]] [--vendor nvidia|amd|sambanova] [--steps F] [--probes F] [--results F] [--cluster F] [--config F] [--days 7] [--now EPOCH]
|
|
22
23
|
[--execute [--live]] also run actions the policy approves automatically
|
|
23
24
|
gpu-health actions list [--status open|all|proposed|approved|executed|rejected]
|
|
24
25
|
gpu-health actions approve ID... --by NAME
|
|
@@ -52,7 +53,7 @@ const readJson = f => (f.endsWith('.jsonl') ? readJsonl(f) : JSON.parse(read(f))
|
|
|
52
53
|
const list = v => (v && v !== true ? String(v).split(',').map(s => s.trim()).filter(Boolean) : []);
|
|
53
54
|
const $ = v => '$' + Math.round(v || 0).toLocaleString('en-US');
|
|
54
55
|
|
|
55
|
-
function config(o) { return loadConfig(o.config ? JSON.parse(read(o.config)) : {}); }
|
|
56
|
+
function config(o) { return loadPlatformNodes(loadConfig(o.config ? JSON.parse(read(o.config)) : {})); }
|
|
56
57
|
function stateDir(o) { return path.resolve(o.state && o.state !== true ? o.state : 'gpu-health-state'); }
|
|
57
58
|
function prevHealth(dir) { const f = path.join(dir, 'health.json'); return fs.existsSync(f) ? JSON.parse(read(f)) : { gpus: {} }; }
|
|
58
59
|
// executed releases feed back into health as results
|
|
@@ -146,7 +147,8 @@ async function main() {
|
|
|
146
147
|
for (const f of list(o.samples)) samples.push(...readSamples(read(f)));
|
|
147
148
|
const cfgIn = config(o);
|
|
148
149
|
for (const f of list(o.prom)) samples.push(...samplesFromExporter(read(f), { t: o.now ? +o.now : undefined, vendor: o.vendor && o.vendor !== true ? o.vendor : undefined, vendors: cfgIn.vendors, mappings: cfgIn.ingest.mappings }));
|
|
149
|
-
|
|
150
|
+
for (const f of list(o['cloud-monitoring'])) samples.push(...samplesFromCloudMonitoring(read(f)));
|
|
151
|
+
if (!samples.length) throw new Error('give --samples (JSONL), --prom (exporter text) and/or --cloud-monitoring (Google Cloud Monitoring timeSeries JSON)');
|
|
150
152
|
const input = { samples, jobs: o.jobs ? readJson(o.jobs) : [], steps: o.steps ? readJsonl(o.steps) : [], probes: o.probes ? readJsonl(o.probes) : [],
|
|
151
153
|
results: o.results ? readJsonl(o.results) : [], cluster: o.cluster ? readJson(o.cluster) : null };
|
|
152
154
|
const { a, store, cfg } = runAnalysis(o, input);
|
package/gpu-ledger/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# gpu-ledger
|
|
2
2
|
|
|
3
3
|
GPU billing and waste for any cluster: who used which GPUs, what it cost, how much of it was useful work, and where
|
|
4
|
-
to save. It runs on its own (Node.js
|
|
4
|
+
to save. It runs on its own (Node.js 22+, no dependencies, no other tool from this repo needed) against what a cluster
|
|
5
5
|
already has: Kubernetes, DCGM and vLLM metrics in Prometheus, Slurm accounting, OpenCost, or a CSV.
|
|
6
6
|
|
|
7
7
|
```
|
|
@@ -70,6 +70,8 @@ Where to save (per month):
|
|
|
70
70
|
| vLLM in Prometheus | `--prom` with `vllm:generation_tokens_total`, `vllm:prompt_tokens_total`, `vllm:request_success_total` | tokens and requests per serving pod and hour |
|
|
71
71
|
| Slurm | `import slurm sacct.txt` | jobs with `gres/gpu`, user, account, partition, state |
|
|
72
72
|
| OpenCost / Kubecost | `import opencost allocation.json` | per-pod GPU-hours from `/allocation` |
|
|
73
|
+
| AWS Cost and Usage Report | `import aws-cur cur.csv[.gz]` (CUR 2.0 data export or legacy CUR, with resource IDs) | GPU instance-hours priced at what was billed: Savings Plan and Reserved effective cost, Spot, on demand. The GPU type and count come from the instance type; tags (`user:team`) attribute |
|
|
74
|
+
| Google Cloud Billing export | `import gcp-billing export.jsonl` (the BigQuery standard or detailed usage cost export, as JSON lines or an array) | GPU and TPU hours from their own SKUs (`Nvidia H100 80GB GPU …`, `TpuV6e …`), net of credits: committed use, spot, calendar mode, on demand. The VM's vCPU and memory are separate lines and not included. GKE cost-allocation labels give the cluster and namespace |
|
|
73
75
|
| Anything else | `import csv FILE --map start=…,end=…,gpus=…,user=…` | your own columns |
|
|
74
76
|
| fleetops | `fleetops data export gpu-ledger --out usage.jsonl --capacity cap.json` | placements, status, utilization and inventory from a fleetops store |
|
|
75
77
|
|
package/gpu-ledger/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gpu-ledger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"private": true,
|
|
6
6
|
"description": "GPU billing and waste for any cluster: who used which GPUs, what it cost, how much was useful, and where to save. Exports FOCUS.",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"bin": {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
"bin": {
|
|
9
|
+
"gpu-ledger": "tools/ledger.mjs"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "node --test tests/*.test.mjs",
|
|
13
|
+
"demo": "node tools/ledger.mjs demo",
|
|
14
|
+
"test:coverage": "node --test --experimental-test-coverage --test-coverage-exclude='tests/**' --test-coverage-exclude='../**' --test-coverage-lines=91 --test-coverage-branches=80 tests/*.test.mjs"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22"
|
|
18
|
+
}
|
|
11
19
|
}
|
|
@@ -4,7 +4,8 @@ import fs from 'node:fs';
|
|
|
4
4
|
import readline from 'node:readline';
|
|
5
5
|
import { gpuKey } from './core.mjs';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// a time that doesn't parse is no time (null), not NaN: the record is dropped or the time left open
|
|
8
|
+
const t = s => { if (s == null || s === '' || s === 'Unknown' || s === 'None') return null; if (typeof s === 'number') return s; const v = Math.floor(Date.parse(/[zZ]|[+-]\d\d:?\d\d$/.test(s) ? s : s.replace(' ', 'T') + 'Z') / 1000); return Number.isFinite(v) ? v : null; };
|
|
8
9
|
const splitCsv = line => { const out = []; let cur = '', q = false; for (let i = 0; i < line.length; i++) { const c = line[i]; if (q) { if (c === '"' && line[i + 1] === '"') { cur += '"'; i++; } else if (c === '"') q = false; else cur += c; } else if (c === '"') q = true; else if (c === ',') { out.push(cur); cur = ''; } else cur += c; } out.push(cur); return out; };
|
|
9
10
|
export const parseCsv = text => { const lines = text.split(/\r?\n/).filter(l => l.trim()); const head = splitCsv(lines[0]).map(h => h.trim()); return lines.slice(1).map(l => { const v = splitCsv(l); return Object.fromEntries(head.map((h, i) => [h, v[i]])); }); };
|
|
10
11
|
|
|
@@ -68,7 +69,7 @@ export function k8s({ pods, nodes, prom = [], cluster = null, now = Math.floor(D
|
|
|
68
69
|
const tok = ser.filter(s => /generation_tokens_total/.test(s.name)), pin = ser.filter(s => /prompt_tokens_total/.test(s.name)), rq = ser.filter(s => /request_success_total/.test(s.name));
|
|
69
70
|
if (!tok.length) { out.push(base); continue; }
|
|
70
71
|
// serving pods: one record per hour with the counters' increase in that hour
|
|
71
|
-
const model = tok[0].model, inc = (ss, a, b) => ss.reduce((acc, s) => { let first = null,
|
|
72
|
+
const model = tok[0].model, inc = (ss, a, b) => ss.reduce((acc, s) => { let first = null, prev = null, sum = 0; for (const [ts, v] of s.values) { if (ts < a || ts > b) continue; if (prev != null) sum += v >= prev ? v - prev : v; prev = v; first ??= v; } return acc + sum; }, 0);
|
|
72
73
|
const e = end ?? now;
|
|
73
74
|
for (let h = Math.floor(start / 3600) * 3600; h < e; h += 3600) {
|
|
74
75
|
const a = Math.max(start, h), b = Math.min(e, h + 3600);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Cloud bills → usage records, priced at what the bill says (rate = billed $ per GPU-hour, rateBasis 'bill').
|
|
2
|
+
// The GPU type and count come from the instance type, through the shared accelerator registry.
|
|
3
|
+
//
|
|
4
|
+
// AWS Cost and Usage Report: the CUR 2.0 data export (snake_case columns; product, resource_tags and tags as JSON maps
|
|
5
|
+
// in CSV) or the legacy CUR (lineItem/…, product/…, resourceTags/user:… columns). It needs resource IDs
|
|
6
|
+
// (INCLUDE_RESOURCES) to give one record per instance; without them, one per usage type and hour. Hourly granularity
|
|
7
|
+
// gives one record per instance-hour; daily works too (a day's usage spread over the day).
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import { parseCsv } from './adapters.mjs';
|
|
10
|
+
import { gpuKey } from './core.mjs';
|
|
11
|
+
|
|
12
|
+
const REG = createRequire(import.meta.url)('../../inference-sizer/src/accelerators.js');
|
|
13
|
+
const t = s => (s == null || s === '' ? null : Math.floor(Date.parse(/[zZ]|[+-]\d\d:?\d\d$/.test(s) ? s : String(s).replace(' ', 'T') + 'Z') / 1000));
|
|
14
|
+
const map = v => { if (!v) return {}; if (typeof v === 'object') return v; try { const o = JSON.parse(v); return o && typeof o === 'object' ? o : {}; } catch { return {}; } };
|
|
15
|
+
const num = v => (v == null || v === '' ? null : +v);
|
|
16
|
+
|
|
17
|
+
const COLS = {
|
|
18
|
+
start: ['line_item_usage_start_date', 'lineItem/UsageStartDate'], end: ['line_item_usage_end_date', 'lineItem/UsageEndDate'],
|
|
19
|
+
product: ['line_item_product_code', 'lineItem/ProductCode'], usageType: ['line_item_usage_type', 'lineItem/UsageType'],
|
|
20
|
+
itemType: ['line_item_line_item_type', 'lineItem/LineItemType'], resource: ['line_item_resource_id', 'lineItem/ResourceId'],
|
|
21
|
+
amount: ['line_item_usage_amount', 'lineItem/UsageAmount'], unblended: ['line_item_unblended_cost', 'lineItem/UnblendedCost'],
|
|
22
|
+
spCost: ['savings_plan_savings_plan_effective_cost', 'savingsPlan/SavingsPlanEffectiveCost'], riCost: ['reservation_effective_cost', 'reservation/EffectiveCost'],
|
|
23
|
+
instanceType: ['product_instance_type', 'product/instanceType'], region: ['product_region_code', 'product/regionCode', 'product_region', 'product/region'],
|
|
24
|
+
account: ['line_item_usage_account_id', 'lineItem/UsageAccountId'],
|
|
25
|
+
};
|
|
26
|
+
const col = (r, k) => { for (const c of COLS[k]) if (r[c] != null && r[c] !== '') return r[c]; return null; };
|
|
27
|
+
// user-defined cost allocation tags: CUR 2.0 writes user:team as user_team in its maps; legacy CUR as resourceTags/user:team
|
|
28
|
+
function tagsOf(r) {
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const m of [map(r.resource_tags), map(r.tags)]) for (const [k, v] of Object.entries(m)) if (v != null && v !== '') out[k.replace(/^(user|resource_tags_user)[_:]/, '')] = String(v);
|
|
31
|
+
for (const [k, v] of Object.entries(r)) { const x = k.match(/^resourceTags\/user:(.+)$/) || k.match(/^resource_tags_user_(.+)$/); if (x && v) out[x[1]] = v; }
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
// how the hour was bought, from the line item type and usage type
|
|
35
|
+
const purchaseOf = (itemType, usageType) => itemType === 'SavingsPlanCoveredUsage' ? 'savings-plan' : itemType === 'DiscountedUsage' ? 'reserved'
|
|
36
|
+
: /SpotUsage/i.test(usageType || '') ? 'spot' : /CapacityBlock/i.test(usageType || '') ? 'capacity-block' : 'on-demand';
|
|
37
|
+
|
|
38
|
+
export function awsCur(text, { cluster = null } = {}) {
|
|
39
|
+
const rows = typeof text === 'string' ? parseCsv(text) : text, out = [], skipped = { notEc2: 0, notGpu: 0, notUsage: 0 }, unknownTypes = new Set();
|
|
40
|
+
rows.forEach((r, i) => {
|
|
41
|
+
if (col(r, 'product') !== 'AmazonEC2') { skipped.notEc2++; return; }
|
|
42
|
+
const itemType = col(r, 'itemType'), usageType = col(r, 'usageType') || '';
|
|
43
|
+
if (!['Usage', 'DiscountedUsage', 'SavingsPlanCoveredUsage'].includes(itemType) || !/(Box|Spot|Dedicated|Host|CapacityBlock)Usage|CapacityBlock/i.test(usageType)) { skipped.notUsage++; return; }
|
|
44
|
+
const itype = col(r, 'instanceType') || map(r.product).instance_type || (usageType.split(':')[1] || null), inst = REG.instanceOf(itype);
|
|
45
|
+
if (!inst) { skipped.notGpu++; if (itype && /^(p|g|trn|inf|dl)\d/.test(itype)) unknownTypes.add(itype); return; }
|
|
46
|
+
const start = t(col(r, 'start')), end = t(col(r, 'end')), hours = num(col(r, 'amount'));
|
|
47
|
+
if (start == null || end == null || !(end > start) || !(hours > 0)) { skipped.notUsage++; return; }
|
|
48
|
+
const cost = itemType === 'SavingsPlanCoveredUsage' ? num(col(r, 'spCost')) : itemType === 'DiscountedUsage' ? num(col(r, 'riCost')) : num(col(r, 'unblended'));
|
|
49
|
+
const tags = tagsOf(r), resource = col(r, 'resource');
|
|
50
|
+
out.push({ id: `${resource || usageType}@${start}`, start, end, gpus: inst.gpus * hours / ((end - start) / 3600), gpuType: gpuKey(inst.chip), cluster: tags.cluster || cluster, provider: 'aws',
|
|
51
|
+
region: col(r, 'region') || undefined, node: resource || undefined, kind: 'instance', name: tags.Name || tags.name || resource || itype, labels: tags, group: resource || itype,
|
|
52
|
+
instanceType: itype, purchase: purchaseOf(itemType, usageType), account: col(r, 'account') || undefined,
|
|
53
|
+
...(cost != null ? { rate: cost / (hours * inst.gpus), billed: cost } : {}), source: 'aws-cur' });
|
|
54
|
+
for (const k of Object.keys(out[out.length - 1])) if (out[out.length - 1][k] === undefined) delete out[out.length - 1][k];
|
|
55
|
+
});
|
|
56
|
+
out.skipped = skipped; out.unknownTypes = [...unknownTypes];
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Google Cloud Billing export to BigQuery (standard or detailed usage cost), as JSON lines or a JSON array — what
|
|
61
|
+
// `bq query --format=json` or an export to newline-delimited JSON gives (CSV can't hold its nested labels and credits).
|
|
62
|
+
// GPUs and TPUs are billed as their own SKUs ("Nvidia H100 80GB GPU running in Americas", "TpuV6e running in
|
|
63
|
+
// Americas"), metered in seconds of one device: so GPU-hours = usage seconds ÷ 3600, and the record covers the
|
|
64
|
+
// accelerator charges only (the VM's vCPU and memory are other lines). Cost is net of credits (committed-use and
|
|
65
|
+
// sustained-use discounts, promotions). Commitment fee lines ("Commitment v1: …") are not usage and are skipped.
|
|
66
|
+
const get = (o, k) => k.split('.').reduce((x, p) => (x == null ? undefined : x[p]), o) ?? o[k];
|
|
67
|
+
function gcpChip(sku) {
|
|
68
|
+
const s = String(sku || '');
|
|
69
|
+
const tpu = s.match(/\bTpu\s?(V\w+)|\bTPU\s?(v\d\w*|7x)|Ironwood|Trillium/i);
|
|
70
|
+
if (tpu) { const m = REG.match(`tpu ${(tpu[1] || tpu[2] || tpu[0]).toLowerCase()}`); return m ? { chip: m.id, kind: 'tpu' } : null; }
|
|
71
|
+
const g = s.match(/\bNvidia\s+(?:Tesla\s+)?(.+?)\s+GPU\b/i);
|
|
72
|
+
if (!g) return null;
|
|
73
|
+
const name = g[1];
|
|
74
|
+
if (/A100/i.test(name) && !/80\s?GB/i.test(name)) return { chip: 'A100-40GB', kind: 'gpu' };
|
|
75
|
+
const m = REG.match(`NVIDIA ${name}`);
|
|
76
|
+
return m ? { chip: m.id, kind: 'gpu' } : { chip: name, kind: 'gpu', unknown: true };
|
|
77
|
+
}
|
|
78
|
+
const gcpPurchase = (sku, credits) => /\bSpot\b|Preemptible/i.test(sku) ? 'spot' : /Calendar Mode/i.test(sku) ? 'calendar-mode' : /Flex[- ]?start|DWS/i.test(sku) ? 'flex-start'
|
|
79
|
+
: (credits || []).some(c => /COMMITTED_USAGE/i.test(c.type || '')) ? 'committed' : 'on-demand';
|
|
80
|
+
export function gcpBilling(text, { cluster = null } = {}) {
|
|
81
|
+
const rows = typeof text !== 'string' ? text : text.trim().startsWith('[') ? JSON.parse(text) : text.split(/\r?\n/).filter(l => l.trim()).map(l => JSON.parse(l));
|
|
82
|
+
const out = [], skipped = { notAccelerator: 0, commitmentFee: 0, notUsage: 0 }, unknownSkus = new Set();
|
|
83
|
+
for (const r of rows) {
|
|
84
|
+
const sku = get(r, 'sku.description') || '';
|
|
85
|
+
if (/^Commitment/i.test(sku)) { skipped.commitmentFee++; continue; }
|
|
86
|
+
const c = gcpChip(sku);
|
|
87
|
+
if (!c) { skipped.notAccelerator++; continue; }
|
|
88
|
+
if (c.unknown) unknownSkus.add(sku);
|
|
89
|
+
const start = t(get(r, 'usage_start_time')), end = t(get(r, 'usage_end_time')), unit = String(get(r, 'usage.unit') || 'seconds'), amount = +get(r, 'usage.amount');
|
|
90
|
+
const secs = /^s(ec(ond)?s?)?$|seconds/i.test(unit) ? amount : /^h(our)?s?$/i.test(unit) ? amount * 3600 : NaN;
|
|
91
|
+
if (start == null || end == null || !(end > start) || !(secs > 0)) { skipped.notUsage++; continue; }
|
|
92
|
+
const credits = get(r, 'credits') || [], cost = +(get(r, 'cost') || 0) + credits.reduce((a, x) => a + (+x.amount || 0), 0);
|
|
93
|
+
const labels = Object.fromEntries((get(r, 'labels') || []).map(l => [l.key, String(l.value)]));
|
|
94
|
+
const resource = get(r, 'resource.name') || undefined, project = get(r, 'project.id');
|
|
95
|
+
const rec = { id: `${resource || `${project}/${sku}`}@${start}`, start, end, gpus: secs / (end - start), gpuType: gpuKey(c.chip), kind: c.kind === 'tpu' ? 'tpu' : 'instance',
|
|
96
|
+
cluster: labels['goog-k8s-cluster-name'] || labels.cluster || cluster, provider: 'gcp', region: get(r, 'location.region') || undefined, node: resource, project,
|
|
97
|
+
namespace: labels['k8s-namespace'], name: labels['k8s-workload-name'] || resource || sku, labels, group: resource || sku, purchase: gcpPurchase(sku, credits), sku,
|
|
98
|
+
rate: cost / (secs / 3600), billed: cost, source: 'gcp-billing' };
|
|
99
|
+
for (const k of Object.keys(rec)) if (rec[k] === undefined || rec[k] === null) delete rec[k];
|
|
100
|
+
out.push(rec);
|
|
101
|
+
}
|
|
102
|
+
out.skipped = skipped; out.unknownSkus = [...unknownSkus];
|
|
103
|
+
return out;
|
|
104
|
+
}
|
package/gpu-ledger/src/core.mjs
CHANGED
|
@@ -9,20 +9,21 @@
|
|
|
9
9
|
// status? ('succeeded'|'failed'|'cancelled'|'preempted'|'running'),
|
|
10
10
|
// util? { busy (0–1: share of GPU-time above the idle threshold), sm (0–1 mean SM activity while busy),
|
|
11
11
|
// memPeak (0–1 of HBM), idleLong (GPU-seconds idle in stretches ≥ 30 min), samples },
|
|
12
|
-
// checkpoint? { intervalS?, lastAt? }, serving? { model, tokensIn, tokensOut, requests }
|
|
12
|
+
// checkpoint? { intervalS?, lastAt? }, serving? { model, tokensIn, tokensOut, requests },
|
|
13
|
+
// rate? ($/GPU-h actually billed, from a cloud bill: wins over the rate card), purchase?, instanceType? }
|
|
13
14
|
//
|
|
14
15
|
// Classes (they add up to the allocation): useful, idle (allocated, GPU not working), lost (work thrown away by a
|
|
15
16
|
// failure or preemption). Unallocated capacity is counted per cluster and GPU type, outside any one workload.
|
|
16
17
|
|
|
18
|
+
import { createRequire } from 'node:module';
|
|
19
|
+
|
|
17
20
|
// Spec-sheet numbers: HBM per GPU, dense BF16 TFLOPS. Used only to say whether a job would fit on another GPU.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'
|
|
23
|
-
|
|
24
|
-
'V100': { hbmGB: 32, tflops: 125 }, 'P100': { hbmGB: 16, tflops: 19 }, 'K80': { hbmGB: 12, tflops: 4 },
|
|
25
|
-
};
|
|
21
|
+
// Chips the sizer knows come from the shared accelerator registry; older and smaller ones are listed here.
|
|
22
|
+
const REG = createRequire(import.meta.url)('../../inference-sizer/src/accelerators.js');
|
|
23
|
+
export const GPU_SPECS = Object.assign(
|
|
24
|
+
Object.fromEntries(REG.ACCELERATORS.map(a => [a.kind === 'tpu' ? a.id : a.short || a.id, { hbmGB: a.hbmGB, tflops: a.tfBf16 }])),
|
|
25
|
+
{ 'H20': { hbmGB: 96, tflops: 148 }, 'A100-40GB': { hbmGB: 40, tflops: 312 }, 'L4': { hbmGB: 24, tflops: 121 }, 'A10': { hbmGB: 24, tflops: 125 },
|
|
26
|
+
'T4': { hbmGB: 16, tflops: 65 }, 'V100': { hbmGB: 32, tflops: 125 }, 'P100': { hbmGB: 16, tflops: 19 }, 'K80': { hbmGB: 12, tflops: 4 } });
|
|
26
27
|
// "NVIDIA-H100-80GB-HBM3", "h100", "Tesla V100-SXM2-32GB" → a key above (or the input when unknown)
|
|
27
28
|
export function gpuKey(s) {
|
|
28
29
|
if (!s) return null;
|
|
@@ -113,7 +114,8 @@ export function classify(r, { from = -Infinity, to = Infinity, now = Infinity, p
|
|
|
113
114
|
const L = lostSpan(r, whole, policy), tailStart = end - L.s, inWin = Math.max(0, Math.min(e, end) - Math.max(s, tailStart));
|
|
114
115
|
const lost = r.gpus * inWin * (busy != null ? busy : 1);
|
|
115
116
|
const useful = Math.max(0, alloc - idle - lost);
|
|
116
|
-
|
|
117
|
+
// a record from a cloud bill carries what was paid per GPU-hour; it wins over the rate card
|
|
118
|
+
const p = r.rate != null ? { rate: r.rate, basis: r.rateBasis || 'bill' } : card ? priceOf(card, prices, r.gpuType, r.provider) : null, rate = p ? p.rate : null;
|
|
117
119
|
const usd = h => (rate == null ? null : rate * h / 3600);
|
|
118
120
|
return {
|
|
119
121
|
r, alloc, useful, idle, lost, idleLong: u.idleLong != null ? u.idleLong * frac : null, lostBasis: L.basis, measured: busy != null,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// gpu-ledger: GPU billing and waste, for any cluster. See README.md.
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
+
import zlib from 'node:zlib';
|
|
4
5
|
import path from 'node:path';
|
|
5
6
|
import { createRequire } from 'node:module';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
import * as A from '../src/adapters.mjs';
|
|
9
|
+
import * as Cloud from '../src/cloud.mjs';
|
|
8
10
|
import { ledger, groupBy, budgets as budgetsOf, loaded } from '../src/ledger.mjs';
|
|
9
11
|
import { insights, sizerFrom } from '../src/insights.mjs';
|
|
10
|
-
import { reportText, showbackCsv, focusCsv
|
|
12
|
+
import { reportText, showbackCsv, focusCsv } from '../src/export.mjs';
|
|
11
13
|
import { html } from '../src/html.mjs';
|
|
12
14
|
import { rateCard } from '../src/core.mjs';
|
|
13
15
|
import { demo } from '../src/demo.mjs';
|
|
@@ -20,6 +22,8 @@ Bring usage in (appends to --out, JSON lines):
|
|
|
20
22
|
(sacct -a -P -X --format=JobID,JobName,User,Account,Partition,State,Start,End,NodeList,AllocTRES)
|
|
21
23
|
gpu-ledger import opencost allocation.json [--cluster C] --out usage.jsonl (/allocation?aggregate=pod&step=1h)
|
|
22
24
|
gpu-ledger import csv FILE [--map start=Start,end=End,gpus=GPUs,user=Owner,...] --out usage.jsonl
|
|
25
|
+
gpu-ledger import aws-cur cur.csv[.gz] [--cluster C] --out usage.jsonl (AWS CUR 2.0 or legacy CUR, with resource IDs)
|
|
26
|
+
gpu-ledger import gcp-billing export.json[l] [--cluster C] --out usage.jsonl (Cloud Billing export to BigQuery, as JSON)
|
|
23
27
|
gpu-ledger import acme acme_trace_kalos.csv --out usage.jsonl (public trace)
|
|
24
28
|
gpu-ledger import philly --jobs cluster_job_log --util cluster_gpu_util --machines cluster_machine_list [--from T --to T] [--capacity-out cap.json] --out usage.jsonl
|
|
25
29
|
|
|
@@ -80,9 +84,11 @@ async function main() {
|
|
|
80
84
|
if (sub === 'slurm') return writeUsage(A.slurm(text(), Object.assign({ gpuType: opt('gpu-type') }, common)));
|
|
81
85
|
if (sub === 'opencost') return writeUsage(A.opencost(json(f), common));
|
|
82
86
|
if (sub === 'csv') return writeUsage(A.csv(text(), Object.assign({ map: Object.fromEntries((opt('map') || '').split(',').filter(Boolean).map(x => x.split('='))) }, common)));
|
|
87
|
+
if (sub === 'aws-cur') { const recs = Cloud.awsCur(f.endsWith('.gz') ? zlib.gunzipSync(fs.readFileSync(f)).toString() : text(), common); if (!J) process.stderr.write(`aws-cur: ${recs.length} GPU instance line(s); skipped ${JSON.stringify(recs.skipped)}${recs.unknownTypes.length ? `; GPU-like instance types not in the registry: ${recs.unknownTypes.join(', ')}` : ''}\n`); return writeUsage(recs); }
|
|
88
|
+
if (sub === 'gcp-billing') { const recs = Cloud.gcpBilling(text(), common); if (!J) process.stderr.write(`gcp-billing: ${recs.length} GPU/TPU line(s); skipped ${JSON.stringify(recs.skipped)}${recs.unknownSkus.length ? `; GPU SKUs not in the registry: ${recs.unknownSkus.join('; ')}` : ''}\n`); return writeUsage(recs); }
|
|
83
89
|
if (sub === 'acme') return writeUsage(A.acme(text(), { cluster: opt('cluster') || 'kalos' }));
|
|
84
90
|
if (sub === 'philly') { const recs = await A.philly({ jobs: json(opt('jobs')), utilPath: opt('util'), machines: opt('machines') ? A.phillyMachines(read(opt('machines'))) : [], from: time(opt('from')), to: time(opt('to')) }); if (opt('capacity-out')) { fs.writeFileSync(opt('capacity-out'), JSON.stringify(recs.inventory, null, 1)); say(`capacity (GPUs reporting utilization) → ${opt('capacity-out')}`); } return writeUsage(recs); }
|
|
85
|
-
throw new Error('import k8s | slurm | opencost | csv | acme | philly');
|
|
91
|
+
throw new Error('import k8s | slurm | opencost | csv | aws-cur | gcp-billing | acme | philly');
|
|
86
92
|
}
|
|
87
93
|
if (cmd === 'demo') {
|
|
88
94
|
const dir = opt('out') || 'ledger-demo', d = demo(); fs.mkdirSync(dir, { recursive: true });
|