Skip to content

Commit 346dfad

Browse files
authored
Merge pull request #1531 from rstudio/cran/1.5.0
CRAN release v1.5.0
2 parents 5dfa188 + fe37f37 commit 346dfad

1,748 files changed

Lines changed: 271611 additions & 56970 deletions

File tree

Some content is hidden

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

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: keras3
22
Type: Package
33
Title: R Interface to 'Keras'
4-
Version: 1.4.0.9000
4+
Version: 1.5.0.9000
55
Authors@R: c(
66
person("Tomasz", "Kalinowski", role = c("aut", "cph", "cre"),
77
email = "tomasz@posit.co"),

NEWS.md

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
# keras3 (development version)
22

3-
- Expanded numeric operations with `op_layer_normalization()`, `op_cbrt()`,
4-
`op_corrcoef()`, `op_deg2rad()`, `op_heaviside()`, the new `op_sparse_sigmoid()`
5-
plus matching `activation_sparse_sigmoid()`, and an `attn_logits_soft_cap`
6-
argument for `op_dot_product_attention()`.
3+
# keras3 1.5.0
4+
5+
- `register_keras_serializable()` now updates R layer wrappers to use the
6+
registered class when called.
7+
8+
- Numeric ops now include `op_layer_normalization()`, `op_cbrt()`,
9+
`op_corrcoef()`, `op_deg2rad()`, `op_heaviside()`, `op_sparse_sigmoid()`,
10+
and `activation_sparse_sigmoid()`. `op_dot_product_attention()` gains
11+
`attn_logits_soft_cap`.
712

813
- Added signal window operations: `op_bartlett()`, `op_blackman()`,
914
`op_hamming()`, `op_hanning()`, and `op_kaiser()`.
1015

1116
- Added `loss_categorical_generalized_cross_entropy()` for training with noisy
1217
labels.
1318

14-
- LoRA-enabled layers (`layer_dense()`, `layer_embedding()`, `layer_einsum_dense()`)
15-
gain a `lora_alpha` argument to scale the adaptation delta independently of the
16-
chosen rank.
19+
- LoRA-enabled layers (`layer_dense()`, `layer_embedding()`,
20+
`layer_einsum_dense()`) gain a `lora_alpha` argument to scale the adaptation
21+
delta independently of the chosen rank.
1722

1823
- Added complex-valued helpers: S3 `Arg()` methods for tensors, `op_angle()`,
1924
and conversions `op_view_as_real()` / `op_view_as_complex()`.
2025

2126
- Added the Muon optimizer via `optimizer_muon()`.
2227

23-
- Added elastic deformation utilities for images: `layer_random_elastic_transform()`
24-
and the lower-level `op_image_elastic_transform()`.
28+
- Added elastic deformation utilities for images:
29+
`layer_random_elastic_transform()` and the lower-level
30+
`op_image_elastic_transform()`.
2531

2632
- Added `as.array()` support for `PIL.Image.Image` objects.
2733

2834
- Transposed convolution utilities now follow the latest Keras API:
29-
`op_conv_transpose()` defaults `strides = 1` and the `layer_conv_*_transpose()`
30-
layers expose `output_padding` for precise shape control.
35+
`op_conv_transpose()` defaults to `strides = 1`, and
36+
`layer_conv_*_transpose()` layers expose `output_padding` for precise shape
37+
control.
3138

3239
- `register_keras_serializable()` now returns a registered Python callable,
3340
making it easier to use with bare R functions.
@@ -38,58 +45,62 @@
3845
- `keras_variable()` now accepts a `synchronization` argument for distributed
3946
strategies.
4047

41-
- `layer_layer_normalization()` removes the `rms_scaling` argument.
48+
- `layer_layer_normalization()` now omits the
49+
`rms_scaling` argument.
4250

43-
- Merging layers now capture `...` with tidy dots (fixes #1525).
51+
- Merging layers now capture `...` with tidy dots (#1525).
4452

45-
- Fixed Ops on JAX `_DimExpr` so symbolic shapes survive arithmetic with R
46-
double scalars.
53+
- JAX `_DimExpr` shapes now remain symbolic when combined with R double scalars.
4754

48-
- `layer_reshape()` can now accept `-1` as a sentinel for an automatically calculated axis size.
55+
- `layer_reshape()` now accepts `-1` as a sentinel for an automatically
56+
calculated axis size.
4957

5058
- `layer_torch_module_wrapper()` gains an `output_shape` argument to help Keras
5159
infer shapes when wrapping PyTorch modules.
5260

53-
- `Layer$add_weight()` gains an `overwrite_with_gradient` option and
54-
layers now provide a `symbolic_call()` method.
61+
- `Layer$add_weight()` gains an `overwrite_with_gradient` option, and layers
62+
now provide a `symbolic_call()` method.
5563

56-
- Added `str()` S3 method for Keras Variables.
64+
- Added `str()` S3 method for Keras `Variable`s.
5765

58-
- Added S3 methods for JAX array:
59-
`str()`, `as.array()`, `as.double()`, `as.integer()`, `as.numeric()`.
66+
- JAX arrays now have S3 methods for `str()`, `as.array()`, `as.double()`,
67+
`as.integer()`, and `as.numeric()`.
6068

61-
- Added base-array compatibility methods for backend tensors: `t()`,
62-
`aperm()`, and `all.equal()`.
69+
- Backend tensors now support base array helpers: `t()`, `aperm()`, and
70+
`all.equal()`.
6371

64-
- Added `pillar::type_sum()` for JAX variables and `JaxVariable`;
65-
extended `str()` coverage to the new JAX variable class.
72+
- Added `pillar::type_sum()` for JAX variables and `JaxVariable`; `str()` now
73+
covers the new JAX variable class.
6674

67-
- `config_max_epochs()`, `config_set_max_epochs()`, `config_max_steps_per_epoch()`,
68-
and `config_set_max_steps_per_epoch()`. The caps can also be set via the
69-
`KERAS_MAX_EPOCHS` and `KERAS_MAX_STEPS_PER_EPOCH` environment variables.
70-
Added `config_is_nnx_enabled()` to check whether JAX NNX features are enabled.
75+
- Added training caps via `config_max_epochs()`, `config_set_max_epochs()`,
76+
`config_max_steps_per_epoch()`, and `config_set_max_steps_per_epoch()`. The
77+
caps can also be set via the `KERAS_MAX_EPOCHS` and
78+
`KERAS_MAX_STEPS_PER_EPOCH` environment variables. Added
79+
`config_is_nnx_enabled()` to check whether JAX NNX features are enabled.
7180

7281
- Built-in dataset loaders now accept `convert = FALSE` to return NumPy arrays
7382
instead of R arrays.
7483

75-
- Updated `plot(history, theme_bw = TRUE)` for `ggplot2` 3.4.0
76-
compatibility.
84+
- `plot(history, theme_bw = TRUE)` is now compatible with `ggplot2` 3.4.0.
7785

78-
- `plot(model)` DPI is now globally configurable via
79-
`options(keras.plot.model.dpi = )`, (defaults to `200`).
86+
- `plot(model)` now reads DPI from `options(keras.plot.model.dpi = 200)`
87+
(default is 200).
8088

8189
- Reexported reticulate functions: `py_help()`, `py_to_r()`, `r_to_py()`,
8290
`py_require()`, and `import()`.
8391

84-
- Support `super()$initialize()` in subclassed Keras classes; improved
85-
`super()` behavior in subclasses.
92+
- `super()$initialize()` now works in subclassed Keras classes, and `super()`
93+
behavior is improved in subclasses.
94+
95+
- `use_backend("jax", gpu = TRUE)` now declares dependencies compatible with
96+
`keras-hub`.
8697

87-
- Updated dependencies declared by `use_backend("jax", gpu=TRUE)`
88-
for compatability with `keras-hub`.
98+
- Exported `named_list()`.
8999

90-
- Exported `named_list()` utility.
100+
- Switching backends twice in a row now works reliably.
91101

92-
- Fixed an issue when switching backends twice in a row.
102+
- `layer_dropout()` now preserves `noise_shape` as an integer array so
103+
length-one shapes are passed to Keras as iterables.
93104

94105
# keras3 1.4.0
95106

R/datasets.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ dataset_cifar100 <- function(label_mode = c("fine", "coarse"), convert = TRUE) {
108108
#'
109109
#' ```
110110
#' train/
111-
#' ├─ x
112-
#' └─ y
111+
#' - x
112+
#' - y
113113
#' test/
114-
#' ├─ x
115-
#' └─ y
114+
#' - x
115+
#' - y
116116
#' ```
117117
#'
118118
#' The `x` data includes integer sequences. If the `num_words` argument was
@@ -195,11 +195,11 @@ dataset_imdb_word_index <- function(path = "imdb_word_index.json") {
195195
#'
196196
#' ```
197197
#' train/
198-
#' ├─ x
199-
#' └─ y
198+
#' - x
199+
#' - y
200200
#' test/
201-
#' ├─ x
202-
#' └─ y
201+
#' - x
202+
#' - y
203203
#' ```
204204
#'
205205
#' ```{r reuters-str-true}
@@ -278,8 +278,8 @@ dataset_mnist <- function(path = "mnist.npz", convert = TRUE) {
278278
#' Loads the California Housing dataset.
279279
#'
280280
#' @description
281-
#' This dataset was obtained from the [StatLib repository](
282-
#' https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html).
281+
#' This dataset was obtained from the StatLib repository
282+
#' (`https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html`).
283283
#'
284284
#' It's a continuous regression dataset with 20,640 samples with
285285
#' 8 features each.

R/layers-regularization.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function (object, l1 = 0, l2 = 0, ...)
9797
layer_dropout <-
9898
function (object, rate, noise_shape = NULL, seed = NULL, ...)
9999
{
100-
args <- capture_args(list(noise_shape = as_integer, seed = as_integer,
100+
args <- capture_args(list(noise_shape = normalize_shape, seed = as_integer,
101101
input_shape = normalize_shape, batch_size = as_integer,
102102
batch_input_shape = normalize_shape), ignore = "object")
103103
create_layer(keras$layers$Dropout, object, args)
@@ -150,7 +150,7 @@ function (object, rate, noise_shape = NULL, seed = NULL, ...)
150150
layer_alpha_dropout <-
151151
function (object, rate, noise_shape = NULL, seed = NULL, ...)
152152
{
153-
args <- capture_args(list(noise_shape = as_integer_array, seed = as_integer,
153+
args <- capture_args(list(noise_shape = normalize_shape, seed = as_integer,
154154
input_shape = normalize_shape, batch_size = as_integer,
155155
batch_input_shape = normalize_shape), ignore = "object")
156156
create_layer(keras$layers$AlphaDropout, object, args)

R/model-persistence.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ function (object, filepath, call_endpoint = "serve", call_training_endpoint = NU
565565
#' # Note that `'my_package'` is used as the `package` argument here, and since
566566
#' # the `name` argument is not provided, `'MyDense'` is used as the `name`.
567567
#' layer_my_dense <- Layer("MyDense")
568-
#' register_keras_serializable(layer_my_dense, package = "my_package")
568+
#' layer_my_dense <-
569+
#' register_keras_serializable(layer_my_dense, package = "my_package")
569570
#'
570571
#' MyDense <- environment(layer_my_dense)$`__class__` # the python class obj
571572
#' stopifnot(exprs = {
@@ -605,7 +606,18 @@ function (object, name = NULL, package = NULL)
605606
c("", "base", "R_GlobalEnv"), "Custom")
606607

607608
keras$saving$register_keras_serializable(package, name)(py_object)
608-
py_object
609+
# Try to update a wrapper, e.g., returned by `Layer()`
610+
if(is.function(object) && exists("__class__", env <- environment(object))) {
611+
old_py_object <- get("__class__", env)
612+
for(nm in names(env)) {
613+
if(identical(get(nm, env), old_py_object))
614+
assign(nm, py_object, env)
615+
}
616+
object
617+
} else {
618+
# return the registered py_object
619+
py_object
620+
}
609621
}
610622

611623

0 commit comments

Comments
 (0)