From 733677e6bfe9d2592587666037c18aafe964ec80 Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Tue, 22 Apr 2025 15:00:28 +0200 Subject: [PATCH 1/2] build(website): use mathjax for --- _pkgdown.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index 0fc1d64457..9b2dc7a175 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -2,11 +2,12 @@ url: https://torch.mlverse.org/docs/ destination: docs template: bootstrap: 5 + math-rendering: mathjax bslib: primary: "#7e1f77" params: ganalytics: G-9ZJSKW3L0N - + development: mode: auto @@ -61,11 +62,11 @@ navbar: - text: basic-nn-module href: articles/examples/basic-nn-module.html - text: dataset - href: articles/examples/dataset.html - -reference: + href: articles/examples/dataset.html + +reference: - title: Tensor creation utilities - contents: + contents: - torch_empty - torch_arange - torch_eye @@ -135,7 +136,7 @@ reference: contents: - starts_with("lr_") - title: Datasets - contents: + contents: - starts_with("dataset") - iterable_dataset - starts_with("dataloader") @@ -178,7 +179,7 @@ reference: contents: - starts_with("cuda_") - title: JIT - contents: + contents: - starts_with("jit") - title: Backends contents: From 3c6af283d5e17a3b52b69bfa4968639f6e361433 Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Wed, 28 May 2025 11:25:26 +0200 Subject: [PATCH 2/2] fix: avoid exploding object sizes with sub-modules --- R/nn.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/R/nn.R b/R/nn.R index 7b03918aee..080360f154 100644 --- a/R/nn.R +++ b/R/nn.R @@ -1,6 +1,16 @@ #' @include utils-data.R NULL +default_parent_env = function() { + env = parent.frame(2) + pe = parent.env(env) + if (all(sapply(c(".__active__", "self", "private", "super"), function(field) exists(field, pe)))) { + get("inherit", pe)$parent_env + } else { + env + } +} + get_inherited_classes <- function(inherit) { inherit_class <- inherit$public_fields$.classes # Filter out classes that we eventually add in our normal flow. @@ -496,7 +506,7 @@ is_nn_module <- function(x) { #' @export nn_module <- function(classname = NULL, inherit = nn_Module, ..., private = NULL, active = NULL, - parent_env = parent.frame()) { + parent_env = default_parent_env()) { if (inherits(inherit, "nn_module")) { inherit <- attr(inherit, "module") }