torch icon indicating copy to clipboard operation
torch copied to clipboard

Errors when caching torch objects in rmarkdown

Open gavril0 opened this issue 4 months ago • 2 comments

Caching torch objects in Rmarkdown document them give errors (see the issue in knitr repository for more details). The underlying issue is that torch objects are implemented with classes (R6/Rcpp) that use reference semantics.

A possible solution is to save reload the object in each cached chunk. However, torch_save and torch_load work only with torch tensors and torch modules, they don't work with torch datasets and torch dataloaders afaik. Morevover, torch objects can be very big which makes this solution not ideal.

Given the complexity of knitr caching mechanism, it would be great to have some guidelines for torch users (see also here and here).

gavril0 avatar Oct 17 '24 10:10 gavril0