| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.LLM.Backprop
Description
Full backward pass through one transformer block. This is the core of the training backprop chain.
Synopsis
- gptBackward :: GptConfig -> Gpt -> [Int] -> [Int] -> (Double, GptGrads)
- bertBackward :: GptConfig -> Gpt -> [Int] -> [Int] -> [Bool] -> (Double, GptGrads)
- data GptGrads = GptGrads {}
- data BlockGrads = BlockGrads {
- bgAttnWq :: !(Matrix Double)
- bgAttnWk :: !(Matrix Double)
- bgAttnWv :: !(Matrix Double)
- bgAttnWo :: !(Matrix Double)
- bgAttnLnGamma :: !(Vector Double)
- bgAttnLnBeta :: !(Vector Double)
- bgFfnW1 :: !(Matrix Double)
- bgFfnW2 :: !(Matrix Double)
- bgFfnB1 :: !(Vector Double)
- bgFfnB2 :: !(Vector Double)
- bgFfnLnGamma :: !(Vector Double)
- bgFfnLnBeta :: !(Vector Double)
- zeroGptGrads :: GptConfig -> GptGrads
- addGptGrads :: GptGrads -> GptGrads -> GptGrads
- scaleGptGrads :: Double -> GptGrads -> GptGrads
- linearBwd :: Matrix Double -> Matrix Double -> Matrix Double -> (Matrix Double, Matrix Double, Vector Double)
- layerNormBwd :: Matrix Double -> Vector Double -> Vector Double -> Double -> Matrix Double -> (Matrix Double, Vector Double, Vector Double)
- geluBwd :: Matrix Double -> Matrix Double -> Matrix Double
- softmaxBwd :: Matrix Double -> Matrix Double -> Matrix Double
- crossEntropyBwd :: Matrix Double -> [Int] -> (Double, Matrix Double)
- maskedCrossEntropyBwd :: Matrix Double -> [Int] -> [Bool] -> (Double, Matrix Double)
Full backward pass
bertBackward :: GptConfig -> Gpt -> [Int] -> [Int] -> [Bool] -> (Double, GptGrads) Source #
BERT-style masked-language-model backward pass.
- inputIds are the (possibly masked) token IDs fed to the model.
- targetIds are the original token IDs to reconstruct.
- mask indicates which positions are supervised.
The model uses bidirectional attention, so every position can attend to every other position.
Gradient types
data BlockGrads Source #
Constructors
| BlockGrads | |
Fields
| |
zeroGptGrads :: GptConfig -> GptGrads Source #
Primitives (exported for testing)
linearBwd :: Matrix Double -> Matrix Double -> Matrix Double -> (Matrix Double, Matrix Double, Vector Double) Source #