| pth_load | R Documentation |
Reads a .pth file saved by torch.save() into plain R arrays.
No Python and no torch: a checkpoint is a zip of one metadata pickle and one
entry per tensor, and both are read here directly.
pth_load(path, names = NULL)
path |
Path to a |
names |
Optional character vector of tensor names to read. The default
reads all of them. Use |
A named list of numeric arrays, in the checkpoint's own order.
Scalars come back as length-1 vectors; everything else carries a
dim. The attribute "file" carries the path.
PyTorch stores a tensor row-major and R stores an array column-major, so the
same bytes describe transposed arrays in the two languages. The tensors come
back with their dimensions reversed — a PyTorch [768, 256]
weight arrives as a 256 x 768 R matrix — which keeps the elements
where they belong without moving a single one. For a linear layer that is
the happy case: x %*% w is then the layer's own arithmetic, no
transpose needed.
pth_catalogue to list a checkpoint without reading it.
## Not run:
w <- pth_load("model.pth")
dim(w$output_layer.weight)
# just the one tensor
pth_load("model.pth", names = "output_layer.bias")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.