Skip to content
/ torch Public

❗ This is a read-only mirror of the CRAN R package repository. torch — Tensors and Neural Networks with 'GPU' Acceleration. Homepage: https://torch.mlverse.org/docshttps://github.com/mlverse/torch Report bugs for this package: https://github.com/mlverse/torch/issues

License

Notifications You must be signed in to change notification settings

cran/torch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

torch

Lifecycle: experimental R build status CRAN status Discord

Installation

torch can be installed from CRAN with:

install.packages("torch")

You can also install the development version with:

remotes::install_github("mlverse/torch")

At the first package load additional software will be installed.

Installation with Docker

If you would like to install with Docker, please read following document.

Examples

You can create torch tensors from R objects with the torch_tensor function and convert them back to R objects with as_array.

library(torch)
x <- array(runif(8), dim = c(2, 2, 2))
y <- torch_tensor(x, dtype = torch_float64())
y
#> torch_tensor
#> (1,.,.) = 
#>   0.5955  0.3436
#>   0.4946  0.4344
#> 
#> (2,.,.) = 
#>   0.9322  0.7824
#>   0.6503  0.7516
#> [ CPUDoubleType{2,2,2} ]
identical(x, as_array(y))
#> [1] TRUE

Simple Autograd Example

In the following snippet we let torch, using the autograd feature, calculate the derivatives:

x <- torch_tensor(1, requires_grad = TRUE)
w <- torch_tensor(2, requires_grad = TRUE)
b <- torch_tensor(3, requires_grad = TRUE)
y <- w * x + b
y$backward()
x$grad
#> torch_tensor
#>  2
#> [ CPUFloatType{1} ]
w$grad
#> torch_tensor
#>  1
#> [ CPUFloatType{1} ]
b$grad
#> torch_tensor
#>  1
#> [ CPUFloatType{1} ]

Contributing

No matter your current skills it’s possible to contribute to torch development. See the contributing guide for more information.

About

❗ This is a read-only mirror of the CRAN R package repository. torch — Tensors and Neural Networks with 'GPU' Acceleration. Homepage: https://torch.mlverse.org/docshttps://github.com/mlverse/torch Report bugs for this package: https://github.com/mlverse/torch/issues

Resources

License

Stars

Watchers

Forks

Packages

No packages published