nn

package
v0.0.0-...-6e6905b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attention

func Attention(ctx ml.Context, query, key, value ml.Tensor, scale float64, cache kvcache.Cache) ml.Tensor

Attention implements scaled dot-product attention for transformer models: Attention(Q, K, V) = softmax(QK^T/√d_k)V

Parameters:

  • ctx: Context for tensor operations
  • query: Query tensor (Q) with shape [d_k, heads, seq_len_q]
  • key: Key tensor (K) with shape [d_k, kv_heads, seq_len_k], can be nil to read from cache only
  • value: Value tensor (V) with shape [d_v, kv_heads, seq_len_k], can be nil to read from cache only
  • scale: Scaling factor, typically 1/√d_k where d_k is the key dimension
  • cache: KV cache to store key/value and get past history, can be nil to only use provided key/value

Returns:

Attention output with shape [d_v, heads, seq_len_q]

func AttentionWithSinks

func AttentionWithSinks(ctx ml.Context, query, key, value, sinks ml.Tensor, scale float64, cache kvcache.Cache) ml.Tensor

Types

type Conv2D

type Conv2D struct {
	Weight ml.Tensor `gguf:"weight"`
}

func (*Conv2D) Forward

func (m *Conv2D) Forward(ctx ml.Context, t ml.Tensor, s0, s1, p0, p1, d0, d1 int) ml.Tensor

type Embedding

type Embedding struct {
	Weight ml.Tensor `gguf:"weight"`
}

func (*Embedding) Forward

func (m *Embedding) Forward(ctx ml.Context, hiddenState ml.Tensor) ml.Tensor

type LayerNorm

type LayerNorm struct {
	Weight ml.Tensor `gguf:"weight"`
	Bias   ml.Tensor `gguf:"bias"`
}

func (*LayerNorm) Forward

func (m *LayerNorm) Forward(ctx ml.Context, t ml.Tensor, eps float32) ml.Tensor

type Linear

type Linear struct {
	Weight ml.Tensor `gguf:"weight"`
	Bias   ml.Tensor `gguf:"bias"`
}

func (*Linear) Forward

func (m *Linear) Forward(ctx ml.Context, t ml.Tensor) ml.Tensor

type LinearBatch

type LinearBatch struct {
	Weight ml.Tensor `gguf:"weight"`
	Bias   ml.Tensor `gguf:"bias"`
}

func (*LinearBatch) Forward

func (m *LinearBatch) Forward(ctx ml.Context, t, indices ml.Tensor) ml.Tensor

type RMSNorm

type RMSNorm struct {
	Weight ml.Tensor `gguf:"weight"`
}

func (*RMSNorm) Forward

func (m *RMSNorm) Forward(ctx ml.Context, t ml.Tensor, eps float32) ml.Tensor

Directories

Path Synopsis
fast provides implementations of fast (fused) operations for increased performance.
fast provides implementations of fast (fused) operations for increased performance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL