circuits-llm
Safe HaskellNone
LanguageGHC2024

Circuit.LLM.Inference

Description

Token sampling and auto-regressive text generation.

Synopsis

Sampling

greedySample :: Vector Double -> Int Source #

Greedy: pick the token with the highest logit.

temperatureSample :: RandomGen g => Double -> Vector Double -> g -> (Int, g) Source #

Temperature sampling.

topKSample :: RandomGen g => Int -> Double -> Vector Double -> g -> (Int, g) Source #

Top-K sampling.

Generation

generate :: GptConfig -> Gpt -> BPEModel -> Text -> Int -> IO Text Source #

Auto-regressive text generation using greedy sampling.

Utilities

argmax :: Vector Double -> Int Source #

Argmax of a vector.

softmaxV :: Vector Double -> Vector Double Source #

Softmax over a vector (numerically stable).

lastRow :: Matrix Double -> Vector Double Source #

Extract the last row of a matrix.