Skip to content

Class: Llama

Defined in: bindings/Llama.ts:40

Properties

onDispose

ts
readonly onDispose: EventRelay<void>;

Defined in: bindings/Llama.ts:81

Accessors

disposed

Get Signature

ts
get disposed(): boolean;

Defined in: bindings/Llama.ts:207

Returns

boolean


classes

Get Signature

ts
get classes(): LlamaClasses;

Defined in: bindings/Llama.ts:211

Returns

LlamaClasses


gpu

Get Signature

ts
get gpu(): LlamaGpuType;

Defined in: bindings/Llama.ts:218

Returns

LlamaGpuType


supportsGpuOffloading

Get Signature

ts
get supportsGpuOffloading(): boolean;

Defined in: bindings/Llama.ts:222

Returns

boolean


supportsMmap

Get Signature

ts
get supportsMmap(): boolean;

Defined in: bindings/Llama.ts:226

Returns

boolean


gpuSupportsMmap

Get Signature

ts
get gpuSupportsMmap(): boolean;

Defined in: bindings/Llama.ts:230

Returns

boolean


supportsMlock

Get Signature

ts
get supportsMlock(): boolean;

Defined in: bindings/Llama.ts:234

Returns

boolean


cpuMathCores

Get Signature

ts
get cpuMathCores(): number;

Defined in: bindings/Llama.ts:239

The number of CPU cores that are useful for math

Returns

number


maxThreads

Get Signature

ts
get maxThreads(): number;

Defined in: bindings/Llama.ts:250

The maximum number of threads that can be used by the Llama instance.

If set to 0, the Llama instance will have no limit on the number of threads.

See the maxThreads option of getLlama for more information.

Returns

number

Set Signature

ts
set maxThreads(value: number): void;

Defined in: bindings/Llama.ts:254

Parameters
ParameterType
valuenumber
Returns

void


numa

Get Signature

ts
get numa(): LlamaNuma;

Defined in: bindings/Llama.ts:261

See the numa option of getLlama for more information

Returns

LlamaNuma


logLevel

Get Signature

ts
get logLevel(): LlamaLogLevel;

Defined in: bindings/Llama.ts:265

Returns

LlamaLogLevel

Set Signature

ts
set logLevel(value: LlamaLogLevel): void;

Defined in: bindings/Llama.ts:269

Parameters
ParameterType
valueLlamaLogLevel
Returns

void


logger

Get Signature

ts
get logger(): (level: LlamaLogLevel, message: string) => void;

Defined in: bindings/Llama.ts:279

Returns
ts
(level: LlamaLogLevel, message: string): void;
Parameters
ParameterType
levelLlamaLogLevel
messagestring
Returns

void

Set Signature

ts
set logger(value: (level: LlamaLogLevel, message: string) => void): void;

Defined in: bindings/Llama.ts:283

Parameters
ParameterType
value(level: LlamaLogLevel, message: string) => void
Returns

void


buildType

Get Signature

ts
get buildType(): "localBuild" | "prebuilt";

Defined in: bindings/Llama.ts:290

Returns

"localBuild" | "prebuilt"


cmakeOptions

Get Signature

ts
get cmakeOptions(): Readonly<Record<string, string>>;

Defined in: bindings/Llama.ts:294

Returns

Readonly<Record<string, string>>


llamaCppRelease

Get Signature

ts
get llamaCppRelease(): {
  repo: string;
  release: string;
};

Defined in: bindings/Llama.ts:298

Returns
ts
{
  repo: string;
  release: string;
}
repo
ts
readonly repo: string;
release
ts
readonly release: string;

systemInfo

Get Signature

ts
get systemInfo(): string;

Defined in: bindings/Llama.ts:302

Returns

string


vramPaddingSize

Get Signature

ts
get vramPaddingSize(): number;

Defined in: bindings/Llama.ts:314

VRAM padding used for memory size calculations, as these calculations are not always accurate. This is set by default to ensure stability, but can be configured when you call getLlama.

See vramPadding on getLlama for more information.

Returns

number


ramPaddingSize

Get Signature

ts
get ramPaddingSize(): number;

Defined in: bindings/Llama.ts:324

RAM padding used for memory size calculations, as these calculations are not always accurate. This is set by default to ensure stability, but can be configured when you call getLlama.

See ramPadding on getLlama for more information.

Returns

number

Methods

dispose()

ts
dispose(): Promise<void>;

Defined in: bindings/Llama.ts:188

Returns

Promise<void>


getVramState()

ts
getVramState(): Promise<{
  total: number;
  used: number;
  free: number;
  unifiedSize: number;
}>;

