Documentation
¶
Index ¶
- Variables
- func BackendInit()
- func FreeModel(model *Model)
- func GetModelArch(modelPath string) (string, error)
- func SchemaToGrammar(schema []byte) []byte
- type Batch
- type Context
- func (c *Context) Decode(batch *Batch) error
- func (c *Context) GetEmbeddingsIth(i int) []float32
- func (c *Context) GetEmbeddingsSeq(seqId int) []float32
- func (c *Context) GetLogitsIth(i int) []float32
- func (c *Context) KvCacheCanShift() bool
- func (c *Context) KvCacheClear()
- func (c *Context) KvCacheSeqAdd(seqId int, p0 int, p1 int, delta int)
- func (c *Context) KvCacheSeqCp(srcSeqId int, dstSeqId int, p0 int, p1 int)
- func (c *Context) KvCacheSeqRm(seqId int, p0 int, p1 int) bool
- func (c *Context) Model() *Model
- func (c *Context) Synchronize()
- type ContextParams
- type Devices
- type Grammar
- type Model
- func (m *Model) AddBOSToken() bool
- func (m *Model) ApplyLoraFromFile(context *Context, loraPath string, scale float32, threads int) error
- func (m *Model) NEmbd() int
- func (m *Model) NumVocab() int
- func (m *Model) TokenIsEog(token int) bool
- func (m *Model) TokenToPiece(token int) string
- func (m *Model) Tokenize(text string, addSpecial bool, parseSpecial bool) ([]int, error)
- func (m *Model) Vocab() *C.struct_llama_vocab
- type ModelParams
- type MtmdChunk
- type MtmdContext
- type SamplingContext
- type SamplingParams
- type TokenData
Constants ¶
This section is empty.
Variables ¶
var ErrKvCacheFull = errors.New("could not find a kv cache slot")
Functions ¶
func BackendInit ¶
func BackendInit()
func GetModelArch ¶ added in v0.4.0
func SchemaToGrammar ¶ added in v0.5.2
SchemaToGrammar converts the provided JSON schema to a grammar. It returns nil if the provided schema is invalid JSON or an invalid JSON schema.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
func NewBatch ¶
Creates a new batch for either word tokens or image embeddings (if embedSize is non-zero). Batches cannot contain both types at the same time. batchSize is the maximum number of entries that can be added per sequence
func (*Batch) Add ¶
Add adds either a token or an image embedding to the batch depending on the type when the batch was initialized. The other argument will be ignored. Adds to the batch with the given position for the given sequence ids, and optionally instructs to include logits.
func (*Batch) IsEmbedding ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewContextWithModel ¶
func NewContextWithModel(model *Model, params ContextParams) (*Context, error)
func (*Context) GetEmbeddingsIth ¶
func (*Context) GetEmbeddingsSeq ¶
Get the embeddings for a sequence id
func (*Context) GetLogitsIth ¶
GetLogitsIth gets the logits for the ith token
func (*Context) KvCacheCanShift ¶ added in v0.6.4
func (*Context) KvCacheClear ¶
func (c *Context) KvCacheClear()
func (*Context) KvCacheSeqAdd ¶
func (*Context) KvCacheSeqCp ¶
func (*Context) Synchronize ¶ added in v0.4.2
func (c *Context) Synchronize()
type ContextParams ¶
type ContextParams struct {
// contains filtered or unexported fields
}
func NewContextParams ¶
func NewContextParams(numCtx int, batchSize int, numSeqMax int, threads int, flashAttention ml.FlashAttentionType, kvCacheType string) ContextParams
type Devices ¶ added in v0.12.11
func EnumerateGPUs ¶ added in v0.11.5
func EnumerateGPUs() []Devices
type Grammar ¶ added in v0.6.7
type Grammar struct {
// contains filtered or unexported fields
}
func NewGrammar ¶ added in v0.6.7
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
func LoadModelFromFile ¶
func LoadModelFromFile(modelPath string, params ModelParams) (*Model, error)
func (*Model) AddBOSToken ¶
func (*Model) ApplyLoraFromFile ¶
func (*Model) TokenIsEog ¶
func (*Model) TokenToPiece ¶
func (*Model) Vocab ¶ added in v0.5.13
func (m *Model) Vocab() *C.struct_llama_vocab
type ModelParams ¶
type MtmdContext ¶ added in v0.11.5
type MtmdContext struct {
// contains filtered or unexported fields
}
vision processing
func NewMtmdContext ¶ added in v0.11.5
func NewMtmdContext(llamaContext *Context, modelPath string) (*MtmdContext, error)
func (*MtmdContext) Free ¶ added in v0.11.5
func (c *MtmdContext) Free()
func (*MtmdContext) MultimodalTokenize ¶ added in v0.12.6
func (c *MtmdContext) MultimodalTokenize(llamaContext *Context, data []byte) ([]MtmdChunk, error)
type SamplingContext ¶
type SamplingContext struct {
// contains filtered or unexported fields
}
sampling TODO: this is a temporary wrapper to allow calling C++ code from CGo
func NewSamplingContext ¶
func NewSamplingContext(model *Model, params SamplingParams) (*SamplingContext, error)
func (*SamplingContext) Accept ¶
func (s *SamplingContext) Accept(id int, applyGrammar bool)
func (*SamplingContext) Reset ¶
func (s *SamplingContext) Reset()