5 Module N_PTH
gullradriel edited this page 2026-10-09 00:55:18 +02:00

PTH: reading the tensors of a PyTorch checkpoint

Structures

Name
struct N_PTH_TENSOR
One tensor of a checkpoint.
struct N_PTH
A checkpoint's tensors.

Functions

Name
N_PTH * n_pth_load(const char * path)
read every tensor of a checkpoint
void n_pth_free(N_PTH ** pth)
release a checkpoint's tensors
const N_PTH_TENSOR * n_pth_find(const N_PTH * pth, const char * name)
find a tensor by its path

Defines

Name
N_PTH_MAX_DIMS
Most dimensions a tensor read may have.

Functions Documentation

function n_pth_load

N_PTH * n_pth_load(
    const char * path
)

read every tensor of a checkpoint

Parameters:

  • path the .pth or .pt file

Return: the tensors, released with n_pth_free(), or NULL when the file is not a checkpoint this reads (not a ZIP, no data.pkl, a pickle it cannot follow, a storage missing or of another type)

function n_pth_free

void n_pth_free(
    N_PTH ** pth
)

release a checkpoint's tensors

Parameters:

  • pth the checkpoint, set to NULL

function n_pth_find

const N_PTH_TENSOR * n_pth_find(
    const N_PTH * pth,
    const char * name
)

find a tensor by its path

Parameters:

  • pth the checkpoint
  • name the path, "state_dict.backbone.0.0.weight"

Return: the tensor, or NULL

Macros Documentation

define N_PTH_MAX_DIMS

#define N_PTH_MAX_DIMS 8

Most dimensions a tensor read may have.