Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data NamedModel model = NamedModel Text model
- pattern (::>) :: Text -> model -> NamedModel model
- class HasForward model input generatorDevice output generatorOutputDevice | model input generatorDevice -> output, model input generatorDevice -> generatorOutputDevice where
- forward :: forall m. MonadThrow m => model -> input -> Generator generatorDevice -> m (output, Generator generatorOutputDevice)
- class GHasForward gModel input generatorDevice output generatorOutputDevice | gModel input generatorDevice -> output, gModel input generatorDevice -> generatorOutputDevice where
- gForward :: forall m c. MonadThrow m => gModel c -> input -> Generator generatorDevice -> m (output, Generator generatorOutputDevice)
- newtype Wrap a = Wrap a
- type family ListToTuple xs = tuple | tuple -> xs where ...
- newtype ModelStack models = ModelStack (ListToTuple models)
- type family ModelSpec model = spec | spec -> model
- class HasInitialize model generatorDevice output generatorOutputDevice | model generatorDevice -> output, model generatorDevice -> generatorOutputDevice where
- initialize :: forall m. MonadThrow m => ModelSpec model -> Generator generatorDevice -> m (output, Generator generatorOutputDevice)
- class GHasInitialize gModelSpec generatorDevice gOutput generatorOutputDevice | gModelSpec generatorDevice -> gOutput, gModelSpec generatorDevice -> generatorOutputDevice where
- gInitialize :: forall m c. MonadThrow m => gModelSpec c -> Generator generatorDevice -> m (gOutput c, Generator generatorOutputDevice)
- data VectorSpec (n :: Nat) (a :: Type) where
- VectorSpec :: forall n a. SNat n -> Vector n (ModelSpec a) -> VectorSpec n a
- type StateDictKey = Text
- type StateDict = Map StateDictKey (ForeignPtr Tensor)
- newtype FromStateDictError = FromStateDictKeyNotFoundError {}
- newtype ToStateDictError = ToStateDictKeyAlreadyInUseError {}
- class HasStateDict model where
- fromStateDict :: forall m. (MonadIO m, MonadThrow m, MonadState StateDict m) => ModelSpec model -> StateDictKey -> m model
- toStateDict :: forall m. (MonadThrow m, MonadState StateDict m) => StateDictKey -> model -> m ()
- class GHasStateDict gModel gModelSpec | gModelSpec -> gModel, gModel -> gModelSpec where
- gFromStateDict :: forall m c. (MonadIO m, MonadThrow m, MonadState StateDict m) => gModelSpec c -> StateDictKey -> m (gModel c)
- gToStateDict :: forall m c. (MonadThrow m, MonadState StateDict m) => StateDictKey -> gModel c -> m ()
- stateDictFromFile :: FilePath -> IO StateDict
- stateDictToFile :: StateDict -> FilePath -> IO ()
Documentation
data NamedModel model Source #
NamedModel Text model |
Instances
Generic (NamedModel model) Source # | |
Defined in Torch.GraduallyTyped.NN.Class from :: NamedModel model -> Rep (NamedModel model) x Source # to :: Rep (NamedModel model) x -> NamedModel model Source # | |
Show model => Show (NamedModel model) Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
Eq model => Eq (NamedModel model) Source # | |
Defined in Torch.GraduallyTyped.NN.Class (==) :: NamedModel model -> NamedModel model -> Bool Source # (/=) :: NamedModel model -> NamedModel model -> Bool Source # | |
Ord model => Ord (NamedModel model) Source # | |
Defined in Torch.GraduallyTyped.NN.Class compare :: NamedModel model -> NamedModel model -> Ordering Source # (<) :: NamedModel model -> NamedModel model -> Bool Source # (<=) :: NamedModel model -> NamedModel model -> Bool Source # (>) :: NamedModel model -> NamedModel model -> Bool Source # (>=) :: NamedModel model -> NamedModel model -> Bool Source # max :: NamedModel model -> NamedModel model -> NamedModel model Source # min :: NamedModel model -> NamedModel model -> NamedModel model Source # | |
HasStateDict model => HasStateDict (NamedModel model) Source # | |
Defined in Torch.GraduallyTyped.NN.Class fromStateDict :: (MonadIO m, MonadThrow m, MonadState StateDict m) => ModelSpec (NamedModel model) -> StateDictKey -> m (NamedModel model) Source # toStateDict :: (MonadThrow m, MonadState StateDict m) => StateDictKey -> NamedModel model -> m () Source # | |
HasForward model input generatorDevice output generatorOutputDevice => HasForward (NamedModel model) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class forward :: MonadThrow m => NamedModel model -> input -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
HasInitialize model generatorDevice output generatorOutputDevice => HasInitialize (NamedModel model) generatorDevice (NamedModel output) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (NamedModel model) -> Generator generatorDevice -> m (NamedModel output, Generator generatorOutputDevice) Source # | |
HasInitialize (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead initialize :: MonadThrow m => ModelSpec (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) -> Generator generatorDevice -> m (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)), Generator generatorDevice) Source # | |
(shape' ~ BroadcastShapesF shape biasShape, Catch shape', output ~ Tensor (gradient <|> biasGradient) (layout <+> biasLayout) (device <+> biasDevice) (dataType <+> biasDataType) shape') => HasForward (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) (Tensor gradient layout device dataType shape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead forward :: MonadThrow m => GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
HasForward (GLinear weight bias) input generatorDevice output generatorDevice => HasForward (GLinear (NamedModel weight) (NamedModel bias)) input generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Linear forward :: MonadThrow m => GLinear (NamedModel weight) (NamedModel bias) -> input -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
HasInitialize (GLinear weight bias) generatorDevice (GLinear weight bias) generatorDevice => HasInitialize (GLinear (NamedModel weight) (NamedModel bias)) generatorDevice (GLinear (NamedModel weight) (NamedModel bias)) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Linear initialize :: MonadThrow m => ModelSpec (GLinear (NamedModel weight) (NamedModel bias)) -> Generator generatorDevice -> m (GLinear (NamedModel weight) (NamedModel bias), Generator generatorDevice) Source # | |
type Rep (NamedModel model) Source # | |
Defined in Torch.GraduallyTyped.NN.Class type Rep (NamedModel model) = D1 ('MetaData "NamedModel" "Torch.GraduallyTyped.NN.Class" "hasktorch-gradually-typed-0.2.0.0-1KV1aIPzzbp6JpSr37tC1K" 'False) (C1 ('MetaCons "NamedModel" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 model))) | |
type ModelSpec (NamedModel model) Source # | |
Defined in Torch.GraduallyTyped.NN.Class |
pattern (::>) :: Text -> model -> NamedModel model Source #
class HasForward model input generatorDevice output generatorOutputDevice | model input generatorDevice -> output, model input generatorDevice -> generatorOutputDevice where Source #
Nothing
:: forall m. MonadThrow m | |
=> model | model |
-> input | model input, typically a tensor or a tuple of tensors |
-> Generator generatorDevice | random generator |
-> m (output, Generator generatorOutputDevice) | output of the model with an updated generator |
forward m i g
for a model m
, an input i
, and a generator g
returns the tuple (o, g')
where o
is the output of the model applied to the input
and g'
is the updated generator.
forward m i g
may throw an exception if the input i
or the generator g
are not compatible with the model m
.
default forward :: forall m. (MonadThrow m, Generic model, GHasForward (Rep model) input generatorDevice output generatorOutputDevice) => model -> input -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #
Instances
(input ~ Tensor gradient layout device dataType shape, output ~ Tensor gradient layout (device <+> generatorDevice) dataType shape, generatorOutputDevice ~ (device <+> generatorDevice), SGetDevice device, SGetGeneratorDevice generatorDevice) => HasForward Dropout input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Dropout | |
HasForward () input generatorDevice input generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(Catch (predShape <+> targetShape), output ~ Tensor (predGradient <|> targetGradient) (predLayout <+> targetLayout) (predDevice <+> targetDevice) (predDataType <+> targetDataType) ('Shape ('[] :: [Dim (Name Symbol) (Size Nat)]))) => HasForward MSELoss (Tensor predGradient predLayout predDevice predDataType predShape, Tensor targetGradient targetLayout targetDevice targetDataType targetShape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Loss | |
MkTransformerPaddingMaskC layout device dataType shape output => HasForward MkTransformerPaddingMask (Tensor gradient layout device dataType shape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type forward :: MonadThrow m => MkTransformerPaddingMask -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
HasForward Gelu (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation | |
HasForward GeluNew (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation | |
HasForward Relu (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation | |
HasForward Tanh (Tensor requiresGradient layout device dataType shape) generator (Tensor requiresGradient layout device dataType shape) generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation | |
MkPosC device shape seqDim seqName seqSize output => HasForward MkAbsPos (Tensor gradient layout device dataType shape) generatorDevice (Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) device ('DataType 'Int64) ('Shape '['Dim ('Name "*") seqSize])) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type | |
HasForward (ListToTuple models) input generatorDevice output generatorOutputDevice => HasForward (ModelStack models) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class forward :: MonadThrow m => ModelStack models -> input -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
HasForward model input generatorDevice output generatorOutputDevice => HasForward (NamedModel model) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class forward :: MonadThrow m => NamedModel model -> input -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
HasForward a input generatorDevice output generatorOutputDevice => HasForward (Wrap a) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(input ~ Tensor inputGradient inputLayout inputDevice inputDataType inputShape, SGetLayout inputLayout, SGetDevice inputDevice, SGetDataType inputDataType, SGetShape inputShape, inputBatchDim ~ (inputShape ! 0), inputSeqDim ~ (inputShape ! 1), Scalar fillValue, rightShiftedInput ~ Tensor (inputGradient <|> 'Gradient 'WithoutGradient) inputLayout inputDevice inputDataType (ReplaceDimF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) (inputShape <+> 'Shape '[inputBatchDim, inputSeqDim]) (AddDimF inputSeqDim ('Dim ('Name "*") ('Size 1))))) => HasForward (ShiftRight fillValue) input generator rightShiftedInput generator Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type forward :: MonadThrow m => ShiftRight fillValue -> input -> Generator generator -> m (rightShiftedInput, Generator generator) Source # | |
(HasForward block (query, attentionBias) generatorDevice output generatorOutputDevice, HasForward block (output, attentionBias) generatorOutputDevice output generatorOutputDevice) => HasForward (GTransformerStack (Vector n block)) (query, attentionBias) generatorDevice output generatorOutputDevice Source # |
┌───────┐ ┌───────────────┐ │ query │ │ attentionBias │ └───┬───┘ └───────┬───────┘ │ │ ▼ │ block◄───────────┤ ▼ │ block◄───────────┤ ▼ │ ... ... ▼ │ block◄───────────┘ │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GStack forward :: MonadThrow m => GTransformerStack (Vector n block) -> (query, attentionBias) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
HasForward (GTransformerStack (Vector 0 block)) (query, attentionBias) generatorDevice query generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GStack forward :: MonadThrow m => GTransformerStack (Vector 0 block) -> (query, attentionBias) -> Generator generatorDevice -> m (query, Generator generatorDevice) Source # | |
HasForward block (query, attentionBias) generatorDevice output generatorOutputDevice => HasForward (GTransformerStack (Vector 1 block)) (query, attentionBias) generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GStack forward :: MonadThrow m => GTransformerStack (Vector 1 block) -> (query, attentionBias) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
MkTransformerCrossAttentionMaskC dataType decoderInputShape decoderInputSeqDim inputPaddingMaskGradient inputPaddingMaskLayout inputPaddingMaskDevice inputPaddingMaksDataType inputPaddingMaskShape seqDim output => HasForward (MkTransformerCrossAttentionMask dataType) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor inputPaddingMaskGradient inputPaddingMaskLayout inputPaddingMaskDevice inputPaddingMaksDataType inputPaddingMaskShape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type forward :: MonadThrow m => MkTransformerCrossAttentionMask dataType -> (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor inputPaddingMaskGradient inputPaddingMaskLayout inputPaddingMaskDevice inputPaddingMaksDataType inputPaddingMaskShape) -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
(HasForward block (query, key, attentionBias, crossAttentionBias) generatorDevice output generatorOutputDevice, HasForward block (output, key, attentionBias, crossAttentionBias) generatorOutputDevice output generatorOutputDevice) => HasForward (GTransformerStack (Vector n block)) (query, key, attentionBias, crossAttentionBias) generatorDevice output generatorOutputDevice Source # |
┌───────┐ ┌─────┐ ┌───────────────┐ ┌────────────────────┐ │ query │ │ key │ │ attentionBias │ │ crossAttentionBias │ └───┬───┘ └──┬──┘ └───────┬───────┘ └─────────┬──────────┘ │ │ │ │ ▼ │ │ │ block◄──────┤◄────────────┤◄───────────────────┤ ▼ │ │ │ block◄──────┤◄────────────┤◄───────────────────┤ ▼ │ │ │ ... ... ... ... ▼ │ │ │ block◄──────┘◄────────────┘◄───────────────────┘ │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GStack forward :: MonadThrow m => GTransformerStack (Vector n block) -> (query, key, attentionBias, crossAttentionBias) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
HasForward (GTransformerStack (Vector 0 block)) (query, key, attentionBias, crossAttentionBias) generator query generator Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GStack forward :: MonadThrow m => GTransformerStack (Vector 0 block) -> (query, key, attentionBias, crossAttentionBias) -> Generator generator -> m (query, Generator generator) Source # | |
HasForward block (query, key, attentionBias, crossAttentionBias) generatorDevice output generatorOutputDevice => HasForward (GTransformerStack (Vector 1 block)) (query, key, attentionBias, crossAttentionBias) generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GStack forward :: MonadThrow m => GTransformerStack (Vector 1 block) -> (query, key, attentionBias, crossAttentionBias) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(shape' ~ SoftmaxF selectDim shape, Catch shape', output ~ Tensor requiresGradient layout device dataType shape') => HasForward (LogSoftmax selectDim) (Tensor requiresGradient layout device dataType shape) generator output generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation forward :: MonadThrow m => LogSoftmax selectDim -> Tensor requiresGradient layout device dataType shape -> Generator generator -> m (output, Generator generator) Source # | |
(shape' ~ SoftmaxF selectDim shape, Catch shape', output ~ Tensor requiresGradient layout device dataType shape') => HasForward (Softmax selectDim) (Tensor requiresGradient layout device dataType shape) generator output generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation | |
(shape' ~ BroadcastShapesF shape biasShape, Catch shape', output ~ Tensor (gradient <|> biasGradient) (layout <+> biasLayout) (device <+> biasDevice) (dataType <+> biasDataType) shape') => HasForward (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) (Tensor gradient layout device dataType shape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead forward :: MonadThrow m => GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
(shape' ~ BroadcastShapesF shape biasShape, Catch shape', output ~ Tensor (gradient <|> biasGradient) (layout <+> biasLayout) (device <+> biasDevice) (dataType <+> biasDataType) shape') => HasForward (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) (Tensor gradient layout device dataType shape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead | |
MkTransformerAttentionMaskC dataType inputGradient inputLayout inputDevice inputDataType inputShape seqDim output => HasForward (MkTransformerAttentionMask dataType) (Tensor inputGradient inputLayout inputDevice inputDataType inputShape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type forward :: MonadThrow m => MkTransformerAttentionMask dataType -> Tensor inputGradient inputLayout inputDevice inputDataType inputShape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
MkTransformerDecoderAttentionMaskC dataType decoderInputLayout decoderInputDevice decoderInputShape seqDim output => HasForward (MkTransformerDecoderAttentionMask dataType) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape) generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type forward :: MonadThrow m => MkTransformerDecoderAttentionMask dataType -> Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
HasForward (GBias ()) (Tensor gradient layout device dataType shape) generatorDevice (Tensor gradient layout device dataType shape) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead | |
MkRelPosC device shape seqDim seqName seqSize output => HasForward (MkRelPos relPosEncBucketDim) (Tensor gradient layout device dataType shape) generatorDevice (Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) device ('DataType 'Int64) ('Shape '['Dim ('Name "*") ('Size 1), 'Dim ('Name "*") seqSize, 'Dim ('Name "*") seqSize])) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type forward :: MonadThrow m => MkRelPos relPosEncBucketDim -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) device ('DataType 'Int64) ('Shape '['Dim ('Name "*") ('Size 1), 'Dim ('Name "*") seqSize, 'Dim ('Name "*") seqSize]), Generator generatorDevice) Source # | |
HasForward (GLinear weight bias) input generatorDevice output generatorDevice => HasForward (GLinear (NamedModel weight) (NamedModel bias)) input generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Linear forward :: MonadThrow m => GLinear (NamedModel weight) (NamedModel bias) -> input -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
(HasForward a input generatorDevice output generatorOutputDevice, HasForward a output generatorOutputDevice output generatorOutputDevice) => HasForward (Vector n a) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
HasForward (Vector 0 a) input generatorDevice input generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
HasForward a input generatorDevice output generatorOutputDevice => HasForward (Vector 1 a) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(HasForward a input generatorDevice outputA generatorOutputADevice, HasForward b outputA generatorOutputADevice output generatorOutputDevice) => HasForward (a, b) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LinearWithBiasF ('Shape '[outputDim, inputDim]) ('Shape '[outputDim]) shape') => HasForward (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim]))) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Linear forward :: MonadThrow m => GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim])) -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LinearWithoutBiasF ('Shape '[outputDim, inputDim]) shape') => HasForward (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) ()) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # | |
(HasForward dense (Tensor gradient layout device dataType shape) generatorDevice tensor0 generatorDevice0, HasForward activation tensor0 generatorDevice0 output generatorOutputDevice) => HasForward (GPooler dense activation) (Tensor gradient layout device dataType shape) generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GPooler | |
(HasForward a input generatorDevice outputA generatorOutputADevice, HasForward b outputA generatorOutputADevice outputB generatorOutputBDevice, HasForward c outputB generatorOutputBDevice output generatorOutputDevice) => HasForward (a, b, c) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(HasForward selfAttention (query, attentionBias) generatorDevice tensor0 generatorDevice0, HasForward feedForwardNetwork tensor0 generatorDevice0 output generatorOutputDevice) => HasForward (GTransformerBlock selfAttention () feedForwardNetwork) (query, attentionBias) generatorDevice output generatorOutputDevice Source # |
┌───────┐ ┌───────────────┐ │ query │ │ attentionBias │ └───┬───┘ └───────┬───────┘ │ │ ▼ │ tbSelfAttention◄──────┘ ▼ tbFeedForwardNetwork │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GBlock forward :: MonadThrow m => GTransformerBlock selfAttention () feedForwardNetwork -> (query, attentionBias) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward selfAttention (query, attentionBias) generatorDevice tensor0 generatorDevice0, HasForward crossAttention (tensor0, key, crossAttentionBias) generatorDevice0 tensor1 generatorDevice1, HasForward feedForwardNetwork tensor1 generatorDevice1 output generatorOutputDevice) => HasForward (GTransformerBlock selfAttention crossAttention feedForwardNetwork) (query, key, attentionBias, crossAttentionBias) generatorDevice output generatorOutputDevice Source # |
┌──────────────────────┐ ┌───────┐ ┌─────┐ ┌────────────────────┐ │ decoderAttentionBias │ │ query │ │ key │ │ crossAttentionBias │ └──────────┬───────────┘ └───┬───┘ └──┬──┘ └─────────┬──────────┘ │ │ │ │ │ ▼ │ │ └──────────►tdbSelfAttention │ │ │ │ │ ▼ ▼ │ tdbCrossAttention◄───────────┘ │ ▼ tdbFeedForwardNetwork │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GBlock forward :: MonadThrow m => GTransformerBlock selfAttention crossAttention feedForwardNetwork -> (query, key, attentionBias, crossAttentionBias) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward layer0 (Tensor gradient layout device dataType shape) generatorDevice (Tensor gradient' layout' device' dataType' shape') generatorDevice', HasForward activation (Tensor gradient' layout' device' dataType' shape') generatorDevice' (Tensor gradient' layout' device' dataType' shape') generatorDevice', HasForward layer1 (Tensor gradient layout device dataType shape) generatorDevice' (Tensor gradient' layout' device' dataType' shape') generatorDevice'', output ~ Tensor gradient' layout' device' dataType' shape', generatorOutputDevice ~ generatorDevice'') => HasForward (GGate layer0 activation layer1) (Tensor gradient layout device dataType shape) generatorDevice output generatorOutputDevice Source # | |
(HasForward a input generatorDevice outputA generatorOutputADevice, HasForward b outputA generatorOutputADevice outputB generatorOutputBDevice, HasForward c outputB generatorOutputBDevice outputC generatorOutputCDevice, HasForward d outputC generatorOutputCDevice output generatorOutputDevice) => HasForward (a, b, c, d) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(HasForward initialLayerNorm (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice tensor0 generatorDevice0, HasForward multiHeadAttention (tensor0, tensor0, tensor0, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice0 tensor1 generatorDevice1, HasForward dropout tensor1 generatorDevice1 (Tensor gradient2 layout2 device2 dataType2 shape2) generatorDevice2, HasForward finalLayerNorm (Tensor (queryGradient <|> gradient2) (queryLayout <+> layout2) (queryDevice <+> device2) (queryDataType <+> dataType2) (BroadcastShapesF queryShape shape2)) generatorDevice2 output generatorOutputDevice, Catch (BroadcastShapesF queryShape shape2)) => HasForward (GSelfAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice output generatorOutputDevice Source # |
┌───────────────┐ ┌───────┐ │ attentionBias │ │ query │ └───────┬───────┘ └───┬───┘ │ │ │ ┌─────┴─────┐ │ │ │ │ ▼ │ │ (saInitialLayerNorm) │ │ │ │ │ ┌────┼────┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ └─►saMultiHeadAttention │ │ │ ▼ │ saDropout │ │ │ └───►add◄───┘ │ ▼ (saFinalLayerNorm) │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GSelfAttention forward :: MonadThrow m => GSelfAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm -> (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward mkPaddingMask input generatorDevice paddingMask generatorDevice, HasForward mkAttentionMask paddingMask generatorDevice attentionMask generatorDevice, HasForward mkPos input generatorDevice pos generatorDevice, HasForward model (EncoderOnlyTransformerInput input inputType pos attentionMask) generatorDevice (EncoderOnlyTransformerOutput output) generatorOutputDevice) => HasForward (GSimplifiedEncoderOnlyTransformer model mkPos mkPaddingMask mkAttentionMask) (SimplifiedEncoderOnlyTransformerInput input inputType) generatorDevice (SimplifiedEncoderOnlyTransformerOutput output paddingMask) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderOnly forward :: MonadThrow m => GSimplifiedEncoderOnlyTransformer model mkPos mkPaddingMask mkAttentionMask -> SimplifiedEncoderOnlyTransformerInput input inputType -> Generator generatorDevice -> m (SimplifiedEncoderOnlyTransformerOutput output paddingMask, Generator generatorOutputDevice) Source # | |
(HasForward initialLayerNorm (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice tensor0 generatorDevice0, HasForward multiHeadAttention (tensor0, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice0 tensor1 generatorDevice1, HasForward dropout tensor1 generatorDevice1 (Tensor gradient2 layout2 device2 dataType2 shape2) generatorDevice2, HasForward finalLayerNorm (Tensor (queryGradient <|> gradient2) (queryLayout <+> layout2) (queryDevice <+> device2) (queryDataType <+> dataType2) (BroadcastShapesF queryShape shape2)) generatorDevice2 output generatorOutputDevice, Catch (BroadcastShapesF queryShape shape2)) => HasForward (GCrossAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice output generatorOutputDevice Source # |
┌───────┐ ┌─────┐ ┌───────────────┐ │ query │ │ key │ │ attentionBias │ └───┬───┘ └──┬──┘ └───────┬───────┘ │ │ │ ┌──────────┤ │ │ │ │ │ │ │ ▼ │ │ │ (caInitialLayerNorm) │ │ │ │ │ │ │ │ ┌───┴───┐ │ │ │ │ │ │ │ ▼ ▼ ▼ │ │ caMultiheadAttention◄─────────┘ │ │ │ ▼ │ caDropout │ │ └──────►add◄───────┘ │ ▼ (caFinalLayerNorm) │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GCrossAttention forward :: MonadThrow m => GCrossAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm -> (Tensor queryGradient queryLayout queryDevice queryDataType queryShape, Tensor keyGradient keyLayout keyDevice keyDataType keyShape, Tensor attentionBiasGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward a input generatorDevice outputA generatorOutputADevice, HasForward b outputA generatorOutputADevice outputB generatorOutputBDevice, HasForward c outputB generatorOutputBDevice outputC generatorOutputCDevice, HasForward d outputC generatorOutputCDevice outputD generatorOutputDDevice, HasForward e outputD generatorOutputDDevice output generatorOutputDevice) => HasForward (a, b, c, d, e) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(HasForward sharedEmbedding input generatorDevice embeddingOutput embeddingGeneratorOutputDevice, embeddingOutput ~ Tensor requiresGradient' layout' device' dataType' shape', HasForward encoder (embeddingOutput, pos, attentionMask) embeddingGeneratorOutputDevice encoderOutput generatorOutputDevice) => HasForward (GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head) (EncoderDecoderTransformerInput' input pos attentionMask) generatorDevice (EncoderDecoderTransformerOutput' encoderOutput) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder forward :: MonadThrow m => GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head -> EncoderDecoderTransformerInput' input pos attentionMask -> Generator generatorDevice -> m (EncoderDecoderTransformerOutput' encoderOutput, Generator generatorOutputDevice) Source # | |
(HasForward encoderEmbedding input generatorDevice embeddingOutput embeddingGeneratorOutputDevice, embeddingOutput ~ Tensor gradient' layout' device' dataType' shape', HasForward encoderTypeEmbedding inputType embeddingGeneratorOutputDevice typeEmbeddingOutput typeEmbeddingGeneratorOutputDevice, typeEmbeddingOutput ~ Tensor gradient'' layout'' device'' dataType'' shape'', HasForward encoder (Tensor (gradient' <|> gradient'') (layout' <+> layout'') (device' <+> device'') (dataType' <+> dataType'') (BroadcastShapesF shape' shape''), pos, attentionMask) typeEmbeddingGeneratorOutputDevice encoderOutput encoderGeneratorOutputDevice, Catch (BroadcastShapesF shape' shape''), HasForward head encoderOutput encoderGeneratorOutputDevice headOutput generatorOutputDevice) => HasForward (GEncoderOnlyTransformer inputEmbedDim encoder encoderEmbedding encoderTypeEmbedding head) (EncoderOnlyTransformerInput input inputType pos attentionMask) generatorDevice (EncoderOnlyTransformerOutput headOutput) generatorOutputDevice Source # |
┌───────┐ ┌───────────┐ ┌─────┐ ┌───────────────┐ │ input │ │ inputType │ │ pos │ │ attentionMask │ └───┬───┘ └─────┬─────┘ └──┬──┘ └──────┬────────┘ │ │ │ │ ▼ ▼ │ │ eotEmbedding eotTypeEmbedding │ │ ▼ ▼ │ │ (embedScaling) (embedScaling) │ │ │ │ │ │ └────►add◄─────┘ │ │ │ │ │ ▼ │ │ eotEncoder◄──────────────┘◄───────────┘ ▼ (eotHead) │ ▼ ┌────────┐ │ output │ └────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderOnly forward :: MonadThrow m => GEncoderOnlyTransformer inputEmbedDim encoder encoderEmbedding encoderTypeEmbedding head -> EncoderOnlyTransformerInput input inputType pos attentionMask -> Generator generatorDevice -> m (EncoderOnlyTransformerOutput headOutput, Generator generatorOutputDevice) Source # | |
(SGetShape normalizedShape, output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LayerNormWithBiasF normalizedShape normalizedShape shape')) => HasForward (LayerNorm 'WithBias gradient device dataType normalizedShape) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Normalization | |
(SGetShape normalizedShape, SGetShape shape', output ~ Tensor (gradient <|> gradient') ('Layout 'Dense <+> layout') (device <+> device') (dataType <+> dataType') (LayerNormWithoutBiasF normalizedShape shape')) => HasForward (LayerNorm 'WithoutBias gradient device dataType normalizedShape) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Normalization forward :: MonadThrow m => LayerNorm 'WithoutBias gradient device dataType normalizedShape -> Tensor gradient' layout' device' dataType' shape' -> Generator generatorDevice -> m (output, Generator generatorDevice) Source # | |
(HasForward sharedEmbedding decoderInput generatorDevice embeddingOutput' embeddingGeneratorOutputDevice', embeddingOutput' ~ Tensor requiresGradient'' layout'' device'' dataType'' shape'', HasForward decoder (embeddingOutput', encoderOutput, decoderPos, decoderAttentionMask, crossAttentionMask) embeddingGeneratorOutputDevice' decoderOutput decoderGeneratorOutputDevice, HasForward head decoderOutput decoderGeneratorOutputDevice headOutput generatorOutputDevice) => HasForward (GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head) (EncoderDecoderTransformerGenerationInput decoderInput encoderOutput decoderPos decoderAttentionMask crossAttentionMask) generatorDevice (EncoderDecoderTransformerOutput headOutput encoderOutput) generatorOutputDevice Source # |
┌───────────────┐ ┌──────────────┐ ┌────────────┐ ┌──────────────────────┐ ┌────────────────────┐ │ encoderOutput │ │ decoderInput │ │ decoderPos │ │ decoderAttentionMask │ │ crossAttentionMask │ └───────┬───────┘ └───────┬──────┘ └──────┬─────┘ └───────────┬──────────┘ └──────────┬─────────┘ │ │ │ │ │ │ ▼ │ │ │ │ edtSharedEmbedding │ │ │ │ ▼ │ │ │ │ (embedScaling) │ │ │ │ ▼ │ │ │ ├────────────►edtDecoder◄───────────┘◄───────────────────┘◄───────────────────────┘ │ │ │ (edtHead) │ │ ▼ ▼ ┌───────────────┐ ┌───────────────┐ │ encoderOutput │ │ decoderOutput │ └───────────────┘ └───────────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder forward :: MonadThrow m => GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head -> EncoderDecoderTransformerGenerationInput decoderInput encoderOutput decoderPos decoderAttentionMask crossAttentionMask -> Generator generatorDevice -> m (EncoderDecoderTransformerOutput headOutput encoderOutput, Generator generatorOutputDevice) Source # | |
(HasForward (GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head) (EncoderDecoderTransformerInput' input pos attentionMask) generatorDevice (EncoderDecoderTransformerOutput' encoderOutput) generatorDevice', HasForward (GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head) (EncoderDecoderTransformerGenerationInput decoderInput encoderOutput decoderPos decoderAttentionMask crossAttentionMask) generatorDevice' (EncoderDecoderTransformerOutput headOutput encoderOutput) generatorOutputDevice) => HasForward (GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head) (EncoderDecoderTransformerInput input decoderInput pos decoderPos attentionMask decoderAttentionMask crossAttentionMask) generatorDevice (EncoderDecoderTransformerOutput headOutput encoderOutput) generatorOutputDevice Source # |
┌───────┐ ┌─────┐ ┌───────────────┐ ┌──────────────┐ ┌────────────┐ ┌──────────────────────┐ ┌────────────────────┐ │ input │ │ pos │ │ attentionMask │ │ decoderInput │ │ decoderPos │ │ decoderAttentionMask │ │ crossAttentionMask │ └───┬───┘ └──┬──┘ └──────┬────────┘ └──────┬───────┘ └─────┬──────┘ └──────────┬───────────┘ └─────────┬──────────┘ │ │ │ │ │ │ │ ▼ │ │ │ │ │ │ edtSharedEmbedding│ │ │ │ │ │ ▼ │ │ │ │ │ │ (embedScaling) │ │ │ │ │ │ ▼ │ │ │ │ │ │ edtEncoder◄───┘◄───────────┘ ▼ │ │ │ │ edtSharedEmbedding │ │ │ │ ▼ │ │ │ │ (embedScaling) │ │ │ │ ▼ │ │ │ ├────────────────────────────────────►edtDecoder◄──────────┘◄───────────────────┘◄───────────────────────┘ │ ▼ │ (edtHead) │ │ ▼ ▼ ┌───────────────┐ ┌───────────────┐ │ encoderOutput │ │ decoderOutput │ └───────────────┘ └───────────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder forward :: MonadThrow m => GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head -> EncoderDecoderTransformerInput input decoderInput pos decoderPos attentionMask decoderAttentionMask crossAttentionMask -> Generator generatorDevice -> m (EncoderDecoderTransformerOutput headOutput encoderOutput, Generator generatorOutputDevice) Source # | |
(HasForward a input generatorDevice outputA generatorOutputADevice, HasForward b outputA generatorOutputADevice outputB generatorOutputBDevice, HasForward c outputB generatorOutputBDevice outputC generatorOutputCDevice, HasForward d outputC generatorOutputCDevice outputD generatorOutputDDevice, HasForward e outputD generatorOutputDDevice outputE generatorOutputEDevice, HasForward f outputE generatorOutputEDevice output generatorOutputDevice) => HasForward (a, b, c, d, e, f) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(HasForward dense (Tensor gradient layout device dataType shape) generatorDevice tensor0 generatorDevice0, HasForward activation tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward layerNorm tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward decoder tensor2 generatorDevice2 (Tensor gradient3 layout3 device3 dataType3 shape3) generatorDevice3, HasForward bias (Tensor gradient3 layout3 device3 dataType3 shape3) generatorDevice3 output generatorOutputDevice) => HasForward (GLMHead inputEmbedDim dense activation layerNorm decoder bias) (Tensor gradient layout device dataType shape) generatorDevice output generatorOutputDevice Source # |
┌───────┐ │ input │ └───┬───┘ │ ▼ (lmHeadDense) ▼ (lmHeadActivation) ▼ (lmHeadLayerNorm) ▼ lmHeadDecoder ▼ (scaling) ▼ (lmHeadBias) │ ▼ ┌───────────────┐ │ decoderOutput │ └───────────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead | |
(HasForward a input generatorDevice outputA generatorOutputADevice, HasForward b outputA generatorOutputADevice outputB generatorOutputBDevice, HasForward c outputB generatorOutputBDevice outputC generatorOutputCDevice, HasForward d outputC generatorOutputCDevice outputD generatorOutputDDevice, HasForward e outputD generatorOutputDDevice outputE generatorOutputEDevice, HasForward f outputE generatorOutputEDevice outputF generatorOutputFDevice, HasForward g outputF generatorOutputFDevice output generatorOutputDevice) => HasForward (a, b, c, d, e, f, g) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(HasForward mkPaddingMask input generatorDevice inputPaddingMask generatorDevice, HasForward mkAttentionMask inputPaddingMask generatorDevice attentionMask generatorDevice, HasForward mkPos input generatorDevice pos generatorDevice, HasForward model (EncoderDecoderTransformerInput' input pos attentionMask) generatorDevice (EncoderDecoderTransformerOutput' encoderOutput) generatorOutputDevice) => HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerInput' input) generatorDevice (SimplifiedEncoderDecoderTransformerOutput' encoderOutput inputPaddingMask) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder forward :: MonadThrow m => GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask -> SimplifiedEncoderDecoderTransformerInput' input -> Generator generatorDevice -> m (SimplifiedEncoderDecoderTransformerOutput' encoderOutput inputPaddingMask, Generator generatorOutputDevice) Source # | |
(HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerInput input decoderInput) generatorDevice (SimplifiedEncoderDecoderTransformerOutput decoderOutput encoderOutput decoderInput inputPaddingMask) generatorOutputDevice, decoderInput ~ Tensor targetGradient targetLayout targetDevice targetDataType (IndexDims ('Indices '['SliceAll :: IndexType (Index Natural), 'SliceUpTo ('NegativeIndex 1)]) targetShape), decoderOutput ~ Tensor doGradient doLayout doDevice doDataType doShape, logProbsShape ~ SoftmaxF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) doShape, Catch logProbsShape, unsqueezedTargetShape ~ UnsqueezeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) targetShape, Catch unsqueezedTargetShape, gatheredLogProbsShape ~ GatherDimF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) unsqueezedTargetShape logProbsShape, Catch gatheredLogProbsShape, Catch (targetDataType <+> 'DataType 'Int64), logLikelihoodShape ~ SqueezeDimF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) gatheredLogProbsShape, Catch logLikelihoodShape, MeanAllCheckF logLikelihoodShape, loss ~ Tensor (targetGradient <|> doGradient) (targetLayout <+> doLayout) (targetDevice <+> doDevice) doDataType ('Shape ('[] :: [Dim (Name Symbol) (Size Nat)])), generatorOutputDevice ~ generatorDevice) => HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerTrainingInput input (Tensor targetGradient targetLayout targetDevice targetDataType targetShape)) generatorDevice (SimplifiedEncoderDecoderTransformerTrainingOutput loss) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder forward :: MonadThrow m => GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask -> SimplifiedEncoderDecoderTransformerTrainingInput input (Tensor targetGradient targetLayout targetDevice targetDataType targetShape) -> Generator generatorDevice -> m (SimplifiedEncoderDecoderTransformerTrainingOutput loss, Generator generatorOutputDevice) Source # | |
(HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerInput' input) generatorDevice (SimplifiedEncoderDecoderTransformerOutput' encoderOutput inputPaddingMask) generatorDevice', HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerGenerationInput decoderInput encoderOutput inputPaddingMask) generatorDevice' (SimplifiedEncoderDecoderTransformerOutput decoderOutput encoderOutput decoderInput inputPaddingMask) generatorOutputDevice) => HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerInput input decoderInput) generatorDevice (SimplifiedEncoderDecoderTransformerOutput decoderOutput encoderOutput decoderInput inputPaddingMask) generatorOutputDevice Source # |
|
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder forward :: MonadThrow m => GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask -> SimplifiedEncoderDecoderTransformerInput input decoderInput -> Generator generatorDevice -> m (SimplifiedEncoderDecoderTransformerOutput decoderOutput encoderOutput decoderInput inputPaddingMask, Generator generatorOutputDevice) Source # | |
(HasForward initialLayerNorm (Tensor inputGradient inputLayout inputDevice inputDataType inputShape) generatorDevice tensor0 generatorDevice0, HasForward initialDropout tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward relPosEnc (Tensor relPosGradient relPosLayout relPosDevice relPosDataType relPosShape) generatorDevice1 (Tensor relPosEncGradient relPosEncLayout relPosEncDevice relPosEncDataType relPosEncShape) generatorDevice2, HasForward stack (tensor1, Tensor (relPosEncGradient <|> attentionMaskGradient) (relPosEncLayout <+> attentionMaskLayout) (relPosEncDevice <+> attentionMaskDevice) (relPosEncDataType <+> attentionMaskDataType) (BroadcastShapesF doubleTransposedRelPosEncShape unsqueezedAttentionMaskShape)) generatorDevice2 tensor3 generatorDevice3, transposedRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) ('SelectDim ('ByIndex 3 :: By Symbol Natural)) relPosEncShape, Catch transposedRelPosEncShape, doubleTransposedRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) transposedRelPosEncShape, Catch doubleTransposedRelPosEncShape, unsqueezedAttentionMaskShape ~ UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) attentionMaskShape, Catch unsqueezedAttentionMaskShape, Catch (BroadcastShapesF doubleTransposedRelPosEncShape unsqueezedAttentionMaskShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor relPosGradient relPosLayout relPosDevice relPosDataType relPosShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) generatorDevice output generatorOutputDevice Source # |
┌───────┐ ┌────────┐ ┌───────────────┐ │ input │ │ relPos │ │ attentionMask │ └───┬───┘ └───┬────┘ └───────┬───────┘ │ │ │ │ ▼ │ │ tRelPosEnc │ │ ▼ │ │ transpose │ │ ▼ ▼ │ transpose unsqueeze ▼ │ │ (tInitialLayerNorm) │ │ ▼ └─────►add◄─────┘ (tInitialDropout) │ ▼ │ tStack◄───────────────┘ ▼ (tFinalLayerNorm) ▼ (tFinalDropout) │ ▼ ┌────────┐ │ output │ └────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer forward :: MonadThrow m => GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor relPosGradient relPosLayout relPosDevice relPosDataType relPosShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward posEnc (Tensor posGradient posLayout posDevice posDataType posShape) generatorDevice (Tensor posEncGradient posEncLayout posEncDevice posEncDataType posEncShape) generatorDevice0, HasForward initialLayerNorm (Tensor (inputGradient <|> posEncGradient) (inputLayout <+> posEncLayout) (inputDevice <+> posEncDevice) (inputDataType <+> posEncDataType) (BroadcastShapesF inputShape posEncShape)) generatorDevice0 tensor1 generatorDevice1, Catch (BroadcastShapesF inputShape posEncShape), HasForward initialDropout tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward stack (tensor2, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) attentionMaskShape)) generatorDevice2 tensor3 generatorDevice3, Catch (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) attentionMaskShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor posGradient posLayout posDevice posDataType posShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) generatorDevice output generatorOutputDevice Source # |
┌───────┐ ┌─────┐ ┌───────────────┐ │ input │ │ pos │ │ attentionMask │ └───┬───┘ └─────┘ └───────┬───────┘ │ │ │ │ ▼ │ │ tPosEnc │ │ │ │ └──►add◄──┘ │ │ │ ▼ │ (tInitialLayerNorm) │ ▼ ▼ (tInitialDropout) unsqueeze ▼ │ tStack◄───────────────┘ ▼ (tFinalLayerNorm) ▼ (tFinalDropout) │ ▼ ┌────────┐ │ output │ └────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer forward :: MonadThrow m => GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor inputGradient inputLayout inputDevice inputDataType inputShape, Tensor posGradient posLayout posDevice posDataType posShape, Tensor attentionMaskGradient attentionMaskLayout attentionMaskDevice attentionMaskDataType attentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward mkPaddingMask decoderInput generatorDevice decoderInputPaddingMask generatorDevice, HasForward mkCrossAttentionMask (rightShiftedDecoderInput, inputPaddingMask) generatorDevice crossAttentionMask generatorDevice, HasForward mkDecoderAttentionMask rightShiftedDecoderInputPaddingMask generatorDevice decoderAttentionMask generatorDevice, HasForward (ShiftRight Int) decoderInput generatorDevice rightShiftedDecoderInput generatorDevice, HasForward (ShiftRight Int) decoderInputPaddingMask generatorDevice rightShiftedDecoderInputPaddingMask generatorDevice, HasForward mkDecoderPos rightShiftedDecoderInput generatorDevice decoderPos generatorDevice, HasForward model (EncoderDecoderTransformerGenerationInput rightShiftedDecoderInput encoderOutput decoderPos decoderAttentionMask crossAttentionMask) generatorDevice (EncoderDecoderTransformerOutput decoderOutput encoderOutput) generatorOutputDevice) => HasForward (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) (SimplifiedEncoderDecoderTransformerGenerationInput decoderInput encoderOutput inputPaddingMask) generatorDevice (SimplifiedEncoderDecoderTransformerOutput decoderOutput encoderOutput decoderInput inputPaddingMask) generatorOutputDevice Source # |
|
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder forward :: MonadThrow m => GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask -> SimplifiedEncoderDecoderTransformerGenerationInput decoderInput encoderOutput inputPaddingMask -> Generator generatorDevice -> m (SimplifiedEncoderDecoderTransformerOutput decoderOutput encoderOutput decoderInput inputPaddingMask, Generator generatorOutputDevice) Source # | |
(SGetLayout layout, KnownNat paddingIdx, Catch (dataType' <+> 'DataType 'Int64), output ~ Tensor (gradient <|> gradient') (layout <+> layout') (device <+> device') dataType (EmbeddingF ('Shape '[embedNumDim, embedDim]) shape')) => HasForward (Embedding gradient layout device dataType embedNumDim embedDim ('Just paddingIdx)) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Sparse | |
(SGetLayout layout, Catch (dataType' <+> 'DataType 'Int64), output ~ Tensor (gradient <|> gradient') (layout <+> layout') (device <+> device') dataType (EmbeddingF ('Shape '[embedNumDim, embedDim]) shape')) => HasForward (Embedding gradient layout device dataType embedNumDim embedDim ('Nothing :: Maybe Nat)) (Tensor gradient' layout' device' dataType' shape') generatorDevice output generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Sparse | |
(HasForward inputLayerNorm (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice tensor0 generatorDevice0, HasForward inputTransformation tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward activation tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward activationDropout tensor2 generatorDevice2 tensor3 generatorDevice3, HasForward outputProjection tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward outputDropout tensor4 generatorDevice4 (Tensor queryGradient5 queryLayout5 queryDevice5 queryDataType5 queryShape5) generatorDevice5, HasForward outputLayerNorm (Tensor (queryGradient <|> queryGradient5) (queryLayout <+> queryLayout5) (queryDevice <+> queryDevice5) (queryDataType <+> queryDataType5) (BroadcastShapesF queryShape queryShape5)) generatorDevice5 output generatorOutputDevice, Catch (BroadcastShapesF queryShape queryShape5)) => HasForward (GTransformerFeedForwardNetwork inputLayerNorm inputTransformation activation activationDropout outputProjection outputDropout outputLayerNorm) (Tensor queryGradient queryLayout queryDevice queryDataType queryShape) generatorDevice output generatorOutputDevice Source # |
┌───────┐ │ query ├────────┐ └───┬───┘ │ │ │ ▼ │ (ffnInputLayerNorm) │ ▼ │ ffnInputTransformation │ ▼ │ ffnActivation │ ▼ │ (ffnActivationDropout) │ ▼ │ ffnOutputProjecton │ ▼ │ ffnOutputDropout │ │ │ ▼ │ add◄──────────┘ │ ▼ (ffnOutputLayerNorm) │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GFeedForwardNetwork forward :: MonadThrow m => GTransformerFeedForwardNetwork inputLayerNorm inputTransformation activation activationDropout outputProjection outputDropout outputLayerNorm -> Tensor queryGradient queryLayout queryDevice queryDataType queryShape -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward initialLayerNorm (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape) generatorDevice tensor0 generatorDevice0, HasForward initialDropout tensor0 generatorDevice0 tensor1 generatorDevice1, HasForward relPosEnc (Tensor decoderRelPosGradient decoderRelPosLayout decoderRelPosDevice decoderRelPosDataType decoderRelPosShape) generatorDevice1 (Tensor decoderRelPosEncGradient decoderRelPosEncLayout decoderRelPosEncDevice decoderRelPosEncDataType decoderRelPosEncShape) generatorDevice2, HasForward stack (tensor1, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor (decoderRelPosEncGradient <|> decoderAttentionMaskGradient) (decoderRelPosEncLayout <+> decoderAttentionMaskLayout) (decoderRelPosEncDevice <+> decoderAttentionMaskDevice) (decoderRelPosEncDataType <+> decoderAttentionMaskDataType) (BroadcastShapesF doubleTransposedDecoderRelPosEncShape unsqueezedDecoderAttentionMaskShape), Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType unsqueezedCrossAttentionMaskShape) generatorDevice2 tensor3 generatorDevice3, transposedDecoderRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) ('SelectDim ('ByIndex 3 :: By Symbol Natural)) decoderRelPosEncShape, Catch transposedDecoderRelPosEncShape, doubleTransposedDecoderRelPosEncShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) transposedDecoderRelPosEncShape, Catch doubleTransposedDecoderRelPosEncShape, unsqueezedDecoderAttentionMaskShape ~ UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) decoderAttentionMaskShape, Catch unsqueezedDecoderAttentionMaskShape, unsqueezedCrossAttentionMaskShape ~ UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) crossAttentionMaskShape, Catch unsqueezedCrossAttentionMaskShape, Catch (BroadcastShapesF doubleTransposedDecoderRelPosEncShape unsqueezedDecoderAttentionMaskShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderRelPosGradient decoderRelPosLayout decoderRelPosDevice decoderRelPosDataType decoderRelPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) generatorDevice output generatorOutputDevice Source # |
┌──────────────┐ ┌───────────────┐ ┌───────────────┐ ┌──────────────────────┐ ┌────────────────────┐ │ decoderInput │ │ encoderOutput │ │ decoderRelPos │ │ decoderAttentionMask │ │ crossAttentionMask │ └──────┬───────┘ └───────┬───────┘ └───────┬───────┘ └──────────┬───────────┘ └─────────┬──────────┘ │ │ │ │ │ │ │ ▼ │ │ │ │ tdRelPosEnc │ │ │ │ ▼ │ │ │ │ transpose │ │ │ │ ▼ ▼ ▼ │ │ transpose unsqueeze unsqueeze ▼ │ │ │ │ (tInitialLayerNorm) │ │ │ │ ▼ │ └────────►add◄────────┘ │ (tInitialDropout) │ │ │ ▼ │ │ │ tStack◄───────────────┘◄────────────────────────────┘◄──────────────────────────────────┘ ▼ (tFinalLayerNorm) ▼ (tFinalDropout) │ ▼ ┌────────┐ │ output │ └────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer forward :: MonadThrow m => GTransformer () relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderRelPosGradient decoderRelPosLayout decoderRelPosDevice decoderRelPosDataType decoderRelPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward posEnc (Tensor decoderPosGradient decoderPosLayout decoderPosDevice decoderPosDataType decoderPosShape) generatorDevice (Tensor decoderPosEncGradient decoderPosEncLayout decoderPosEncDevice decoderPosEncDataType decoderPosEncShape) generatorDevice0, HasForward initialLayerNorm (Tensor (decoderInputGradient <|> decoderPosEncGradient) (decoderInputLayout <+> decoderPosEncLayout) (decoderInputDevice <+> decoderPosEncDevice) (decoderInputDataType <+> decoderPosEncDataType) (BroadcastShapesF decoderInputShape decoderPosEncShape)) generatorDevice0 tensor1 generatorDevice1, HasForward initialDropout tensor1 generatorDevice1 tensor2 generatorDevice2, HasForward stack (tensor2, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) decoderAttentionMaskShape), Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) crossAttentionMaskShape)) generatorDevice2 tensor3 generatorDevice3, Catch (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) decoderAttentionMaskShape), Catch (UnsqueezeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) crossAttentionMaskShape), Catch (BroadcastShapesF decoderInputShape decoderPosEncShape), HasForward finalLayerNorm tensor3 generatorDevice3 tensor4 generatorDevice4, HasForward finalDropout tensor4 generatorDevice4 output generatorOutputDevice) => HasForward (GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout) (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderPosGradient decoderPosLayout decoderPosDevice decoderPosDataType decoderPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) generatorDevice output generatorOutputDevice Source # |
┌──────────────┐ ┌────────────┐ ┌───────────────┐ ┌──────────────────────┐ ┌────────────────────┐ │ decoderInput │ │ decoderPos │ │ encoderOutput │ │ decoderAttentionMask │ │ crossAttentionMask │ └──────┬───────┘ └──────┬─────┘ └───────┬───────┘ └──────────┬───────────┘ └──────────┬─────────┘ │ │ │ │ │ │ ▼ │ │ │ │ tdPosEnc │ │ │ │ │ │ │ │ └──────►add◄──────┘ │ │ │ │ │ │ │ ▼ │ │ │ (tInitialLayerNorm) │ │ │ ▼ │ ▼ ▼ (tInitialDropout) │ unsqueeze unsqueeze ▼ │ │ │ tStack◄──────────────────────┘◄────────────────────┘◄────────────────────────┘ ▼ (tFinalLayerNorm) ▼ (tFinalDropout) │ ▼ ┌────────┐ │ output │ └────────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer forward :: MonadThrow m => GTransformer posEnc () initialLayerNorm initialDropout stack finalLayerNorm finalDropout -> (Tensor decoderInputGradient decoderInputLayout decoderInputDevice decoderInputDataType decoderInputShape, Tensor encoderOutputGradient encoderOutputLayout encoderOutputDevice encoderOutputDataType encoderOutputShape, Tensor decoderPosGradient decoderPosLayout decoderPosDevice decoderPosDataType decoderPosShape, Tensor decoderAttentionMaskGradient decoderAttentionMaskLayout decoderAttentionMaskDevice decoderAttentionMaskDataType decoderAttentionMaskShape, Tensor crossAttentionMaskGradient crossAttentionMaskLayout crossAttentionMaskDevice crossAttentionMaskDataType crossAttentionMaskShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasForward qInProj (Tensor queryRequiresGradient queryLayout queryDevice queryDataType queryShape) generatorDevice (Tensor qRequiresGradient qLayout qDevice qDataType qShape0) qGeneratorOutputDevice, reshapedQShape0 ~ ReshapeF qShape0 ('Shape '[batchDim, querySeqDim, headDim, headEmbedDim]), Catch reshapedQShape0, qShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) reshapedQShape0, Catch qShape, HasForward kInProj (Tensor keyRequiresGradient keyLayout keyDevice keyDataType keyShape) qGeneratorOutputDevice (Tensor qRequiresGradient kLayout kDevice kDataType kShape0) kGeneratorOutputDevice, reshapedKShape0 ~ ReshapeF kShape0 ('Shape '[batchDim, keySeqDim, headDim, headEmbedDim]), Catch reshapedKShape0, transposedReshapedKShape0 ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) reshapedKShape0, Catch transposedReshapedKShape0, doubleTransposedReshapedKShape0 ~ TransposeF ('SelectDim ('ByIndex 2 :: By Symbol Natural)) ('SelectDim ('ByIndex 3 :: By Symbol Natural)) transposedReshapedKShape0, Catch doubleTransposedReshapedKShape0, multipliedQDoubleTransposedReshapedKShape0 ~ MatmulF qShape doubleTransposedReshapedKShape0, Catch multipliedQDoubleTransposedReshapedKShape0, weightsShape0 ~ SoftmaxF ('SelectDim ('ByIndex 3 :: By Symbol Natural)) (BroadcastShapesF multipliedQDoubleTransposedReshapedKShape0 attentionBiasShape), Catch (BroadcastShapesF multipliedQDoubleTransposedReshapedKShape0 attentionBiasShape), Catch weightsShape0, HasForward dropout (Tensor (qRequiresGradient <|> attentionBiasRequiresGradient) (qLayout <+> (kLayout <+> attentionBiasLayout)) (qDevice <+> (kDevice <+> attentionBiasDevice)) (qDataType <+> (kDataType <+> attentionBiasDataType)) weightsShape0) kGeneratorOutputDevice (Tensor weightsRequiresGradient weightsLayout weightsDevice weightsDataType weightsShape) weightsGeneratorOutputDevice, HasForward vInProj (Tensor valueRequiresGradient valueLayout valueDevice valueDataType valueShape) weightsGeneratorOutputDevice (Tensor weightsRequiresGradient vLayout vDevice vDataType vShape0) vGeneratorOutputDevice, reshapedVShape0 ~ ReshapeF vShape0 ('Shape '[batchDim, keySeqDim, headDim, headEmbedDim]), Catch reshapedVShape0, transposedReshapedVShape ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) reshapedVShape0, Catch transposedReshapedVShape, multipliedWeightsTransposedReshapedVShape ~ MatmulF weightsShape transposedReshapedVShape, Catch multipliedWeightsTransposedReshapedVShape, outputQueryShape0 ~ TransposeF ('SelectDim ('ByIndex 1 :: By Symbol Natural)) ('SelectDim ('ByIndex 2 :: By Symbol Natural)) multipliedWeightsTransposedReshapedVShape, Catch outputQueryShape0, HasForward outProj (Tensor weightsRequiresGradient (weightsLayout <+> vLayout) (weightsDevice <+> vDevice) (weightsDataType <+> vDataType) reshapedOutputQueryShape0) vGeneratorOutputDevice output generatorOutputDevice, reshapedOutputQueryShape0 ~ ReshapeF outputQueryShape0 ('Shape '[batchDim, querySeqDim, embedDim]), Catch reshapedOutputQueryShape0, SGetShape queryShape, SGetShape keyShape, SGetShape valueShape, batchDim ~ BatchDim queryShape keyShape valueShape, querySeqDim ~ QuerySeqDim queryShape, keySeqDim ~ KeySeqDim keyShape valueShape) => HasForward (GMultiHeadAttention headDim headEmbedDim embedDim qInProj kInProj vInProj outProj dropout) (Tensor queryRequiresGradient queryLayout queryDevice queryDataType queryShape, Tensor keyRequiresGradient keyLayout keyDevice keyDataType keyShape, Tensor valueRequiresGradient valueLayout valueDevice valueDataType valueShape, Tensor attentionBiasRequiresGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) generatorDevice output generatorOutputDevice Source # |
┌───────────────┐ ┌───────┐ ┌─────┐ ┌───────┐ │ attentionBias │ │ query │ │ key │ │ value │ └───────┬───────┘ └───┬───┘ └──┬──┘ └───┬───┘ │ │ │ │ │ ▼ ▼ ▼ │ mhaQInProj mhaKInProj mhaVInProj │ ▼ │ │ │ (scaling) │ │ │ ▼ ▼ ▼ │ reshape reshape reshape │ ▼ ▼ ▼ │ transpose transpose transpose │ │ ▼ │ │ │ transpose │ │ │ │ │ │ └───►matmul◄───┘ │ │ ▼ │ │ (scaling) │ │ │ │ └──────────►add◄────────────┘ │ ▼ │ softmax │ ▼ │ mhaDropout │ │ │ └──────────────►matmul◄───────────────┘ ▼ transpose ▼ reshape ▼ mhaOutProj │ ▼ ┌───────┐ │ query │ └───────┘ |
Defined in Torch.GraduallyTyped.NN.Transformer.GMultiHeadAttention forward :: MonadThrow m => GMultiHeadAttention headDim headEmbedDim embedDim qInProj kInProj vInProj outProj dropout -> (Tensor queryRequiresGradient queryLayout queryDevice queryDataType queryShape, Tensor keyRequiresGradient keyLayout keyDevice keyDataType keyShape, Tensor valueRequiresGradient valueLayout valueDevice valueDataType valueShape, Tensor attentionBiasRequiresGradient attentionBiasLayout attentionBiasDevice attentionBiasDataType attentionBiasShape) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # |
class GHasForward gModel input generatorDevice output generatorOutputDevice | gModel input generatorDevice -> output, gModel input generatorDevice -> generatorOutputDevice where Source #
gForward :: forall m c. MonadThrow m => gModel c -> input -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #
Instances
GHasForward (U1 :: Type -> Type) input generatorDevice input generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
(GHasForward gModelA inputA generatorDevice outputA generatorOutputADevice, GHasForward gModelB outputA generatorOutputADevice outputB generatorOutputDevice) => GHasForward (gModelA :*: gModelB) inputA generatorDevice outputB generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
HasForward model input generatorDevice output generatorOutputDevice => GHasForward (K1 i model :: Type -> Type) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class | |
GHasForward gModel input generatorDevice output generatorOutputDevice => GHasForward (M1 i t gModel) input generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class |
Wrap a |
Instances
type family ListToTuple xs = tuple | tuple -> xs where ... Source #
ListToTuple '[] = () | |
ListToTuple '[a] = Wrap a | |
ListToTuple '[a, b] = (a, b) | |
ListToTuple '[a, b, c] = (a, b, c) | |
ListToTuple '[a, b, c, d] = (a, b, c, d) | |
ListToTuple '[a, b, c, d, e] = (a, b, c, d, e) | |
ListToTuple '[a, b, c, d, e, f] = (a, b, c, d, e, f) | |
ListToTuple '[a, b, c, d, e, f, g] = (a, b, c, d, e, f, g) |
newtype ModelStack models Source #
ModelStack (ListToTuple models) |
Instances
type family ModelSpec model = spec | spec -> model Source #
Instances
class HasInitialize model generatorDevice output generatorOutputDevice | model generatorDevice -> output, model generatorDevice -> generatorOutputDevice where Source #
Nothing
initialize :: forall m. MonadThrow m => ModelSpec model -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #
default initialize :: forall m. (MonadThrow m, Generic (ModelSpec model), Generic output, GHasInitialize (Rep (ModelSpec model)) generatorDevice (Rep output) generatorOutputDevice) => ModelSpec model -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #
Instances
HasInitialize Gelu generatorDevice Gelu generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Activation initialize :: MonadThrow m => ModelSpec Gelu -> Generator generatorDevice -> m (Gelu, Generator generatorDevice) Source # | |
HasInitialize GeluNew generator GeluNew generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation initialize :: MonadThrow m => ModelSpec GeluNew -> Generator generator -> m (GeluNew, Generator generator) Source # | |
HasInitialize Relu generatorDevice Relu generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Activation initialize :: MonadThrow m => ModelSpec Relu -> Generator generatorDevice -> m (Relu, Generator generatorDevice) Source # | |
HasInitialize Tanh generator Tanh generator Source # | |
Defined in Torch.GraduallyTyped.NN.Activation initialize :: MonadThrow m => ModelSpec Tanh -> Generator generator -> m (Tanh, Generator generator) Source # | |
HasInitialize Dropout generatorDevice Dropout generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Dropout initialize :: MonadThrow m => ModelSpec Dropout -> Generator generatorDevice -> m (Dropout, Generator generatorDevice) Source # | |
HasInitialize MSELoss generatorDevice MSELoss generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Loss initialize :: MonadThrow m => ModelSpec MSELoss -> Generator generatorDevice -> m (MSELoss, Generator generatorDevice) Source # | |
HasInitialize EncoderDecoderTransformerHasEmbedScaling generatorDevice EncoderDecoderTransformerHasEmbedScaling generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder initialize :: MonadThrow m => ModelSpec EncoderDecoderTransformerHasEmbedScaling -> Generator generatorDevice -> m (EncoderDecoderTransformerHasEmbedScaling, Generator generatorDevice) Source # | |
HasInitialize EncoderOnlyTransformerHasEmbedScaling generatorDevice EncoderOnlyTransformerHasEmbedScaling generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderOnly initialize :: MonadThrow m => ModelSpec EncoderOnlyTransformerHasEmbedScaling -> Generator generatorDevice -> m (EncoderOnlyTransformerHasEmbedScaling, Generator generatorDevice) Source # | |
HasInitialize LMHeadHasScaling generatorDevice LMHeadHasScaling generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead initialize :: MonadThrow m => ModelSpec LMHeadHasScaling -> Generator generatorDevice -> m (LMHeadHasScaling, Generator generatorDevice) Source # | |
HasInitialize MultiHeadAttentionHasScaling generatorDevice MultiHeadAttentionHasScaling generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GMultiHeadAttention initialize :: MonadThrow m => ModelSpec MultiHeadAttentionHasScaling -> Generator generatorDevice -> m (MultiHeadAttentionHasScaling, Generator generatorDevice) Source # | |
HasInitialize MkAbsPos generatorDevice MkAbsPos generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type initialize :: MonadThrow m => ModelSpec MkAbsPos -> Generator generatorDevice -> m (MkAbsPos, Generator generatorDevice) Source # | |
HasInitialize MkTransformerPaddingMask generatorDevice MkTransformerPaddingMask generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type initialize :: MonadThrow m => ModelSpec MkTransformerPaddingMask -> Generator generatorDevice -> m (MkTransformerPaddingMask, Generator generatorDevice) Source # | |
HasInitialize () generatorDevice () generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec () -> Generator generatorDevice -> m ((), Generator generatorDevice) Source # | |
HasInitialize (LogSoftmax selectDim) generatorDevice (LogSoftmax selectDim) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Activation initialize :: MonadThrow m => ModelSpec (LogSoftmax selectDim) -> Generator generatorDevice -> m (LogSoftmax selectDim, Generator generatorDevice) Source # | |
HasInitialize (Softmax selectDim) generatorDevice (Softmax selectDim) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Activation initialize :: MonadThrow m => ModelSpec (Softmax selectDim) -> Generator generatorDevice -> m (Softmax selectDim, Generator generatorDevice) Source # | |
HasInitialize (a, b, c, d, e, f, g) generatorDevice (a', b', c', d', e', f', g') generatorOutputDevice => HasInitialize (ModelStack '[a, b, c, d, e, f, g]) generatorDevice (ModelStack '[a', b', c', d', e', f', g']) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[a, b, c, d, e, f, g]) -> Generator generatorDevice -> m (ModelStack '[a', b', c', d', e', f', g'], Generator generatorOutputDevice) Source # | |
HasInitialize (a, b, c, d, e, f) generatorDevice (a', b', c', d', e', f') generatorOutputDevice => HasInitialize (ModelStack '[a, b, c, d, e, f]) generatorDevice (ModelStack '[a', b', c', d', e', f']) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[a, b, c, d, e, f]) -> Generator generatorDevice -> m (ModelStack '[a', b', c', d', e', f'], Generator generatorOutputDevice) Source # | |
HasInitialize (a, b, c, d, e) generatorDevice (a', b', c', d', e') generatorOutputDevice => HasInitialize (ModelStack '[a, b, c, d, e]) generatorDevice (ModelStack '[a', b', c', d', e']) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[a, b, c, d, e]) -> Generator generatorDevice -> m (ModelStack '[a', b', c', d', e'], Generator generatorOutputDevice) Source # | |
HasInitialize (a, b, c, d) generatorDevice (a', b', c', d') generatorOutputDevice => HasInitialize (ModelStack '[a, b, c, d]) generatorDevice (ModelStack '[a', b', c', d']) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[a, b, c, d]) -> Generator generatorDevice -> m (ModelStack '[a', b', c', d'], Generator generatorOutputDevice) Source # | |
HasInitialize (a, b, c) generatorDevice (a', b', c') generatorOutputDevice => HasInitialize (ModelStack '[a, b, c]) generatorDevice (ModelStack '[a', b', c']) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[a, b, c]) -> Generator generatorDevice -> m (ModelStack '[a', b', c'], Generator generatorOutputDevice) Source # | |
HasInitialize (a, b) generatorDevice (a', b') generatorOutputDevice => HasInitialize (ModelStack '[a, b]) generatorDevice (ModelStack '[a', b']) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[a, b]) -> Generator generatorDevice -> m (ModelStack '[a', b'], Generator generatorOutputDevice) Source # | |
HasInitialize a generatorDevice a' generatorOutputDevice => HasInitialize (ModelStack '[a]) generatorDevice (ModelStack '[a']) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[a]) -> Generator generatorDevice -> m (ModelStack '[a'], Generator generatorOutputDevice) Source # | |
HasInitialize (ModelStack ('[] :: [Type])) generatorDevice (ModelStack ('[] :: [Type])) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (ModelStack '[]) -> Generator generatorDevice -> m (ModelStack '[], Generator generatorDevice) Source # | |
HasInitialize model generatorDevice output generatorOutputDevice => HasInitialize (NamedModel model) generatorDevice (NamedModel output) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (NamedModel model) -> Generator generatorDevice -> m (NamedModel output, Generator generatorOutputDevice) Source # | |
HasInitialize a generatorDevice a' generatorOutputDevice => HasInitialize (Wrap a) generatorDevice (Wrap a') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (Wrap a) -> Generator generatorDevice -> m (Wrap a', Generator generatorOutputDevice) Source # | |
HasInitialize (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead initialize :: MonadThrow m => ModelSpec (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) -> Generator generatorDevice -> m (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)), Generator generatorDevice) Source # | |
HasInitialize (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) generatorDevice (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead | |
HasInitialize (GBias ()) generatorDevice (GBias ()) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead initialize :: MonadThrow m => ModelSpec (GBias ()) -> Generator generatorDevice -> m (GBias (), Generator generatorDevice) Source # | |
(HasInitialize block generatorDevice block' generatorDevice, numLayers' ~ (numLayers + 1)) => HasInitialize (GTransformerStack (Vector numLayers' block)) generatorDevice (GTransformerStack (Vector numLayers' block')) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GStack initialize :: MonadThrow m => ModelSpec (GTransformerStack (Vector numLayers' block)) -> Generator generatorDevice -> m (GTransformerStack (Vector numLayers' block'), Generator generatorDevice) Source # | |
HasInitialize (MkRelPos relPosEncBucketDim) generatorDevice (MkRelPos relPosEncBucketDim) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type initialize :: MonadThrow m => ModelSpec (MkRelPos relPosEncBucketDim) -> Generator generatorDevice -> m (MkRelPos relPosEncBucketDim, Generator generatorDevice) Source # | |
HasInitialize (MkTransformerAttentionMask dataType) generatorDevice (MkTransformerAttentionMask dataType) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type initialize :: MonadThrow m => ModelSpec (MkTransformerAttentionMask dataType) -> Generator generatorDevice -> m (MkTransformerAttentionMask dataType, Generator generatorDevice) Source # | |
HasInitialize (MkTransformerCrossAttentionMask dataType) generatorDevice (MkTransformerCrossAttentionMask dataType) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type initialize :: MonadThrow m => ModelSpec (MkTransformerCrossAttentionMask dataType) -> Generator generatorDevice -> m (MkTransformerCrossAttentionMask dataType, Generator generatorDevice) Source # | |
HasInitialize (MkTransformerDecoderAttentionMask dataType) generatorDevice (MkTransformerDecoderAttentionMask dataType) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type initialize :: MonadThrow m => ModelSpec (MkTransformerDecoderAttentionMask dataType) -> Generator generatorDevice -> m (MkTransformerDecoderAttentionMask dataType, Generator generatorDevice) Source # | |
HasInitialize (ShiftRight fillValue) generatorDevice (ShiftRight fillValue) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.Type initialize :: MonadThrow m => ModelSpec (ShiftRight fillValue) -> Generator generatorDevice -> m (ShiftRight fillValue, Generator generatorDevice) Source # | |
HasInitialize (SDim dim) generatorDevice (SDim dim) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (SDim dim) -> Generator generatorDevice -> m (SDim dim, Generator generatorDevice) Source # | |
(output ~ GLinear (Tensor gradient ('Layout 'Dense) (device <+> generatorDevice) dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) (device <+> generatorDevice) dataType ('Shape '[outputDim])), generatorOutputDevice ~ (device <+> generatorDevice), SGetGeneratorDevice generatorDevice, SGetGeneratorDevice generatorOutputDevice) => HasInitialize (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim]))) generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Linear | |
(output ~ GLinear (Tensor gradient ('Layout 'Dense) (device <+> generatorDevice) dataType ('Shape '[outputDim, inputDim])) (), generatorOutputDevice ~ (device <+> generatorDevice), SGetGeneratorDevice generatorDevice) => HasInitialize (GLinear (Tensor gradient ('Layout 'Dense) device dataType ('Shape '[outputDim, inputDim])) ()) generatorDevice output generatorOutputDevice Source # | TODO: Add |
Defined in Torch.GraduallyTyped.NN.Linear | |
HasInitialize (GLinear weight bias) generatorDevice (GLinear weight bias) generatorDevice => HasInitialize (GLinear (NamedModel weight) (NamedModel bias)) generatorDevice (GLinear (NamedModel weight) (NamedModel bias)) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Linear initialize :: MonadThrow m => ModelSpec (GLinear (NamedModel weight) (NamedModel bias)) -> Generator generatorDevice -> m (GLinear (NamedModel weight) (NamedModel bias), Generator generatorDevice) Source # | |
(HasInitialize a generatorDevice output generatorOutputDevice, HasInitialize a generatorOutputDevice output generatorOutputDevice, n' ~ (n + 1)) => HasInitialize (Vector n' a) generatorDevice (Vector n' output) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (Vector n' a) -> Generator generatorDevice -> m (Vector n' output, Generator generatorOutputDevice) Source # | |
(HasInitialize a generatorDevice outputA generatorOutputADevice, HasInitialize b generatorOutputADevice outputB generatorOutputDevice) => HasInitialize (a, b) generatorDevice (outputA, outputB) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (a, b) -> Generator generatorDevice -> m ((outputA, outputB), Generator generatorOutputDevice) Source # | |
(HasInitialize selfAttention generatorDevice selfAttention' generatorDevice0, HasInitialize crossAttention generatorDevice0 crossAttention' generatorDevice1, HasInitialize feedForwardNetwork generatorDevice1 feedForwardNetwork' generatorOutputDevice) => HasInitialize (GTransformerBlock selfAttention crossAttention feedForwardNetwork) generatorDevice (GTransformerBlock selfAttention' crossAttention' feedForwardNetwork') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GBlock initialize :: MonadThrow m => ModelSpec (GTransformerBlock selfAttention crossAttention feedForwardNetwork) -> Generator generatorDevice -> m (GTransformerBlock selfAttention' crossAttention' feedForwardNetwork', Generator generatorOutputDevice) Source # | |
(HasInitialize layer0 generatorDevice layer0' generatorDevice0, HasInitialize activation generatorDevice0 activation' generatorDevice1, HasInitialize layer1 generatorDevice1 layer1' generatorOutputDevice) => HasInitialize (GGate layer0 activation layer1) generatorDevice (GGate layer0' activation' layer1') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GFeedForwardNetwork initialize :: MonadThrow m => ModelSpec (GGate layer0 activation layer1) -> Generator generatorDevice -> m (GGate layer0' activation' layer1', Generator generatorOutputDevice) Source # | |
(HasInitialize a generatorDevice outputA generatorOutputADevice, HasInitialize b generatorOutputADevice outputB generatorOutputBDevice, HasInitialize c generatorOutputBDevice outputC generatorOutputDevice) => HasInitialize (a, b, c) generatorDevice (outputA, outputB, outputC) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (a, b, c) -> Generator generatorDevice -> m ((outputA, outputB, outputC), Generator generatorOutputDevice) Source # | |
(HasInitialize initialLayerNorm generatorDevice initialLayerNorm' generatorDevice0, HasInitialize multiHeadAttention generatorDevice0 multiHeadAttention' generatorDevice1, HasInitialize dropout generatorDevice1 dropout' generatorDevice2, HasInitialize finalLayerNorm generatorDevice2 finalLayerNorm' generatorOutputDevice) => HasInitialize (GCrossAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) generatorDevice (GCrossAttention initialLayerNorm' multiHeadAttention' dropout' finalLayerNorm') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GCrossAttention initialize :: MonadThrow m => ModelSpec (GCrossAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) -> Generator generatorDevice -> m (GCrossAttention initialLayerNorm' multiHeadAttention' dropout' finalLayerNorm', Generator generatorOutputDevice) Source # | |
(HasInitialize model generatorDevice model' generatorDevice0, HasInitialize mkPos generatorDevice0 mkPos' generatorDevice1, HasInitialize mkPaddingMask generatorDevice1 mkPaddingMask' generatorDevice2, HasInitialize mkAttentionMask generatorDevice2 mkAttentionMask' generatorOutputDevice) => HasInitialize (GSimplifiedEncoderOnlyTransformer model mkPos mkPaddingMask mkAttentionMask) generatorDevice (GSimplifiedEncoderOnlyTransformer model' mkPos' mkPaddingMask' mkAttentionMask') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderOnly initialize :: MonadThrow m => ModelSpec (GSimplifiedEncoderOnlyTransformer model mkPos mkPaddingMask mkAttentionMask) -> Generator generatorDevice -> m (GSimplifiedEncoderOnlyTransformer model' mkPos' mkPaddingMask' mkAttentionMask', Generator generatorOutputDevice) Source # | |
(HasInitialize initialLayerNorm generatorDevice initialLayerNorm' generatorDevice0, HasInitialize multiHeadAttention generatorDevice0 multiHeadAttention' generatorDevice1, HasInitialize dropout generatorDevice1 dropout' generatorDevice2, HasInitialize finalLayerNorm generatorDevice2 finalLayerNorm' generatorOutputDevice) => HasInitialize (GSelfAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) generatorDevice (GSelfAttention initialLayerNorm' multiHeadAttention' dropout' finalLayerNorm') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GSelfAttention initialize :: MonadThrow m => ModelSpec (GSelfAttention initialLayerNorm multiHeadAttention dropout finalLayerNorm) -> Generator generatorDevice -> m (GSelfAttention initialLayerNorm' multiHeadAttention' dropout' finalLayerNorm', Generator generatorOutputDevice) Source # | |
(HasInitialize a generatorDevice outputA generatorOutputADevice, HasInitialize b generatorOutputADevice outputB generatorOutputBDevice, HasInitialize c generatorOutputBDevice outputC generatorOutputCDevice, HasInitialize d generatorOutputCDevice outputD generatorOutputDevice) => HasInitialize (a, b, c, d) generatorDevice (outputA, outputB, outputC, outputD) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (a, b, c, d) -> Generator generatorDevice -> m ((outputA, outputB, outputC, outputD), Generator generatorOutputDevice) Source # | |
HasInitialize (LayerNorm hasBias gradient device dataType normalizedShape) generatorDevice (LayerNorm hasBias gradient device dataType normalizedShape) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Normalization initialize :: MonadThrow m => ModelSpec (LayerNorm hasBias gradient device dataType normalizedShape) -> Generator generatorDevice -> m (LayerNorm hasBias gradient device dataType normalizedShape, Generator generatorDevice) Source # | |
(HasInitialize encoder generatorDevice encoder' generatorDevice0, HasInitialize decoder generatorDevice0 decoder' generatorDevice1, HasInitialize sharedEmbedding generatorDevice1 sharedEmbedding' generatorDevice2, HasInitialize head generatorDevice2 head' generatorOutputDevice) => HasInitialize (GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head) generatorDevice (GEncoderDecoderTransformer inputEmbedDim encoder' decoder' sharedEmbedding' head') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder initialize :: MonadThrow m => ModelSpec (GEncoderDecoderTransformer inputEmbedDim encoder decoder sharedEmbedding head) -> Generator generatorDevice -> m (GEncoderDecoderTransformer inputEmbedDim encoder' decoder' sharedEmbedding' head', Generator generatorOutputDevice) Source # | |
(HasInitialize encoder generatorDevice encoder' generatorDevice0, HasInitialize encoderEmbedding generatorDevice0 encoderEmbedding' generatorDevice1, HasInitialize encoderTypeEmbedding generatorDevice1 encoderTypeEmbedding' generatorDevice2, HasInitialize head generatorDevice2 head' generatorOutputDevice) => HasInitialize (GEncoderOnlyTransformer inputEmbedDim encoder encoderEmbedding encoderTypeEmbedding head) generatorDevice (GEncoderOnlyTransformer inputEmbedDim encoder' encoderEmbedding' encoderTypeEmbedding' head') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderOnly initialize :: MonadThrow m => ModelSpec (GEncoderOnlyTransformer inputEmbedDim encoder encoderEmbedding encoderTypeEmbedding head) -> Generator generatorDevice -> m (GEncoderOnlyTransformer inputEmbedDim encoder' encoderEmbedding' encoderTypeEmbedding' head', Generator generatorOutputDevice) Source # | |
(HasInitialize a generatorDevice outputA generatorOutputADevice, HasInitialize b generatorOutputADevice outputB generatorOutputBDevice, HasInitialize c generatorOutputBDevice outputC generatorOutputCDevice, HasInitialize d generatorOutputCDevice outputD generatorOutputDDevice, HasInitialize e generatorOutputDDevice outputE generatorOutputDevice) => HasInitialize (a, b, c, d, e) generatorDevice (outputA, outputB, outputC, outputD, outputE) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (a, b, c, d, e) -> Generator generatorDevice -> m ((outputA, outputB, outputC, outputD, outputE), Generator generatorOutputDevice) Source # | |
(HasInitialize dense generatorDevice dense' generatorDevice0, HasInitialize activation generatorDevice0 activation' generatorDevice1, HasInitialize layerNorm generatorDevice1 layerNorm' generatorDevice2, HasInitialize decoder generatorDevice2 decoder' generatorDevice3, HasInitialize bias generatorDevice3 bias' generatorOutputDevice) => HasInitialize (GLMHead inputEmbedDim dense activation layerNorm decoder bias) generatorDevice (GLMHead inputEmbedDim dense' activation' layerNorm' decoder' bias') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead initialize :: MonadThrow m => ModelSpec (GLMHead inputEmbedDim dense activation layerNorm decoder bias) -> Generator generatorDevice -> m (GLMHead inputEmbedDim dense' activation' layerNorm' decoder' bias', Generator generatorOutputDevice) Source # | |
(HasInitialize a generatorDevice outputA generatorOutputADevice, HasInitialize b generatorOutputADevice outputB generatorOutputBDevice, HasInitialize c generatorOutputBDevice outputC generatorOutputCDevice, HasInitialize d generatorOutputCDevice outputD generatorOutputDDevice, HasInitialize e generatorOutputDDevice outputE generatorOutputEDevice, HasInitialize f generatorOutputEDevice outputF generatorOutputDevice) => HasInitialize (a, b, c, d, e, f) generatorDevice (outputA, outputB, outputC, outputD, outputE, outputF) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (a, b, c, d, e, f) -> Generator generatorDevice -> m ((outputA, outputB, outputC, outputD, outputE, outputF), Generator generatorOutputDevice) Source # | |
(output ~ Embedding gradient layout (device <+> generatorDevice) dataType embedNumDim embedDim paddingIdx, generatorOutputDevice ~ (device <+> generatorDevice), SGetGeneratorDevice generatorDevice) => HasInitialize (Embedding gradient layout device dataType embedNumDim embedDim paddingIdx) generatorDevice output generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Sparse initialize :: MonadThrow m => ModelSpec (Embedding gradient layout device dataType embedNumDim embedDim paddingIdx) -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source # | |
(HasInitialize model generatorDevice model' generatorDevice0, HasInitialize mkPos generatorDevice0 mkPos' generatorDevice1, HasInitialize mkDecoderPos generatorDevice1 mkDecoderPos' generatorDevice2, HasInitialize mkPaddingMask generatorDevice2 mkPaddingMask' generatorDevice3, HasInitialize mkAttentionMask generatorDevice3 mkAttentionMask' generatorDevice4, HasInitialize mkCrossAttentionMask generatorDevice4 mkCrossAttentionMask' generatorDevice5, HasInitialize mkDecoderAttentionMask generatorDevice5 mkDecoderAttentionMask' generatorOutputDevice) => HasInitialize (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) generatorDevice (GSimplifiedEncoderDecoderTransformer model' mkPos' mkDecoderPos' mkPaddingMask' mkAttentionMask' mkCrossAttentionMask' mkDecoderAttentionMask') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GEncoderDecoder initialize :: MonadThrow m => ModelSpec (GSimplifiedEncoderDecoderTransformer model mkPos mkDecoderPos mkPaddingMask mkAttentionMask mkCrossAttentionMask mkDecoderAttentionMask) -> Generator generatorDevice -> m (GSimplifiedEncoderDecoderTransformer model' mkPos' mkDecoderPos' mkPaddingMask' mkAttentionMask' mkCrossAttentionMask' mkDecoderAttentionMask', Generator generatorOutputDevice) Source # | |
(HasInitialize inputLayerNorm generatorDevice inputLayerNorm' generatorDevice0, HasInitialize inputTransformation generatorDevice0 inputTransformation' generatorDevice1, HasInitialize activation generatorDevice1 activation' generatorDevice2, HasInitialize activationDropout generatorDevice2 activationDropout' generatorDevice3, HasInitialize outputProjection generatorDevice3 outputProjection' generatorDevice4, HasInitialize outputDropout generatorDevice4 outputDropout' generatorDevice5, HasInitialize outputLayerNorm generatorDevice5 outputLayerNorm' generatorOutputDevice) => HasInitialize (GTransformerFeedForwardNetwork inputLayerNorm inputTransformation activation activationDropout outputProjection outputDropout outputLayerNorm) generatorDevice (GTransformerFeedForwardNetwork inputLayerNorm' inputTransformation' activation' activationDropout' outputProjection' outputDropout' outputLayerNorm') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GFeedForwardNetwork initialize :: MonadThrow m => ModelSpec (GTransformerFeedForwardNetwork inputLayerNorm inputTransformation activation activationDropout outputProjection outputDropout outputLayerNorm) -> Generator generatorDevice -> m (GTransformerFeedForwardNetwork inputLayerNorm' inputTransformation' activation' activationDropout' outputProjection' outputDropout' outputLayerNorm', Generator generatorOutputDevice) Source # | |
(HasInitialize posEnc generatorDevice posEnc' generatorDevice0, HasInitialize relPosEnc generatorDevice0 relPosEnc' generatorDevice1, HasInitialize initialLayerNorm generatorDevice1 initialLayerNorm' generatorDevice2, HasInitialize initialDropout generatorDevice2 initialDropout' generatorDevice3, HasInitialize stack generatorDevice3 stack' generatorDevice4, HasInitialize finalLayerNorm generatorDevice4 finalLayerNorm' generatorDevice5, HasInitialize finalDropout generatorDevice5 finalDropout' generatorOutputDevice) => HasInitialize (GTransformer posEnc relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout) generatorDevice (GTransformer posEnc' relPosEnc' initialLayerNorm' initialDropout' stack' finalLayerNorm' finalDropout') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GTransformer initialize :: MonadThrow m => ModelSpec (GTransformer posEnc relPosEnc initialLayerNorm initialDropout stack finalLayerNorm finalDropout) -> Generator generatorDevice -> m (GTransformer posEnc' relPosEnc' initialLayerNorm' initialDropout' stack' finalLayerNorm' finalDropout', Generator generatorOutputDevice) Source # | |
(HasInitialize a generatorDevice outputA generatorOutputADevice, HasInitialize b generatorOutputADevice outputB generatorOutputBDevice, HasInitialize c generatorOutputBDevice outputC generatorOutputCDevice, HasInitialize d generatorOutputCDevice outputD generatorOutputDDevice, HasInitialize e generatorOutputDDevice outputE generatorOutputEDevice, HasInitialize f generatorOutputEDevice outputF generatorOutputFDevice, HasInitialize g generatorOutputFDevice outputG generatorOutputDevice) => HasInitialize (a, b, c, d, e, f, g) generatorDevice (outputA, outputB, outputC, outputD, outputE, outputF, outputG) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class initialize :: MonadThrow m => ModelSpec (a, b, c, d, e, f, g) -> Generator generatorDevice -> m ((outputA, outputB, outputC, outputD, outputE, outputF, outputG), Generator generatorOutputDevice) Source # | |
(HasInitialize qInProj generatorDevice qInProj' generatorDevice0, HasInitialize kInProj generatorDevice0 kInProj' generatorDevice1, HasInitialize vInProj generatorDevice1 vInProj' generatorDevice2, HasInitialize outProj generatorDevice2 outProj' generatorDevice3, HasInitialize dropout generatorDevice3 dropout' generatorOutputDevice) => HasInitialize (GMultiHeadAttention headDim headEmbedDim embedDim qInProj kInProj vInProj outProj dropout) generatorDevice (GMultiHeadAttention headDim headEmbedDim embedDim qInProj' kInProj' vInProj' outProj' dropout') generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Transformer.GMultiHeadAttention initialize :: MonadThrow m => ModelSpec (GMultiHeadAttention headDim headEmbedDim embedDim qInProj kInProj vInProj outProj dropout) -> Generator generatorDevice -> m (GMultiHeadAttention headDim headEmbedDim embedDim qInProj' kInProj' vInProj' outProj' dropout', Generator generatorOutputDevice) Source # |
class GHasInitialize gModelSpec generatorDevice gOutput generatorOutputDevice | gModelSpec generatorDevice -> gOutput, gModelSpec generatorDevice -> generatorOutputDevice where Source #
gInitialize :: forall m c. MonadThrow m => gModelSpec c -> Generator generatorDevice -> m (gOutput c, Generator generatorOutputDevice) Source #
Instances
GHasInitialize (U1 :: Type -> Type) generatorDevice (U1 :: Type -> Type) generatorDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class gInitialize :: MonadThrow m => U1 c -> Generator generatorDevice -> m (U1 c, Generator generatorDevice) Source # | |
(GHasInitialize gModelSpecA generatorDevice gOutputA generatorOutputADevice, GHasInitialize gModelSpecB generatorOutputADevice gOutputB generatorOutputDevice) => GHasInitialize (gModelSpecA :*: gModelSpecB) generatorDevice (gOutputA :*: gOutputB) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class gInitialize :: MonadThrow m => (gModelSpecA :*: gModelSpecB) c -> Generator generatorDevice -> m ((gOutputA :*: gOutputB) c, Generator generatorOutputDevice) Source # | |
(HasInitialize model generatorDevice output generatorOutputDevice, ModelSpec model ~ modelSpec) => GHasInitialize (K1 i modelSpec :: Type -> Type) generatorDevice (K1 i output :: Type -> Type) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class gInitialize :: MonadThrow m => K1 i modelSpec c -> Generator generatorDevice -> m (K1 i output c, Generator generatorOutputDevice) Source # | |
GHasInitialize gModelSpec generatorDevice gOutput generatorOutputDevice => GHasInitialize (M1 i t gModelSpec) generatorDevice (M1 i t gOutput) generatorOutputDevice Source # | |
Defined in Torch.GraduallyTyped.NN.Class gInitialize :: MonadThrow m => M1 i t gModelSpec c -> Generator generatorDevice -> m (M1 i t gOutput c, Generator generatorOutputDevice) Source # |
data VectorSpec (n :: Nat) (a :: Type) where Source #
VectorSpec :: forall n a. SNat n -> Vector n (ModelSpec a) -> VectorSpec n a |
Instances
Show (ModelSpec a) => Show (VectorSpec n a) Source # | |
Defined in Torch.GraduallyTyped.NN.Class |
type StateDictKey = Text Source #
type StateDict = Map StateDictKey (ForeignPtr Tensor) Source #
newtype FromStateDictError Source #
Instances
newtype ToStateDictError Source #
Instances
class HasStateDict model where Source #
Nothing
fromStateDict :: forall m. (MonadIO m, MonadThrow m, MonadState StateDict m) => ModelSpec model -> StateDictKey -> m model Source #
default fromStateDict :: forall m. (MonadIO m, MonadThrow m, MonadState StateDict m, Generic model, Generic (ModelSpec model), GHasStateDict (Rep model) (Rep (ModelSpec model))) => ModelSpec model -> StateDictKey -> m model Source #
toStateDict :: forall m. (MonadThrow m, MonadState StateDict m) => StateDictKey -> model -> m () Source #
default toStateDict :: forall m. (MonadThrow m, MonadState StateDict m, Generic model, GHasStateDict (Rep model) (Rep (ModelSpec model))) => StateDictKey -> model -> m () Source #
Instances
class GHasStateDict gModel gModelSpec | gModelSpec -> gModel, gModel -> gModelSpec where Source #
gFromStateDict :: forall m c. (MonadIO m, MonadThrow m, MonadState StateDict m) => gModelSpec c -> StateDictKey -> m (gModel c) Source #
gToStateDict :: forall m c. (MonadThrow m, MonadState StateDict m) => StateDictKey -> gModel c -> m () Source #