Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix: correct CUDA backend installation and migration issues (#7130)

Akarshan Biswas499bad51124d
diff --git a/extensions/llamacpp-extension/src/backend.ts b/extensions/llamacpp-extension/src/backend.ts
index 6d5ad7657..1b91920b5 100644
--- a/extensions/llamacpp-extension/src/backend.ts
+++ b/extensions/llamacpp-extension/src/backend.ts
@@ -325,7 +325,7 @@ export async function downloadBackend(
source === 'github'
? `https://github.com/janhq/llama.cpp/releases/download/${version}/cudart-llama-bin-${platformName}-cu13.0-x64.tar.gz`
: `https://catalog.jan.ai/llama.cpp/releases/${version}/cudart-llama-bin-${platformName}-cu13.0-x64.tar.gz`,
- save_path: await joinPath([backendDir, 'build', 'bin', 'cuda12.tar.gz']),
+ save_path: await joinPath([backendDir, 'build', 'bin', 'cuda13.tar.gz']),
proxy: proxyConfig,
model_id: taskId,
})
@@ -457,17 +457,18 @@ async function _fetchGithubReleases(
}
}
-// accept backendDir (full path) and cuda version (e.g. '11.7' or '12.0')
+// accept backendDir (full path) and cuda version (e.g. '11.7' or '12.0' or '13.0')
async function _isCudaInstalled(
backendDir: string,
version: string
): Promise<boolean> {
const sysInfo = await getSystemInfo()
- const os_type = sysInfo.os_type // not sure the reason behind this naming convention
+ const os_type = sysInfo.os_type
+
const libnameLookup = {
'windows-11.7': `cudart64_110.dll`,
'windows-12.0': `cudart64_12.dll`,
- 'windows-13.0': `cudart64_130.dll`,
+ 'windows-13.0': `cudart64_13.dll`,
'linux-11.7': `libcudart.so.11.0`,
'linux-12.0': `libcudart.so.12`,
'linux-13.0': `libcudart.so.13`,
diff --git a/extensions/llamacpp-extension/src/index.ts b/extensions/llamacpp-extension/src/index.ts
index d7e8e7890..32563acbe 100644
--- a/extensions/llamacpp-extension/src/index.ts
+++ b/extensions/llamacpp-extension/src/index.ts
@@ -351,21 +351,29 @@ export default class llamacpp_extension extends AIEngine {
logger.warn(
`Migration from '${storedBackendType}' to '${mappedNewBackendType}' skipped: New type not available in supported backends. Using old preference for now.`
)
+ // Keep the original type if new type not available
+ effectiveStoredBackendType = storedBackendType
}
}
- // Find the latest version of the stored backend type
+
+ // Use effectiveStoredBackendType (which is now the migrated type)
const preferredBackendString = this.findLatestVersionForBackend(
version_backends,
- effectiveStoredBackendType
+ effectiveStoredBackendType // Use the effective (migrated) type here
)
+
if (preferredBackendString) {
- bestAvailableBackendString = preferredBackendString
+ // The returned string has the original asset name, we need to normalize it
+ const [version, backend] = preferredBackendString.split('/')
+ const normalizedBackend = mapOldBackendToNew(backend)
+ bestAvailableBackendString = `${version}/${normalizedBackend}`
+
logger.info(
`Using stored backend preference: ${bestAvailableBackendString}`
)
} else {
logger.warn(
- `Stored backend type '${storedBackendType}' not available, falling back to best backend`
+ `Stored backend type '${effectiveStoredBackendType}' not available, falling back to best backend`
)
// Clear the invalid stored preference
this.clearStoredBackendType()
@@ -414,16 +422,17 @@ export default class llamacpp_extension extends AIEngine {
savedBackendSetting &&
savedBackendSetting !== originalDefaultBackendValue
) {
- initialUiDefault = savedBackendSetting
- // Store the backend type from the saved setting only if different
- const [, backendType] = savedBackendSetting.split('/')
- if (backendType) {
+ const [savedVersion, savedBackend] = savedBackendSetting.split('/')
+ if (savedVersion && savedBackend) {
+ const normalizedBackend = mapOldBackendToNew(savedBackend)
+ initialUiDefault = `${savedVersion}/${normalizedBackend}`
+
+ // Store the backend type from the saved setting only if different
const currentStoredBackend = this.getStoredBackendType()
- const effectiveBackendType = mapOldBackendToNew(backendType)
- if (currentStoredBackend !== effectiveBackendType) {
- this.setStoredBackendType(effectiveBackendType)
+ if (currentStoredBackend !== normalizedBackend) {
+ this.setStoredBackendType(normalizedBackend)
logger.info(
- `Stored backend type preference from saved setting: ${effectiveBackendType}`
+ `Stored backend type preference from saved setting: ${normalizedBackend}`
)
}
}
@@ -433,11 +442,10 @@ export default class llamacpp_extension extends AIEngine {
const [, backendType] = bestAvailableBackendString.split('/')
if (backendType) {
const currentStoredBackend = this.getStoredBackendType()
- const effectiveBackendType = mapOldBackendToNew(backendType)
- if (currentStoredBackend !== effectiveBackendType) {
- this.setStoredBackendType(effectiveBackendType)
+ if (currentStoredBackend !== backendType) {
+ this.setStoredBackendType(backendType)
logger.info(
- `Stored backend type preference from best available: ${effectiveBackendType}`
+ `Stored backend type preference from best available: ${backendType}`
)
}
}