Skip to content

Class: LlamaModel

Properties

tokenizer

ts
readonly tokenizer: Tokenizer;

Defined in

evaluator/LlamaModel/LlamaModel.ts:160


onDispose

ts
readonly onDispose: EventRelay<void>;

Defined in

evaluator/LlamaModel/LlamaModel.ts:161

Accessors

disposed

ts
get disposed(): boolean

Returns

boolean

Defined in

evaluator/LlamaModel/LlamaModel.ts:266


tokens

ts
get tokens(): LlamaModelTokens

Returns

LlamaModelTokens

Defined in

evaluator/LlamaModel/LlamaModel.ts:270


filename

ts
get filename(): undefined | string

Returns

undefined | string

Defined in

evaluator/LlamaModel/LlamaModel.ts:274


fileInfo

ts
get fileInfo(): GgufFileInfo

Returns

GgufFileInfo

Defined in

evaluator/LlamaModel/LlamaModel.ts:278


fileInsights

ts
get fileInsights(): GgufInsights

Returns

GgufInsights

Defined in

evaluator/LlamaModel/LlamaModel.ts:282


gpuLayers

ts
get gpuLayers(): number

Number of layers offloaded to the GPU. If GPU support is disabled, this will always be 0.

Returns

number

Defined in

evaluator/LlamaModel/LlamaModel.ts:290


size

ts
get size(): number

Total model size in memory in bytes

Returns

number

Defined in

evaluator/LlamaModel/LlamaModel.ts:297


flashAttentionSupported

ts
get flashAttentionSupported(): boolean

Returns

boolean

Defined in

evaluator/LlamaModel/LlamaModel.ts:303


defaultContextFlashAttention

ts
get defaultContextFlashAttention(): boolean

Returns

boolean

Defined in

evaluator/LlamaModel/LlamaModel.ts:307


trainContextSize

ts
get trainContextSize(): number

The context size the model was trained on

Returns

number

Defined in

evaluator/LlamaModel/LlamaModel.ts:589


embeddingVectorSize

ts
get embeddingVectorSize(): number

The size of an embedding vector the model can produce

Returns

number

Defined in

evaluator/LlamaModel/LlamaModel.ts:599


vocabularyType

ts
get vocabularyType(): LlamaVocabularyType

Returns

LlamaVocabularyType

Defined in

evaluator/LlamaModel/LlamaModel.ts:608

Methods

dispose()

ts
dispose(): Promise<void>

Returns

Promise<void>

Defined in

evaluator/LlamaModel/LlamaModel.ts:252


tokenize()

tokenize(text, specialTokens, options)

ts
tokenize(
   text: string, 
   specialTokens?: boolean, 
   options?: "trimLeadingSpace"): Token[]

Transform text into tokens that can be fed to the model

Parameters
ParameterTypeDescription
textstringthe text to tokenize
specialTokens?booleanif set to true, text that correspond to special tokens will be tokenized to those tokens. For example, <s> will be tokenized to the BOS token if specialTokens is set to true, otherwise it will be tokenized to tokens that corresponds to the plaintext <s> string.
options?"trimLeadingSpace"additional options for tokenization. If set to "trimLeadingSpace", a leading space will be trimmed from the tokenized output if the output has an additional space at the beginning.
Returns

Token[]

Defined in

evaluator/LlamaModel/LlamaModel.ts:321

tokenize(text, specialTokens)

ts
tokenize(text: BuiltinSpecialTokenValue, specialTokens: "builtin"): Token[]
Parameters
ParameterType
textBuiltinSpecialTokenValue
specialTokens"builtin"
Returns

Token[]

Defined in

evaluator/LlamaModel/LlamaModel.ts:322


detokenize()

ts
detokenize(
   tokens: readonly Token[], 
   specialTokens?: boolean, 
   lastTokens?: readonly Token[]): string

Transform tokens into text

Parameters

ParameterTypeDefault valueDescription
tokensreadonly Token[]undefinedthe tokens to detokenize.
specialTokens?booleanfalseif set to true, special tokens will be detokenized to their corresponding token text representation. Recommended for debugging purposes only. > Note: there may be additional spaces around special tokens that were not present in the original text - this is not a bug, this is how the tokenizer is supposed to work. Defaults to false.
lastTokens?readonly Token[]undefinedthe last few tokens that preceded the tokens to detokenize. If provided, the last few tokens will be used to determine whether a space has to be added before the current tokens or not, and apply other detokenizer-specific heuristics to provide the correct text continuation to the existing tokens. Using it may have no effect with some models, but it is still recommended.

Returns

string

Defined in

evaluator/LlamaModel/LlamaModel.ts:435


getTokenAttributes()

ts
getTokenAttributes(token: Token): TokenAttributes

Parameters

ParameterType
tokenToken

Returns

TokenAttributes

Defined in

evaluator/LlamaModel/LlamaModel.ts:456


isSpecialToken()

ts
isSpecialToken(token: undefined | Token): boolean

Check whether the given token is a special token (a control-type token or a token with no normal text representation)

Parameters

ParameterType
tokenundefined | Token

Returns

boolean

Defined in

evaluator/LlamaModel/LlamaModel.ts:467


iterateAllTokens()

ts
iterateAllTokens(): Generator<Token, void, unknown>

Returns

Generator<Token, void, unknown>

Defined in

evaluator/LlamaModel/LlamaModel.ts:482


isEogToken()

ts
isEogToken(token: undefined | Token): boolean

Check whether the given token is an EOG (End Of Generation) token, like EOS or EOT.

Parameters

ParameterType
tokenundefined | Token

Returns

boolean

Defined in

evaluator/LlamaModel/LlamaModel.ts:495


createContext()

ts
createContext(options: LlamaContextOptions): Promise<LlamaContext>

Parameters

ParameterType
optionsLlamaContextOptions

Returns

Promise<LlamaContext>

Defined in

evaluator/LlamaModel/LlamaModel.ts:502


createEmbeddingContext()

ts
createEmbeddingContext(options: LlamaEmbeddingContextOptions): Promise<LlamaEmbeddingContext>

Parameters

ParameterType
optionsLlamaEmbeddingContextOptions

Returns

Promise<LlamaEmbeddingContext>

Defined in

evaluator/LlamaModel/LlamaModel.ts:516


getWarnings()

ts
getWarnings(): string[]

Get warnings about the model file that would affect its usage.

These warnings include all the warnings generated by GgufInsights, but are more comprehensive.

Returns

string[]

Defined in

evaluator/LlamaModel/LlamaModel.ts:535