Defined in: bindings/Llama.ts:334

The total amount of VRAM that is currently being used.

unifiedSize represents the amount of VRAM that is shared between the CPU and GPU. On SoC devices, this is usually the same as total.

Returns

Promise<{ total: number; used: number; free: number; unifiedSize: number; }>


getRamState()

ts
getRamState(): Promise<RamState>;

Defined in: bindings/Llama.ts:348

Get the state of the system RAM

Returns

Promise<RamState>


getSwapState()

ts
getSwapState(): Promise<{
  maxSize: number;
  allocated: number;
  used: number;
}>;

Defined in: bindings/Llama.ts:366

Get the state of the swap memory.

maxSize - The maximum size of the swap memory that the system can allocate. If the swap size is dynamic (like on macOS), this will be Infinity.

allocated - The total size allocated by the system for swap memory.

used - The amount of swap memory that is currently being used from the allocated size.

On Windows, this will return the info for the page file.

Returns

Promise<{ maxSize: number; allocated: number; used: number; }>


getLlamaMemoryUsage()

ts
getLlamaMemoryUsage(): Promise<{
  gpuVram: number;
  cpuRam: number;
}>;

Defined in: bindings/Llama.ts:395

Get the total memory usage of this Llama instance

Returns

Promise<{ gpuVram: number; cpuRam: number; }>


setVramCap()

ts
setVramCap(bytes: number | null): Promise<void>;

Defined in: bindings/Llama.ts:416

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.

Parameters

ParameterType
bytesnumber | null

Returns

Promise<void>


getVramCap()

ts
getVramCap(): number | null;

Defined in: bindings/Llama.ts:431

Get the current VRAM cap in bytes. See `setVramCap` for more information.

Defaults to null, which means no cap is set.

Returns

number | null


setRamCap()

ts
setRamCap(bytes: number | null): Promise<void>;

Defined in: bindings/Llama.ts:455

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.

Parameters

ParameterType
bytesnumber | null

Returns

Promise<void>


getRamCap()

ts
getRamCap(): number | null;

Defined in: bindings/Llama.ts:472

Get the current RAM cap in bytes. See `setRamCap` for more information.

Defaults to null, which means no cap is set.

Returns

number | null


getGpuDeviceNames()

ts
getGpuDeviceNames(): Promise<string[]>;

Defined in: bindings/Llama.ts:476

Returns

Promise<string[]>


loadModel()

ts
loadModel(options: LlamaModelOptions): Promise<LlamaModel>;

Defined in: bindings/Llama.ts:484

Parameters

ParameterType
optionsLlamaModelOptions

Returns

Promise<LlamaModel>


createGrammarForJsonSchema()

ts
createGrammarForJsonSchema<T, Defs>(schema: Readonly<T> & GbnfJsonSchema<Defs>): Promise<LlamaJsonSchemaGrammar<T, Defs>>;

Defined in: bindings/Llama.ts:504

Type Parameters

Type ParameterDefault type
T extends | GbnfJsonBasicSchema | GbnfJsonConstSchema | GbnfJsonEnumSchema | GbnfJsonBasicStringSchema | GbnfJsonFormatStringSchema | GbnfJsonOneOfSchema<Defs> | GbnfJsonObjectSchema<string, Defs> | GbnfJsonArraySchema<Defs> | GbnfJsonRefSchema<Defs>-
Defs extends GbnfJsonDefList<Defs>Record<any, any>

Parameters

ParameterType
schemaReadonly<T> & GbnfJsonSchema<Defs>

Returns

Promise<LlamaJsonSchemaGrammar<T, Defs>>

See


getGrammarFor()

ts
getGrammarFor(type: 
  | "json"
  | "json_arr"
  | "english"
  | "list"
  | "c"
  | "arithmetic"
  | "japanese"
  | "chess"): Promise<LlamaGrammar>;

Defined in: bindings/Llama.ts:512

Parameters

ParameterType
type| "json" | "json_arr" | "english" | "list" | "c" | "arithmetic" | "japanese" | "chess"

Returns

Promise<LlamaGrammar>


createGrammar()

ts
createGrammar(options: LlamaGrammarOptions): Promise<LlamaGrammar>;

Defined in: bindings/Llama.ts:519

Parameters

ParameterType
optionsLlamaGrammarOptions

Returns

Promise<LlamaGrammar>

See

Using Grammar tutorial


defaultConsoleLogger()

ts
static defaultConsoleLogger(level: LlamaLogLevel, message: string): void;

Defined in: bindings/Llama.ts:786

Parameters

ParameterType
levelLlamaLogLevel
messagestring

Returns

void