Spaces:
Runtime error
Runtime error
Add dates on logs
Browse files- bench/src/core/logger.ts +33 -0
- bench/src/node/benchmark.ts +8 -7
- bench/src/server/hf-dataset.ts +4 -3
- bench/src/server/index.ts +13 -12
- bench/src/server/queue.ts +7 -6
- leaderboard/src/leaderboard/app.py +2 -1
bench/src/core/logger.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Simple logger utility that adds timestamps to console output
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
function formatTimestamp(): string {
|
| 6 |
+
const now = new Date();
|
| 7 |
+
const year = now.getFullYear();
|
| 8 |
+
const month = String(now.getMonth() + 1).padStart(2, '0');
|
| 9 |
+
const day = String(now.getDate()).padStart(2, '0');
|
| 10 |
+
const hours = String(now.getHours()).padStart(2, '0');
|
| 11 |
+
const minutes = String(now.getMinutes()).padStart(2, '0');
|
| 12 |
+
const seconds = String(now.getSeconds()).padStart(2, '0');
|
| 13 |
+
|
| 14 |
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const logger = {
|
| 18 |
+
log: (...args: any[]) => {
|
| 19 |
+
console.log(`[${formatTimestamp()}]`, ...args);
|
| 20 |
+
},
|
| 21 |
+
|
| 22 |
+
info: (...args: any[]) => {
|
| 23 |
+
console.info(`[${formatTimestamp()}]`, ...args);
|
| 24 |
+
},
|
| 25 |
+
|
| 26 |
+
warn: (...args: any[]) => {
|
| 27 |
+
console.warn(`[${formatTimestamp()}]`, ...args);
|
| 28 |
+
},
|
| 29 |
+
|
| 30 |
+
error: (...args: any[]) => {
|
| 31 |
+
console.error(`[${formatTimestamp()}]`, ...args);
|
| 32 |
+
},
|
| 33 |
+
};
|
bench/src/node/benchmark.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { BenchmarkRawResult, aggregateMetrics } from "../core/metrics.js";
|
|
| 6 |
import { ensureEmptyDir } from "./cache.js";
|
| 7 |
import { getSystemInfo } from "../core/sysinfo.js";
|
| 8 |
import { getTaskInput } from "../core/task-inputs.js";
|
|
|
|
| 9 |
|
| 10 |
async function benchOnce(
|
| 11 |
modelId: string,
|
|
@@ -48,13 +49,13 @@ export async function runNodeBenchmark(options: BenchmarkOptions): Promise<Bench
|
|
| 48 |
const cacheDir = path.resolve(".bench-cache/default");
|
| 49 |
env.cacheDir = cacheDir;
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
const results: BenchmarkRawResult[] = [];
|
| 60 |
|
|
|
|
| 6 |
import { ensureEmptyDir } from "./cache.js";
|
| 7 |
import { getSystemInfo } from "../core/sysinfo.js";
|
| 8 |
import { getTaskInput } from "../core/task-inputs.js";
|
| 9 |
+
import { logger } from "../core/logger.js";
|
| 10 |
|
| 11 |
async function benchOnce(
|
| 12 |
modelId: string,
|
|
|
|
| 49 |
const cacheDir = path.resolve(".bench-cache/default");
|
| 50 |
env.cacheDir = cacheDir;
|
| 51 |
|
| 52 |
+
logger.log(`Model : ${modelId}`);
|
| 53 |
+
logger.log(`Task : ${task}`);
|
| 54 |
+
logger.log(`Mode : ${mode}`);
|
| 55 |
+
logger.log(`Repeats : ${repeats}`);
|
| 56 |
+
logger.log(`DType : ${dtype || 'auto'}`);
|
| 57 |
+
logger.log(`Batch Size: ${batchSize}`);
|
| 58 |
+
logger.log(`Cache : ${cacheDir}`);
|
| 59 |
|
| 60 |
const results: BenchmarkRawResult[] = [];
|
| 61 |
|
bench/src/server/hf-dataset.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
import { uploadFile, listFiles } from "@huggingface/hub";
|
| 11 |
import { generateBenchmarkPath, type BenchmarkSettings } from "../core/benchmark-id.js";
|
| 12 |
import type { QueuedBenchmark } from "./queue.js";
|
|
|
|
| 13 |
|
| 14 |
export interface HFDatasetConfig {
|
| 15 |
repo: string;
|
|
@@ -142,9 +143,9 @@ export class HFDatasetUploader {
|
|
| 142 |
commitDescription: `Benchmark ID: ${benchmark.id}\nStatus: ${benchmark.status}\nTimestamp: ${new Date(benchmark.timestamp).toISOString()}`,
|
| 143 |
});
|
| 144 |
|
| 145 |
-
|
| 146 |
} catch (error: any) {
|
| 147 |
-
|
| 148 |
throw error;
|
| 149 |
}
|
| 150 |
}
|
|
@@ -172,7 +173,7 @@ export class HFDatasetUploader {
|
|
| 172 |
}
|
| 173 |
return files;
|
| 174 |
} catch (error: any) {
|
| 175 |
-
|
| 176 |
throw error;
|
| 177 |
}
|
| 178 |
}
|
|
|
|
| 10 |
import { uploadFile, listFiles } from "@huggingface/hub";
|
| 11 |
import { generateBenchmarkPath, type BenchmarkSettings } from "../core/benchmark-id.js";
|
| 12 |
import type { QueuedBenchmark } from "./queue.js";
|
| 13 |
+
import { logger } from "../core/logger.js";
|
| 14 |
|
| 15 |
export interface HFDatasetConfig {
|
| 16 |
repo: string;
|
|
|
|
| 143 |
commitDescription: `Benchmark ID: ${benchmark.id}\nStatus: ${benchmark.status}\nTimestamp: ${new Date(benchmark.timestamp).toISOString()}`,
|
| 144 |
});
|
| 145 |
|
| 146 |
+
logger.log(`β Uploaded to HF Dataset: ${filePath}`);
|
| 147 |
} catch (error: any) {
|
| 148 |
+
logger.error(`β Failed to upload to HF Dataset: ${filePath}`, error.message);
|
| 149 |
throw error;
|
| 150 |
}
|
| 151 |
}
|
|
|
|
| 173 |
}
|
| 174 |
return files;
|
| 175 |
} catch (error: any) {
|
| 176 |
+
logger.error("β Failed to list files from HF Dataset", error.message);
|
| 177 |
throw error;
|
| 178 |
}
|
| 179 |
}
|
bench/src/server/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { HFDatasetUploader } from "./hf-dataset.js";
|
|
| 7 |
import { randomUUID } from "crypto";
|
| 8 |
import { z } from "zod";
|
| 9 |
import { config as dotenvConfig } from "dotenv";
|
|
|
|
| 10 |
|
| 11 |
// Load environment variables
|
| 12 |
dotenvConfig();
|
|
@@ -26,9 +27,9 @@ const hfUploader = new HFDatasetUploader(
|
|
| 26 |
);
|
| 27 |
|
| 28 |
if (hfUploader.isEnabled()) {
|
| 29 |
-
|
| 30 |
} else {
|
| 31 |
-
|
| 32 |
}
|
| 33 |
|
| 34 |
// Enable CORS for development
|
|
@@ -38,9 +39,9 @@ app.use("/*", cors());
|
|
| 38 |
queue.on("completed", async (benchmark) => {
|
| 39 |
try {
|
| 40 |
await storage.appendResult(benchmark);
|
| 41 |
-
|
| 42 |
} catch (error) {
|
| 43 |
-
|
| 44 |
}
|
| 45 |
|
| 46 |
// Upload to HF Dataset if enabled
|
|
@@ -48,7 +49,7 @@ queue.on("completed", async (benchmark) => {
|
|
| 48 |
try {
|
| 49 |
await hfUploader.uploadResult(benchmark);
|
| 50 |
} catch (error) {
|
| 51 |
-
|
| 52 |
// Don't fail the whole operation if HF upload fails
|
| 53 |
}
|
| 54 |
}
|
|
@@ -57,9 +58,9 @@ queue.on("completed", async (benchmark) => {
|
|
| 57 |
queue.on("failed", async (benchmark) => {
|
| 58 |
try {
|
| 59 |
await storage.appendResult(benchmark);
|
| 60 |
-
|
| 61 |
} catch (error) {
|
| 62 |
-
|
| 63 |
}
|
| 64 |
|
| 65 |
// Don't upload failed benchmarks to HF Dataset
|
|
@@ -68,19 +69,19 @@ queue.on("failed", async (benchmark) => {
|
|
| 68 |
|
| 69 |
// Log queue events
|
| 70 |
queue.on("added", (benchmark) => {
|
| 71 |
-
|
| 72 |
});
|
| 73 |
|
| 74 |
queue.on("started", (benchmark) => {
|
| 75 |
-
|
| 76 |
});
|
| 77 |
|
| 78 |
queue.on("completed", (benchmark) => {
|
| 79 |
-
|
| 80 |
});
|
| 81 |
|
| 82 |
queue.on("failed", (benchmark) => {
|
| 83 |
-
|
| 84 |
});
|
| 85 |
|
| 86 |
// API Endpoints
|
|
@@ -282,7 +283,7 @@ serve({
|
|
| 282 |
fetch: app.fetch,
|
| 283 |
port: PORT,
|
| 284 |
}, (info) => {
|
| 285 |
-
|
| 286 |
π Benchmark Server running on http://localhost:${info.port}
|
| 287 |
|
| 288 |
API Endpoints:
|
|
|
|
| 7 |
import { randomUUID } from "crypto";
|
| 8 |
import { z } from "zod";
|
| 9 |
import { config as dotenvConfig } from "dotenv";
|
| 10 |
+
import { logger } from "../core/logger.js";
|
| 11 |
|
| 12 |
// Load environment variables
|
| 13 |
dotenvConfig();
|
|
|
|
| 27 |
);
|
| 28 |
|
| 29 |
if (hfUploader.isEnabled()) {
|
| 30 |
+
logger.log(`π€ HF Dataset upload enabled: ${process.env.HF_DATASET_REPO}`);
|
| 31 |
} else {
|
| 32 |
+
logger.log("π€ HF Dataset upload disabled (set HF_DATASET_REPO and HF_TOKEN to enable)");
|
| 33 |
}
|
| 34 |
|
| 35 |
// Enable CORS for development
|
|
|
|
| 39 |
queue.on("completed", async (benchmark) => {
|
| 40 |
try {
|
| 41 |
await storage.appendResult(benchmark);
|
| 42 |
+
logger.log(`β Benchmark ${benchmark.id} saved to file`);
|
| 43 |
} catch (error) {
|
| 44 |
+
logger.error(`β Failed to save benchmark ${benchmark.id}:`, error);
|
| 45 |
}
|
| 46 |
|
| 47 |
// Upload to HF Dataset if enabled
|
|
|
|
| 49 |
try {
|
| 50 |
await hfUploader.uploadResult(benchmark);
|
| 51 |
} catch (error) {
|
| 52 |
+
logger.error(`β Failed to upload benchmark ${benchmark.id} to HF Dataset:`, error);
|
| 53 |
// Don't fail the whole operation if HF upload fails
|
| 54 |
}
|
| 55 |
}
|
|
|
|
| 58 |
queue.on("failed", async (benchmark) => {
|
| 59 |
try {
|
| 60 |
await storage.appendResult(benchmark);
|
| 61 |
+
logger.log(`β Failed benchmark ${benchmark.id} saved to file`);
|
| 62 |
} catch (error) {
|
| 63 |
+
logger.error(`β Failed to save failed benchmark ${benchmark.id}:`, error);
|
| 64 |
}
|
| 65 |
|
| 66 |
// Don't upload failed benchmarks to HF Dataset
|
|
|
|
| 69 |
|
| 70 |
// Log queue events
|
| 71 |
queue.on("added", (benchmark) => {
|
| 72 |
+
logger.log(`π₯ Added to queue: ${benchmark.id} (${benchmark.platform}/${benchmark.modelId})`);
|
| 73 |
});
|
| 74 |
|
| 75 |
queue.on("started", (benchmark) => {
|
| 76 |
+
logger.log(`π Started: ${benchmark.id}`);
|
| 77 |
});
|
| 78 |
|
| 79 |
queue.on("completed", (benchmark) => {
|
| 80 |
+
logger.log(`β
Completed: ${benchmark.id} in ${(benchmark.completedAt! - benchmark.startedAt!) / 1000}s`);
|
| 81 |
});
|
| 82 |
|
| 83 |
queue.on("failed", (benchmark) => {
|
| 84 |
+
logger.log(`β Failed: ${benchmark.id} - ${benchmark.error}`);
|
| 85 |
});
|
| 86 |
|
| 87 |
// API Endpoints
|
|
|
|
| 283 |
fetch: app.fetch,
|
| 284 |
port: PORT,
|
| 285 |
}, (info) => {
|
| 286 |
+
logger.log(`
|
| 287 |
π Benchmark Server running on http://localhost:${info.port}
|
| 288 |
|
| 289 |
API Endpoints:
|
bench/src/server/queue.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import { EventEmitter } from "events";
|
| 2 |
import { BenchmarkResult } from "../core/types.js";
|
|
|
|
| 3 |
|
| 4 |
export interface BenchmarkRequest {
|
| 5 |
id: string;
|
|
@@ -80,14 +81,14 @@ export class BenchmarkQueue extends EventEmitter {
|
|
| 80 |
if (error instanceof Error) {
|
| 81 |
pending.error = error.message;
|
| 82 |
// Log full error details to console
|
| 83 |
-
|
| 84 |
-
|
| 85 |
if (error.stack) {
|
| 86 |
-
|
| 87 |
}
|
| 88 |
} else {
|
| 89 |
pending.error = String(error);
|
| 90 |
-
|
| 91 |
}
|
| 92 |
pending.completedAt = Date.now();
|
| 93 |
this.emit("failed", pending);
|
|
@@ -114,7 +115,7 @@ export class BenchmarkQueue extends EventEmitter {
|
|
| 114 |
];
|
| 115 |
if (request.dtype) args.push(`--dtype=${request.dtype}`);
|
| 116 |
|
| 117 |
-
|
| 118 |
|
| 119 |
return new Promise((resolve, reject) => {
|
| 120 |
const proc = spawn("tsx", args, { cwd: process.cwd() });
|
|
@@ -167,7 +168,7 @@ export class BenchmarkQueue extends EventEmitter {
|
|
| 167 |
if (request.browser) args.push(`--browser=${request.browser}`);
|
| 168 |
if (request.headed) args.push(`--headed=true`);
|
| 169 |
|
| 170 |
-
|
| 171 |
|
| 172 |
return new Promise((resolve, reject) => {
|
| 173 |
const proc = spawn("tsx", args, { cwd: process.cwd() });
|
|
|
|
| 1 |
import { EventEmitter } from "events";
|
| 2 |
import { BenchmarkResult } from "../core/types.js";
|
| 3 |
+
import { logger } from "../core/logger.js";
|
| 4 |
|
| 5 |
export interface BenchmarkRequest {
|
| 6 |
id: string;
|
|
|
|
| 81 |
if (error instanceof Error) {
|
| 82 |
pending.error = error.message;
|
| 83 |
// Log full error details to console
|
| 84 |
+
logger.error(`\nβ Benchmark ${pending.id} failed:`);
|
| 85 |
+
logger.error(` Message: ${error.message}`);
|
| 86 |
if (error.stack) {
|
| 87 |
+
logger.error(` Stack trace:\n${error.stack}`);
|
| 88 |
}
|
| 89 |
} else {
|
| 90 |
pending.error = String(error);
|
| 91 |
+
logger.error(`\nβ Benchmark ${pending.id} failed: ${pending.error}`);
|
| 92 |
}
|
| 93 |
pending.completedAt = Date.now();
|
| 94 |
this.emit("failed", pending);
|
|
|
|
| 115 |
];
|
| 116 |
if (request.dtype) args.push(`--dtype=${request.dtype}`);
|
| 117 |
|
| 118 |
+
logger.log(`\n[Queue] Dispatching node benchmark with command: tsx ${args.join(' ')}`);
|
| 119 |
|
| 120 |
return new Promise((resolve, reject) => {
|
| 121 |
const proc = spawn("tsx", args, { cwd: process.cwd() });
|
|
|
|
| 168 |
if (request.browser) args.push(`--browser=${request.browser}`);
|
| 169 |
if (request.headed) args.push(`--headed=true`);
|
| 170 |
|
| 171 |
+
logger.log(`\n[Queue] Dispatching web benchmark with command: tsx ${args.join(' ')}`);
|
| 172 |
|
| 173 |
return new Promise((resolve, reject) => {
|
| 174 |
const proc = spawn("tsx", args, { cwd: process.cwd() });
|
leaderboard/src/leaderboard/app.py
CHANGED
|
@@ -19,7 +19,8 @@ from leaderboard.formatters import apply_formatting
|
|
| 19 |
# Configure logging
|
| 20 |
logging.basicConfig(
|
| 21 |
level=logging.INFO,
|
| 22 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
# Load environment variables
|
|
|
|
| 19 |
# Configure logging
|
| 20 |
logging.basicConfig(
|
| 21 |
level=logging.INFO,
|
| 22 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 23 |
+
datefmt='%Y-%m-%d %H:%M:%S'
|
| 24 |
)
|
| 25 |
|
| 26 |
# Load environment variables
|