ThArrays
A Julia interface for PyTorch's C++ backend.
Features
ThArrays.Tensor
: PyTorch Tensor as an Array-like data type in JuliaThArrays.ThAD
: AD using PyTorch C++ backendThArrays.TrackerAD
: AD using Tracker.jl and PyTorch C++ backend mixed, on your choiceThArrays.ThJIT
: using TorchScript in Julia
Getting Started
-
Install the package:
] add ThArrays
-
Read the docs here, or
-
Experiment in the Julia REPL directly:
julia> using ThArrays julia> t = Tensor( -rand(3, 3) ) PyTorch.Tensor{Float64, 2}: -0.1428 -0.7099 -0.1446 -0.3447 -0.0686 -0.8287 -0.2692 -0.0501 -0.2092 [ CPUDoubleType{3,3} ] julia> sin(t)^2 + cos(t)^2 PyTorch.Tensor{Float64, 2}: 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 [ CPUDoubleType{3,3} ] julia> ThAD.gradient(x->sum(sin(x)+x^2), rand(3,3)) (PyTorch.Tensor{Float64, 2}: 2.3776 1.5465 2.0206 1.2542 1.2081 2.1156 2.1034 1.1568 2.2599 [ CPUDoubleType{3,3} ] ,) julia>
You can find more examples under the
test
directory.