Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
*.cpuprofile

/dist
/tsconfig.tsbuildinfo
/docs-site
/docs/api
/templates/packed
Expand Down
24 changes: 23 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ export default defineConfig({
],
module: ts.ModuleKind.ES2022,
target: ts.ScriptTarget.ES2022,
moduleDetection: ts.ModuleDetectionKind.Force
moduleDetection: ts.ModuleDetectionKind.Force,
rootDir: undefined
},
tsModule: ts
}
Expand Down Expand Up @@ -468,6 +469,27 @@ export default defineConfig({
detailedView: true,
miniSearch: {
searchOptions: {
fuzzy: 0.05,
tokenize(query: string) {
const maxRemovedSpaces = 3;
const words = query.match(/[\p{L}\p{N}]+/gu) ?? [];
const terms = new Set(words);

for (let start = 0; start < words.length; start++) {
let joined = words[start]!;

for (let removedSpaces = 1; removedSpaces <= maxRemovedSpaces; removedSpaces++) {
const nextWord = words[start + removedSpaces];
if (nextWord == null)
break;

joined += nextWord;
terms.add(joined);
}
}

return [...terms];
},
boostDocument(term, documentId, storedFields) {
const firstTitle = (storedFields?.titles as string[])?.[0];
if (firstTitle?.startsWith("Type Alias: "))
Expand Down
3 changes: 2 additions & 1 deletion .vitepress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
"noUncheckedIndexedAccess": true,
"moduleDetection": "force",
"skipLibCheck": true,
"moduleResolution": "bundler",
"moduleResolution": "node16",
"resolveJsonModule": true,
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "..",
"outDir": "./dist",
"strict": true,
"sourceMap": true,
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export default defineConfig({
allow: []
}],
"@typescript-eslint/explicit-member-accessibility": ["warn"],
"@typescript-eslint/consistent-type-definitions": ["warn", "type"],
"@stylistic/member-delimiter-style": ["warn", {
multiline: {
delimiter: "comma",
Expand Down
2 changes: 1 addition & 1 deletion llama/addon/AddonModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Napi::Value AddonModel::Dispose(const Napi::CallbackInfo& info) {
return worker->GetPromise();
} else {
disposeMT();

Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(info.Env());
deferred.Resolve(info.Env().Undefined());
return deferred.Promise();
Expand Down
2 changes: 2 additions & 0 deletions llama/addon/addonGlobals.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <sstream>
#include <vector>
#include <algorithm>
#include <limits>
#include "addonGlobals.h"
#include "napi.h"

Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-arm64/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-arm64/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-armv7l/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-armv7l/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-riscv64/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-riscv64/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64-cuda-ext/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64-cuda-ext/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64-cuda/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64-cuda/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64-vulkan/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64-vulkan/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/linux-x64/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/mac-arm64-metal/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/mac-arm64-metal/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/mac-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/mac-x64/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-arm64/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-arm64/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64-cuda-ext/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64-cuda-ext/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64-cuda/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64-cuda/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64-vulkan/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64-vulkan/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/@node-llama-cpp/win-x64/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": false,
Expand Down
1 change: 1 addition & 0 deletions packages/create-node-llama-cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/dist
/tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/create-node-llama-cpp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"strictNullChecks": true,
"isolatedModules": true,
"noEmit": false,
"rootDir": "./src",
"outDir": "./dist",
"strict": true,
"sourceMap": true,
Expand Down
44 changes: 26 additions & 18 deletions src/bindings/Llama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ export class Llama {
/**
* Cap the amount of VRAM that this Llama instance is allowed to use in bytes.
* This is useful for constraining the resource usage of models and contexts created with the Llama instance.
*
*
* Capping to a value that's too low may cause model loads and context creations to either fail or not fully offload to VRAM,
* causing inference to be significantly slower.
*
*
* Setting a cap will only affect future model loads and context creations.
*
*
* Use with caution.
* Setting to `null` disables the cap.
*
*
* Defaults to `null`.
*/
public async setVramCap(bytes: number | null) {
Expand All @@ -425,7 +425,7 @@ export class Llama {

/**
* Get the current VRAM cap in bytes. See {@link setVramCap `setVramCap`} for more information.
*
*
* Defaults to `null`, which means no cap is set.
*/
public getVramCap() {
Expand All @@ -435,21 +435,21 @@ export class Llama {
/**
* Cap the amount of RAM that this Llama instance is allowed to use in bytes.
* This is useful for constraining the resource usage of models and contexts created with the Llama instance.
*
*
* Capping to a value that's too low may cause model loads and context creations to fail.
* Capping to any value will exclude swap from the resource calculations,
* so extremely large models may not load at all even if you have enough swap available.
*
*
* Setting a cap will only affect future model loads and context creations.
*
*
* On unified memory systems, capping the RAM may also effectively cap the VRAM, as they are shared.
* On such systems, it's recommended to either cap the VRAM or the RAM (but not both),
* and if you need to cap both then make sure to set the RAM cap to a value greater than the VRAM cap.
* > **Note:** You can detect a unified memory system by checking whether `getVramState().unifiedSize` is greater than 0.
*
*
* Use with caution.
* Setting to `null` disables the cap.
*
*
* Defaults to `null`.
*/
public async setRamCap(bytes: number | null) {
Expand All @@ -459,14 +459,14 @@ export class Llama {
throw new RangeError("RAM cap must be a non-negative number or null");
else if (bytes != null)
bytes = Math.floor(bytes);

this._ramOrchestrator.memoryCap = bytes;
this._swapOrchestrator.memoryCap = bytes == null ? null : 0; // if RAM is capped, we can't count on swap for calculation
}

/**
* Get the current RAM cap in bytes. See {@link setRamCap `setRamCap`} for more information.
*
*
* Defaults to `null`, which means no cap is set.
*/
public getRamCap() {
Expand Down Expand Up @@ -641,15 +641,23 @@ export class Llama {
// llama.cpp uses dots to indicate progress, so we don't want to print them as different lines,
// and instead, append to the same log line
if (logMessageIsOnlyDots(message) && this._logger === Llama.defaultConsoleLogger) {
const stdout = LlamaLogLevelGreaterThanOrEqual(level, LlamaLogLevel.warn)
? process.stderr
: process.stdout;

if (logMessageIsOnlyDots(this._previousLog) && level === this._previousLogLevel) {
process.stdout.write(message);
stdout.write(message);
} else {
this._nextLogNeedNewLine = true;
process.stdout.write(prefixAndColorMessage(message, getColorForLogLevel(level)));
stdout.write(prefixAndColorMessage(message, getColorForLogLevel(level)));
}
} else {
if (this._nextLogNeedNewLine) {
process.stdout.write("\n");
const stdout = LlamaLogLevelGreaterThanOrEqual(this._previousLogLevel ?? level, LlamaLogLevel.warn)
? process.stderr
: process.stdout;

stdout.write("\n");
this._nextLogNeedNewLine = false;
}

Expand Down Expand Up @@ -707,7 +715,7 @@ export class Llama {
const vramOrchestrator = new MemoryOrchestrator(getBalancedVramState.bind(undefined, bindings, true));
const ramOrchestrator = new MemoryOrchestrator(async () => {
const {total, wired} = await getBalancedRamState(bindings);

return {
total,
free: total - wired,
Expand Down Expand Up @@ -810,7 +818,7 @@ export class Llama {
default:
void (level satisfies never);
console.warn(getConsoleLogPrefix() + getColorForLogLevel(LlamaLogLevel.warn)(`Unknown log level: ${level}`));
console.log(prefixAndColorMessage(message, getColorForLogLevel(level)));
console.warn(prefixAndColorMessage(message, getColorForLogLevel(level)));
}
}
}
Expand Down Expand Up @@ -899,7 +907,7 @@ async function getBalancedVramState(bindings: BindingModule, balanceUnifiedMemor

const nonUnifiedMemoryRam = systemMemoryInfo.total - unifiedSize;
const lockedUnifiedVram = Math.max(0, Math.min(systemMemoryInfo.wired ?? 0, systemMemoryInfo.total) - nonUnifiedMemoryRam);

currentUsed = Math.max(currentUsed, Math.min(lockedUnifiedVram, unifiedSize));
} catch (err) {
// do nothing
Expand Down
Loading
Loading