Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to libtorch v2.0.1 #1085

Merged
merged 31 commits into from Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
42fca1a
updating to libtorch v2.0.1
dfalbel Jul 24, 2023
8d2f7ba
Avoid tests warnings, mostly related to partial argument matching.
dfalbel Jul 25, 2023
04b7095
Rm cuda 11.6
dfalbel Jul 31, 2023
c2259a0
Exclude `torch_symeig` docs as the function itself was removed.
dfalbel Jul 31, 2023
e7d82d2
Fix device printing test.
dfalbel Jul 31, 2023
a68b65b
Remove the `correction` argument from `var` and `std`.
dfalbel Jul 31, 2023
b832051
return_complex is now required when calling stft.
dfalbel Jul 31, 2023
d0e22c3
Fix tensor address checking.
dfalbel Aug 1, 2023
6157631
Fix partial matching.
dfalbel Aug 1, 2023
7b09ae4
Fix shape in test. The matrix input is still suported in some OS's, b…
dfalbel Aug 1, 2023
3ee2b4a
re-document
dfalbel Aug 2, 2023
4d0d6f5
Rm cuda 11.6
dfalbel Aug 2, 2023
13f4d90
Adapt to new MPS callbacks.
dfalbel Aug 2, 2023
e7eb56f
try eval = FALSE
dfalbel Aug 2, 2023
02c9889
Fix warning about unexpected arguments.
dfalbel Aug 2, 2023
b31214e
set eval false
dfalbel Aug 2, 2023
2c7cf4b
remove eval = FALSE
dfalbel Aug 2, 2023
6486ceb
use devel image as the cudnn one has been removed.
dfalbel Aug 3, 2023
8158d15
Actually use this image.
dfalbel Aug 3, 2023
924435d
run on local gpu
dfalbel Aug 3, 2023
b1b5370
maybe match the minor version too?
dfalbel Aug 3, 2023
375bccf
Allow additional architectures.
dfalbel Aug 3, 2023
926a185
set cuda arch before executing
dfalbel Aug 3, 2023
ea5a42a
force cudnn
dfalbel Aug 3, 2023
251a0b8
correctly set var
dfalbel Aug 5, 2023
4255d65
Try forcing cuda architectures.
dfalbel Aug 7, 2023
8d857cf
don't need the '
dfalbel Aug 7, 2023
5de48f3
Try setting all?
dfalbel Aug 7, 2023
a856dab
Specify archs manually.
dfalbel Aug 7, 2023
cae7cff
additional fixes for the GPU.
dfalbel Aug 8, 2023
930d09f
tolerance
dfalbel Aug 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/lantern.yaml
Expand Up @@ -19,7 +19,6 @@ jobs:
- {os: macOS, version: cpu-m1, runner: [self-hosted, m1]}

- {os: ubuntu, version: cpu, runner: ubuntu-latest}
- {os: ubuntu, version: cu11.6, runner: [self-hosted, gce, disk]}
- {os: ubuntu, version: cu11.7, runner: [self-hosted, gce, disk]}

- {os: windows, version: cpu, runner: windows-2019}
Expand All @@ -33,12 +32,9 @@ jobs:

# specify the CUDA patch for each major/minor version.
# required for cuda installation
- config: {version: cu11.6}
cuda: 11.6
cuda_patch: 1
- config: {version: cu11.7}
cuda: 11.7
cuda_patch: 0
cuda_patch: 1

exclude:
- config: {os: macOS}
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/main.yaml
Expand Up @@ -33,8 +33,7 @@ jobs:
- {os: ubuntu, r_version: release, version: cpu, runner: ubuntu-20.04}
# the precxx11abi R version is whichever is specified in the selected container.
- {os: centos, r_version: '', version: cpu, runner: ubuntu-20.04, precxx11abi: 1}
- {os: ubuntu, r_version: release, version: cu11.6, runner: [self-hosted, gce, gpu]}
- {os: ubuntu, r_version: release, version: cu11.7, runner: [self-hosted, gce, gpu]}
- {os: ubuntu, r_version: release, version: cu11.7, runner: [self-hosted, gpu-local]}

- {os: windows, r_version: release, version: cpu, runner: windows-latest}
- {os: windows, r_version: 3.6, version: cpu, runner: windows-latest}
Expand All @@ -43,12 +42,9 @@ jobs:

- config: {os: centos, precxx11abi: 1}
container: rstudio/r-base:4.2-centos7

- config: {os: ubuntu, version: cu11.6}
container: {image: 'nvidia/cuda:11.6.0-cudnn8-devel-ubuntu18.04', options: '--gpus all --runtime=nvidia'}

