tensor_checkpoint.bend checks
raw source on the hub · import stelliferous@0.0.4.0/tensor_checkpoint.bend as Tensor_checkpoint
A PyTorch checkpoint: the ZIP archive torch.save writes, whose data.pkl holds the saved object and whose data/<key> entries hold the storages. The saved module tree, or a state dict, gives one tensor per state-dict entry under its PyTorch name, read from its storage in the stored format.
12 imports
import Base import ./storage_bytes.bend as Bytes import ./checkpoint_zip.bend as Archive import ./checkpoint_pickle.bend as Pickle import ./storage_element_format.bend as Formats import ./tensor.bend as Tensors import ./tensor_file.bend as Files import ./tensor_model.bend as Models import ./tensor_view.bend as Views import ./tensor_shape.bend as Shapes import ./storage_copy.bend as Copy import ./storage_buffer.bend as Buffers
Types
type Described source · line 27 · raw
Data
What the pickle says about one state-dict entry: the storage class, the key of its entry, the element offset in the storage, the shape and the axes of the view of the storage, one extent and stride each.
Described@name:String -> @kind:String -> @key:String -> @offset:U32 -> @shape:List<&2, U32> -> @axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> Described
Unusable@name:String -> @detail:String -> Described
type Task source · line 32 · raw
Data
A module still to walk, with the prefix of its tensors' names.
Task@prefix:String -> @module:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> Task
type Loading source · line 35 · raw
Type
Loading@file:File -> @store:0xa2af805348d03b11eb853850859654f6/tensor_model.Store -> @remaining:List<&2, Described> -> Loading
Definitions
def Tensor source · line 18 · raw
Type
def operation source · line 21 · raw
String
def numbers source · line 41 · raw
@items:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> List<&2, U32>
def all_numbers source · line 47 · raw
@items:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> Bool
def prepended source · line 54 · raw
@+extent:U32 -> @+stride:U32 -> @axes:Maybe<&2, List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis>> -> Maybe<&2, List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis>>
The axes of the tensor as the library views them.
def axes_of source · line 59 · raw
@extents:List<&2, U32> -> @strides:List<&2, U32> -> Maybe<&2, List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis>>
def described_layout source · line 66 · raw
@axes:Maybe<&2, List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis>> -> @+name:String -> @+kind:String -> @+key:String -> @+offset:U32 -> @+shape:List<&2, U32> -> Described
def described_numbers source · line 71 · raw
@plain:Bool -> @+name:String -> @+kind:String -> @+key:String -> @+offset:U32 -> @+sizes:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> @+strides:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> Described
def described_storage source · line 77 · raw
@+name:String -> @id:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> @+offset:U32 -> @+sizes:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> @+strides:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> Described
The persistent id of a storage: ('storage', torch.<Kind>Storage, key, location, count).
def described_arguments source · line 83 · raw
@+name:String -> @arguments:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> Described
def described_call source · line 89 · raw
@rebuilt:Bool -> @+name:String -> @arguments:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> Described
def tensor_of source · line 94 · raw
@+name:String -> @value:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> Described
def unwrapped source · line 100 · raw
@parameter:Bool -> @+name:String -> @inner:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> @+whole:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> Described
def described source · line 106 · raw
@+name:String -> @+value:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> Described
A parameter is _rebuild_parameter(tensor, requires_grad, hooks).
def listed source · line 117 · raw
@set:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value>
def named source · line 123 · raw
@names:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> @+name:String -> Bool
def entries_of source · line 129 · raw
@value:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value>
def own source · line 136 · raw
@entries:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> @+prefix:String -> @+excluded:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> @+found:List<&2, Described> -> List<&2, Described>
The tensors of one dictionary, newest first onto the found list; None and the excluded names are skipped.
def children source · line 144 · raw
@entries:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> @+prefix:String -> List<&2, Task>
def state_of source · line 151 · raw
@module:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value>
def walk source · line 157 · raw
@fuel:Nat -> @todo:List<&2, Task> -> @found:List<&2, Described> -> List<&2, Described>
Every module is one step, so the byte count of the pickle bounds the walk.
def plain source · line 168 · raw
@entries:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value> -> @found:List<&2, Described> -> List<&2, Described>
A state dict: names to tensors, in order.
def is_module source · line 174 · raw
@value:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> Bool
def rooted source · line 179 · raw
@module:Bool -> @+fuel:Nat -> @+value:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> List<&2, Described>
def tensors_of source · line 186 · raw
@+fuel:Nat -> @+value:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Value -> List<&2, Described>
The saved object: a module, a checkpoint dictionary whose "model" is one, or a state dict.
def format_classified source · line 193 · raw
@half:Bool -> @bfloat:Bool -> @float:Bool -> @double:Bool -> @long:Bool -> @int:Bool -> Maybe<&2, 0xa2af805348d03b11eb853850859654f6/storage_element_format.Format>
def format_of source · line 203 · raw
@+kind:String -> Maybe<&2, 0xa2af805348d03b11eb853850859654f6/storage_element_format.Format>
def fault source · line 207 · raw
@+path:String -> @+name:String -> @+detail:String -> @shape:List<&2, U32> -> Tensor
def storage_name source · line 210 · raw
@+prefix:List<&2, U32> -> @+key:String -> List<&2, U32>
def bounded source · line 213 · raw
@+count:U32 -> @+width:U32 -> @+offset:U32 -> @+length:U32 -> Bool
def joined source · line 220 · raw
@product:Maybe<&2, U32> -> @rest:Maybe<&2, U32> -> Maybe<&2, U32>
The elements a view reaches from its offset: one past its last address, or none when an extent is zero. None when that does not fit a word.
def last_address source · line 225 · raw
@axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> Maybe<&2, U32>
def reach source · line 230 · raw
@empty:Bool -> @axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> Maybe<&2, U32>
def strided_values source · line 235 · raw
@status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+count:U32 -> @storage:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<F32> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<F32>
def strided source · line 243 · raw
@tensor:Tensor -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+shape:List<&2, U32> -> Tensor
A row-major view is read as the tensor itself. Any other view is read as the elements it reaches and copied through the view into row-major storage.
def rearranged source · line 248 · raw
@pair:Pair(File, Tensor) -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+shape:List<&2, U32> -> Pair(File, Tensor)
def arranged source · line 252 · raw
@row_major:Bool -> @file:File -> @+path:String -> @+shape:List<&2, U32> -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+span:U32 -> @+start:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
def within source · line 261 · raw
@fits:Bool -> @file:File -> @+path:String -> @+name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+span:U32 -> @+start:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
The elements the view reaches lie within the entry.
def spanned source · line 266 · raw
@span:Maybe<&2, U32> -> @file:File -> @+path:String -> @+name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+data:U32 -> @+offset:U32 -> @+length:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
def located source · line 273 · raw
@data:Maybe<&2, U32> -> @file:File -> @+path:String -> @+name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+offset:U32 -> @+length:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
def stored source · line 278 · raw
@pair:Pair(File, Maybe<&2, U32>) -> @+path:String -> @+name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+offset:U32 -> @+length:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
def recorded source · line 282 · raw
@record:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> @file:File -> @+path:String -> @+name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+offset:U32 -> @+format:0xa2af805348d03b11eb853850859654f6/storage_element_format.Format -> IO(Pair(File, Tensor))
def formatted source · line 290 · raw
@format:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/storage_element_format.Format> -> @file:File -> @+path:String -> @+name:String -> @+kind:String -> @+key:String -> @+offset:U32 -> @+shape:List<&2, U32> -> @+axes:List<&2, 0xa2af805348d03b11eb853850859654f6/tensor_view.Axis> -> @+records:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> @+prefix:List<&2, U32> -> IO(Pair(File, Tensor))
def load_one source · line 296 · raw
@described:Described -> @file:File -> @+path:String -> @+records:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> @+prefix:List<&2, U32> -> IO(Pair(File, Tensor))
def name_of source · line 301 · raw
@described:Described -> String
def entered source · line 306 · raw
@pair:Pair(File, Tensor) -> @+name:String -> @store:0xa2af805348d03b11eb853850859654f6/tensor_model.Store -> @remaining:List<&2, Described> -> Loading
def load_all source · line 311 · raw
@fuel:Nat -> @loading:Loading -> @+path:String -> @+records:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> @+prefix:List<&2, U32> -> IO(Loading)
The described tensors are visited last first, so the store lists them in order.
def closed source · line 320 · raw
@loading:Loading -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def refused source · line 326 · raw
@file:File -> @+path:String -> @+detail:String -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def parsed source · line 331 · raw
@outcome:0xa2af805348d03b11eb853850859654f6/checkpoint_pickle.Parsed -> @file:File -> @+path:String -> @+records:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> @+prefix:List<&2, U32> -> @+count:Nat -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def fetched source · line 340 · raw
@outcome:0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Fetched -> @+path:String -> @+records:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> @+prefix:List<&2, U32> -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def pickled source · line 346 · raw
@record:Maybe<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> @file:File -> @+path:String -> @+records:List<&2, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Record> -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def listed_archive source · line 354 · raw
@listing:0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Listing -> @file:File -> @+path:String -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def directory source · line 359 · raw
@pair:Pair(File, 0xa2af805348d03b11eb853850859654f6/checkpoint_zip.Listing) -> @+path:String -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def opened source · line 363 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @+path:String -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
def load source · line 374 · raw
@+path:String -> IO(0xa2af805348d03b11eb853850859654f6/tensor_model.Store)
One tensor per state-dict entry under its PyTorch name. FP16 and BFloat16 values widen exactly; integers round to the nearest FP32. A file that is not a checkpoint gives a store whose every take reports why.