Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit de351c6

Browse files
authored
chore: add benchmark options (#690)
1 parent 65da850 commit de351c6

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

cortex-js/src/infrastructure/commanders/benchmark.command.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { CommandRunner, SubCommand } from 'nest-commander';
1+
import { CommandRunner, SubCommand, Option } from 'nest-commander';
22
import { BenchmarkCliUsecases } from './usecases/benchmark.cli.usecases';
3+
import { BenchmarkConfig } from './types/benchmark-config.interface';
34

45
@SubCommand({
56
name: 'benchmark',
@@ -12,7 +13,34 @@ export class BenchmarkCommand extends CommandRunner {
1213
super();
1314
}
1415

15-
async run(): Promise<void> {
16-
return this.benchmarkUsecases.benchmark();
16+
async run(
17+
_input: string[],
18+
options?: Partial<BenchmarkConfig>,
19+
): Promise<void> {
20+
return this.benchmarkUsecases.benchmark(options ?? {});
21+
}
22+
23+
@Option({
24+
flags: '-n, --num_rounds <num_rounds>',
25+
description: 'Number of rounds to run the benchmark',
26+
})
27+
parseRounds(value: number) {
28+
return value;
29+
}
30+
31+
@Option({
32+
flags: '-c, --concurrency <concurrency>',
33+
description: 'Number of concurrent requests to run the benchmark',
34+
})
35+
parseConcurrency(value: number) {
36+
return value;
37+
}
38+
39+
@Option({
40+
flags: '-o, --output <output>',
41+
description: 'Output format for the benchmark results. json or table',
42+
})
43+
parseOutput(value: string) {
44+
return value;
1745
}
1846
}

cortex-js/src/infrastructure/commanders/usecases/benchmark.cli.usecases.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ export class BenchmarkCliUsecases {
2828
/**
2929
* Benchmark and analyze the performance of a specific AI model using a variety of system resources
3030
*/
31-
async benchmark() {
31+
async benchmark(options: Partial<BenchmarkConfig>) {
3232
return this.getBenchmarkConfig().then((config) => {
33-
this.config = config;
33+
this.config = {
34+
...config,
35+
...options,
36+
};
3437

3538
// TODO: Using OpenAI client or Cortex client to benchmark?
3639
this.openai = new OpenAI({
@@ -41,6 +44,7 @@ export class BenchmarkCliUsecases {
4144

4245
const serveProcess = spawn('cortex', ['serve'], {
4346
detached: false,
47+
shell: process.platform == 'win32',
4448
});
4549

4650
return this.cortexUsecases
@@ -261,8 +265,21 @@ export class BenchmarkCliUsecases {
261265
fs.writeFileSync(outputFilePath, JSON.stringify(output, null, 2));
262266
console.log(`Benchmark results and metrics saved to ${outputFilePath}`);
263267

264-
console.log(
265-
inspect(output, { showHidden: false, depth: null, colors: true }),
266-
);
268+
if (this.config.output === 'table') {
269+
console.log('Results:');
270+
output.results.forEach((round) => {
271+
console.log('Round ' + round.round + ':');
272+
console.table(round.results);
273+
});
274+
console.log('Metrics:');
275+
console.table(output.metrics);
276+
} else
277+
console.log(
278+
inspect(output, {
279+
showHidden: false,
280+
depth: null,
281+
colors: true,
282+
}),
283+
);
267284
}
268285
}

cortex-js/src/infrastructure/constants/benchmark.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export const defaultBenchmarkConfiguration: BenchmarkConfig = {
2626
},
2727
},
2828
prompts: {
29-
min: 102,
29+
min: 1024,
3030
max: 2048,
3131
samples: 10,
3232
},
33-
output: 'json',
33+
output: 'table',
3434
hardware: ['cpu', 'gpu', 'psu', 'chassis', 'ram'],
3535
concurrency: 1,
3636
num_rounds: 10,

0 commit comments

Comments
 (0)