Learn R Programming

ggmlR (version 0.8.4)

pth_catalogue: List the tensors in a PyTorch checkpoint

Description

Reads the metadata of a .pth file --- the tensor names, shapes and dtypes --- without reading the tensors. A checkpoint is a zip holding one pickle of metadata and one entry per tensor, so the catalogue is cheap whatever the file weighs.

Usage

pth_catalogue(path)

Value

A data.frame with one row per tensor and the columns name,

shape (as "a x b"), dtype, n (element count),

bytes, and entry (the zip entry holding the data). The attribute "file" carries the path.

Arguments

path

Path to a .pth file saved by torch.save().

Details

What comes back is the checkpoint's own state_dict order, which is the order the model's modules were built in.

Examples

Run this code
if (FALSE) {
cat <- pth_catalogue("model.pth")
head(cat)
sum(cat$n)          # total parameters
}

Run the code above in your browser using DataLab