transformer

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package transformer provides transformer building blocks such as the Transformer `Block` used in encoder/decoder stacks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block[T tensor.Numeric] struct {
	// contains filtered or unexported fields
}

Block represents a single Transformer block.

func NewTransformerBlock

func NewTransformerBlock[T tensor.Numeric](
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	modelDim, ffnDim int,
	attention graph.Node[T],
	opts ...BlockOption[T],
) (*Block[T], error)

NewTransformerBlock creates a new Transformer block.

func (*Block[T]) Attention added in v0.3.0

func (b *Block[T]) Attention() graph.Node[T]

Attention returns the attention layer of the Transformer block.

func (*Block[T]) Attributes added in v0.3.0

func (b *Block[T]) Attributes() map[string]any

Attributes returns the attributes of the Transformer block.

func (*Block[T]) Backward

func (b *Block[T]) Backward(_ context.Context, _ types.BackwardMode, dOut *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) ([]*tensor.TensorNumeric[T], error)

Backward computes the backward pass of the Transformer block.

func (*Block[T]) Engine added in v0.3.0

func (b *Block[T]) Engine() compute.Engine[T]

Engine returns the compute engine used by the Transformer block.

func (*Block[T]) Forward

func (b *Block[T]) Forward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Forward computes the forward pass of the Transformer block.

func (*Block[T]) OpType added in v0.3.0

func (b *Block[T]) OpType() string

OpType returns the operator type of the Transformer block.

func (*Block[T]) OutputShape

func (b *Block[T]) OutputShape() []int

OutputShape returns the output shape of the Transformer block.

func (*Block[T]) Parameters

func (b *Block[T]) Parameters() []*graph.Parameter[T]

Parameters returns the parameters of the Transformer block.

type BlockOption added in v0.3.0

type BlockOption[T tensor.Numeric] func(*BlockOptions[T])

BlockOption is a function that applies an option to BlockOptions.

func WithEpsilon added in v0.3.0

func WithEpsilon[T tensor.Numeric](epsilon T) BlockOption[T]

WithEpsilon sets the epsilon value for the RMS normalization layers.

type BlockOptions added in v0.3.0

type BlockOptions[T tensor.Numeric] struct {
	Epsilon T
}

BlockOptions holds configuration options for the Transformer block.

Jump to

Keyboard shortcuts

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