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

Commit 420a35d

Browse files
authored
chore: specify engine version to pull (#942)
1 parent 8e83991 commit 420a35d

File tree

6 files changed

+63
-42
lines changed

6 files changed

+63
-42
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,12 @@ export class EnginesCommand extends BaseCommand {
7575
parseVulkan() {
7676
return true;
7777
}
78+
79+
@Option({
80+
flags: '-v, --version <version>',
81+
description: 'Select version to install',
82+
})
83+
parseVersion(value: string) {
84+
return value;
85+
}
7886
}

cortex-js/src/infrastructure/commanders/engines/engines-init.command.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { exit, stdin, stdout } from 'node:process';
2-
import { Option, SubCommand } from 'nest-commander';
1+
import { SubCommand } from 'nest-commander';
32
import { SetCommandContext } from '../decorators/CommandContext';
43
import { ContextService } from '@/infrastructure/services/context/context.service';
54
import { Engines } from '../types/engine.interface';
@@ -10,6 +9,7 @@ import { defaultInstallationOptions } from '@/utils/init';
109
import { Presets, SingleBar } from 'cli-progress';
1110
import { CortexClient } from '../services/cortex.client';
1211
import ora from 'ora';
12+
import { InitEngineDto } from '@/infrastructure/dtos/engines/engines.dto';
1313

1414
@SubCommand({
1515
name: '<name> init',
@@ -31,7 +31,7 @@ export class EnginesInitCommand extends BaseCommand {
3131

3232
async runCommand(
3333
passedParams: string[],
34-
options: { vulkan: boolean },
34+
options: InitEngineDto,
3535
): Promise<void> {
3636
const engine = passedParams[0];
3737
const params = passedParams.includes(Engines.llamaCPP)
@@ -51,6 +51,7 @@ export class EnginesInitCommand extends BaseCommand {
5151
}
5252
stopCortexSpinner.succeed('Cortex stopped');
5353
console.log(`Installing engine ${engine}...`);
54+
5455
await this.cortex.engines.init(engine, params);
5556
const response = await this.cortex.events.downloadEvent();
5657

@@ -77,13 +78,4 @@ export class EnginesInitCommand extends BaseCommand {
7778
console.log('Engine installed successfully');
7879
process.exit(0);
7980
}
80-
81-
@Option({
82-
flags: '-vk, --vulkan',
83-
description: 'Install Vulkan engine',
84-
defaultValue: false,
85-
})
86-
parseVulkan() {
87-
return true;
88-
}
8981
}

cortex-js/src/infrastructure/commanders/types/init-options.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export interface InitOptions {
55
cudaVersion?: '11' | '12';
66
silent?: boolean;
77
vulkan?: boolean;
8+
version?: string;
89
}

cortex-js/src/infrastructure/controllers/engines.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class EnginesController {
8282
@Post(':name(*)/init')
8383
initialize(@Param('name') name: string, @Body() body: InitEngineDto | undefined, @Res() res: Response) {
8484
try{
85-
this.initUsescases.installEngine(body, 'latest', name, true);
85+
this.initUsescases.installEngine(body, name, true);
8686
res.json({
8787
message: 'Engine initialization started successfully.',
8888
})

cortex-js/src/infrastructure/dtos/engines/engines.dto.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,52 @@ export class InitEngineDto {
5555
})
5656
@IsString()
5757
runMode?: 'CPU' | 'GPU';
58+
5859
@ApiProperty({
5960
type: String,
6061
example: 'Nvidia',
6162
description: 'The type of GPU that you want to use.',
6263
})
6364
@IsString()
6465
gpuType?: 'Nvidia' | 'Others (Vulkan)';
66+
6567
@ApiProperty({
6668
type: String,
6769
example: 'AVX',
6870
description: 'The instructions that you want to use.',
6971
})
7072
@IsString()
7173
instructions?: 'AVX' | 'AVX2' | 'AVX512' | undefined;
74+
7275
@ApiProperty({
7376
type: String,
7477
example: '11',
7578
description: 'The version of CUDA that you want to use.',
7679
})
7780
@IsString()
7881
cudaVersion?: '11' | '12';
82+
7983
@ApiProperty({
8084
type: Boolean,
8185
example: true,
8286
description: 'Silent mode.',
8387
})
8488
@IsBoolean()
8589
silent?: boolean;
90+
8691
@ApiProperty({
8792
type: Boolean,
8893
example: true,
8994
description: 'Install Vulkan engine.',
9095
})
9196
@IsBoolean()
9297
vulkan?: boolean;
98+
99+
@ApiProperty({
100+
type: String,
101+
example: true,
102+
description: 'Engine version.',
103+
})
104+
@IsBoolean()
105+
version?: string;
93106
}

cortex-js/src/usecases/engines/engines.usecase.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export class EnginesUsecases {
7474
*/
7575
installEngine = async (
7676
options?: InitOptions,
77-
version: string = 'latest',
7877
engine: string = 'default',
7978
force: boolean = false,
8079
): Promise<any> => {
@@ -95,30 +94,34 @@ export class EnginesUsecases {
9594
engine === Engines.llamaCPP &&
9695
(options?.vulkan ||
9796
(options?.runMode === 'GPU' && options?.gpuType !== 'Nvidia'));
98-
installPackages.push(this.installAcceleratedEngine(version, engine, [
99-
process.platform === 'win32'
100-
? '-windows'
101-
: process.platform === 'darwin'
102-
? '-mac'
103-
: '-linux',
104-
// CPU Instructions - CPU | GPU Non-Vulkan
105-
options?.instructions && !isVulkan
106-
? `-${options?.instructions?.toLowerCase()}`
107-
: '',
108-
// Cuda
109-
options?.runMode === 'GPU' && options?.gpuType === 'Nvidia' && !isVulkan
110-
? `cuda-${options.cudaVersion ?? '12'}`
111-
: '',
112-
// Vulkan
113-
isVulkan ? '-vulkan' : '',
97+
installPackages.push(
98+
this.installAcceleratedEngine(options?.version ?? 'latest', engine, [
99+
process.platform === 'win32'
100+
? '-windows'
101+
: process.platform === 'darwin'
102+
? '-mac'
103+
: '-linux',
104+
// CPU Instructions - CPU | GPU Non-Vulkan
105+
options?.instructions && !isVulkan
106+
? `-${options?.instructions?.toLowerCase()}`
107+
: '',
108+
// Cuda
109+
options?.runMode === 'GPU' &&
110+
options?.gpuType === 'Nvidia' &&
111+
!isVulkan
112+
? `cuda-${options.cudaVersion ?? '12'}`
113+
: '',
114+
// Vulkan
115+
isVulkan ? '-vulkan' : '',
114116

115-
// Arch
116-
engine !== Engines.tensorrtLLM
117-
? process.arch === 'arm64'
118-
? '-arm64'
119-
: '-amd64'
120-
: '',
121-
]));
117+
// Arch
118+
engine !== Engines.tensorrtLLM
119+
? process.arch === 'arm64'
120+
? '-arm64'
121+
: '-amd64'
122+
: '',
123+
]),
124+
);
122125
}
123126

124127
if (
@@ -128,11 +131,13 @@ export class EnginesUsecases {
128131
options?.gpuType === 'Nvidia' &&
129132
!options?.vulkan)
130133
)
131-
installPackages.push(this.installCudaToolkitDependency(
132-
engine === Engines.tensorrtLLM
133-
? MIN_CUDA_VERSION
134-
: options?.cudaVersion,
135-
));
134+
installPackages.push(
135+
this.installCudaToolkitDependency(
136+
engine === Engines.tensorrtLLM
137+
? MIN_CUDA_VERSION
138+
: options?.cudaVersion,
139+
),
140+
);
136141
await Promise.all(installPackages);
137142
// Update states
138143
await this.extensionRepository.findOne(engine).then((e) => {
@@ -252,6 +257,8 @@ export class EnginesUsecases {
252257
matchers.every((matcher) => asset.name.includes(matcher)),
253258
);
254259

260+
console.log('Downloading ', toDownloadAsset.name);
261+
255262
if (!toDownloadAsset) {
256263
console.log(
257264
`Could not find engine file for platform ${process.platform}`,

0 commit comments

Comments
 (0)