Skip to content
Open
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
50 changes: 45 additions & 5 deletions dashboard/sync/src/functions/syncMsbenchEvalMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app, HttpRequest, HttpResponseInit, InvocationContext, Timer } from "@azure/functions";
import { TableClient } from "@azure/data-tables";
import { AzureCliCredential, ManagedIdentityCredential } from "@azure/identity";
import { createHash } from "node:crypto";
import { listMsbenchDates, enumerateMsbenchBlobs, getMsbenchBlobContent } from "../msbenchBlobEnumerator";
import type { BlobTreeNode } from "../shared/blobTree";

Expand All @@ -13,10 +14,25 @@ interface EvalReport {
total_steps: number;
model: string;
instance_id: string;
benchmark?: string;
resolved?: boolean;
[key: string]: unknown;
}

interface EvalReportWithPath extends EvalReport {
blobPath: string;
}

function toSafeString(value: string | undefined): string | undefined {
const trimmed = value?.trim();
return trimmed ? trimmed : undefined;
}

function buildMsbenchRowKey(instanceId: string, benchmark: string, model: string): string {
const payload = JSON.stringify([instanceId, benchmark, model]);
return createHash("sha256").update(payload).digest("base64url");
}

function getEvalTableClient(): TableClient {
if (!MSBENCH_STORAGE_ACCOUNT) {
throw new Error("MSBENCH_STORAGE_ACCOUNT environment variable is not set");
Expand Down Expand Up @@ -57,6 +73,22 @@ async function getProcessedDates(tableClient: TableClient): Promise<Set<string>>
return dates;
}

async function deleteDatePartition(tableClient: TableClient, partitionKey: string, context: InvocationContext): Promise<number> {
let deleted = 0;
for await (const entity of tableClient.listEntities({
queryOptions: {
filter: `PartitionKey eq '${partitionKey}'`,
select: ["rowKey"],
},
})) {
await tableClient.deleteEntity(partitionKey, entity.rowKey);
deleted++;
}

context.log(`Deleted ${deleted} existing rows for date ${partitionKey} before re-sync`);
return deleted;
}

async function runSync(context: InvocationContext, force = false): Promise<{ synced: number; dates?: string[]; message?: string }> {
const tableClient = getEvalTableClient();
const blobDates = await listMsbenchDates();
Expand Down Expand Up @@ -84,17 +116,22 @@ async function runSync(context: InvocationContext, force = false): Promise<{ syn
const dateNode = tree[date];
if (!dateNode) continue;

if (force) {
await deleteDatePartition(tableClient, date, context);
}

const evalPaths = collectEvalReportPaths(dateNode);

// Download reports with bounded concurrency
const reports: (EvalReport | null)[] = [];
const reports: (EvalReportWithPath | null)[] = [];
for (let i = 0; i < evalPaths.length; i += CONCURRENCY_LIMIT) {
const batch = evalPaths.slice(i, i + CONCURRENCY_LIMIT);
const batchResults = await Promise.all(
batch.map(async (path) => {
try {
const raw = await getMsbenchBlobContent(path);
return JSON.parse(raw) as EvalReport;
const report = JSON.parse(raw) as EvalReport;
return { ...report, blobPath: path };
} catch {
context.log(`Skipping malformed eval report: ${path}`);
return null;
Expand All @@ -106,12 +143,15 @@ async function runSync(context: InvocationContext, force = false): Promise<{ syn

for (const report of reports) {
if (!report) continue;
const benchmark = report.instance_id || "unknown";
const model = report.model || "unknown";
const fallbackInstanceId = `path:${report.blobPath}`;
const instanceId = toSafeString(report.instance_id) ?? fallbackInstanceId;
const benchmark = toSafeString(report.benchmark) ?? instanceId;
const model = toSafeString(report.model) ?? "unknown";

await tableClient.upsertEntity({
partitionKey: date,
rowKey: `${benchmark}_${model}`,
rowKey: buildMsbenchRowKey(instanceId, benchmark, model),
instance_id: instanceId,
Comment on lines 151 to +154
benchmark,
model,
totalConsumedTokens: Number(report.total_consumed_tokens) || 0,
Expand Down