Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Tensor (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where
- UnsafeTensor :: forall gradient layout device dataType shape. ForeignPtr Tensor -> Tensor gradient layout device dataType shape
- data TensorSpec (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where
- TensorSpec :: forall gradient layout device dataType shape. {..} -> TensorSpec gradient layout device dataType shape
- type UncheckedTensor = Tensor 'UncheckedGradient 'UncheckedLayout 'UncheckedDevice 'UncheckedDataType 'UncheckedShape
- type UncheckedParameter = Tensor ('Gradient 'WithGradient) 'UncheckedLayout 'UncheckedDevice 'UncheckedDataType 'UncheckedShape
- type CPUTensor = Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) ('Device 'CPU)
- type CPUParameter = Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU)
- type SparseCPUTensor = Tensor ('Gradient 'WithoutGradient) ('Layout 'Sparse) ('Device 'CPU)
- type SparseCPUParameter = Tensor ('Gradient 'WithGradient) ('Layout 'Sparse) ('Device 'CPU)
- type CUDATensor deviceId = Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) ('Device ('CUDA deviceId))
- type CUDAParameter deviceId = Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device ('CUDA deviceId))
- type SparseCUDATensor deviceId = Tensor ('Gradient 'WithoutGradient) ('Layout 'Sparse) ('Device ('CUDA deviceId))
- type SparseCUDAParameter deviceId = Tensor ('Gradient 'WithGradient) ('Layout 'Sparse) ('Device ('CUDA deviceId))
- withoutGradient :: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape -> IO (Tensor ('Gradient 'WithoutGradient) layout device dataType shape)
- withGradient :: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape -> IO (Tensor ('Gradient 'WithGradient) layout device dataType shape)
- sSetGradient :: forall gradient gradient' layout device dataType shape. SGradient gradient -> Tensor gradient' layout device dataType shape -> IO (Tensor gradient layout device dataType shape)
- class SGetGradient (gradient :: Gradient RequiresGradient) where
- sGetGradient :: forall layout device dataType shape. Tensor gradient layout device dataType shape -> SGradient gradient
- getRequiresGradient :: forall layout device dataType shape. Tensor gradient layout device dataType shape -> RequiresGradient
- data GradientError = GradientError {}
- sCheckedGradient :: forall gradient' m gradient layout device dataType shape. (SGetGradient gradient, MonadThrow m, Catch (gradient <+> gradient')) => SGradient gradient' -> Tensor gradient layout device dataType shape -> m (Tensor gradient' layout device dataType shape)
- checkedGradient :: forall gradient' m gradient layout device dataType shape. (SingI gradient', SGetGradient gradient, MonadThrow m, Catch (gradient <+> gradient')) => Tensor gradient layout device dataType shape -> m (Tensor gradient' layout device dataType shape)
- uncheckedGradient :: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape -> Tensor 'UncheckedGradient layout device dataType shape
- toDense :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor gradient ('Layout 'Dense) device dataType shape)
- toSparse :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor gradient ('Layout 'Sparse) device dataType shape)
- sSetLayout :: forall m gradient layout layout' device dataType shape. MonadThrow m => SLayout layout -> Tensor gradient layout' device dataType shape -> m (Tensor gradient layout device dataType shape)
- class SGetLayout (layout :: Layout LayoutType) where
- sGetLayout :: forall gradient device dataType shape. Tensor gradient layout device dataType shape -> SLayout layout
- getLayoutType :: forall gradient device dataType shape. Tensor gradient layout device dataType shape -> LayoutType
- data LayoutError = LayoutError {}
- sCheckedLayout :: forall layout' m gradient layout device dataType shape. (SGetLayout layout, MonadThrow m, Catch (layout <+> layout')) => SLayout layout' -> Tensor gradient layout device dataType shape -> m (Tensor gradient layout' device dataType shape)
- checkedLayout :: forall layout' m gradient layout device dataType shape. (SingI layout', SGetLayout layout, MonadThrow m, Catch (layout <+> layout')) => Tensor gradient layout device dataType shape -> m (Tensor gradient layout' device dataType shape)
- uncheckedLayout :: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape -> Tensor gradient 'UncheckedLayout device dataType shape
- cpu :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor gradient layout ('Device 'CPU) dataType shape)
- cuda :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor gradient layout ('Device ('CUDA 0)) dataType shape)
- sSetDevice :: forall m gradient layout device device' dataType shape. MonadThrow m => SDevice device -> Tensor gradient layout device' dataType shape -> m (Tensor gradient layout device dataType shape)
- class SGetDevice (device :: Device (DeviceType Nat)) where
- sGetDevice :: forall gradient layout dataType shape. Tensor gradient layout device dataType shape -> SDevice device
- getDeviceType :: forall gradient layout dataType shape. Tensor gradient layout device dataType shape -> DeviceType Int16
- data DeviceError = DeviceError {}
- sCheckedDevice :: forall device' m gradient layout device dataType shape. (SGetDevice device, MonadThrow m, Catch (device <+> device')) => SDevice device' -> Tensor gradient layout device dataType shape -> m (Tensor gradient layout device' dataType shape)
- checkedDevice :: forall device' m gradient layout device dataType shape. (SingI device', SGetDevice device, MonadThrow m, Catch (device <+> device')) => Tensor gradient layout device dataType shape -> m (Tensor gradient layout device' dataType shape)
- uncheckedDevice :: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape -> Tensor gradient layout 'UncheckedDevice dataType shape
- bool :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Bool) shape)
- byte :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'UInt8) shape)
- char :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int8) shape)
- short :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int16) shape)
- int :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int32) shape)
- long :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int64) shape)
- half :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor gradient layout device ('DataType 'Half) shape)
- float :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor gradient layout device ('DataType 'Float) shape)
- double :: forall m gradient layout device dataType shape. MonadThrow m => Tensor gradient layout device dataType shape -> m (Tensor gradient layout device ('DataType 'Double) shape)
- sSetDataType :: forall m gradient layout device dataType dataType' shape. MonadThrow m => SDataType dataType -> Tensor gradient layout device dataType' shape -> m (Tensor gradient layout device dataType shape)
- class SGetDataType (dataType :: DataType DType) where
- data DataTypeError = DataTypeError {
- dtExpected :: DType
- dtActual :: DType
- sCheckedDataType :: forall dataType' m gradient layout device dataType shape. (SGetDataType dataType, MonadThrow m, Catch (dataType <+> dataType')) => SDataType dataType' -> Tensor gradient layout device dataType shape -> m (Tensor gradient layout device dataType' shape)
- checkedDataType :: forall dataType' m gradient layout device dataType shape. (SingI dataType', SGetDataType dataType, MonadThrow m, Catch (dataType <+> dataType')) => Tensor gradient layout device dataType shape -> m (Tensor gradient layout device dataType' shape)
- uncheckedDataType :: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape -> Tensor gradient layout device 'UncheckedDataType shape
- class SGetShape (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where
- class SGetDims (dims :: [Dim (Name Symbol) (Size Nat)]) where
- dimsError :: forall a. a
- dimNameError :: forall a. String -> String -> a
- dimSizeError :: forall a b. Show a => a -> a -> b
- dimNameSizeError :: forall a b. Show a => String -> String -> a -> a -> b
- class SGetDim (dim :: Dim (Name Symbol) (Size Nat)) where
- data ShapeError = ShapeError {}
- sCheckedShape :: forall shape' m gradient layout device dataType shape. (SGetShape shape, MonadThrow m, Catch (shape <+> shape')) => SShape shape' -> Tensor gradient layout device dataType shape -> m (Tensor gradient layout device dataType shape')
- checkedShape :: forall shape' m gradient layout device dataType shape. (SingI shape', SGetShape shape, MonadThrow m, Catch (shape <+> shape')) => Tensor gradient layout device dataType shape -> m (Tensor gradient layout device dataType shape')
- uncheckedDim :: forall selectDim gradient layout device dataType shape. Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType (ReplaceDimF selectDim shape ('Dim 'UncheckedName 'UncheckedSize))
- uncheckedShape :: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType 'UncheckedShape
- gitHubErrorMsg :: String
- isContiguous :: Tensor gradient layout device dataType shape -> Bool
- contiguous :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape
- withTensor :: Tensor gradient layout device dataType shape -> (Ptr () -> IO a) -> IO a
- class TensorLikeRaw a where
- guessDim :: Maybe a -> Maybe Int
- guessInnerDims :: MonadThrow m => Maybe a -> m [Int]
- tensorPeekElemOff :: Ptr () -> Int -> [Int] -> IO a
- tensorPokeElemOff :: Ptr () -> Int -> [Int] -> a -> IO ()
- guessDims :: forall a m. (TensorLikeRaw a, MonadThrow m) => Maybe a -> m [Int]
- unexpectedDimsError :: forall a m b. (TensorLikeRaw a, MonadThrow m) => [Int] -> Maybe a -> m b
- class TensorLike a (dType :: DType) (dims :: [Dim (Name Symbol) (Size Nat)]) | a -> dims, a -> dType where
- sToTensor :: forall gradient layout device m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims))
- fromTensor :: forall gradient layout device. Tensor gradient layout device ('DataType dType) ('Shape dims) -> a
- toTensor :: forall gradient layout device a dType dims m. (TensorLike a dType dims, SingI gradient, SingI layout, SingI device, MonadThrow m) => a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims))
- sToTensorRaw :: forall gradient layout device a dType dims m. (TensorLike a dType dims, TensorLikeRaw a, SingI dType, MonadThrow m) => SGradient gradient -> SLayout layout -> SDevice device -> a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims))
- fromTensorRaw :: forall gradient layout device a dType dims. (TensorLike a dType dims, TensorLikeRaw a, SGetDims dims) => Tensor gradient layout device ('DataType dType) ('Shape dims) -> a
- data DimMismatchError = DimMismatchError {}
- checkDims :: MonadThrow m => [Int] -> [Int] -> m ()
- unzip3 :: Functor f => f (a, b, c) -> (f a, f b, f c)
- sSetTensorOptions :: forall gradient layout device dataType gradientFrom layoutFrom deviceFrom dataTypeFrom shape. SGradient gradient -> SLayout layout -> SDevice device -> SDataType dataType -> Tensor gradientFrom layoutFrom deviceFrom dataTypeFrom shape -> IO (Tensor gradient layout device dataType shape)
- setTensorOptions :: forall gradient layout device dataType gradientFrom layoutFrom deviceFrom dataTypeFrom shape. (SingI gradient, SingI layout, SingI device, SingI dataType) => Tensor gradientFrom layoutFrom deviceFrom dataTypeFrom shape -> IO (Tensor gradient layout device dataType shape)
Documentation
>>>
import Torch.GraduallyTyped.Prelude.List (SList (..))
>>>
import Torch.GraduallyTyped
newtype Tensor (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where Source #
A gradually typed tensor.
┌─► Compute device, e.g. `'DeviceCPU
│ │ ┌─► List of dimensions, e.g. `'Shape '[ 'Dim 'UncheckedName ('Size 8), 'Dim 'UncheckedName ('Size 1) ]` │ │ Tensor gradient layout device dataType shape │ │ │ │ │ └─► Data type, e.g. `'DataTypeDType
│ │ │ └─► Memory layout, e.g. `'LayoutDense
│ └─► Whether or not the tensor requires a gradient, e.g. `'GradientWithGradient
for one that does
UnsafeTensor :: forall gradient layout device dataType shape. ForeignPtr Tensor -> Tensor gradient layout device dataType shape | Unsafe constructor for tensors.
Do not call this constructor directly,
use smart constructors like |
Instances
Castable (CatListF selectDim (Tensor gradient layout device dataType shape)) (ForeignPtr Tensor) => HasCat selectDim Type [] (Tensor gradient layout device dataType shape :: TYPE LiftedRep) Source # | |
Defined in Torch.GraduallyTyped.Tensor.IndexingSlicingJoining sCat :: MonadThrow m => SSelectDim selectDim -> [Tensor gradient layout device dataType shape] -> m (CatF selectDim (Tensor gradient layout device dataType shape) []) Source # cat :: (SingI selectDim, MonadThrow m) => [Tensor gradient layout device dataType shape] -> m (CatF selectDim (Tensor gradient layout device dataType shape) []) Source # | |
(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 | |
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 | |
Castable [Tensor gradient layout device dataType shape] (ForeignPtr TensorList) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type cast :: [Tensor gradient layout device dataType shape] -> (ForeignPtr TensorList -> IO r) -> IO r Source # uncast :: ForeignPtr TensorList -> ([Tensor gradient layout device dataType shape] -> IO r) -> IO r 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 # | |
(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 # | |
(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 | |
Castable (HList tensors) [ForeignPtr Tensor] => Castable (HList (Tensor gradient layout device dataType shape ': tensors)) [ForeignPtr Tensor] Source # | |
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 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 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 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 # | |
Num (Tensor gradient layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type (+) :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source # (-) :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source # (*) :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source # negate :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source # abs :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source # signum :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source # fromInteger :: Integer -> Tensor gradient layout device dataType shape Source # | |
Show (Tensor gradient layout device dataType shape) Source # | |
HasGrad (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.Autograd type Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # type Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # grad :: Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) -> Tensor ('Gradient 'WithGradient) layout device dataType shape -> Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # | |
HasStateDict (Tensor gradient layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.NN.Class fromStateDict :: (MonadIO m, MonadThrow m, MonadState StateDict m) => ModelSpec (Tensor gradient layout device dataType shape) -> StateDictKey -> m (Tensor gradient layout device dataType shape) Source # toStateDict :: (MonadThrow m, MonadState StateDict m) => StateDictKey -> Tensor gradient layout device dataType shape -> m () Source # | |
Castable (Tensor gradient layout device dataType shape) (ForeignPtr Tensor) 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 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 (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 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 # | |
(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 # | |
type CatF selectDim (Tensor gradient layout device dataType shape :: TYPE LiftedRep) [] Source # | |
type Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.Autograd type Gradients (Tensor ('Gradient 'WithGradient) layout device dataType shape) = Tensor ('Gradient 'WithoutGradient) layout device dataType shape | |
type Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.Autograd type Loss (Tensor ('Gradient 'WithGradient) layout device dataType shape) = Tensor ('Gradient 'WithoutGradient) layout device dataType shape | |
type ModelSpec (Tensor gradient layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.NN.Class type ModelSpec (Tensor gradient layout device dataType shape) = TensorSpec gradient layout device dataType shape |
data TensorSpec (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) (dataType :: DataType DType) (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where Source #
TensorSpec | |
|
Instances
Generic (TensorSpec gradient layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type from :: TensorSpec gradient layout device dataType shape -> Rep (TensorSpec gradient layout device dataType shape) x Source # to :: Rep (TensorSpec gradient layout device dataType shape) x -> TensorSpec gradient layout device dataType shape Source # | |
Show (TensorSpec gradient layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
type Rep (TensorSpec gradient layout device dataType shape) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type type Rep (TensorSpec gradient layout device dataType shape) = D1 ('MetaData "TensorSpec" "Torch.GraduallyTyped.Tensor.Type" "hasktorch-gradually-typed-0.2.0.0-1KV1aIPzzbp6JpSr37tC1K" 'False) (C1 ('MetaCons "TensorSpec" 'PrefixI 'True) ((S1 ('MetaSel ('Just "tsGradient") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SGradient gradient)) :*: S1 ('MetaSel ('Just "tsLayout") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SLayout layout))) :*: (S1 ('MetaSel ('Just "tsDevice") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SDevice device)) :*: (S1 ('MetaSel ('Just "tsDataType") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SDataType dataType)) :*: S1 ('MetaSel ('Just "tsShape") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SShape shape)))))) |
type UncheckedTensor = Tensor 'UncheckedGradient 'UncheckedLayout 'UncheckedDevice 'UncheckedDataType 'UncheckedShape Source #
Alias for an untyped tensor without gradients.
type UncheckedParameter = Tensor ('Gradient 'WithGradient) 'UncheckedLayout 'UncheckedDevice 'UncheckedDataType 'UncheckedShape Source #
Alias for an untyped tensor with gradients.
type CPUTensor = Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) ('Device 'CPU) Source #
Alias for a tensor on CPU memory without gradients.
type CPUParameter = Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) Source #
Alias for a tensor on CPU memory with gradients.
type SparseCPUTensor = Tensor ('Gradient 'WithoutGradient) ('Layout 'Sparse) ('Device 'CPU) Source #
Alias for a sparse tensor on CPU memory without gradients.
type SparseCPUParameter = Tensor ('Gradient 'WithGradient) ('Layout 'Sparse) ('Device 'CPU) Source #
Alias for a sparse tensor on CPU memory with gradients.
type CUDATensor deviceId = Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) ('Device ('CUDA deviceId)) Source #
Alias for a tensor on CUDA memory without gradients.
type CUDAParameter deviceId = Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device ('CUDA deviceId)) Source #
Alias for a tensor on CUDA memory with gradients.
type SparseCUDATensor deviceId = Tensor ('Gradient 'WithoutGradient) ('Layout 'Sparse) ('Device ('CUDA deviceId)) Source #
Alias for a sparse tensor on CUDA memory without gradients.
type SparseCUDAParameter deviceId = Tensor ('Gradient 'WithGradient) ('Layout 'Sparse) ('Device ('CUDA deviceId)) Source #
Alias for a sparse tensor on CUDA memory with gradients.
:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> IO (Tensor ('Gradient 'WithoutGradient) layout device dataType shape) | copy of the input tensor without gradient computations turned off. |
Takes a tensor that may or may not require gradient computations and returns a copy that does not require them.
:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> IO (Tensor ('Gradient 'WithGradient) layout device dataType shape) | copy of the input tensor with gradient computations turned on. |
Takes a tensor that does not requires gradient computations and returns a copy that requires them.
sSetGradient :: forall gradient gradient' layout device dataType shape. SGradient gradient -> Tensor gradient' layout device dataType shape -> IO (Tensor gradient layout device dataType shape) Source #
Turn gradient computations off or on for a tensor.
class SGetGradient (gradient :: Gradient RequiresGradient) where Source #
:: forall layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> SGradient gradient | information about whether or not gradient computations are required |
Returns the gradually typed information for whether or not gradient computations for the tensor are turned on.
>>>
sOnes' gradient = sOnes $ TensorSpec gradient (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- sOnes' $ SGradient SWithGradient
>>>
sGetGradient t
SGradient SWithGradient>>>
t <- sOnes' $ SUncheckedGradient WithoutGradient
>>>
sGetGradient t
SUncheckedGradient WithoutGradient
:: forall layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> RequiresGradient | information about whether or not gradient computations are required |
Returns the untyped memory layout of the input tensor.
>>>
sOnes' gradient = sOnes $ TensorSpec gradient (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- sOnes' $ SGradient SWithGradient
>>>
getRequiresGradient t
WithGradient>>>
t <- sOnes' $ SUncheckedGradient WithoutGradient
>>>
getRequiresGradient t
WithoutGradient
Instances
data GradientError Source #
Instances
Exception GradientError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
Show GradientError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type |
:: forall gradient' m gradient layout device dataType shape. (SGetGradient gradient, MonadThrow m, Catch (gradient <+> gradient')) | |
=> SGradient gradient' | layout |
-> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient' layout device dataType shape) | annotated output tensor wrapped in |
Checks whether or not gradient computations are required for a tensor
and returns a statically annotated copy of it wrapped in a MonadThrow
m
.
For instance, if m
is Maybe
, then the result will be wrapped in Just
if and only if gradients are computed for the tensor according to the argument gradient
.
If gradients are expected but none are computed, then the result will be Nothing
.
If gradients are not expected but are computed, then the result will be Nothing
as well.
In the REPL, m
will default to IO
:
>>> t <- sOnes $ TensorSpec (SUncheckedGradient WithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName "batch" :&: SSize
32 :|: SName "feature" :&: SSize
8 :|: SNil)
>>> t' <- sCheckedGradient (SGradient SWithGradient) t
>>> :type t'
t'
:: Tensor
('Gradient 'WithGradient)
('Layout 'Dense)
('Device 'CPU)
('DataType 'Float)
('Shape
'[ 'Dim ('Name "batch") ('Size 32),
'Dim ('Name "feature") ('Size 8)])
>>> t' <- sCheckedGradient (SGradient SWithoutGradient) t
*** Exception: GradientError {geExpected = WithoutGradient, geActual = WithGradient}
:: forall gradient' m gradient layout device dataType shape. (SingI gradient', SGetGradient gradient, MonadThrow m, Catch (gradient <+> gradient')) | |
=> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient' layout device dataType shape) | annotated output tensor wrapped in |
:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> Tensor 'UncheckedGradient layout device dataType shape | tensor without checked layout |
Returns the input tensor but with UncheckedGradeint
as gradient type annotation.
Any static information about whether or not the gradient computation is required for the tensor is lost.
However, the tensor's underlying data structure is not changed.
>>>
t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>>
:type uncheckedGradient t
uncheckedGradient t :: Tensor 'UncheckedGradient ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor gradient ('Layout 'Dense) device dataType shape) | dense copy |
Returns a dense copy of the tensor.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor gradient ('Layout 'Sparse) device dataType shape) | sparse copy |
Returns a sparse copy of the tensor.
sSetLayout :: forall m gradient layout layout' device dataType shape. MonadThrow m => SLayout layout -> Tensor gradient layout' device dataType shape -> m (Tensor gradient layout device dataType shape) Source #
Set the memory layout of a tensor to a given layout.
class SGetLayout (layout :: Layout LayoutType) where Source #
:: forall gradient device dataType shape. Tensor gradient layout device dataType shape | input |
-> SLayout layout | memory layout |
Returns the gradually typed memory layout of the input tensor.
>>>
sOnes' layout = sOnes $ TensorSpec (SGradient SWithGradient) layout (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- sOnes' $ SLayout SDense
>>>
sGetLayout t
SLayout SDense>>>
t <- sOnes' $ SUncheckedLayout Dense
>>>
sGetLayout t
SUncheckedLayout Dense
:: forall gradient device dataType shape. Tensor gradient layout device dataType shape | input |
-> LayoutType | memory layout |
Returns the untyped memory layout of the input tensor.
>>>
sOnes' layout = sOnes $ TensorSpec (SGradient SWithGradient) layout (SDevice SCPU) (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- sOnes' $ SLayout SDense
>>>
getLayoutType t
Dense>>>
t <- sOnes' $ SUncheckedLayout Dense
>>>
getLayoutType t
Dense
Instances
data LayoutError Source #
Instances
Exception LayoutError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
Show LayoutError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type |
:: forall layout' m gradient layout device dataType shape. (SGetLayout layout, MonadThrow m, Catch (layout <+> layout')) | |
=> SLayout layout' | layout |
-> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient layout' device dataType shape) | annotated output tensor wrapped in |
Checks whether or not the input tensor has the memory layout layout
and returns a statically annotated copy of it wrapped in a MonadThrow
m
.
For instance, if m
is Maybe
, then the result will be wrapped in Just
if and only if the tensor has indeed the memory layout layout
.
If it does not have it, then the result will be Nothing
.
In the REPL, m
will default to IO
:
>>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SUncheckedLayout Dense) (SDevice SCPU) (SDataType SFloat) (SShape $ SName "batch" :&: SSize
32 :|: SName "feature" :&: SSize
8 :|: SNil)
>>> t' <- sCheckedLayout (SLayout SDense) t
>>> :type t'
t'
:: Tensor
('Gradient 'WithGradient)
('Layout 'Dense)
('Device 'CPU)
('DataType 'Float)
('Shape
'[ 'Dim ('Name "batch") ('Size 32),
'Dim ('Name "feature") ('Size 8)])
>>> t' <- sCheckedLayout (SLayout SSparse) t
*** Exception: LayoutError {leExpected = Sparse, leActual = Dense}
:: forall layout' m gradient layout device dataType shape. (SingI layout', SGetLayout layout, MonadThrow m, Catch (layout <+> layout')) | |
=> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient layout' device dataType shape) | annotated output tensor wrapped in |
:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> Tensor gradient 'UncheckedLayout device dataType shape | tensor without checked layout |
Returns the input tensor but with UncheckedLayout
as memory layout type annotation.
Any static information about the tensor's memory layout is thus erased.
However, the tensor's underlying data structure is not changed.
>>>
t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>>
:type uncheckedLayout t
uncheckedLayout t :: Tensor ('Gradient 'WithGradient) 'UncheckedLayout ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor gradient layout ('Device 'CPU) dataType shape) | copy in CPU memory |
Returns a copy of the tensor in CPU memory.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor gradient layout ('Device ('CUDA 0)) dataType shape) | copy in CUDA memory |
Returns a copy of the tensor in CUDA memory.
sSetDevice :: forall m gradient layout device device' dataType shape. MonadThrow m => SDevice device -> Tensor gradient layout device' dataType shape -> m (Tensor gradient layout device dataType shape) Source #
Reallocates a tensor on the specified device.
class SGetDevice (device :: Device (DeviceType Nat)) where Source #
:: forall gradient layout dataType shape. Tensor gradient layout device dataType shape | input |
-> SDevice device | compute device of the input tensor |
Returns the gradually typed compute device of the input tensor.
>>>
ones' device = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) device (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- ones' $ SDevice SCPU
>>>
sGetDevice t
SDevice SCPU>>>
t <- ones' $ SUncheckedDevice CPU
>>>
sGetDevice t
SUncheckedDevice CPU
:: forall gradient layout dataType shape. Tensor gradient layout device dataType shape | input |
-> DeviceType Int16 | compute device of the input tensor |
Returns the untyped compute device of the input tensor.
>>>
ones' device = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) device (SDataType SFloat) (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- ones' $ SDevice SCPU
>>>
getDeviceType t
CPU>>>
t <- ones' $ SUncheckedDevice CPU
>>>
getDeviceType t
CPU
Instances
data DeviceError Source #
Instances
Exception DeviceError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
Show DeviceError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type |
:: forall device' m gradient layout device dataType shape. (SGetDevice device, MonadThrow m, Catch (device <+> device')) | |
=> SDevice device' | device |
-> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient layout device' dataType shape) | annotated output tensor wrapped in |
Checks whether or not the input tensor is in the memory of device
and returns a statically annotated copy of it wrapped in a MonadThrow
m
.
For instance, if m
is Maybe
, then the result will be wrapped in Just
if and only if the tensor is indeed on device
.
If it is not, then the result will be Nothing
.
In the REPL, m
will default to IO
:
>>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SUncheckedDevice CPU) (SDataType SFloat) (SShape $ SName "batch" :&: SSize
32 :|: SName "feature" :&: SSize
8 :|: SNil)
>>> t' <- sCheckedDevice (SDevice SCPU) t
>>> :type t'
t'
:: Tensor
('Gradient 'WithGradient)
('Layout 'Dense)
('Device 'CPU)
('DataType 'Float)
('Shape
'[ 'Dim ('Name "batch") ('Size 32),
'Dim ('Name "feature") ('Size 8)])
>>> t' <- sCheckedDevice (SDevice (SCUDA @0)) t
*** Exception: DeviceError {deExpected = CUDA 0, deActual = CPU}
:: forall device' m gradient layout device dataType shape. (SingI device', SGetDevice device, MonadThrow m, Catch (device <+> device')) | |
=> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient layout device' dataType shape) | annotated output tensor wrapped in |
:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> Tensor gradient layout 'UncheckedDevice dataType shape | tensor without checked device |
Returns the input tensor but with UncheckedDevice
as device type annotation.
Any static information about the tensor's device is thus erased.
However, the tensor's underlying data structure is not changed.
>>>
t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>>
:type uncheckedDevice t
uncheckedDevice t :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) 'UncheckedDevice ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Bool) shape) |
|
Returns a copy of the tensor converted to DType
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'UInt8) shape) |
|
Returns a copy of the tensor converted to UInt8
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int8) shape) |
|
Returns a copy of the tensor converted to Int8
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int16) shape) |
|
Returns a copy of the tensor converted to DType
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int32) shape) |
|
Returns a copy of the tensor converted to Int32
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor ('Gradient 'WithoutGradient) layout device ('DataType 'Int64) shape) |
|
Returns a copy of the tensor converted to Int64
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor gradient layout device ('DataType 'Half) shape) |
|
Returns a copy of the tensor converted to the 16-bit floating point format Half
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor gradient layout device ('DataType 'Float) shape) |
|
Returns a copy of the tensor converted to the 32-bit floating point format DType
.
:: forall m gradient layout device dataType shape. MonadThrow m | |
=> Tensor gradient layout device dataType shape | input |
-> m (Tensor gradient layout device ('DataType 'Double) shape) |
|
Returns a copy of the tensor converted to the 32-bit floating point format DType
.
sSetDataType :: forall m gradient layout device dataType dataType' shape. MonadThrow m => SDataType dataType -> Tensor gradient layout device dataType' shape -> m (Tensor gradient layout device dataType shape) Source #
Set the data type of a tensor to the specified data type.
class SGetDataType (dataType :: DataType DType) where Source #
:: forall gradient layout device shape. Tensor gradient layout device dataType shape | input |
-> SDataType dataType | data type of the input tensor |
Returns the gradually typed compute data type of the input tensor.
>>>
sOnes' dataType = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) dataType (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- sOnes' $ SDataType SFloat
>>>
sGetDataType t
SDataType SFloat>>>
t <- sOnes' $ SUncheckedDataType Float
>>>
sGetDataType t
SUncheckedDataType Float
:: forall gradient layout device shape. Tensor gradient layout device dataType shape | input |
-> DType | data type of the input tensor |
Returns the untyped compute data type of the input tensor.
>>>
sOnes' dataType = sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) dataType (SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil)
>>>
t <- sOnes' $ SDataType SFloat
>>>
getDType t
Float>>>
t <- sOnes' $ SUncheckedDataType Float
>>>
getDType t
Float
Instances
data DataTypeError Source #
Instances
Exception DataTypeError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
Show DataTypeError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type |
:: forall dataType' m gradient layout device dataType shape. (SGetDataType dataType, MonadThrow m, Catch (dataType <+> dataType')) | |
=> SDataType dataType' | data type |
-> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient layout device dataType' shape) | annotated output tensor wrapped in |
Checks whether or not the input tensor has the data type dataType
and returns a statically annotated copy of it wrapped in a MonadThrow
m
.
For instance, if m
is Maybe
, then the result will be wrapped in Just
if and only if the tensor has indeed the data type dataType
.
If it does not have it, then the result will be Nothing
.
In the REPL, m
will default to IO
:
>>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SUncheckedDataType Float) (SShape $ SName "batch" :&: SSize
32 :|: SName "feature" :&: SSize
8 :|: SNil)
>>> t' <- checkedDataType ('DataType 'Float) t
>>> :type t'
t'
:: Tensor
('Gradient 'WithGradient)
('Layout 'Dense)
('Device 'CPU)
('DataType 'Float)
('Shape
'[ 'Dim ('Name "batch") ('Size 32),
'Dim ('Name "feature") ('Size 8)])
>>> t' <- checkedDataType
('DataType 'Double) t
*** Exception: DataTypeError {dtExpected = Double, dtActual = Float}
:: forall dataType' m gradient layout device dataType shape. (SingI dataType', SGetDataType dataType, MonadThrow m, Catch (dataType <+> dataType')) | |
=> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient layout device dataType' shape) | annotated output tensor wrapped in |
:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> Tensor gradient layout device 'UncheckedDataType shape | tensor without checked data type |
Returns the input tensor but with UncheckedDataType
as data-type type annotation.
Any static information about the tensor's data type is thus erased.
However, the tensor's underlying data structure is not changed.
>>>
t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>>
:type uncheckedDataType t
uncheckedDataType t :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) 'UncheckedDataType ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
class SGetShape (shape :: Shape [Dim (Name Symbol) (Size Nat)]) where Source #
sGetShape :: forall gradient layout device dataType. Tensor gradient layout device dataType shape -> SShape shape Source #
Returns the gradually typed shape of the input tensor.
>>>
sOnes' = sOnes . TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat)
>>>
t <- sOnes' . SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil
>>>
sGetShape t
SShape (SCons (SDim {sDimName = SName, sDimSize = SSize}) (SCons (SDim {sDimName = SName, sDimSize = SSize}) SNil))>>>
t <- sOnes' . SUncheckedShape $ [Dim "batch" 32, Dim "feature" 8]
>>>
sGetShape t
SUncheckedShape [Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]>>>
t <- sOnes' . SShape $ SUncheckedName "batch" :&: SUncheckedSize 32 :|: SUncheckedName "feature" :&: SSize @32 :|: SNil
>>>
sGetShape t
SShape (SCons (SDim {sDimName = SUncheckedName "batch", sDimSize = SUncheckedSize 32}) (SCons (SDim {sDimName = SUncheckedName "feature", sDimSize = SSize}) SNil))>>>
t <- sOnes' . SShape $ SName @"batch" :&: SUncheckedSize 32 :|: SName @"feature" :&: SUncheckedSize 8 :|: SNil
>>>
sGetShape t
SShape (SCons (SDim {sDimName = SName, sDimSize = SUncheckedSize 32}) (SCons (SDim {sDimName = SName, sDimSize = SUncheckedSize 8}) SNil))
getDims :: forall gradient layout device dataType. Tensor gradient layout device dataType shape -> [Dim String Integer] Source #
Returns the untyped shape of the input tensor.
>>>
sOnes' = sOnes . TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat)
>>>
t <- sOnes' . SShape $ SName @"batch" :&: SSize @32 :|: SName @"feature" :&: SSize @8 :|: SNil
>>>
getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]>>>
t <- sOnes' . SUncheckedShape $ [Dim "batch" 32, Dim "feature" 8]
>>>
getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]>>>
t <- sOnes' . SShape $ SUncheckedName "batch" :&: SUncheckedSize 32 :|: SUncheckedName "feature" :&: SSize @32 :|: SNil
>>>
getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 32}]>>>
t <- sOnes' . SShape $ SName @"batch" :&: SUncheckedSize 32 :|: SName @"feature" :&: SUncheckedSize 8 :|: SNil
>>>
getDims t
[Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]
Instances
class SGetDims (dims :: [Dim (Name Symbol) (Size Nat)]) where Source #
dimNameError :: forall a. String -> String -> a Source #
dimSizeError :: forall a b. Show a => a -> a -> b Source #
class SGetDim (dim :: Dim (Name Symbol) (Size Nat)) where Source #
Instances
(KnownSymbol name, KnownNat size) => SGetDim ('Dim ('Name name) ('Size size)) Source # | |
KnownSymbol name => SGetDim ('Dim ('Name name) ('UncheckedSize :: Size Nat)) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
KnownNat size => SGetDim ('Dim ('UncheckedName :: Name Symbol) ('Size size)) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
SGetDim ('Dim ('UncheckedName :: Name Symbol) ('UncheckedSize :: Size Nat)) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sGetDim :: String -> Integer -> SDim ('Dim 'UncheckedName 'UncheckedSize) Source # |
data ShapeError Source #
Instances
Exception ShapeError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
Show ShapeError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type |
:: forall shape' m gradient layout device dataType shape. (SGetShape shape, MonadThrow m, Catch (shape <+> shape')) | |
=> SShape shape' | shape |
-> Tensor gradient layout device dataType shape | input tensor |
-> m (Tensor gradient layout device dataType shape') | annotated output tensor wrapped in |
Checks whether or not the input tensor has the shape shape
and returns a statically annotated copy of it wrapped in a MonadThrow
m
.
For instance, if m
is Maybe
, then the result will be wrapped in Just
if and only if the tensor has indeed the shape shape
.
If it is not, then the result will be Nothing
.
In the REPL, m
will default to IO
:
>>> t <- sOnes $ TensorSpec (SGradient SWithGradient) (SLayout SDense) (SDevice SCPU) (SDataType SFloat) (SUncheckedShape [Dim "batch" 32, Dim "feature" 8])
>>> t' <- sCheckedShape (SShape $ SName "batch" :&: SSize
32 :|: SName "feature" :&: SSize
8 :|: SNil) t
>>> :type t'
t'
:: Tensor
('Gradient 'WithGradient)
('Layout 'Dense)
('Device 'CPU)
('DataType 'Float)
('Shape
'[ 'Dim ('Name "batch") ('Size 32),
'Dim ('Name "feature") ('Size 8)])
>>> t' <- sCheckedShape (SShape $ SUncheckedName "batch" :&: SSize 32 :|: SName
"feature" :&: SUncheckedSize 8 :|: SNil) t
>>> :type t'
t'
:: Tensor
('Gradient 'WithGradient)
('Layout 'Dense)
('Device 'CPU)
('DataType 'Float)
('Shape
'[ 'Dim 'UncheckedName ('Size 32),
'Dim ('Name "feature") 'UncheckedSize])
>>> t' <- sCheckedShape (SShape $ SName "batch" :&: SSize
32 :|: SName @"feature" :&: SUncheckedSize 32 :|: SNil) t
*** Exception: ShapeError {seExpected = [Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 32}], seActual = [Dim {dimName = "batch", dimSize = 32},Dim {dimName = "feature", dimSize = 8}]}
:: forall selectDim gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> Tensor gradient layout device dataType (ReplaceDimF selectDim shape ('Dim 'UncheckedName 'UncheckedSize)) | tensor with the selected dimensions unchecked |
Returns the input tensor but with the selected dimension replaces with UncheckedDim
as dimension type annotation.
The static information about the selected tensor dimension is thus erased.
However, the tensor's underlying data structure is not changed.
>>>
t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>>
:type uncheckedDim @('SelectDim ('ByName "batch")) t
uncheckedDim @('SelectDim ('ByName "batch")) t :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim 'UncheckedName 'UncheckedSize, 'Dim ('Name "feature") ('Size 8)])>>>
t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>>
:type uncheckedDim @('SelectDim ('ByIndex 1)) t
uncheckedDim @('SelectDim ('ByIndex 1)) t :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) ('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim 'UncheckedName 'UncheckedSize])
:: forall gradient layout device dataType shape. Tensor gradient layout device dataType shape | input tensor |
-> Tensor gradient layout device dataType 'UncheckedShape | tensor without checked shape |
Returns the input tensor but with UncheckedShape
as shape type annotation.
Any static information about the tensor's shape is thus erased.
However, the tensor's underlying data structure is not changed.
>>>
t <- ones @('Gradient 'WithGradient) @('Layout 'Dense) @('Device 'CPU) @('DataType 'Float) @('Shape '[ 'Dim ('Name "batch") ('Size 32), 'Dim ('Name "feature") ('Size 8)])
>>>
:type uncheckedShape t
uncheckedShape t :: Tensor ('Gradient 'WithGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Float) 'UncheckedShape
isContiguous :: Tensor gradient layout device dataType shape -> Bool Source #
contiguous :: Tensor gradient layout device dataType shape -> Tensor gradient layout device dataType shape Source #
class TensorLikeRaw a where Source #
:: Maybe a | value
|
-> Maybe Int | dimension
|
Guesses outer dim.
>>>
guessDim @[[Int]] $ pure [[1, 2], [3, 4], [5, 6]]
Just 3
:: MonadThrow m | |
=> Maybe a | value
|
-> m [Int] | inner dimensions |
Guesses inner dims.
>>>
guessInnerDims @[[Int]] $ pure [[1, 2], [3, 4], [5, 6]]
[2]
Reads a value from a tensor.
Writes a value to a tensor.
Instances
TensorLikeRaw Bool Source # | |
TensorLikeRaw Double Source # | |
TensorLikeRaw Float Source # | |
TensorLikeRaw Int Source # | |
TensorLikeRaw a => TensorLikeRaw (Vector a) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
TensorLikeRaw a => TensorLikeRaw [a] Source # | |
(KnownNat n, TensorLikeRaw a) => TensorLikeRaw (Vector n a) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
(TensorLikeRaw a, TensorLikeRaw b) => TensorLikeRaw (a, b) Source # | |
(TensorLikeRaw a, TensorLikeRaw b, TensorLikeRaw c) => TensorLikeRaw (a, b, c) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type |
guessDims :: forall a m. (TensorLikeRaw a, MonadThrow m) => Maybe a -> m [Int] Source #
Guesses dims: concatenates guessDim
with guessInnerDims
.
>>>
guessDims @[[Int]] $ pure [[1, 2], [3, 4], [5, 6]]
[3,2]
unexpectedDimsError :: forall a m b. (TensorLikeRaw a, MonadThrow m) => [Int] -> Maybe a -> m b Source #
class TensorLike a (dType :: DType) (dims :: [Dim (Name Symbol) (Size Nat)]) | a -> dims, a -> dType where Source #
sToTensor :: forall gradient layout device m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims)) Source #
Creates a tensor from a TensorLike
value.
>>>
t <- sToTensor (SGradient SWithoutGradient) (SLayout SDense) (SDevice SCPU) ([(1, 2), (3, 4), (5, 6)] :: [(Int, Int)])
>>>
t
Tensor Int64 [3,2] [[ 1, 2], [ 3, 4], [ 5, 6]]>>>
:type t
t :: Tensor ('Gradient 'WithoutGradient) ('Layout 'Dense) ('Device 'CPU) ('DataType 'Int64) ('Shape '[ 'Dim ('Name "*") 'UncheckedSize, 'Dim ('Name "*") ('Size 2)])
fromTensor :: forall gradient layout device. Tensor gradient layout device ('DataType dType) ('Shape dims) -> a Source #
Creates a TensorLike
from a tensor.
Instances
TensorLike Bool 'Bool ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Bool0 -> m (Tensor gradient layout device ('DataType 'Bool) ('Shape '[])) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Bool) ('Shape '[]) -> Bool0 Source # | |
TensorLike Double 'Double ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Double0 -> m (Tensor gradient layout device ('DataType 'Double) ('Shape '[])) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Double) ('Shape '[]) -> Double0 Source # | |
TensorLike Float 'Float ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Float0 -> m (Tensor gradient layout device ('DataType 'Float) ('Shape '[])) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Float) ('Shape '[]) -> Float0 Source # | |
TensorLike Int 'Int64 ('[] :: [Dim (Name Symbol) (Size Nat)]) Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Int -> m (Tensor gradient layout device ('DataType 'Int64) ('Shape '[])) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType 'Int64) ('Shape '[]) -> Int Source # | |
(TensorLike a dType dims, TensorLikeRaw a, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape dims) ('Dim ('Name "*") ('UncheckedSize :: Size Nat))) => TensorLike (Vector a) dType dimsOut Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Vector a -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> Vector a Source # | |
(TensorLike a dType dims, TensorLikeRaw a, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape dims) ('Dim ('Name "*") ('UncheckedSize :: Size Nat))) => TensorLike [a] dType dimsOut Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> [a] -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> [a] Source # | |
(KnownNat n, TensorLike a dType dims, TensorLikeRaw a, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape dims) ('Dim ('Name "*") ('Size n))) => TensorLike (Vector n a) dType dimsOut Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> Vector n a -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> Vector n a Source # | |
(TensorLike a dType dims, TensorLike b dType dims', TensorLikeRaw a, TensorLikeRaw b, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape (dims <+> dims')) ('Dim ('Name "*") ('Size 2))) => TensorLike (a, b) dType dimsOut Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> (a, b) -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> (a, b) Source # | |
(TensorLike a dType dims, TensorLike b dType dims', TensorLike c dType dims', TensorLikeRaw a, TensorLikeRaw b, TensorLikeRaw c, SingI dType, SGetDims dimsOut, 'Shape dimsOut ~ InsertDimF ('SelectDim ('ByIndex 0 :: By Symbol Natural)) ('Shape (dims <+> dims')) ('Dim ('Name "*") ('Size 3))) => TensorLike (a, b, c) dType dimsOut Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type sToTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)) m. MonadThrow m => SGradient gradient -> SLayout layout -> SDevice device -> (a, b, c) -> m (Tensor gradient layout device ('DataType dType) ('Shape dimsOut)) Source # fromTensor :: forall (gradient :: Gradient RequiresGradient) (layout :: Layout LayoutType) (device :: Device (DeviceType Nat)). Tensor gradient layout device ('DataType dType) ('Shape dimsOut) -> (a, b, c) Source # |
toTensor :: forall gradient layout device a dType dims m. (TensorLike a dType dims, SingI gradient, SingI layout, SingI device, MonadThrow m) => a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims)) Source #
Non-singleton version of sToTensor
.
sToTensorRaw :: forall gradient layout device a dType dims m. (TensorLike a dType dims, TensorLikeRaw a, SingI dType, MonadThrow m) => SGradient gradient -> SLayout layout -> SDevice device -> a -> m (Tensor gradient layout device ('DataType dType) ('Shape dims)) Source #
fromTensorRaw :: forall gradient layout device a dType dims. (TensorLike a dType dims, TensorLikeRaw a, SGetDims dims) => Tensor gradient layout device ('DataType dType) ('Shape dims) -> a Source #
data DimMismatchError Source #
Instances
Exception DimMismatchError Source # | |
Show DimMismatchError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type | |
Eq DimMismatchError Source # | |
Defined in Torch.GraduallyTyped.Tensor.Type (==) :: DimMismatchError -> DimMismatchError -> Bool Source # (/=) :: DimMismatchError -> DimMismatchError -> Bool Source # |
sSetTensorOptions :: forall gradient layout device dataType gradientFrom layoutFrom deviceFrom dataTypeFrom shape. SGradient gradient -> SLayout layout -> SDevice device -> SDataType dataType -> Tensor gradientFrom layoutFrom deviceFrom dataTypeFrom shape -> IO (Tensor gradient layout device dataType shape) Source #
setTensorOptions :: forall gradient layout device dataType gradientFrom layoutFrom deviceFrom dataTypeFrom shape. (SingI gradient, SingI layout, SingI device, SingI dataType) => Tensor gradientFrom layoutFrom deviceFrom dataTypeFrom shape -> IO (Tensor gradient layout device dataType shape) Source #
Orphan instances
Castable (HList ('[] :: [k])) [ForeignPtr Tensor] Source # | |
Castable (HList l) [ForeignPtr Tensor] => Castable (HList l) (ForeignPtr TensorList) Source # | |
cast :: HList l -> (ForeignPtr TensorList -> IO r) -> IO r Source # uncast :: ForeignPtr TensorList -> (HList l -> IO r) -> IO r Source # |