libtorch-ffi 2.0.1.9 → 2.0.1.10
raw patch · 4 files changed
+18/−11 lines, 4 filesdep −optparse-applicativedep ~template-haskellsetup-changedPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies removed: optparse-applicative
Dependency ranges changed: template-haskell
API changes (from Hackage documentation)
+ Torch.Internal.Managed.Autograd: gradWithOptions :: Bool -> Bool -> Bool -> ForeignPtr Tensor -> ForeignPtr TensorList -> IO (ForeignPtr TensorList)
+ Torch.Internal.Unmanaged.Autograd: gradWithOptions :: CBool -> CBool -> CBool -> Ptr Tensor -> Ptr TensorList -> IO (Ptr TensorList)
Files
- Setup.hs +4/−4
- libtorch-ffi.cabal +5/−3
- src/Torch/Internal/Managed/Autograd.hs +2/−0
- src/Torch/Internal/Unmanaged/Autograd.hs +7/−4
Setup.hs view
@@ -70,7 +70,7 @@ getLibtorchVersion = do mVersion <- lookupEnv "LIBTORCH_VERSION" case mVersion of- Nothing -> return "2.5.0"+ Nothing -> return "2.9.1" Just other -> return other getLocalUserLibtorchDir :: IO FilePath@@ -97,7 +97,7 @@ getCudaFlavor :: IO String getCudaFlavor = do- fromMaybe "cpu" <$> lookupEnv "LIBTORCH_CUDA_VERSION" -- "cpu" | "cu117" | "cu118" | "cu121"+ fromMaybe "cpu" <$> lookupEnv "LIBTORCH_CUDA_VERSION" -- "cpu" | "cu126" | "cu128" | "cu130" ensureLibtorch :: IO (Maybe FilePath) ensureLibtorch = do@@ -188,9 +188,9 @@ , "libtorch-macos-x86_64.zip" ) _ -> error "Unsupported macOS arch" Linux -> case flavor of- "cpu" -> ( "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-" ++ v ++ "%2Bcpu.zip"+ "cpu" -> ( "https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-" ++ v ++ "%2Bcpu.zip" , "libtorch-linux.zip" )- cudaVersion -> ( "https://download.pytorch.org/libtorch/" ++ cudaVersion ++"/libtorch-cxx11-abi-shared-with-deps-" ++ v ++ "%2B" ++ cudaVersion ++ ".zip"+ cudaVersion -> ( "https://download.pytorch.org/libtorch/" ++ cudaVersion ++"/libtorch-shared-with-deps-" ++ v ++ "%2B" ++ cudaVersion ++ ".zip" , "libtorch-linux-" ++ cudaVersion ++ ".zip" ) Windows -> error "Windows not supported by this setup"
libtorch-ffi.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: libtorch-ffi-version: 2.0.1.9+version: 2.0.1.10 -- The prefix(2.0) of this version("2.0.0.0") is the same as libtorch's one. synopsis: Haskell bindings for PyTorch description: This package provides Haskell bindings to libtorch, the C++ library underlying PyTorch, specifically designed for the Hasktorch ecosystem.@@ -155,9 +155,8 @@ build-depends: base >= 4.7 && < 5 , inline-c-cpp >= 0.5.0.2 && < 0.6.0.0 , inline-c >= 0.9.1.10 && < 0.10- , optparse-applicative >= 0.14.3.0 && < 0.19 , containers >= 0.6.7 && < 0.8- , template-haskell >= 2.20.0 && < 2.23+ , template-haskell >= 2.20.0 && < 2.24 , bytestring >= 0.11.5 && < 0.13 , safe-exceptions >= 0.1.7 && < 0.2 , sysinfo >= 0.1.1 && < 0.2@@ -193,6 +192,9 @@ if !flag(gcc) cxx-options: -std=c++17 ghc-options: -optcxx-std=c++17+ else+ cxx-options: -std=c++17+ ghc-options: -optcxx-std=c++17 default-extensions: Strict , StrictData cxx-sources: csrc/hasktorch_finalizer.cpp
src/Torch/Internal/Managed/Autograd.hs view
@@ -14,6 +14,8 @@ grad :: ForeignPtr Tensor -> ForeignPtr TensorList -> IO (ForeignPtr TensorList) grad = _cast2 Unmanaged.grad +gradWithOptions :: Bool -> Bool -> Bool -> ForeignPtr Tensor -> ForeignPtr TensorList -> IO (ForeignPtr TensorList)+gradWithOptions = _cast5 Unmanaged.gradWithOptions makeIndependent :: ForeignPtr Tensor -> CBool -> IO (ForeignPtr Tensor) makeIndependent = _cast2 Unmanaged.makeIndependent
src/Torch/Internal/Unmanaged/Autograd.hs view
@@ -25,7 +25,10 @@ C.include "<ATen/core/functional.h>" grad :: Ptr Tensor -> Ptr TensorList -> IO (Ptr TensorList)-grad y inputs = [C.throwBlock| std::vector<at::Tensor>* {+grad = gradWithOptions 1 0 0++gradWithOptions :: CBool -> CBool -> CBool -> Ptr Tensor -> Ptr TensorList -> IO (Ptr TensorList)+gradWithOptions keepGraph createGraph accumulateGrad y inputs = [C.throwBlock| std::vector<at::Tensor>* { torch::autograd::Variable y = *$(at::Tensor* y); const auto & inputs = *$(std::vector<at::Tensor>* inputs); @@ -59,9 +62,9 @@ auto & engine = torch::autograd::Engine::get_default_engine(); auto outputs = engine.execute(roots, grads,- /*keep_graph=*/true,- /*create_graph=*/false,- /*accumulate_grad=*/false, // https://github.com/pytorch/pytorch/pull/46855+ /*keep_graph=*/$(bool keepGraph),+ /*create_graph=*/$(bool createGraph),+ /*accumulate_grad=*/$(bool accumulateGrad), // https://github.com/pytorch/pytorch/pull/46855 // https://github.com/pytorch/pytorch/issues/46373 output_edges);