Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: specify engine version to pull #942

Merged
merged 1 commit into from
Jul 30, 2024
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
8 changes: 8 additions & 0 deletions cortex-js/src/infrastructure/commanders/engines.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,12 @@ export class EnginesCommand extends BaseCommand {
parseVulkan() {
return true;
}

@Option({
flags: '-v, --version <version>',
description: 'Select version to install',
})
parseVersion(value: string) {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { exit, stdin, stdout } from 'node:process';
import { Option, SubCommand } from 'nest-commander';
import { SubCommand } from 'nest-commander';
import { SetCommandContext } from '../decorators/CommandContext';
import { ContextService } from '@/infrastructure/services/context/context.service';
import { Engines } from '../types/engine.interface';
Expand All @@ -10,6 +9,7 @@ import { defaultInstallationOptions } from '@/utils/init';
import { Presets, SingleBar } from 'cli-progress';
import { CortexClient } from '../services/cortex.client';
import ora from 'ora';
import { InitEngineDto } from '@/infrastructure/dtos/engines/engines.dto';

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

async runCommand(
passedParams: string[],
options: { vulkan: boolean },
options: InitEngineDto,
): Promise<void> {
const engine = passedParams[0];
const params = passedParams.includes(Engines.llamaCPP)
Expand All @@ -51,6 +51,7 @@ export class EnginesInitCommand extends BaseCommand {
}
stopCortexSpinner.succeed('Cortex stopped');
console.log(`Installing engine ${engine}...`);

await this.cortex.engines.init(engine, params);
const response = await this.cortex.events.downloadEvent();

Expand All @@ -77,13 +78,4 @@ export class EnginesInitCommand extends BaseCommand {
console.log('Engine installed successfully');
process.exit(0);
}

@Option({
flags: '-vk, --vulkan',
description: 'Install Vulkan engine',
defaultValue: false,
})
parseVulkan() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface InitOptions {
cudaVersion?: '11' | '12';
silent?: boolean;
vulkan?: boolean;
version?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class EnginesController {
@Post(':name(*)/init')
initialize(@Param('name') name: string, @Body() body: InitEngineDto | undefined, @Res() res: Response) {
try{
this.initUsescases.installEngine(body, 'latest', name, true);
this.initUsescases.installEngine(body, name, true);
res.json({
message: 'Engine initialization started successfully.',
})
Expand Down
13 changes: 13 additions & 0 deletions cortex-js/src/infrastructure/dtos/engines/engines.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,52 @@ export class InitEngineDto {
})
@IsString()
runMode?: 'CPU' | 'GPU';

@ApiProperty({
type: String,
example: 'Nvidia',
description: 'The type of GPU that you want to use.',
})
@IsString()
gpuType?: 'Nvidia' | 'Others (Vulkan)';

@ApiProperty({
type: String,
example: 'AVX',
description: 'The instructions that you want to use.',
})
@IsString()
instructions?: 'AVX' | 'AVX2' | 'AVX512' | undefined;

@ApiProperty({
type: String,
example: '11',
description: 'The version of CUDA that you want to use.',
})
@IsString()
cudaVersion?: '11' | '12';

@ApiProperty({
type: Boolean,
example: true,
description: 'Silent mode.',
})
@IsBoolean()
silent?: boolean;

@ApiProperty({
type: Boolean,
example: true,
description: 'Install Vulkan engine.',
})
@IsBoolean()
vulkan?: boolean;

@ApiProperty({
type: String,
example: true,
description: 'Engine version.',
})
@IsBoolean()
version?: string;
}
65 changes: 36 additions & 29 deletions cortex-js/src/usecases/engines/engines.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class EnginesUsecases {
*/
installEngine = async (
options?: InitOptions,
version: string = 'latest',
engine: string = 'default',
force: boolean = false,
): Promise<any> => {
Expand All @@ -95,30 +94,34 @@ export class EnginesUsecases {
engine === Engines.llamaCPP &&
(options?.vulkan ||
(options?.runMode === 'GPU' && options?.gpuType !== 'Nvidia'));
installPackages.push(this.installAcceleratedEngine(version, engine, [
process.platform === 'win32'
? '-windows'
: process.platform === 'darwin'
? '-mac'
: '-linux',
// CPU Instructions - CPU | GPU Non-Vulkan
options?.instructions && !isVulkan
? `-${options?.instructions?.toLowerCase()}`
: '',
// Cuda
options?.runMode === 'GPU' && options?.gpuType === 'Nvidia' && !isVulkan
? `cuda-${options.cudaVersion ?? '12'}`
: '',
// Vulkan
isVulkan ? '-vulkan' : '',
installPackages.push(
this.installAcceleratedEngine(options?.version ?? 'latest', engine, [
process.platform === 'win32'
? '-windows'
: process.platform === 'darwin'
? '-mac'
: '-linux',
// CPU Instructions - CPU | GPU Non-Vulkan
options?.instructions && !isVulkan
? `-${options?.instructions?.toLowerCase()}`
: '',
// Cuda
options?.runMode === 'GPU' &&
options?.gpuType === 'Nvidia' &&
!isVulkan
? `cuda-${options.cudaVersion ?? '12'}`
: '',
// Vulkan
isVulkan ? '-vulkan' : '',

// Arch
engine !== Engines.tensorrtLLM
? process.arch === 'arm64'
? '-arm64'
: '-amd64'
: '',
]));
// Arch
engine !== Engines.tensorrtLLM
? process.arch === 'arm64'
? '-arm64'
: '-amd64'
: '',
]),
);
}

if (
Expand All @@ -128,11 +131,13 @@ export class EnginesUsecases {
options?.gpuType === 'Nvidia' &&
!options?.vulkan)
)
installPackages.push(this.installCudaToolkitDependency(
engine === Engines.tensorrtLLM
? MIN_CUDA_VERSION
: options?.cudaVersion,
));
installPackages.push(
this.installCudaToolkitDependency(
engine === Engines.tensorrtLLM
? MIN_CUDA_VERSION
: options?.cudaVersion,
),
);
await Promise.all(installPackages);
// Update states
await this.extensionRepository.findOne(engine).then((e) => {
Expand Down Expand Up @@ -252,6 +257,8 @@ export class EnginesUsecases {
matchers.every((matcher) => asset.name.includes(matcher)),
);

console.log('Downloading ', toDownloadAsset.name);

if (!toDownloadAsset) {
console.log(
`Could not find engine file for platform ${process.platform}`,
Expand Down
Loading