@infernetprotocol/deploy-providers 0.1.22 → 0.1.26
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/package.json +2 -2
- package/src/digitalocean.js +258 -0
- package/src/index.js +96 -13
- package/src/pricing.js +6 -1
- package/src/providers/crusoe.js +278 -0
- package/src/providers/datacrunch.js +301 -0
- package/src/providers/hyperstack.js +277 -0
- package/src/providers/lambda.js +396 -0
- package/src/providers/runpod.js +382 -0
- package/src/providers/tensordock.js +362 -0
- package/src/providers/voltagepark.js +281 -0
- package/src/vast.js +245 -0
- package/src/vllm-bootstrap.js +145 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunPod adapter — IPIP-0019 DeployProvider implementation.
|
|
3
|
+
*
|
|
4
|
+
* RunPod's API is GraphQL at https://api.runpod.io/graphql, authenticated
|
|
5
|
+
* via api_key query parameter. The pod boots with the Infernet provider
|
|
6
|
+
* Docker image (built by .github/workflows/release.yml and published to
|
|
7
|
+
* GHCR).
|
|
8
|
+
*
|
|
9
|
+
* The legacy module-level functions in ../runpod.js are still exported for
|
|
10
|
+
* the existing `infernet deploy runpod` CLI flow; this class is the new
|
|
11
|
+
* surface that the lifecycle commands (list/status/destroy/stop/start)
|
|
12
|
+
* and the pricing-aware preset dispatch consume.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { DeployProvider, NotSupportedError } from "./base.js";
|
|
16
|
+
import { canonicalize, aliasesFor } from "../gpu-normalize.js";
|
|
17
|
+
import * as state from "../state.js";
|
|
18
|
+
import { pollVllmHealth } from "../vllm-bootstrap.js";
|
|
19
|
+
|
|
20
|
+
const API_URL = "https://api.runpod.io/graphql";
|
|
21
|
+
|
|
22
|
+
// Operators can override either the image or the API URL via env vars,
|
|
23
|
+
// useful for self-hosted forks of the provider container or testing
|
|
24
|
+
// against RunPod's staging cluster.
|
|
25
|
+
const DEFAULT_IMAGE =
|
|
26
|
+
process.env.INFERNET_PROVIDER_IMAGE
|
|
27
|
+
?? "ghcr.io/infernetprotocol/infernet-provider:latest";
|
|
28
|
+
|
|
29
|
+
// vLLM official OpenAI-compatible image. Used when engine="vllm" and
|
|
30
|
+
// the operator hasn't passed an explicit image. RunPod's docker pods
|
|
31
|
+
// can't easily install vLLM into the Infernet image post-boot, so we
|
|
32
|
+
// swap to a vllm-ready image and let the daemon talk to localhost:8000.
|
|
33
|
+
const DEFAULT_VLLM_IMAGE =
|
|
34
|
+
process.env.INFERNET_VLLM_IMAGE
|
|
35
|
+
?? "vllm/vllm-openai:latest";
|
|
36
|
+
|
|
37
|
+
export class RunPodProvider extends DeployProvider {
|
|
38
|
+
constructor(config = {}) {
|
|
39
|
+
super({ ...config, providerId: "runpod" });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Internal: POST a GraphQL request, throw on errors with masked key. */
|
|
43
|
+
async _gql(query, variables) {
|
|
44
|
+
const url = `${API_URL}?api_key=${encodeURIComponent(this.config.apiKey)}`;
|
|
45
|
+
const res = await fetch(url, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { "Content-Type": "application/json" },
|
|
48
|
+
body: JSON.stringify({ query, variables })
|
|
49
|
+
});
|
|
50
|
+
const body = await res.json().catch(() => ({}));
|
|
51
|
+
if (!res.ok || body.errors) {
|
|
52
|
+
const msg = body?.errors?.[0]?.message ?? res.statusText ?? `HTTP ${res.status}`;
|
|
53
|
+
const err = new Error(`RunPod API error: ${msg}`);
|
|
54
|
+
err.status = res.status;
|
|
55
|
+
err.body = body;
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
return body.data;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ---- Discovery ----
|
|
62
|
+
|
|
63
|
+
async validateAuth() {
|
|
64
|
+
const data = await this._gql(`query { myself { id email } }`);
|
|
65
|
+
const me = data?.myself;
|
|
66
|
+
if (!me?.id) throw new Error("RunPod: API key invalid (no user returned)");
|
|
67
|
+
return { ok: true, accountInfo: { id: me.id, email: me.email } };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async listGpuTypes() {
|
|
71
|
+
const data = await this._gql(`query gpuTypes {
|
|
72
|
+
gpuTypes { id displayName memoryInGb communityPrice secureCloud }
|
|
73
|
+
}`);
|
|
74
|
+
return (data?.gpuTypes ?? []).map((g) => ({
|
|
75
|
+
id: g.id,
|
|
76
|
+
name: g.displayName,
|
|
77
|
+
vramGb: g.memoryInGb ?? 0,
|
|
78
|
+
pricePerHour: g.communityPrice ?? null,
|
|
79
|
+
cloud: g.secureCloud ? "secure" : "community"
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async listRegions() {
|
|
84
|
+
// RunPod doesn't expose explicit regions in the public GraphQL —
|
|
85
|
+
// the closest concept is community vs secure cloud.
|
|
86
|
+
return [
|
|
87
|
+
{ id: "community", name: "Community Cloud" },
|
|
88
|
+
{ id: "secure", name: "Secure Cloud" }
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async findOffers(request = {}) {
|
|
93
|
+
const types = await this.listGpuTypes();
|
|
94
|
+
|
|
95
|
+
const wantCanonical = request.gpu ? canonicalize(request.gpu) : null;
|
|
96
|
+
const aliases = wantCanonical
|
|
97
|
+
? [wantCanonical, ...aliasesFor(wantCanonical)].map((a) => a.toLowerCase())
|
|
98
|
+
: null;
|
|
99
|
+
|
|
100
|
+
const offers = [];
|
|
101
|
+
for (const t of types) {
|
|
102
|
+
const nameLower = (t.name ?? "").toLowerCase();
|
|
103
|
+
if (aliases && !aliases.some((a) => nameLower.includes(a))) continue;
|
|
104
|
+
if (request.vramMin && t.vramGb < request.vramMin) continue;
|
|
105
|
+
if (
|
|
106
|
+
request.maxPricePerHour != null &&
|
|
107
|
+
t.pricePerHour != null &&
|
|
108
|
+
t.pricePerHour > request.maxPricePerHour
|
|
109
|
+
) continue;
|
|
110
|
+
|
|
111
|
+
offers.push({
|
|
112
|
+
providerId: "runpod",
|
|
113
|
+
offerId: t.id,
|
|
114
|
+
gpu: { name: t.name, count: request.gpuCount ?? 1, vramGb: t.vramGb },
|
|
115
|
+
pricePerHour: t.pricePerHour ?? 0,
|
|
116
|
+
deployStyle: "docker",
|
|
117
|
+
available: t.pricePerHour != null,
|
|
118
|
+
region: t.cloud,
|
|
119
|
+
raw: t
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return offers;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ---- Lifecycle ----
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Resolve a canonical GPU name (e.g. "4090") to a RunPod gpuTypeId
|
|
129
|
+
* by matching against displayName aliases.
|
|
130
|
+
*/
|
|
131
|
+
async _resolveGpuTypeId(gpu) {
|
|
132
|
+
if (!gpu) return null;
|
|
133
|
+
const canonical = canonicalize(gpu) ?? gpu;
|
|
134
|
+
const aliases = [canonical, ...aliasesFor(canonical)].map((a) => a.toLowerCase());
|
|
135
|
+
const types = await this.listGpuTypes();
|
|
136
|
+
const match = types.find((t) =>
|
|
137
|
+
aliases.some((a) => (t.name ?? "").toLowerCase().includes(a))
|
|
138
|
+
);
|
|
139
|
+
return match?.id ?? null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async createNode(request = {}) {
|
|
143
|
+
const {
|
|
144
|
+
gpu, gpuTypeId, gpuCount = 1, name,
|
|
145
|
+
env = {}, containerDiskGb = 20, volumeInGb = 0,
|
|
146
|
+
controlPlaneUrl = "", engine = "ollama", model = null,
|
|
147
|
+
hourlyPrice = 0, vramGb = 0, region = null
|
|
148
|
+
} = request;
|
|
149
|
+
|
|
150
|
+
// For vLLM mode, swap the image + expose 8000 (vLLM API) alongside
|
|
151
|
+
// the Infernet daemon port. The vllm/vllm-openai image takes the
|
|
152
|
+
// model + flags as `docker run` ARGS, passed via dockerArgs below.
|
|
153
|
+
const isVllm = engine === "vllm";
|
|
154
|
+
const image = request.image
|
|
155
|
+
?? (isVllm ? DEFAULT_VLLM_IMAGE : DEFAULT_IMAGE);
|
|
156
|
+
const ports = request.ports
|
|
157
|
+
?? (isVllm ? "46337/tcp,8000/tcp" : "46337/tcp");
|
|
158
|
+
const vllmConfig = request.vllm ?? {};
|
|
159
|
+
const dockerArgs = isVllm
|
|
160
|
+
? this._composeVllmDockerArgs({ model, ...vllmConfig })
|
|
161
|
+
: "";
|
|
162
|
+
|
|
163
|
+
const finalGpuTypeId = gpuTypeId ?? await this._resolveGpuTypeId(gpu);
|
|
164
|
+
if (!finalGpuTypeId) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`runpod: could not resolve gpu="${gpu}" to a RunPod gpuTypeId. ` +
|
|
167
|
+
`Pass --gpu-type <id> directly, or check listGpuTypes() for available IDs.`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const localId = state.generateNodeId();
|
|
172
|
+
const podName = name ?? localId;
|
|
173
|
+
const cloudType = region === "secure" ? "SECURE" : "COMMUNITY";
|
|
174
|
+
|
|
175
|
+
const envInput = Object.entries({
|
|
176
|
+
INFERNET_NODE_NAME: podName,
|
|
177
|
+
INFERNET_P2P_PORT: "46337",
|
|
178
|
+
...env
|
|
179
|
+
}).map(([key, value]) => ({ key, value: String(value) }));
|
|
180
|
+
|
|
181
|
+
const data = await this._gql(`
|
|
182
|
+
mutation create($input: PodFindAndDeployOnDemandInput!) {
|
|
183
|
+
podFindAndDeployOnDemand(input: $input) {
|
|
184
|
+
id desiredStatus imageName machineId
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
`, {
|
|
188
|
+
input: {
|
|
189
|
+
name: podName,
|
|
190
|
+
imageName: image,
|
|
191
|
+
gpuTypeId: finalGpuTypeId,
|
|
192
|
+
cloudType,
|
|
193
|
+
gpuCount,
|
|
194
|
+
containerDiskInGb: containerDiskGb,
|
|
195
|
+
volumeInGb,
|
|
196
|
+
ports,
|
|
197
|
+
env: envInput,
|
|
198
|
+
dockerArgs
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const pod = data?.podFindAndDeployOnDemand;
|
|
203
|
+
if (!pod?.id) throw new Error("runpod: create returned no pod id");
|
|
204
|
+
|
|
205
|
+
const record = {
|
|
206
|
+
id: localId,
|
|
207
|
+
provider: "runpod",
|
|
208
|
+
providerNodeId: pod.id,
|
|
209
|
+
name: podName,
|
|
210
|
+
gpu: gpu ?? finalGpuTypeId,
|
|
211
|
+
gpuCount,
|
|
212
|
+
vramGb,
|
|
213
|
+
region: cloudType.toLowerCase(),
|
|
214
|
+
hourlyPrice,
|
|
215
|
+
engine,
|
|
216
|
+
model: model ?? undefined,
|
|
217
|
+
status: "creating",
|
|
218
|
+
createdAt: new Date().toISOString(),
|
|
219
|
+
controlPlaneUrl
|
|
220
|
+
};
|
|
221
|
+
await state.saveNode(record);
|
|
222
|
+
return record;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async waitUntilReady(node, timeoutMs = 5 * 60 * 1000) {
|
|
226
|
+
if (!node?.providerNodeId) {
|
|
227
|
+
throw new Error("runpod: waitUntilReady requires node.providerNodeId");
|
|
228
|
+
}
|
|
229
|
+
const deadline = Date.now() + timeoutMs;
|
|
230
|
+
const pollInterval = 5000;
|
|
231
|
+
|
|
232
|
+
while (Date.now() < deadline) {
|
|
233
|
+
const data = await this._gql(`
|
|
234
|
+
query pod($id: String!) {
|
|
235
|
+
pod(input: { podId: $id }) {
|
|
236
|
+
id desiredStatus
|
|
237
|
+
runtime { ports { ip privatePort publicPort type } }
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
`, { id: node.providerNodeId });
|
|
241
|
+
|
|
242
|
+
const pod = data?.pod;
|
|
243
|
+
if (pod?.desiredStatus === "RUNNING" && pod?.runtime?.ports?.length) {
|
|
244
|
+
const port46337 = pod.runtime.ports.find((p) => String(p.privatePort) === "46337");
|
|
245
|
+
const endpointUrl = port46337?.ip && port46337?.publicPort
|
|
246
|
+
? `http://${port46337.ip}:${port46337.publicPort}`
|
|
247
|
+
: null;
|
|
248
|
+
return state.updateNode(node.id, { status: "running", endpointUrl });
|
|
249
|
+
}
|
|
250
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
await state.updateNode(node.id, {
|
|
254
|
+
status: "error",
|
|
255
|
+
error_log: `pod did not reach RUNNING within ${Math.round(timeoutMs / 1000)}s`
|
|
256
|
+
});
|
|
257
|
+
throw new Error(
|
|
258
|
+
`RunPod pod ${node.providerNodeId} did not reach RUNNING within ${Math.round(timeoutMs / 1000)}s`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Compose `docker run` ARGS for vllm/vllm-openai. */
|
|
263
|
+
_composeVllmDockerArgs(cfg = {}) {
|
|
264
|
+
const args = [`--model ${shellQuote(cfg.model)}`, "--host 0.0.0.0", `--port ${cfg.port ?? 8000}`];
|
|
265
|
+
if (cfg.servedModelName) args.push(`--served-model-name ${shellQuote(cfg.servedModelName)}`);
|
|
266
|
+
if (cfg.maxModelLen) args.push(`--max-model-len ${Number(cfg.maxModelLen)}`);
|
|
267
|
+
if (cfg.tensorParallelSize) args.push(`--tensor-parallel-size ${Number(cfg.tensorParallelSize)}`);
|
|
268
|
+
if (cfg.gpuMemoryUtilization) args.push(`--gpu-memory-utilization ${Number(cfg.gpuMemoryUtilization)}`);
|
|
269
|
+
if (cfg.quantization && cfg.quantization !== "none") args.push(`--quantization ${shellQuote(cfg.quantization)}`);
|
|
270
|
+
if (cfg.dtype && cfg.dtype !== "auto") args.push(`--dtype ${shellQuote(cfg.dtype)}`);
|
|
271
|
+
return args.join(" ");
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async bootstrapNode(node, request = {}) {
|
|
275
|
+
// The Infernet provider Docker image starts the daemon on boot,
|
|
276
|
+
// so bootstrap is just a health-check on the published port.
|
|
277
|
+
if (!node?.endpointUrl) {
|
|
278
|
+
return { ok: false, reason: "no endpointUrl on node — call waitUntilReady first" };
|
|
279
|
+
}
|
|
280
|
+
// vLLM mode: poll /v1/models on the vllm port (default 8000).
|
|
281
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
282
|
+
// node.endpointUrl is the daemon URL (port 46337); we need
|
|
283
|
+
// the vllm port on the same IP. Extract the host.
|
|
284
|
+
const host = node.endpointUrl.replace(/^https?:\/\//, "").split(":")[0];
|
|
285
|
+
return pollVllmHealth(host, { port: request.vllm?.port ?? 8000 });
|
|
286
|
+
}
|
|
287
|
+
const healthEndpoint = `${node.endpointUrl}/health`;
|
|
288
|
+
try {
|
|
289
|
+
const ctrl = new AbortController();
|
|
290
|
+
const t = setTimeout(() => ctrl.abort(), 5000);
|
|
291
|
+
const res = await fetch(healthEndpoint, { signal: ctrl.signal });
|
|
292
|
+
clearTimeout(t);
|
|
293
|
+
return { ok: res.ok, healthEndpoint };
|
|
294
|
+
} catch (err) {
|
|
295
|
+
return { ok: false, reason: err?.message ?? String(err), healthEndpoint };
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async getNode(nodeId) {
|
|
300
|
+
const local = await state.loadNode(nodeId);
|
|
301
|
+
if (!local || local.provider !== "runpod") {
|
|
302
|
+
throw new Error(`runpod: no local record for nodeId=${nodeId}`);
|
|
303
|
+
}
|
|
304
|
+
// Best-effort live status; ignore failures so the local record
|
|
305
|
+
// is still returned.
|
|
306
|
+
try {
|
|
307
|
+
const data = await this._gql(`
|
|
308
|
+
query pod($id: String!) {
|
|
309
|
+
pod(input: { podId: $id }) { id desiredStatus }
|
|
310
|
+
}
|
|
311
|
+
`, { id: local.providerNodeId });
|
|
312
|
+
if (data?.pod?.desiredStatus) local.liveStatus = data.pod.desiredStatus;
|
|
313
|
+
} catch { /* best-effort */ }
|
|
314
|
+
return local;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async listNodes() {
|
|
318
|
+
const all = await state.listNodes();
|
|
319
|
+
return all.filter((n) => n.provider === "runpod");
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async stopNode(nodeId) {
|
|
323
|
+
const local = await state.loadNode(nodeId);
|
|
324
|
+
if (!local || local.provider !== "runpod") {
|
|
325
|
+
throw new Error(`runpod: no local record for nodeId=${nodeId}`);
|
|
326
|
+
}
|
|
327
|
+
await this._gql(`
|
|
328
|
+
mutation stop($id: String!) {
|
|
329
|
+
podStop(input: { podId: $id }) { id desiredStatus }
|
|
330
|
+
}
|
|
331
|
+
`, { id: local.providerNodeId });
|
|
332
|
+
await state.updateNode(nodeId, { status: "stopped" });
|
|
333
|
+
return { ok: true };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async startNode(nodeId) {
|
|
337
|
+
const local = await state.loadNode(nodeId);
|
|
338
|
+
if (!local || local.provider !== "runpod") {
|
|
339
|
+
throw new Error(`runpod: no local record for nodeId=${nodeId}`);
|
|
340
|
+
}
|
|
341
|
+
await this._gql(`
|
|
342
|
+
mutation start($id: String!, $count: Int!) {
|
|
343
|
+
podResume(input: { podId: $id, gpuCount: $count }) { id desiredStatus }
|
|
344
|
+
}
|
|
345
|
+
`, { id: local.providerNodeId, count: local.gpuCount ?? 1 });
|
|
346
|
+
await state.updateNode(nodeId, { status: "running" });
|
|
347
|
+
return { ok: true };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async destroyNode(nodeId) {
|
|
351
|
+
const local = await state.loadNode(nodeId);
|
|
352
|
+
if (!local || local.provider !== "runpod") {
|
|
353
|
+
throw new Error(`runpod: no local record for nodeId=${nodeId}`);
|
|
354
|
+
}
|
|
355
|
+
await this._gql(`
|
|
356
|
+
mutation terminate($id: String!) { podTerminate(input: { podId: $id }) }
|
|
357
|
+
`, { id: local.providerNodeId });
|
|
358
|
+
await state.updateNode(nodeId, { status: "destroyed" });
|
|
359
|
+
return { ok: true };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async logs(nodeId, _opts = {}) {
|
|
363
|
+
const local = await state.loadNode(nodeId).catch(() => null);
|
|
364
|
+
const dashUrl = local?.providerNodeId
|
|
365
|
+
? `https://www.runpod.io/console/pods/${local.providerNodeId}`
|
|
366
|
+
: "https://www.runpod.io/console/pods";
|
|
367
|
+
// RunPod's GraphQL API doesn't expose container stdout/stderr.
|
|
368
|
+
// Throw NotSupportedError but augment the message with a useful link.
|
|
369
|
+
const err = new NotSupportedError("logs", "runpod");
|
|
370
|
+
err.message =
|
|
371
|
+
`runpod: container logs are not exposed via the GraphQL API.\n` +
|
|
372
|
+
`View logs at: ${dashUrl}`;
|
|
373
|
+
throw err;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** Single-quote a string for safe inclusion in a shell command. */
|
|
378
|
+
function shellQuote(s) {
|
|
379
|
+
return `'${String(s).replace(/'/g, "'\\''")}'`;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export default RunPodProvider;
|