Skip to content

Commit a2ddaa2

Browse files
authored
feat: NUMA policy (#482)
* feat: NUMA policy * feat(`inspect gpu` command): log prebuilt binaries and cloned source releases * fix: level of some internal logs * fix: upgrade to latest `lifecycle-utils` * fix: various bugs
1 parent 59cf309 commit a2ddaa2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+631
-463
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
matrix:
5858
config:
5959
- name: "Windows for x64"
60-
os: windows-2019
60+
os: windows-2022
6161
artifact: "win-x64"
6262
- name: "Windows for Arm"
6363
os: windows-2022

.vitepress/utils/ensureLocalImage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function ensureLocalImage(url: string, name: string, {
5555
if (resolvedImages.has(cacheKey))
5656
return resolvedImages.get(cacheKey)!;
5757

58-
return await withLock(cacheKey[0], cacheKey[1], async () => {
58+
return await withLock([resolvedImages, ...cacheKey], async () => {
5959
if (resolvedImages.has(cacheKey))
6060
return resolvedImages.get(cacheKey)!;
6161

@@ -185,7 +185,9 @@ function getFileExtension(format: keyof FormatEnum | undefined) {
185185
async function fetchWithRetry(url: string, retires: number = 5, waitTime: number = 1000 * 2) {
186186
for (let i = retires; i >= 0; i--) {
187187
try {
188-
return await fetch(url);
188+
return await fetch(url, {
189+
redirect: "follow"
190+
});
189191
} catch (err) {
190192
if (i === 0) {
191193
console.error(`Failed to fetch image: ${url}`, err);

docs/guide/embedding.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ const documents = [
172172
"Cleaning the house is a good way to keep it tidy"
173173
];
174174

175-
const query = "Tell me a goegraphical fact";
175+
const query = "Tell me a nature geographical fact";
176176
const rankedDocuments = await context.rankAndSort(query, documents);
177177

178178
const topDocument = rankedDocuments[0]!;
@@ -185,7 +185,7 @@ console.log("Ranked documents:", rankedDocuments);
185185
```
186186
> This example will produce this output:
187187
> ```
188-
> query: Tell me a goegraphical fact
188+
> query: Tell me a nature geographical fact
189189
> Top document: Mount Everest is the tallest mountain in the world
190190
> Second document: The capital of France is Paris
191191
> ```

llama/addon/addon.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,36 @@ Napi::Value addonLoadBackends(const Napi::CallbackInfo& info) {
196196
return info.Env().Undefined();
197197
}
198198

199+
Napi::Value addonSetNuma(const Napi::CallbackInfo& info) {
200+
const bool numaDisabled = info.Length() == 0
201+
? true
202+
: info[0].IsBoolean()
203+
? !info[0].As<Napi::Boolean>().Value()
204+
: false;
205+
206+
if (numaDisabled)
207+
return info.Env().Undefined();
208+
209+
const auto numaType = info[0].IsString()
210+
? info[0].As<Napi::String>().Utf8Value()
211+
: "";
212+
213+
if (numaType == "distribute") {
214+
llama_numa_init(GGML_NUMA_STRATEGY_DISTRIBUTE);
215+
} else if (numaType == "isolate") {
216+
llama_numa_init(GGML_NUMA_STRATEGY_ISOLATE);
217+
} else if (numaType == "numactl") {
218+
llama_numa_init(GGML_NUMA_STRATEGY_NUMACTL);
219+
} else if (numaType == "mirror") {
220+
llama_numa_init(GGML_NUMA_STRATEGY_MIRROR);
221+
} else {
222+
Napi::Error::New(info.Env(), std::string("Invalid NUMA strategy \"") + numaType + "\"").ThrowAsJavaScriptException();
223+
return info.Env().Undefined();
224+
}
225+
226+
return info.Env().Undefined();
227+
}
228+
199229
Napi::Value addonInit(const Napi::CallbackInfo& info) {
200230
if (backendInitialized) {
201231
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(info.Env());
@@ -255,6 +285,7 @@ Napi::Object registerCallback(Napi::Env env, Napi::Object exports) {
255285
Napi::PropertyDescriptor::Function("getSwapInfo", getSwapInfo),
256286
Napi::PropertyDescriptor::Function("getMemoryInfo", getMemoryInfo),
257287
Napi::PropertyDescriptor::Function("loadBackends", addonLoadBackends),
288+
Napi::PropertyDescriptor::Function("setNuma", addonSetNuma),
258289
Napi::PropertyDescriptor::Function("init", addonInit),
259290
Napi::PropertyDescriptor::Function("dispose", addonDispose),
260291
});

package-lock.json

Lines changed: 50 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
"@types/yargs": "^17.0.33",
158158
"@vitest/coverage-v8": "^3.1.3",
159159
"@vitest/ui": "^3.1.3",
160-
"electron": "^36.2.0",
160+
"electron": "^37.2.4",
161161
"eslint": "^9.26.0",
162162
"eslint-import-resolver-typescript": "^4.3.4",
163163
"eslint-plugin-import": "^2.31.0",
@@ -178,12 +178,12 @@
178178
"typescript-eslint": "^8.32.0",
179179
"vite-node": "^3.1.3",
180180
"vitepress": "^1.6.3",
181-
"vitepress-plugin-llms": "https://pkg.pr.new/vitepress-plugin-llms@51",
181+
"vitepress-plugin-llms": "^1.7.2",
182182
"vitest": "^3.1.3",
183183
"zx": "^8.5.4"
184184
},
185185
"dependencies": {
186-
"@huggingface/jinja": "^0.5.0",
186+
"@huggingface/jinja": "^0.5.1",
187187
"async-retry": "^1.3.3",
188188
"bytes": "^3.1.2",
189189
"chalk": "^5.4.1",
@@ -197,7 +197,7 @@
197197
"ignore": "^7.0.4",
198198
"ipull": "^3.9.2",
199199
"is-unicode-supported": "^2.1.0",
200-
"lifecycle-utils": "^2.0.1",
200+
"lifecycle-utils": "^3.0.1",
201201
"log-symbols": "^7.0.0",
202202
"nanoid": "^5.1.5",
203203
"node-addon-api": "^8.3.1",

src/bindings/AddonTypes.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Token} from "../types.js";
2+
import {LlamaNuma} from "./types.js";
23

34

45
export type BindingModule = {
@@ -85,6 +86,7 @@ export type BindingModule = {
8586
total: number
8687
},
8788
init(): Promise<void>,
89+
setNuma(numa?: LlamaNuma): void,
8890
loadBackends(forceLoadLibrariesSearchPath?: string): void,
8991
dispose(): Promise<void>
9092
};
@@ -159,15 +161,15 @@ export type AddonContext = {
159161
};
160162

161163
export type BatchLogitIndex = number & {
162-
__batchLogitIndex: never
164+
readonly __batchLogitIndex: never
163165
};
164166

165167
export type AddonGrammar = {
166168
isTextCompatible(testText: string): boolean
167169
};
168170

169171
export type AddonGrammarEvaluationState = "AddonGrammarEvaluationState" & {
170-
__brand: never
172+
readonly __brand: never
171173
};
172174

173175
export type AddonSampler = {

0 commit comments

Comments
 (0)