pt_forward: Run a piece transformer

View source: R/piece_transformer.R

pt_forwardR Documentation

Run a piece transformer

Description

Reads a state, or a batch of them, and returns a value per action.

Usage

pt_forward(model, state)

Arguments

model

A pt_transformer, normally from pt_transformer_load.

state

Colours in 0..num_classes-1: an integer vector of state_size for one state, or a matrix with state_size columns — one state per row — for a batch. A solved 4x4x4 is rep(0:5, each = 16).

Value

For one state, a numeric vector of n_actions values, one per move. For a batch, a matrix with one row per state and one column per action.

One state or many

A batch is not a convenience here, it is the way to get the work done quickly. Every layer but the attention treats a row on its own, so a batch of states is the same arithmetic on taller matrices — and a tall matmul is what BLAS is good at, where a short one spends its time in the call rather than the multiply. Scoring the ten states of a beam in one call is several times faster than scoring them one after another.

See Also

pt_transformer_load

Examples

## Not run: 
model <- pt_transformer_load("model.pth")
solved <- rep(0:5, each = 16)

pt_forward(model, solved)                       # 24 values
pt_forward(model, rbind(solved, solved))        # 2 x 24

## End(Not run)

ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.