hasktorch 0.2.1.7 → 0.2.1.8
raw patch · 4 files changed
+48/−10 lines, 4 filesdep ~ghc-typelits-extradep ~ghc-typelits-knownnatdep ~ghc-typelits-natnormalisePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ghc-typelits-extra, ghc-typelits-knownnat, ghc-typelits-natnormalise, libtorch-ffi, lifted-async, random, template-haskell
API changes (from Hackage documentation)
+ Torch.Autograd: GradOptions :: Bool -> Bool -> Bool -> GradOptions
+ Torch.Autograd: [accumulateGrad] :: GradOptions -> Bool
+ Torch.Autograd: [createGraph] :: GradOptions -> Bool
+ Torch.Autograd: [keepGraph] :: GradOptions -> Bool
+ Torch.Autograd: data GradOptions
+ Torch.Autograd: gradWithOptions :: GradOptions -> Tensor -> [IndependentTensor] -> [Tensor]
+ Torch.Autograd: instance Data.Default.Internal.Default Torch.Autograd.GradOptions
+ Torch.Autograd: instance GHC.Show.Show Torch.Autograd.GradOptions
- Torch.Typed.NN.Convolution: conv1dForward :: forall (stride :: Nat) (padding :: Nat) {kernelSize :: Nat} {inputSize :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 stride) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType stride) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize) :: Constraint), Assert (OrdCond (CmpNat (kernelSize - 1) (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize, KnownNat kernelSize, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat padding, KnownNat stride) => Conv1d inputChannelSize outputChannelSize kernelSize w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize + (2 * padding)) - kernelSize) stride + 1]
+ Torch.Typed.NN.Convolution: conv1dForward :: forall (stride :: Nat) (padding :: Nat) {kernelSize :: Nat} {inputSize :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize) :: Constraint), Assert (OrdCond (CmpNat 1 stride) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType stride) :: Constraint), Assert (OrdCond (CmpNat (kernelSize - 1) (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize, KnownNat kernelSize, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat padding, KnownNat stride) => Conv1d inputChannelSize outputChannelSize kernelSize w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize + (2 * padding)) - kernelSize) stride + 1]
- Torch.Typed.NN.Convolution: conv2dForward :: forall (stride :: (Nat, Nat)) (padding :: (Nat, Nat)) {kernelSize1 :: Nat} {inputSize1 :: Nat} {kernelSize0 :: Nat} {inputSize0 :: Nat} {inputChannelSize :: Nat} {outputChannelSize :: Nat} {batchSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Snd stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Fst stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint), KnownNat inputChannelSize, KnownNat outputChannelSize, KnownNat kernelSize0, KnownNat kernelSize1, KnownNat inputSize0, KnownNat inputSize1, KnownNat batchSize, KnownNat (Fst stride), KnownNat (Fst padding), KnownNat (Snd stride), KnownNat (Snd padding)) => Conv2d inputChannelSize outputChannelSize kernelSize0 kernelSize1 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst padding)) - kernelSize0) (Fst stride) + 1, Div ((inputSize1 + (2 * Snd padding)) - kernelSize1) (Snd stride) + 1]
+ Torch.Typed.NN.Convolution: conv2dForward :: forall (stride :: (Nat, Nat)) (padding :: (Nat, Nat)) {kernelSize1 :: Nat} {inputSize1 :: Nat} {kernelSize0 :: Nat} {inputSize0 :: Nat} {inputChannelSize :: Nat} {outputChannelSize :: Nat} {batchSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat 1 (Fst stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat 1 (Snd stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint), KnownNat inputChannelSize, KnownNat outputChannelSize, KnownNat kernelSize0, KnownNat kernelSize1, KnownNat inputSize0, KnownNat inputSize1, KnownNat batchSize, KnownNat (Fst stride), KnownNat (Fst padding), KnownNat (Snd stride), KnownNat (Snd padding)) => Conv2d inputChannelSize outputChannelSize kernelSize0 kernelSize1 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst padding)) - kernelSize0) (Fst stride) + 1, Div ((inputSize1 + (2 * Snd padding)) - kernelSize1) (Snd stride) + 1]
- Torch.Typed.NN.Convolution: conv3dForward :: forall (stride :: (Nat, Nat, Nat)) (padding :: (Nat, Nat, Nat)) {kernelSize0 :: Nat} {inputSize0 :: Nat} {kernelSize2 :: Nat} {inputSize2 :: Nat} {kernelSize1 :: Nat} {inputSize1 :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize2 (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize2) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Snd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd3 stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Trd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Trd3 stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Fst3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst3 stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize2) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize2) :: Constraint), Assert (OrdCond (CmpNat (kernelSize2 - 1) (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize2 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize2, KnownNat inputSize1, KnownNat inputSize0, KnownNat kernelSize2, KnownNat kernelSize1, KnownNat kernelSize0, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat (Trd3 padding), KnownNat (Trd3 stride), KnownNat (Snd3 padding), KnownNat (Snd3 stride), KnownNat (Fst3 padding), KnownNat (Fst3 stride)) => Conv3d inputChannelSize outputChannelSize kernelSize0 kernelSize1 kernelSize2 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1, inputSize2] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst3 padding)) - kernelSize0) (Fst3 stride) + 1, Div ((inputSize1 + (2 * Snd3 padding)) - kernelSize1) (Snd3 stride) + 1, Div ((inputSize2 + (2 * Trd3 padding)) - kernelSize2) (Trd3 stride) + 1]
+ Torch.Typed.NN.Convolution: conv3dForward :: forall (stride :: (Nat, Nat, Nat)) (padding :: (Nat, Nat, Nat)) {kernelSize2 :: Nat} {inputSize2 :: Nat} {kernelSize1 :: Nat} {inputSize1 :: Nat} {kernelSize0 :: Nat} {inputSize0 :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize2 (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize2) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat 1 (Fst3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst3 stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat 1 (Snd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd3 stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize2) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize2) :: Constraint), Assert (OrdCond (CmpNat 1 (Trd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Trd3 stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize2 - 1) (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize2 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize2, KnownNat inputSize1, KnownNat inputSize0, KnownNat kernelSize2, KnownNat kernelSize1, KnownNat kernelSize0, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat (Trd3 padding), KnownNat (Trd3 stride), KnownNat (Snd3 padding), KnownNat (Snd3 stride), KnownNat (Fst3 padding), KnownNat (Fst3 stride)) => Conv3d inputChannelSize outputChannelSize kernelSize0 kernelSize1 kernelSize2 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1, inputSize2] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst3 padding)) - kernelSize0) (Fst3 stride) + 1, Div ((inputSize1 + (2 * Snd3 padding)) - kernelSize1) (Snd3 stride) + 1, Div ((inputSize2 + (2 * Trd3 padding)) - kernelSize2) (Trd3 stride) + 1]
- Torch.Typed.NN.Convolution: convTranspose1dForward :: forall (stride :: Nat) (padding :: Nat) {kernelSize :: Nat} {inputSize :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 stride) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType stride) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize) :: Constraint), Assert (OrdCond (CmpNat (kernelSize - 1) (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize, KnownNat kernelSize, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat padding, KnownNat stride) => ConvTranspose1d inputChannelSize outputChannelSize kernelSize w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize + (2 * padding)) - kernelSize) stride + 1]
+ Torch.Typed.NN.Convolution: convTranspose1dForward :: forall (stride :: Nat) (padding :: Nat) {kernelSize :: Nat} {inputSize :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize) :: Constraint), Assert (OrdCond (CmpNat 1 stride) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType stride) :: Constraint), Assert (OrdCond (CmpNat (kernelSize - 1) (inputSize + (2 * padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize + (2 * padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize, KnownNat kernelSize, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat padding, KnownNat stride) => ConvTranspose1d inputChannelSize outputChannelSize kernelSize w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize + (2 * padding)) - kernelSize) stride + 1]
- Torch.Typed.NN.Convolution: convTranspose2dForward :: forall (stride :: (Nat, Nat)) (padding :: (Nat, Nat)) {kernelSize1 :: Nat} {inputSize1 :: Nat} {kernelSize0 :: Nat} {inputSize0 :: Nat} {inputChannelSize :: Nat} {outputChannelSize :: Nat} {batchSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Snd stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Fst stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint), KnownNat inputChannelSize, KnownNat outputChannelSize, KnownNat kernelSize0, KnownNat kernelSize1, KnownNat inputSize0, KnownNat inputSize1, KnownNat batchSize, KnownNat (Fst stride), KnownNat (Fst padding), KnownNat (Snd stride), KnownNat (Snd padding)) => ConvTranspose2d inputChannelSize outputChannelSize kernelSize0 kernelSize1 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst padding)) - kernelSize0) (Fst stride) + 1, Div ((inputSize1 + (2 * Snd padding)) - kernelSize1) (Snd stride) + 1]
+ Torch.Typed.NN.Convolution: convTranspose2dForward :: forall (stride :: (Nat, Nat)) (padding :: (Nat, Nat)) {kernelSize1 :: Nat} {inputSize1 :: Nat} {kernelSize0 :: Nat} {inputSize0 :: Nat} {inputChannelSize :: Nat} {outputChannelSize :: Nat} {batchSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat 1 (Fst stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat 1 (Snd stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd padding))) :: Constraint), KnownNat inputChannelSize, KnownNat outputChannelSize, KnownNat kernelSize0, KnownNat kernelSize1, KnownNat inputSize0, KnownNat inputSize1, KnownNat batchSize, KnownNat (Fst stride), KnownNat (Fst padding), KnownNat (Snd stride), KnownNat (Snd padding)) => ConvTranspose2d inputChannelSize outputChannelSize kernelSize0 kernelSize1 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst padding)) - kernelSize0) (Fst stride) + 1, Div ((inputSize1 + (2 * Snd padding)) - kernelSize1) (Snd stride) + 1]
- Torch.Typed.NN.Convolution: convTranspose3dForward :: forall (stride :: (Nat, Nat, Nat)) (padding :: (Nat, Nat, Nat)) {kernelSize0 :: Nat} {inputSize0 :: Nat} {kernelSize2 :: Nat} {inputSize2 :: Nat} {kernelSize1 :: Nat} {inputSize1 :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize2 (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize2) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Snd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd3 stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Trd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Trd3 stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 (Fst3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst3 stride)) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize2) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize2) :: Constraint), Assert (OrdCond (CmpNat (kernelSize2 - 1) (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize2 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize2, KnownNat inputSize1, KnownNat inputSize0, KnownNat kernelSize2, KnownNat kernelSize1, KnownNat kernelSize0, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat (Trd3 padding), KnownNat (Trd3 stride), KnownNat (Snd3 padding), KnownNat (Snd3 stride), KnownNat (Fst3 padding), KnownNat (Fst3 stride)) => ConvTranspose3d inputChannelSize outputChannelSize kernelSize0 kernelSize1 kernelSize2 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1, inputSize2] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst3 padding)) - kernelSize0) (Fst3 stride) + 1, Div ((inputSize1 + (2 * Snd3 padding)) - kernelSize1) (Snd3 stride) + 1, Div ((inputSize2 + (2 * Trd3 padding)) - kernelSize2) (Trd3 stride) + 1]
+ Torch.Typed.NN.Convolution: convTranspose3dForward :: forall (stride :: (Nat, Nat, Nat)) (padding :: (Nat, Nat, Nat)) {kernelSize2 :: Nat} {inputSize2 :: Nat} {kernelSize1 :: Nat} {inputSize1 :: Nat} {kernelSize0 :: Nat} {inputSize0 :: Nat} {batchSize :: Nat} {outputChannelSize :: Nat} {inputChannelSize :: Nat} {w1 :: DType} {w2 :: (DeviceType, Nat)}. (Assert (OrdCond (CmpNat kernelSize2 (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize2) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize1 (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize1) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat kernelSize0 (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType kernelSize0) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint) ~ (), Assert (OrdCond (CmpNat 1 kernelSize0) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize0) :: Constraint), Assert (OrdCond (CmpNat 1 (Fst3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Fst3 stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize0 - 1) (inputSize0 + (2 * Fst3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize0 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize0 + (2 * Fst3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize1) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize1) :: Constraint), Assert (OrdCond (CmpNat 1 (Snd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Snd3 stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize1 - 1) (inputSize1 + (2 * Snd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize1 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize1 + (2 * Snd3 padding))) :: Constraint), Assert (OrdCond (CmpNat 1 kernelSize2) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType kernelSize2) :: Constraint), Assert (OrdCond (CmpNat 1 (Trd3 stride)) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType 1) ':<>: 'Text " <= ") ':<>: 'ShowType (Trd3 stride)) :: Constraint), Assert (OrdCond (CmpNat (kernelSize2 - 1) (inputSize2 + (2 * Trd3 padding))) 'True 'True 'False) (TypeError ((('Text "Cannot satisfy: " ':<>: 'ShowType (kernelSize2 - 1)) ':<>: 'Text " <= ") ':<>: 'ShowType (inputSize2 + (2 * Trd3 padding))) :: Constraint), KnownNat batchSize, KnownNat inputSize2, KnownNat inputSize1, KnownNat inputSize0, KnownNat kernelSize2, KnownNat kernelSize1, KnownNat kernelSize0, KnownNat outputChannelSize, KnownNat inputChannelSize, KnownNat (Trd3 padding), KnownNat (Trd3 stride), KnownNat (Snd3 padding), KnownNat (Snd3 stride), KnownNat (Fst3 padding), KnownNat (Fst3 stride)) => ConvTranspose3d inputChannelSize outputChannelSize kernelSize0 kernelSize1 kernelSize2 w1 w2 -> Tensor w2 w1 '[batchSize, inputChannelSize, inputSize0, inputSize1, inputSize2] -> Tensor w2 w1 '[batchSize, outputChannelSize, Div ((inputSize0 + (2 * Fst3 padding)) - kernelSize0) (Fst3 stride) + 1, Div ((inputSize1 + (2 * Snd3 padding)) - kernelSize1) (Snd3 stride) + 1, Div ((inputSize2 + (2 * Trd3 padding)) - kernelSize2) (Trd3 stride) + 1]
Files
- hasktorch.cabal +8/−8
- src/Torch/Autograd.hs +16/−0
- src/Torch/Typed/Autograd.hs +22/−0
- test/Torch/Typed/FunctionalSpec2.hs +2/−2
hasktorch.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: hasktorch-version: 0.2.1.7+version: 0.2.1.8 synopsis: Haskell bindings to libtorch, supporting both typed and untyped tensors. description: Hasktorch is a library for tensors and neural networks in Haskell. It is an independent open source community project which leverages the core C++ libraries shared by PyTorch. homepage: https://github.com/hasktorch/hasktorch#readme@@ -107,15 +107,15 @@ cpp-options: -D__APPLE__ build-depends: async >= 2.2.5 && < 2.3 , base >= 4.7 && < 5- , libtorch-ffi == 2.0.1.*+ , libtorch-ffi >= 2.0.1.10 && < 2.0.2 , libtorch-ffi-helper == 2.0.0.* , finite-typelits >= 0.1 && < 0.3- , ghc-typelits-extra >= 0.4.6 && < 0.5- , ghc-typelits-knownnat >= 0.7.9 && < 0.8- , ghc-typelits-natnormalise >= 0.7.9 && < 0.8+ , ghc-typelits-extra >= 0.4.6 && < 0.6+ , ghc-typelits-knownnat >= 0.7.9 && < 0.9+ , ghc-typelits-natnormalise >= 0.7.9 && < 0.10 , mtl >= 2.3.1 && < 2.4 , safe-exceptions >= 0.1.7 && < 0.2- , random >= 1.2.1 && < 1.3+ , random >= 1.2.1 && < 1.4 , reflection >= 2.1 && < 2.2 , stm >= 2.5.1 && < 2.6 , JuicyPixels >= 3.3 && < 3.4@@ -131,7 +131,7 @@ , pipes-csv >= 1.4.3 && < 1.5 , lens-family-core >= 2.1.3 && < 2.2 , cassava >= 0.5.3 && < 0.6- , lifted-async >= 0.10.2 && < 0.11+ , lifted-async >= 0.10.2 && < 0.12 , monad-control >= 1.0.3 && < 1.1 , foldl >= 1.4 && < 1.5 , transformers-base >= 0.4.6 && < 0.5@@ -140,7 +140,7 @@ , containers >= 0.6.7 && < 0.8 , inline-c >= 0.9.1 && < 0.10 , vector-sized >= 1.5 && < 1.7- , template-haskell >= 2.20.0 && < 2.23+ , template-haskell >= 2.20.0 && < 2.24 , megaparsec >= 9.5 && < 9.8 , half >= 0.3 && < 0.4 , constraints >= 0.14 && < 0.15
src/Torch/Autograd.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE RecordWildCards #-} module Torch.Autograd where @@ -14,7 +15,9 @@ import qualified Torch.Internal.Managed.Type.Tensor as ATen import qualified Torch.Internal.Type as ATen import Torch.Tensor+import Data.Default.Class + -- | Note: to create an `IndependentTensor` use `makeIndependent`; -- | otherwise, Torch will complain the parameter does not require a gradient. newtype IndependentTensor = IndependentTensor@@ -22,8 +25,21 @@ } deriving (Show, Generic) +data GradOptions = GradOptions+ { keepGraph :: Bool+ , createGraph :: Bool+ , accumulateGrad :: Bool+ }+ deriving (Show)++instance Default GradOptions where+ def = GradOptions True False False+ grad :: Tensor -> [IndependentTensor] -> [Tensor] grad y inputs = unsafePerformIO $ cast2 Torch.Internal.Managed.Autograd.grad y (map toDependent inputs)++gradWithOptions :: GradOptions -> Tensor -> [IndependentTensor] -> [Tensor]+gradWithOptions GradOptions{..} y inputs = unsafePerformIO $ cast5 Torch.Internal.Managed.Autograd.gradWithOptions keepGraph createGraph accumulateGrad y (map toDependent inputs) requiresGrad :: Tensor -> Bool requiresGrad t = unsafePerformIO $ cast1 ATen.tensor_requires_grad t
src/Torch/Typed/Autograd.hs view
@@ -9,6 +9,7 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE NoStarIsType #-}+{-# LANGUAGE RecordWildCards #-} module Torch.Typed.Autograd ( Torch.Typed.Autograd.HasGrad,@@ -28,10 +29,13 @@ import qualified Torch.Tensor as D import Torch.Typed.Parameter import Torch.Typed.Tensor+import Torch.Autograd (GradOptions(..)) + class HasGrad a b | a -> b where -- | calculate gradients of a zero-dimensional tensor with respect to a list of parameters grad :: forall dtype device. Tensor device dtype '[] -> a -> b+ gradWithOptions :: forall dtype device. GradOptions -> Tensor device dtype '[] -> a -> b toDependent :: a -> b @@ -49,6 +53,15 @@ LibTorch.grad loss [Torch.Typed.Autograd.toDependent input]+ gradWithOptions GradOptions{..} loss input =+ head . unsafePerformIO $+ ATen.cast5+ LibTorch.gradWithOptions+ keepGraph+ createGraph+ accumulateGrad+ loss+ [Torch.Typed.Autograd.toDependent input] toDependent = Torch.Typed.Parameter.toDependent instance HasGrad (HList ('[] :: [Type])) (HList ('[] :: [Type])) where@@ -66,6 +79,15 @@ unsafePerformIO $ ATen.cast2 LibTorch.grad+ loss+ (Torch.Typed.Autograd.toDependent inputs)+ gradWithOptions GradOptions{..} loss inputs =+ unsafePerformIO $+ ATen.cast5+ LibTorch.gradWithOptions+ keepGraph+ createGraph+ accumulateGrad loss (Torch.Typed.Autograd.toDependent inputs) toDependent (a :. as) =
test/Torch/Typed/FunctionalSpec2.hs view
@@ -635,8 +635,8 @@ it "solve" $ do let solveShapes = hzip- (Proxy @'[1, 0] :. Proxy @'[1, 2] :. Proxy @'[2, 1] :. Proxy @'[3, 1, 2] :. HNil)- (Proxy @'[1, 1] :. Proxy @'[1, 1] :. Proxy @'[2, 2] :. Proxy @'[3, 1, 1] :. HNil)+ (Proxy @'[1, 2] :. Proxy @'[2, 1] :. Proxy @'[3, 1, 2] :. HNil)+ (Proxy @'[1, 1] :. Proxy @'[2, 2] :. Proxy @'[3, 1, 1] :. HNil) case device of Device {deviceType = CPU, deviceIndex = 0} -> hfoldrM @IO SolveSpec () (hattach cpu (hproduct standardFloatingPointDTypes solveShapes))