hasktorch-gradually-typed-0.2.0.0: experimental project for hasktorch
Safe HaskellSafe-Inferred
LanguageHaskell2010

Torch.GraduallyTyped.NN.Transformer.GLMHead

Synopsis

Documentation

data LMHeadHasScaling Source #

A data type that represents whether or not the language modelling head has a scaled decoder output.

Instances

Instances details
Generic LMHeadHasScaling Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Associated Types

type Rep LMHeadHasScaling :: Type -> Type Source #

Show LMHeadHasScaling Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Eq LMHeadHasScaling Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Ord LMHeadHasScaling Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

HasStateDict LMHeadHasScaling Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

HasInitialize LMHeadHasScaling generatorDevice LMHeadHasScaling generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

initialize :: MonadThrow m => ModelSpec LMHeadHasScaling -> Generator generatorDevice -> m (LMHeadHasScaling, Generator generatorDevice) Source #

type Rep LMHeadHasScaling Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

type Rep LMHeadHasScaling = D1 ('MetaData "LMHeadHasScaling" "Torch.GraduallyTyped.NN.Transformer.GLMHead" "hasktorch-gradually-typed-0.2.0.0-1KV1aIPzzbp6JpSr37tC1K" 'False) (C1 ('MetaCons "LMHeadWithScaling" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "LMHeadWithoutScaling" 'PrefixI 'False) (U1 :: Type -> Type))
type ModelSpec LMHeadHasScaling Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

data GLMHead (inputEmbedDim :: Dim (Name Symbol) (Size Nat)) (dense :: Type) (activation :: Type) (layerNorm :: Type) (decoder :: Type) (bias :: Type) where Source #

Generic language modelling head for transformer encoders and decoders.

  • inputEmbedDim is the dimension of the input embedding.
  • dense is a dense layer.
  • activation is an activation function.
  • layerNorm is a layer normalization layer.
  • decoder is a decoder layer.
  • bias is a bias layer.

Constructors

GLMHead 

Fields

Instances

Instances details
Generic (GLMHead inputEmbedDim dense activation layerNorm decoder bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Associated Types

type Rep (GLMHead inputEmbedDim dense activation layerNorm decoder bias) :: Type -> Type Source #

Methods

from :: GLMHead inputEmbedDim dense activation layerNorm decoder bias -> Rep (GLMHead inputEmbedDim dense activation layerNorm decoder bias) x Source #

to :: Rep (GLMHead inputEmbedDim dense activation layerNorm decoder bias) x -> GLMHead inputEmbedDim dense activation layerNorm decoder bias Source #

(Show dense, Show activation, Show layerNorm, Show decoder, Show bias) => Show (GLMHead inputEmbedDim dense activation layerNorm decoder bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

showsPrec :: Int -> GLMHead inputEmbedDim dense activation layerNorm decoder bias -> ShowS Source #

show :: GLMHead inputEmbedDim dense activation layerNorm decoder bias -> String Source #

showList :: [GLMHead inputEmbedDim dense activation layerNorm decoder bias] -> ShowS Source #

(HasStateDict dense, HasStateDict activation, HasStateDict layerNorm, HasStateDict decoder, HasStateDict bias) => HasStateDict (GLMHead inputEmbedDim dense activation layerNorm decoder bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

fromStateDict :: (MonadIO m, MonadThrow m, MonadState StateDict m) => ModelSpec (GLMHead inputEmbedDim dense activation layerNorm decoder bias) -> StateDictKey -> m (GLMHead inputEmbedDim dense activation layerNorm decoder bias) Source #

toStateDict :: (MonadThrow m, MonadState StateDict m) => StateDictKey -> GLMHead inputEmbedDim dense activation layerNorm decoder bias -> m () 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 # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

initialize :: MonadThrow m => ModelSpec (GLMHead inputEmbedDim dense activation layerNorm decoder bias) -> Generator generatorDevice -> m (GLMHead inputEmbedDim dense' activation' layerNorm' decoder' bias', Generator generatorOutputDevice) Source #

(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 #

HasForward instance for LMHead.

    ┌───────┐
    │ input │
    └───┬───┘
        │
        ▼
  (lmHeadDense)
        ▼
(lmHeadActivation)
        ▼
(lmHeadLayerNorm)
        ▼
  lmHeadDecoder
        ▼
    (scaling)
        ▼
   (lmHeadBias)
        │
        ▼
┌───────────────┐
│ decoderOutput │
└───────────────┘
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

forward :: MonadThrow m => GLMHead inputEmbedDim dense activation layerNorm decoder bias -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorOutputDevice) Source #

type Rep (GLMHead inputEmbedDim dense activation layerNorm decoder bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

type Rep (GLMHead inputEmbedDim dense activation layerNorm decoder bias) = D1 ('MetaData "GLMHead" "Torch.GraduallyTyped.NN.Transformer.GLMHead" "hasktorch-gradually-typed-0.2.0.0-1KV1aIPzzbp6JpSr37tC1K" 'False) (C1 ('MetaCons "GLMHead" 'PrefixI 'True) ((S1 ('MetaSel ('Just "lmHeadInputEmbedDim") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SDim inputEmbedDim)) :*: (S1 ('MetaSel ('Just "lmHeadDense") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 dense) :*: S1 ('MetaSel ('Just "lmHeadActivation") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 activation))) :*: ((S1 ('MetaSel ('Just "lmHeadLayerNorm") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 layerNorm) :*: S1 ('MetaSel ('Just "lmHeadDecoder") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 decoder)) :*: (S1 ('MetaSel ('Just "lmHeadBias") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 bias) :*: S1 ('MetaSel ('Just "lmHeadHasScaling") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LMHeadHasScaling)))))
type ModelSpec (GLMHead inputEmbedDim dense activation layerNorm decoder bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

type ModelSpec (GLMHead inputEmbedDim dense activation layerNorm decoder bias) = GLMHead inputEmbedDim (ModelSpec dense) (ModelSpec activation) (ModelSpec layerNorm) (ModelSpec decoder) (ModelSpec bias)

data GBias (bias :: Type) where Source #

Generic data type for biasing the language model head.

Constructors

GBias :: forall bias. bias -> GBias bias 

Instances

Instances details
Generic (GBias bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Associated Types

type Rep (GBias bias) :: Type -> Type Source #

Methods

from :: GBias bias -> Rep (GBias bias) x Source #

to :: Rep (GBias bias) x -> GBias bias Source #

Show bias => Show (GBias bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

showsPrec :: Int -> GBias bias -> ShowS Source #

show :: GBias bias -> String Source #

showList :: [GBias bias] -> ShowS Source #

Eq bias => Eq (GBias bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

(==) :: GBias bias -> GBias bias -> Bool Source #

(/=) :: GBias bias -> GBias bias -> Bool Source #

Ord bias => Ord (GBias bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

compare :: GBias bias -> GBias bias -> Ordering Source #

(<) :: GBias bias -> GBias bias -> Bool Source #

(<=) :: GBias bias -> GBias bias -> Bool Source #

(>) :: GBias bias -> GBias bias -> Bool Source #

(>=) :: GBias bias -> GBias bias -> Bool Source #

max :: GBias bias -> GBias bias -> GBias bias Source #

min :: GBias bias -> GBias bias -> GBias bias Source #

HasStateDict bias => HasStateDict (GBias bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

HasInitialize (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice (GBias (NamedModel (Tensor biasGradient biasLayout biasDevice biasDataType biasShape))) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

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 # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

initialize :: MonadThrow m => ModelSpec (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape)) -> Generator generatorDevice -> m (GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape), Generator generatorDevice) Source #

HasInitialize (GBias ()) generatorDevice (GBias ()) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

initialize :: MonadThrow m => ModelSpec (GBias ()) -> Generator generatorDevice -> m (GBias (), 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 # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

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 # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

forward :: MonadThrow m => GBias (Tensor biasGradient biasLayout biasDevice biasDataType biasShape) -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (output, Generator generatorDevice) Source #

HasForward (GBias ()) (Tensor gradient layout device dataType shape) generatorDevice (Tensor gradient layout device dataType shape) generatorDevice Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

Methods

forward :: MonadThrow m => GBias () -> Tensor gradient layout device dataType shape -> Generator generatorDevice -> m (Tensor gradient layout device dataType shape, Generator generatorDevice) Source #

type Rep (GBias bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

type Rep (GBias bias) = D1 ('MetaData "GBias" "Torch.GraduallyTyped.NN.Transformer.GLMHead" "hasktorch-gradually-typed-0.2.0.0-1KV1aIPzzbp6JpSr37tC1K" 'False) (C1 ('MetaCons "GBias" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 bias)))
type ModelSpec (GBias bias) Source # 
Instance details

Defined in Torch.GraduallyTyped.NN.Transformer.GLMHead

type ModelSpec (GBias bias) = GBias (ModelSpec bias)

type family GLMHeadF (style :: TransformerStyle) (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (inputEmbedDim :: Dim (Name Symbol) (Size Nat)) (vocabDim :: Dim (Name Symbol) (Size Nat)) :: Type where ... Source #

Equations

GLMHeadF style gradient device dataType inputEmbedDim vocabDim = GLMHead inputEmbedDim (LMHeadDenseF style gradient device dataType inputEmbedDim) (LMHeadActivationF style) (LMHeadLayerNormF style gradient device dataType inputEmbedDim) (LMHeadDecoderF style gradient device dataType inputEmbedDim vocabDim) (LMHeadBiasF style gradient device dataType vocabDim) 

type family LMHeadDenseF (style :: TransformerStyle) (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (inputEmbedDim :: Dim (Name Symbol) (Size Nat)) :: Type where ... Source #

Specifies the dense layer of the language model head.

Equations

LMHeadDenseF 'T5 _ _ _ _ = () 
LMHeadDenseF 'ByT5 gradient device dataType inputEmbedDim = LMHeadDenseF 'T5 gradient device dataType inputEmbedDim 
LMHeadDenseF 'BART _ _ _ _ = () 
LMHeadDenseF 'MBART gradient device dataType inputEmbedDim = LMHeadDenseF 'BART gradient device dataType inputEmbedDim 
LMHeadDenseF 'Pegasus gradient device dataType inputEmbedDim = LMHeadDenseF 'BART gradient device dataType inputEmbedDim 
LMHeadDenseF 'BERT gradient device dataType inputEmbedDim = NamedModel (GLinearF 'WithBias gradient device dataType inputEmbedDim inputEmbedDim) 
LMHeadDenseF 'RoBERTa gradient device dataType inputEmbedDim = LMHeadDenseF 'BERT gradient device dataType inputEmbedDim 

type family LMHeadLayerNormF (style :: TransformerStyle) (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (inputEmbedDim :: Dim (Name Symbol) (Size Nat)) :: Type where ... Source #

Specifies the layer normalization layer of the language model head.

Equations

LMHeadLayerNormF 'T5 _ _ _ _ = () 
LMHeadLayerNormF 'ByT5 gradient device dataType inputEmbedDim = LMHeadLayerNormF 'T5 gradient device dataType inputEmbedDim 
LMHeadLayerNormF 'BART _ _ _ _ = () 
LMHeadLayerNormF 'MBART gradient device dataType inputEmbedDim = LMHeadLayerNormF 'BART gradient device dataType inputEmbedDim 
LMHeadLayerNormF 'Pegasus gradient device dataType inputEmbedDim = LMHeadLayerNormF 'BART gradient device dataType inputEmbedDim 
LMHeadLayerNormF 'BERT gradient device dataType inputEmbedDim = NamedModel (LayerNorm 'WithBias gradient device dataType ('Shape '[inputEmbedDim])) 
LMHeadLayerNormF 'RoBERTa gradient device dataType inputEmbedDim = LMHeadLayerNormF 'BERT gradient device dataType inputEmbedDim 

type family LMHeadDecoderF (style :: TransformerStyle) (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (inputEmbedDim :: Dim (Name Symbol) (Size Nat)) (vocabDim :: Dim (Name Symbol) (Size Nat)) :: Type where ... Source #

Specifies the decoder layer of the language model head.

Equations

LMHeadDecoderF 'T5 gradient device dataType inputEmbedDim vocabDim = NamedModel (GLinearF 'WithoutBias gradient device dataType inputEmbedDim vocabDim) 
LMHeadDecoderF 'ByT5 gradient device dataType inputEmbedDim vocabDim = LMHeadDecoderF 'T5 gradient device dataType inputEmbedDim vocabDim 
LMHeadDecoderF 'BART gradient device dataType inputEmbedDim vocabDim = NamedModel (GLinearF 'WithoutBias gradient device dataType inputEmbedDim vocabDim) 
LMHeadDecoderF 'MBART gradient device dataType inputEmbedDim vocabDim = LMHeadDecoderF 'BART gradient device dataType inputEmbedDim vocabDim 
LMHeadDecoderF 'Pegasus gradient device dataType inputEmbedDim vocabDim = LMHeadDecoderF 'BART gradient device dataType inputEmbedDim vocabDim 
LMHeadDecoderF 'BERT gradient device dataType inputEmbedDim vocabDim = NamedModel (GLinearF 'WithBias gradient device dataType inputEmbedDim vocabDim) 
LMHeadDecoderF 'RoBERTa gradient device dataType inputEmbedDim vocabDim = LMHeadDecoderF 'BERT gradient device dataType inputEmbedDim vocabDim 

type family LMHeadBiasF (style :: TransformerStyle) (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (vocabDim :: Dim (Name Symbol) (Size Nat)) :: Type where ... Source #

Specifies the bias layer of the language model head.

Equations

LMHeadBiasF 'T5 _ _ _ _ = GBias () 
LMHeadBiasF 'ByT5 gradient device dataType vocabDim = LMHeadBiasF 'T5 gradient device dataType vocabDim 
LMHeadBiasF 'BART gradient device dataType vocabDim = GBias (NamedModel (Tensor gradient ('Layout 'Dense) device dataType ('Shape '['Dim ('Name "*") ('Size 1), vocabDim]))) 
LMHeadBiasF 'MBART gradient device dataType vocabDim = LMHeadBiasF 'BART gradient device dataType vocabDim 
LMHeadBiasF 'Pegasus gradient device dataType vocabDim = LMHeadBiasF 'BART gradient device dataType vocabDim 
LMHeadBiasF 'BERT _ _ _ _ = GBias () 
LMHeadBiasF 'RoBERTa gradient device dataType vocabDim = LMHeadBiasF 'BERT gradient device dataType vocabDim 

lmHeadSpec :: forall style gradient device dataType inputEmbedDim vocabDim. STransformerStyle style -> SGradient gradient -> SDevice device -> SDataType dataType -> SDim inputEmbedDim -> SDim vocabDim -> Double -> ModelSpec (GLMHeadF style gradient device dataType inputEmbedDim vocabDim) Source #

Specifies the parameters of the language model head.

type family LMHeadOutputF (style :: TransformerStyle) (decoderOutput :: Type) (gradient :: Gradient RequiresGradient) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (vocabDim :: Dim (Name Symbol) (Size Nat)) :: Type where ... Source #

Equations

LMHeadOutputF 'T5 decoderOutput _ _ _ _ = decoderOutput 
LMHeadOutputF 'ByT5 decoderOutput gradient device dataType vocabDim = LMHeadOutputF 'T5 decoderOutput gradient device dataType vocabDim 
LMHeadOutputF 'BART (Tensor gradient' layout' device' dataType' shape') gradient device dataType vocabDim = Tensor (gradient' <|> gradient) (layout' <+> 'Layout 'Dense) (device' <+> device) (dataType' <+> dataType) (BroadcastShapesF shape' ('Shape '['Dim ('Name "*") ('Size 1), vocabDim])) 
LMHeadOutputF 'MBART decoderOutput gradient device dataType vocabDim = LMHeadOutputF 'BART decoderOutput gradient device dataType vocabDim 
LMHeadOutputF 'Pegasus decoderOutput gradient device dataType vocabDim = LMHeadOutputF 'BART decoderOutput gradient device dataType vocabDim 
LMHeadOutputF 'RoBERTa decoderOutput _ _ _ _ = decoderOutput 
LMHeadOutputF 'BERT decoderOutput _ _ _ _ = decoderOutput