Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 18 additions & 82 deletions scripts/checks/run-llama-cpp-dgx-spark-qualification.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import net from "node:net";
import path from "node:path";
import { fileURLToPath } from "node:url";

import {
buildLlamaCppHostLocalDockerArgv,
type VerifiedLocalModelArtifact,
} from "../../src/lib/inference/llama-cpp/host-local-runtime.ts";
import {
LLAMA_CPP_DGX_SPARK_MODEL_PATH_PATTERN,
LLAMA_CPP_DGX_SPARK_QUALIFICATION_IMAGE_REPOSITORY,
Expand All @@ -27,8 +31,6 @@ const registryImage =
const registryOwnerLabel = "io.nvidia.nemoclaw.llama-cpp-qualification-owner";
const localImageRepository = LLAMA_CPP_DGX_SPARK_QUALIFICATION_IMAGE_REPOSITORY;
const expectedWorkflowRef = "NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main";
const containerModelPath = "/models/Nemotron-3-Nano-30B-A3B-UD-Q4_K_XL.gguf";
const containerApiKeyPath = "/run/secrets/llama-cpp-api-key";
const maximumPlanBytes = 1024 * 1024;
const maximumDockerfileBytes = 1024 * 1024;
const maximumModelBytes = 128 * 1024 * 1024 * 1024;
Expand Down Expand Up @@ -303,86 +305,23 @@ export function buildServerContainerArgv(
apiKeyHostPath: string;
containerName: string;
imageReference: string;
modelHostPath: string;
model: VerifiedLocalModelArtifact;
networkName: string;
registryOwner: string;
runtimeGid: number;
runtimeUid: number;
},
): string[] {
const { resources } = plan.recipe.runtime;
const { serve } = plan.recipe;
const runtimeUid = requiredInteger(options.runtimeUid, "runtime uid", 1, 2_147_483_647);
const runtimeGid = requiredInteger(options.runtimeGid, "runtime gid", 1, 2_147_483_647);
return [
"run",
"--detach",
"--name",
options.containerName,
"--label",
`${registryOwnerLabel}=${options.registryOwner}`,
"--network",
options.networkName,
"--user",
`${runtimeUid}:${runtimeGid}`,
"--publish",
`127.0.0.1::${serve.port}`,
"--read-only",
"--cap-drop",
"ALL",
"--security-opt",
"no-new-privileges=true",
"--memory",
`${resources.memoryBytes}b`,
"--memory-swap",
`${resources.memoryBytes}b`,
"--pids-limit",
String(resources.pidsLimit),
"--gpus",
"1",
"--tmpfs",
`/tmp:rw,noexec,nosuid,nodev,size=${resources.writableStorageBytes},uid=${runtimeUid},gid=${runtimeGid},mode=1777`,
"--mount",
`type=bind,source=${options.modelHostPath},target=${containerModelPath},readonly`,
"--mount",
`type=bind,source=${options.apiKeyHostPath},target=${containerApiKeyPath},readonly`,
options.imageReference,
"--model",
containerModelPath,
"--alias",
plan.recipe.model.servedName,
"--host",
"0.0.0.0",
"--port",
String(serve.port),
"--gpu-layers",
"all",
"--ctx-size",
String(serve.contextSize),
"--parallel",
String(serve.slots),
"--sleep-idle-seconds",
String(serve.idleSleepSeconds),
"--batch-size",
String(serve.batchSize),
"--ubatch-size",
String(serve.microBatchSize),
"--cache-type-k",
serve.kvCache.key,
"--cache-type-v",
serve.kvCache.value,
"--flash-attn",
"on",
"--timeout",
String(serve.limits.requestTimeoutSeconds),
"--api-key-file",
containerApiKeyPath,
"--metrics",
"--no-ui",
"--no-slots",
"--no-mmproj",
"--no-agent",
];
return buildLlamaCppHostLocalDockerArgv(plan.recipe, {
apiKeyHostPath: options.apiKeyHostPath,
containerName: options.containerName,
imageReference: options.imageReference,
model: options.model,
network: { isolation: "docker-internal", name: options.networkName },
ownerLabel: { name: registryOwnerLabel, value: options.registryOwner },
runtimeGid: options.runtimeGid,
runtimeUid: options.runtimeUid,
});
}

export function validateStartupLog(log: string): { offloadedLayers: number; totalLayers: number } {
Expand Down Expand Up @@ -560,10 +499,7 @@ function validateCandidateCheckout(invocation: QualificationInvocation): string
return root;
}

function hashModelFile(
modelHostPath: string,
plan: QualificationPlan,
): { digest: string; sizeBytes: number } {
function hashModelFile(modelHostPath: string, plan: QualificationPlan): VerifiedLocalModelArtifact {
if (path.basename(modelHostPath) !== plan.recipe.model.file.path) {
throw new Error("model file name does not match the qualification plan");
}
Expand Down Expand Up @@ -607,7 +543,7 @@ function hashModelFile(
if (digest !== plan.recipe.model.file.digest) {
throw new Error("model file digest does not match the qualification plan");
}
return { digest, sizeBytes: after.size };
return { digest, hostPath: modelHostPath, sizeBytes: after.size };
} finally {
fs.closeSync(descriptor);
}
Expand Down Expand Up @@ -943,7 +879,7 @@ async function runQualification(
apiKeyHostPath,
containerName: names.containerName,
imageReference: image.reference,
modelHostPath: invocation.modelHostPath,
model,
networkName: names.networkName,
registryOwner: names.registryOwner,
runtimeGid,
Expand Down
Loading
Loading