@mlbottleneck/engine 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.
- package/LICENSE +21 -0
- package/README.md +121 -0
- package/localmaxxing-snapshot.json +1 -0
- package/mlbottleneck-engine.d.ts +167 -0
- package/mlbottleneck-engine.mjs +7802 -0
- package/mlbottleneck-engine.umd.js +7810 -0
- package/package.json +49 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Type definitions for the ML Bottleneck engine SDK.
|
|
2
|
+
|
|
3
|
+
export type QuantFamily = 'float32' | 'float16' | 'bfloat16' | 'int8' | 'fp8' | 'q6' | 'q5' | 'q4' | 'q3' | 'q2';
|
|
4
|
+
export type Runtime = 'auto' | 'llama_cpp' | 'ollama' | 'mlx' | 'vllm' | 'sglang' | 'tensorrt_llm' | 'exo';
|
|
5
|
+
export type Strategy = 'auto' | 'pipeline' | 'tensor' | 'data' | 'expert' | 'sequence' | 'context' | 'hybrid_tp_pp' | 'hybrid_tp_dp';
|
|
6
|
+
export type SpeculationMethod = 'mtp' | 'dflash' | 'dspark' | 'eagle3' | 'draft_model' | 'ngram' | 'suffix';
|
|
7
|
+
export type Confidence = 'strong' | 'directional' | 'uncalibrated' | 'input-derived';
|
|
8
|
+
|
|
9
|
+
export interface ModelArchitecture {
|
|
10
|
+
/** Start from a catalog preset and override fields. */
|
|
11
|
+
preset?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
hfId?: string;
|
|
14
|
+
totalParamsB: number;
|
|
15
|
+
activeParamsB?: number;
|
|
16
|
+
hiddenSize: number;
|
|
17
|
+
numLayers: number;
|
|
18
|
+
numHeads: number;
|
|
19
|
+
numKVHeads?: number;
|
|
20
|
+
headDim?: number;
|
|
21
|
+
intermediateSize?: number;
|
|
22
|
+
vocabSize?: number;
|
|
23
|
+
isMoE?: boolean;
|
|
24
|
+
numExperts?: number;
|
|
25
|
+
activeExperts?: number;
|
|
26
|
+
attentionMechanism?: 'auto' | 'standard' | 'grouped_query' | 'multi_query' | 'mla' | 'sliding_window' | 'hybrid_linear' | 'hybrid_ssm';
|
|
27
|
+
contextLength?: number;
|
|
28
|
+
/** Model ships a multi-token-prediction head (enables the `mtp` method). */
|
|
29
|
+
useMTP?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface HardwareSpec {
|
|
33
|
+
/** Catalog template key, e.g. "RTX 4090" (case/space-insensitive). */
|
|
34
|
+
template?: string;
|
|
35
|
+
/** Number of identical devices. */
|
|
36
|
+
count?: number;
|
|
37
|
+
name?: string;
|
|
38
|
+
memoryGB?: number;
|
|
39
|
+
localBandwidthGBps?: number;
|
|
40
|
+
networkBandwidthGBps?: number;
|
|
41
|
+
computeTFlops?: Partial<Record<'float32' | 'float16' | 'bfloat16' | 'int8' | 'fp8' | 'q4', number>>;
|
|
42
|
+
/** Measured sustained bandwidth (GB/s) when you have it; replaces the modeled efficiency. */
|
|
43
|
+
sustainedBandwidthGBps?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface SpeculationRequest {
|
|
47
|
+
method?: SpeculationMethod;
|
|
48
|
+
/** Draft tokens per step (defaults to the method's published value). */
|
|
49
|
+
tokens?: number;
|
|
50
|
+
/** First-token acceptance, 0-1. */
|
|
51
|
+
acceptance?: number;
|
|
52
|
+
/** Draft model size as a fraction of the target (draft_model only). */
|
|
53
|
+
draftRatio?: number;
|
|
54
|
+
draftModel?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface PredictRequest {
|
|
58
|
+
model: string | ModelArchitecture;
|
|
59
|
+
hardware: string | HardwareSpec | Array<string | HardwareSpec>;
|
|
60
|
+
/** Family ("q4") or format label ("Q4_K_M", "MXFP4", "AWQ"); default q4. */
|
|
61
|
+
quantization?: QuantFamily | string;
|
|
62
|
+
runtime?: Runtime;
|
|
63
|
+
strategy?: Strategy;
|
|
64
|
+
batchSize?: number;
|
|
65
|
+
promptTokens?: number;
|
|
66
|
+
outputTokens?: number;
|
|
67
|
+
kvCacheCompression?: 'none' | 'q8_kv' | 'q4_kv' | string;
|
|
68
|
+
/** MoE only: pin this many layers' routed experts to system RAM (llama.cpp --n-cpu-moe N). */
|
|
69
|
+
cpuMoeLayers?: number;
|
|
70
|
+
optimization?: 'none' | 'speculative' | string;
|
|
71
|
+
speculation?: SpeculationRequest;
|
|
72
|
+
usage?: { hoursPerDay?: number; costPerKwh?: number };
|
|
73
|
+
/** Attach the full engine output (`raw`). */
|
|
74
|
+
includeRaw?: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface DeviceSummary {
|
|
78
|
+
name: string;
|
|
79
|
+
template: string;
|
|
80
|
+
memoryGB: number;
|
|
81
|
+
residentWeightGB: number | null;
|
|
82
|
+
kvCacheGB: number | null;
|
|
83
|
+
memoryUtilization: number | null;
|
|
84
|
+
hasOverflow: boolean;
|
|
85
|
+
overflowMode: 'experts' | 'weights' | string | null;
|
|
86
|
+
decodeTokensPerSecond: number | null;
|
|
87
|
+
prefillTokensPerSecond: number | null;
|
|
88
|
+
rooflineTokensPerSecond: number | null;
|
|
89
|
+
dominant: string | null;
|
|
90
|
+
/** 'memory' (weight stream), 'compute' (batched GEMMs), or 'attention' (score arithmetic over a deep KV). */
|
|
91
|
+
coreBinding: 'memory' | 'compute' | 'attention' | null;
|
|
92
|
+
decodeBreakdownMs: {
|
|
93
|
+
weightRead: number | null; kvRead: number | null; compute: number | null; attentionCompute: number | null; runtime: number | null;
|
|
94
|
+
draft: number | null; coordination: number | null; total: number | null;
|
|
95
|
+
} | null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface Prediction {
|
|
99
|
+
fits: boolean;
|
|
100
|
+
strategy: { key: Strategy; label: string; reasoning: string | null; auto: boolean };
|
|
101
|
+
decode: {
|
|
102
|
+
tokensPerSecond: number | null;
|
|
103
|
+
msPerToken: number | null;
|
|
104
|
+
perUserTokensPerSecond: number | null;
|
|
105
|
+
withoutSpeculation: number | null;
|
|
106
|
+
speculationMultiplier: number | null;
|
|
107
|
+
};
|
|
108
|
+
prefill: { tokensPerSecond: number | null; timeToFirstTokenSeconds: number | null };
|
|
109
|
+
ceiling: {
|
|
110
|
+
physicalTokensPerSecond: number | null;
|
|
111
|
+
latencyBoundTokensPerSecond: number | null;
|
|
112
|
+
optimizedTokensPerSecond: number | null;
|
|
113
|
+
expectedTokensPerSecond: number | null;
|
|
114
|
+
engineTokensPerSecond: number | null;
|
|
115
|
+
correctionFactor: number | null;
|
|
116
|
+
confidence: Confidence;
|
|
117
|
+
peers: number;
|
|
118
|
+
verifiedPeers: number;
|
|
119
|
+
} | null;
|
|
120
|
+
memory: { modelSizeGB: number | null; residentWeightsGB: number | null; kvCacheGB: number | null; availableGB: number | null };
|
|
121
|
+
bottleneck: string | null;
|
|
122
|
+
power: { watts: number | null; tdpWatts: number | null; costPerDay: number | null; costPer1KTokens: number | null } | null;
|
|
123
|
+
devices: DeviceSummary[];
|
|
124
|
+
warnings: string[];
|
|
125
|
+
config: {
|
|
126
|
+
model: string; quantization: QuantFamily; quantFormat: string | null; runtime: Runtime;
|
|
127
|
+
batchSize: number; promptTokens: number; outputTokens: number;
|
|
128
|
+
speculation: { method: string; label: string; tokensPerStep: number | null } | null;
|
|
129
|
+
};
|
|
130
|
+
raw?: { config: any; devices: any[]; metrics: any[]; strategy: any; calibration: any };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface ModelListing {
|
|
134
|
+
key: string; label: string; hfId: string | null; totalParamsB: number; activeParamsB: number;
|
|
135
|
+
isMoE: boolean; contextLength: number | null; supersededBy: string | null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface HardwareListing {
|
|
139
|
+
key: string; name: string; type: string | null; memoryGB: number; bandwidthGBps: number;
|
|
140
|
+
computeTFlops: Record<string, number> | null; backend: string | null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface EvidenceSnapshot {
|
|
144
|
+
generatedAt?: string;
|
|
145
|
+
goldCases: any[];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface Engine {
|
|
149
|
+
version: string;
|
|
150
|
+
evidenceGeneratedAt: string | null;
|
|
151
|
+
predict(request: PredictRequest): Prediction;
|
|
152
|
+
sweep(request: PredictRequest, options?: { maxContext?: number; levels?: number[] }): { context: any; concurrency: any };
|
|
153
|
+
listModels(): ModelListing[];
|
|
154
|
+
listHardware(): HardwareListing[];
|
|
155
|
+
setEvidence(snapshot: EvidenceSnapshot): void;
|
|
156
|
+
runtimes: Runtime[];
|
|
157
|
+
strategies: Strategy[];
|
|
158
|
+
quantizations: QuantFamily[];
|
|
159
|
+
speculationMethods: SpeculationMethod[];
|
|
160
|
+
catalogs: { MODEL_PRESETS: Record<string, any>; DEVICE_TEMPLATES: Record<string, any>; FRAMEWORK_PROFILES: Record<string, any>; SPECULATION_METHODS: Record<string, any>; QUANT_FORMATS: any[] };
|
|
161
|
+
/** Lower-level engine functions, same signatures as in engine.js. */
|
|
162
|
+
engine: Record<string, (...args: any[]) => any>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function createEngine(options?: { snapshot?: EvidenceSnapshot }): Engine;
|
|
166
|
+
export const version: string;
|
|
167
|
+
export default createEngine;
|