- config: {os: ubuntu, version: cu11.7}
container: {image: 'nvidia/cuda:11.7.0-cudnn8-devel-ubuntu18.04', options: '--gpus all --runtime=nvidia'}
container: {image: 'nvidia/cuda:11.7.1-cudnn8-devel-ubuntu18.04', options: '--gpus all --runtime=nvidia'}

runs-on: ${{ matrix.config.runner }}
container: ${{ matrix.container }}
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Expand Up @@ -801,7 +801,6 @@ export(torch_sub)
export(torch_subtract)
export(torch_sum)
export(torch_svd)
export(torch_symeig)
export(torch_t)
export(torch_take)
export(torch_tan)
Expand Down
940 changes: 488 additions & 452 deletions R/RcppExports.R

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions R/distributions-multivariate_normal.R
Expand Up @@ -57,12 +57,8 @@
# Ref: https://nbviewer.jupyter.org/gist/fehiepsi/5ef8e09e61604f10607380467eb82006#Precision-to-scale_tril
Lf <- linalg_cholesky(torch_flip(P, c(-2, -1)))
L_inv <- torch_transpose(torch_flip(Lf, c(-2, -1)), -2, -1)
torch_linalg_solve_triangular(
L_inv,
torch_eye(head2(P$shape, -1),
upper = FALSE,
dtype = P$dtype, device = P$device),
)
Id <- torch_eye(head2(P$shape, -1), dtype=P$dtype, device=P$device)
torch_linalg_solve_triangular(L_inv, Id, upper = FALSE)
}

