Skip to content

Commit fac2ddb

Browse files
authored
Merge pull request #1492 from rstudio/reexport-dotty
Update backend defaults
2 parents 4c32d21 + 54610e4 commit fac2ddb

File tree

880 files changed

+96
-166607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

880 files changed

+96
-166607
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ jobs:
7575
upgrade: 'TRUE'
7676

7777
- name: Install Keras
78-
run: keras3::install_keras(python_version = '${{ matrix.python }}')
78+
run: |
79+
options(echo = TRUE)
80+
print(sessionInfo())
81+
# print(Sys.info())
82+
print(keras3::op_convert_to_tensor("Hello World!"))
83+
print(reticulate::py_config())
7984
8085
- uses: r-lib/actions/check-r-package@v2
8186
with:

DESCRIPTION

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Depends:
2929
R (>= 4.0)
3030
Imports:
3131
generics (>= 0.0.1),
32-
reticulate (>= 1.40.0.9000),
32+
reticulate (>= 1.41.0),
3333
tensorflow (>= 2.16.0),
3434
tfruns (>= 1.5.2),
3535
magrittr,
@@ -55,5 +55,3 @@ Suggests:
5555
jpeg
5656
RoxygenNote: 7.3.2
5757
VignetteBuilder: knitr
58-
Remotes:
59-
rstudio/reticulate

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
- `dotty::.` is now reexported.
1313

14+
- `%*%` now dispatches to `op_matmul()` for tensorflow tensors, which
15+
has relaxed shape constraints compared to `tf$matmul()`.
16+
1417
## Added compatibility with Keras v3.8.0. User-facing changes:
1518

1619
- New symbols:

R/install.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ install_keras <- function(
3737

3838
# lspci doens't list GPUs on WSL Linux, but nvidia-smi does.
3939
nvidia_smi_listed <- tryCatch(
40-
system("nvidia-smi -L", intern = TRUE),
40+
system("nvidia-smi -L", intern = TRUE, ignore.stderr = TRUE),
4141
warning = function(w) character(),
4242
error = function(e) character()
4343
)
@@ -164,11 +164,11 @@ use_backend <- function(backend, gpu = NA) {
164164
macOS_tensorflow = {
165165

166166
if (is.na(gpu))
167-
gpu <- TRUE
167+
gpu <- FALSE
168168

169169
if (gpu) {
170-
py_require("tensorflow", action = "remove")
171-
py_require(c("tensorflow-macos", "tensorflow-metal"), python_version = "<3.12")
170+
# py_require("tensorflow", action = "remove")
171+
py_require(c("tensorflow", "tensorflow-metal"))
172172
} else {
173173
py_require(action = "remove", c("tensorflow-macos", "tensorflow-metal"))
174174
py_require("tensorflow")
@@ -256,7 +256,7 @@ use_backend <- function(backend, gpu = NA) {
256256

257257
Windows_tensorflow = {
258258
if(isTRUE(gpu)) warning("GPU usage not supported on Windows. Please use WSL.")
259-
py_require("tensorflow")
259+
py_require(c("tensorflow", "numpy<2"))
260260
},
261261

262262
Windows_jax = {
@@ -322,7 +322,7 @@ has_gpu <- function() {
322322

323323
# lspci doens't list GPUs on WSL Linux, but nvidia-smi does.
324324
nvidia_smi_listed <- tryCatch(
325-
system("nvidia-smi -L", intern = TRUE),
325+
system("nvidia-smi -L", intern = TRUE, ignore.stderr = TRUE),
326326
warning = function(w) character(),
327327
error = function(e) character()
328328
)

R/package.R

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,39 @@ keras <- NULL
5252
.onLoad <- function(libname, pkgname) {
5353

5454
# tensorflow:::.onLoad() registers some reticulate class filter hooks
55-
# we need to identify tensors reliably.
55+
# we need to identify tensorflow tensors reliably.
5656
requireNamespace("tensorflow", quietly = TRUE)
5757
maybe_register_S3_methods()
5858

59+
registerS3method("%*%", "tensorflow.tensor", op_matmul, baseenv())
60+
5961
# if KERAS_PYTHON is defined then forward it to RETICULATE_PYTHON
6062
keras_python <- get_keras_python()
6163
if (!is.null(keras_python))
6264
Sys.setenv(RETICULATE_PYTHON = keras_python)
6365

64-
# default backend is tensorflow for now
65-
# the tensorflow R package calls `py_require()` to ensure GPU is usable on Linux
6666
py_require(c(
6767
"keras", "pydot", "scipy", "pandas", "Pillow",
68-
"ipython", "tensorflow_datasets"
68+
"ipython" #, "tensorflow_datasets"
6969
))
7070

71+
# default backend is tensorflow for now
72+
# the tensorflow R package calls `py_require()` to ensure GPU is usable on Linux
73+
# use_backend() includes py_require(action = "remove") calls to undo
74+
# what tensorflow:::.onLoad() did. Keep them in sync!
75+
backend <- Sys.getenv("KERAS_BACKEND", "tensorflow")
76+
gpu <- NA
77+
if (endsWith(backend, "-cpu")) {
78+
gpu <- FALSE
79+
backend <- sub("-cpu$", "", backend)
80+
Sys.setenv("KERAS_BACKEND" = backend)
81+
} else if (endsWith(backend, "-gpu")) {
82+
gpu <- TRUE
83+
backend <- sub("-gpu$", "", backend)
84+
Sys.setenv("KERAS_BACKEND" = backend)
85+
}
86+
use_backend(backend, gpu)
87+
7188
# delay load keras
7289
try(keras <<- import("keras", delay_load = list(
7390

docs/404.html

Lines changed: 0 additions & 105 deletions
This file was deleted.

docs/CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/LICENSE-text.html

Lines changed: 0 additions & 77 deletions
This file was deleted.

docs/apple-touch-icon-120x120.png

-3.69 KB
Binary file not shown.

docs/apple-touch-icon-152x152.png

-5.09 KB
Binary file not shown.

0 commit comments

Comments
 (0)