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

Commit 5859371

Browse files
feat: check Cuda version for Tensorrt-llm models
1 parent a543315 commit 5859371

File tree

6 files changed

+59
-7
lines changed

6 files changed

+59
-7
lines changed

cortex-js/src/infrastructure/commanders/models/model-pull.command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ModelPullCommand extends CommandRunner {
4343
}
4444
const modelId = passedParams[0];
4545

46-
checkModelCompatibility(modelId);
46+
await checkModelCompatibility(modelId);
4747

4848
await this.modelsCliUsecases.pullModel(modelId).catch((e: Error) => {
4949
if (e instanceof ModelNotFoundException)

cortex-js/src/infrastructure/commanders/models/model-start.command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ export class ModelStartCommand extends CommandRunner {
6565
process.exit(1);
6666
}
6767

68-
checkModelCompatibility(modelId);
68+
await checkModelCompatibility(modelId);
6969
checkingSpinner.succeed('Model found');
70+
7071
const engine = existingModel.engine || Engines.llamaCPP;
7172
// Pull engine if not exist
7273
if (

cortex-js/src/infrastructure/commanders/shortcuts/run.command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export class RunCommand extends CommandRunner {
8181
checkingSpinner.succeed('Model found');
8282

8383
// Check model compatibility on this machine
84-
checkModelCompatibility(modelId);
84+
await checkModelCompatibility(modelId);
85+
8586
const engine = existingModel.engine || Engines.llamaCPP;
8687
// Pull engine if not exist
8788
if (

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ export const CUDA_DOWNLOAD_URL =
4949
'https://catalog.jan.ai/dist/cuda-dependencies/<version>/<platform>/cuda.tar.gz';
5050

5151
export const telemetryServerUrl = 'https://telemetry.jan.ai';
52+
53+
export const MIN_CUDA_VERSION = '12.3';

cortex-js/src/utils/cuda.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type GpuSettingInfo = {
1515
* @returns CUDA Version 11 | 12
1616
*/
1717
export const cudaVersion = async () => {
18+
1819
let filesCuda12: string[];
1920
let filesCuda11: string[];
2021
let paths: string[];
@@ -71,6 +72,33 @@ export const checkNvidiaGPUExist = (): Promise<boolean> => {
7172
});
7273
};
7374

75+
export const getCudaVersion = (): Promise<string> => {
76+
return new Promise<string>((resolve, reject) => {
77+
// Execute the nvidia-smi command
78+
exec('nvidia-smi', (error, stdout) => {
79+
if (!error) {
80+
const cudaVersionLine = stdout.split('\n').find(line => line.includes('CUDA Version'));
81+
82+
if (cudaVersionLine) {
83+
// Extract the CUDA version number
84+
const cudaVersionMatch = cudaVersionLine.match(/CUDA Version:\s+(\d+\.\d+)/);
85+
if (cudaVersionMatch) {
86+
const cudaVersion = cudaVersionMatch[1];
87+
resolve(cudaVersion);
88+
} else {
89+
reject('CUDA Version not found.');
90+
}
91+
} else {
92+
reject('CUDA Version not found.');
93+
}
94+
} else {
95+
reject(error);
96+
}
97+
98+
});
99+
});
100+
};
101+
74102
/**
75103
* Get GPU information from the system
76104
* @returns GPU information

cortex-js/src/utils/model-check.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
export const checkModelCompatibility = (modelId: string) => {
1+
import { MIN_CUDA_VERSION } from "@/infrastructure/constants/cortex";
2+
import { getCudaVersion } from "./cuda";
3+
4+
export const checkModelCompatibility = async (modelId: string) => {
25
if (modelId.includes('onnx') && process.platform !== 'win32') {
36
console.error('The ONNX engine does not support this OS yet.');
47
process.exit(1);
58
}
69

7-
if (modelId.includes('tensorrt-llm') && process.platform === 'darwin') {
8-
console.error('Tensorrt-LLM models are not supported on this OS');
9-
process.exit(1);
10+
if (modelId.includes('tensorrt-llm') ) {
11+
if(process.platform === 'darwin'){
12+
console.error('Tensorrt-LLM models are not supported on this OS');
13+
process.exit(1);
14+
}
15+
16+
try{
17+
const version = await getCudaVersion();
18+
const [currentMajor, currentMinor] = version.split('.').map(Number);
19+
const [requiredMajor, requiredMinor] = MIN_CUDA_VERSION.split('.').map(Number);
20+
const isMatchRequired = currentMajor > requiredMajor || (currentMajor === requiredMajor && currentMinor >= requiredMinor);
21+
if (!isMatchRequired) {
22+
console.error(`CUDA version ${version} is not compatible with TensorRT-LLM models. Required version: ${MIN_CUDA_VERSION}`);
23+
process.exit(1);
24+
}
25+
} catch (e) {
26+
console.error(e.message ?? e);
27+
process.exit(1);
28+
}
29+
1030
}
1131
};

0 commit comments

Comments
 (0)