MultivariateNormal <- R6::R6Class(
Expand Down
99 changes: 45 additions & 54 deletions R/gen-method.R
Expand Up @@ -277,39 +277,52 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "_is_zerotensor", function() { args <- list()
Tensor$set("public", "_is_all_true", function() { args <- list()
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor")
nd_args <- "self"
return_types <- list(list('bool'))
return_types <- list(list('Tensor'))
call_c_function(
fun_name = '_is_zerotensor',
fun_name = '_is_all_true',
args = args,
expected_types = expected_types,
nd_args = nd_args,
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "_neg_view", function() { args <- list()
Tensor$set("public", "_is_any_true", function() { args <- list()
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor")
nd_args <- "self"
return_types <- list(list('Tensor'))
call_c_function(
fun_name = '_neg_view',
fun_name = '_is_any_true',
args = args,
expected_types = expected_types,
nd_args = nd_args,
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "_nested_tensor_layer_norm", function(weight, bias, eps) { args <- mget(x = c("weight", "bias", "eps"))
Tensor$set("public", "_is_zerotensor", function() { args <- list()
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", weight = "Tensor", bias = "Tensor", eps = "double")
nd_args <- c("self", "weight", "bias", "eps")
expected_types <- list(self = "Tensor")
nd_args <- "self"
return_types <- list(list('bool'))
call_c_function(
fun_name = '_is_zerotensor',
args = args,
expected_types = expected_types,
nd_args = nd_args,
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "_neg_view", function() { args <- list()
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor")
nd_args <- "self"
return_types <- list(list('Tensor'))
call_c_function(
fun_name = '_nested_tensor_layer_norm',
fun_name = '_neg_view',
args = args,
expected_types = expected_types,
nd_args = nd_args,
Expand Down Expand Up @@ -5269,19 +5282,6 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "prelu_backward", function(grad_output, weight) { args <- mget(x = c("grad_output", "weight"))
args <- c(list(self = self), args)
expected_types <- list(grad_output = "Tensor", self = "Tensor", weight = "Tensor")
nd_args <- c("grad_output", "self", "weight")
return_types <- list(list("Tensor", "Tensor"))
call_c_function(
fun_name = 'prelu_backward',
args = args,
expected_types = expected_types,
nd_args = nd_args,
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "prod", function(dim, keepdim = FALSE, dtype = NULL) { args <- mget(x = c("dim", "keepdim", "dtype"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", dim = c("int64_t", "Dimname"), keepdim = "bool",
Expand Down Expand Up @@ -6417,7 +6417,8 @@ call_c_function(
)})
Tensor$set("public", "squeeze", function(dim) { args <- mget(x = c("dim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", dim = c("int64_t", "Dimname"))
expected_types <- list(self = "Tensor", dim = c("int64_t", "Dimname", "IntArrayRef"
))
nd_args <- c("self", "dim")
return_types <- list(list('Tensor'))
call_c_function(
Expand All @@ -6430,7 +6431,8 @@ call_c_function(
)})
Tensor$set("public", "squeeze_", function(dim) { args <- mget(x = c("dim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", dim = c("int64_t", "Dimname"))
expected_types <- list(self = "Tensor", dim = c("int64_t", "IntArrayRef", "Dimname"
))
nd_args <- c("self", "dim")
return_types <- list(list('Tensor'))
call_c_function(
Expand All @@ -6455,11 +6457,11 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "std", function(dim, correction, unbiased = TRUE, keepdim = FALSE) { args <- mget(x = c("dim", "correction", "unbiased", "keepdim"))
Tensor$set("public", "std", function(dim, unbiased = TRUE, keepdim = FALSE) { args <- mget(x = c("dim", "unbiased", "keepdim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", dim = c("IntArrayRef", "DimnameList"),
correction = "int64_t", unbiased = "bool", keepdim = "bool")
nd_args <- c("self", "dim", "correction")
unbiased = "bool", keepdim = "bool")
nd_args <- c("self", "dim")
return_types <- list(list('Tensor'))
call_c_function(
fun_name = 'std',
Expand Down Expand Up @@ -6642,19 +6644,6 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "symeig", function(eigenvectors = FALSE, upper = TRUE) { args <- mget(x = c("eigenvectors", "upper"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", eigenvectors = "bool", upper = "bool")
nd_args <- "self"
return_types <- list(list("Tensor", "Tensor"))
call_c_function(
fun_name = 'symeig',
args = args,
expected_types = expected_types,
nd_args = nd_args,
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "t", function() { args <- list()
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor")
Expand Down Expand Up @@ -6841,9 +6830,10 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "to_sparse", function(sparse_dim) { args <- mget(x = c("sparse_dim"))
Tensor$set("public", "to_sparse", function(layout = NULL, sparse_dim, blocksize = NULL, dense_dim = NULL) { args <- mget(x = c("layout", "sparse_dim", "blocksize", "dense_dim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", sparse_dim = "int64_t")
expected_types <- list(self = "Tensor", layout = "Layout", sparse_dim = "int64_t",
blocksize = "IntArrayRef", dense_dim = "int64_t")
nd_args <- c("self", "sparse_dim")
return_types <- list(list('Tensor'))
call_c_function(
Expand All @@ -6854,9 +6844,9 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "to_sparse_bsc", function(blocksize) { args <- mget(x = c("blocksize"))
Tensor$set("public", "to_sparse_bsc", function(blocksize, dense_dim = NULL) { args <- mget(x = c("blocksize", "dense_dim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", blocksize = "IntArrayRef")
expected_types <- list(self = "Tensor", blocksize = "IntArrayRef", dense_dim = "int64_t")
nd_args <- c("self", "blocksize")
return_types <- list(list('Tensor'))
call_c_function(
Expand All @@ -6867,9 +6857,9 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "to_sparse_bsr", function(blocksize) { args <- mget(x = c("blocksize"))
Tensor$set("public", "to_sparse_bsr", function(blocksize, dense_dim = NULL) { args <- mget(x = c("blocksize", "dense_dim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", blocksize = "IntArrayRef")
expected_types <- list(self = "Tensor", blocksize = "IntArrayRef", dense_dim = "int64_t")
nd_args <- c("self", "blocksize")
return_types <- list(list('Tensor'))
call_c_function(
Expand All @@ -6880,9 +6870,9 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "to_sparse_csc", function() { args <- list()
Tensor$set("public", "to_sparse_csc", function(dense_dim = NULL) { args <- mget(x = c("dense_dim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor")
expected_types <- list(self = "Tensor", dense_dim = "int64_t")
nd_args <- "self"
return_types <- list(list('Tensor'))
call_c_function(
Expand All @@ -6893,9 +6883,9 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "to_sparse_csr", function() { args <- list()
Tensor$set("public", "to_sparse_csr", function(dense_dim = NULL) { args <- mget(x = c("dense_dim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor")
expected_types <- list(self = "Tensor", dense_dim = "int64_t")
nd_args <- "self"
return_types <- list(list('Tensor'))
call_c_function(
Expand Down Expand Up @@ -7223,11 +7213,11 @@ call_c_function(
return_types = return_types,
fun_type = 'method'
)})
Tensor$set("public", "var", function(dim, correction, unbiased = TRUE, keepdim = FALSE) { args <- mget(x = c("dim", "correction", "unbiased", "keepdim"))
Tensor$set("public", "var", function(dim, unbiased = TRUE, keepdim = FALSE) { args <- mget(x = c("dim", "unbiased", "keepdim"))
args <- c(list(self = self), args)
expected_types <- list(self = "Tensor", dim = c("IntArrayRef", "DimnameList"),
correction = "int64_t", unbiased = "bool", keepdim = "bool")
nd_args <- c("self", "dim", "correction")
unbiased = "bool", keepdim = "bool")
nd_args <- c("self", "dim")
return_types <- list(list('Tensor'))
call_c_function(
fun_name = 'var',
Expand Down Expand Up @@ -7291,7 +7281,8 @@ call_c_function(
)})
Tensor$set("public", "where", function(condition, other) { args <- mget(x = c("condition", "other"))
args <- c(list(self = self), args)
expected_types <- list(condition = "Tensor", self = "Tensor", other = "Tensor")
expected_types <- list(condition = "Tensor", self = "Tensor", other = c("Tensor",
"Scalar"))
nd_args <- c("condition", "self", "other")
return_types <- list(list('Tensor'))
call_c_function(
Expand Down
48 changes: 0 additions & 48 deletions R/gen-namespace-docs.R
Expand Up @@ -5161,59 +5161,11 @@ NULL
#' @export
NULL


#' Symeig
#'
#' @section symeig(input, eigenvectors=False, upper=TRUE) -> (Tensor, Tensor) :
#'
#' This function returns eigenvalues and eigenvectors
#' of a real symmetric matrix `input` or a batch of real symmetric matrices,
#' represented by a namedtuple (eigenvalues, eigenvectors).
#'
#' This function calculates all eigenvalues (and vectors) of `input`
#' such that \eqn{\mbox{input} = V \mbox{diag}(e) V^T}.
#'
#' The boolean argument `eigenvectors` defines computation of
#' both eigenvectors and eigenvalues or eigenvalues only.
#'
#' If it is `FALSE`, only eigenvalues are computed. If it is `TRUE`,
#' both eigenvalues and eigenvectors are computed.
#'
#' Since the input matrix `input` is supposed to be symmetric,
#' only the upper triangular portion is used by default.
#'
#' If `upper` is `FALSE`, then lower triangular portion is used.
#'
#' @note The eigenvalues are returned in ascending order. If `input` is a batch of matrices,
#' then the eigenvalues of each matrix in the batch is returned in ascending order.
#'
#' @note Irrespective of the original strides, the returned matrix `V` will
#' be transposed, i.e. with strides `V.contiguous().transpose(-1, -2).stride()`.
#'
#' @note Extra care needs to be taken when backward through outputs. Such
#' operation is really only stable when all eigenvalues are distinct.
#' Otherwise, `NaN` can appear as the gradients are not properly defined.
#'
#'
#' @param self (Tensor) the input tensor of size \eqn{(*, n, n)} where `*` is zero or more batch dimensions consisting of symmetric matrices.
#' @param eigenvectors (boolean, optional) controls whether eigenvectors have to be computed
#' @param upper (boolean, optional) controls whether to consider upper-triangular or lower-triangular region
#'
#' @name torch_symeig
#'
#' @export
NULL


#' Eig
#'
#' @section eig(input, eigenvectors=False, out=NULL) -> (Tensor, Tensor) :
#'
#' Computes the eigenvalues and eigenvectors of a real square matrix.
#'
#' @note
#' Since eigenvalues and eigenvectors might be complex, backward pass is supported only
#' for [`torch_symeig`]
#'
#'
#' @param self (Tensor) the square matrix of shape \eqn{(n \times n)} for which the eigenvalues and eigenvectors will be computed
Expand Down
23 changes: 0 additions & 23 deletions R/gen-namespace-examples.R
Expand Up @@ -2393,29 +2393,6 @@ NULL
NULL
# -> triangular_solve <-

# -> symeig: 27bc25d51797de06954ef84fde11f765 <-
#'
#' @name torch_symeig
#'
#' @examples
#'
#' a = torch_randn(c(5, 5))
#' a = a + a$t() # To make a symmetric
#' a
#' o = torch_symeig(a, eigenvectors=TRUE)
#' e = o[[1]]
#' v = o[[2]]
#' e
#' v
#' a_big = torch_randn(c(5, 2, 2))
#' a_big = a_big + a_big$transpose(-2, -1) # To make a_big symmetric
#' o = a_big$symeig(eigenvectors=TRUE)
#' e = o[[1]]
#' v = o[[2]]
#' torch_allclose(torch_matmul(v, torch_matmul(e$diag_embed(), v$transpose(-2, -1))), a_big)
NULL
# -> symeig <-

# -> eig: 94b4710518b0b3d3bf08c75dda217258 <-
#'
#' @name torch_eig
Expand Down