xwm.tools¶
Checkpointing and model summaries.
Utilities: checkpointing and model introspection.
Modules:
| Name | Description |
|---|---|
checkpoint |
Saving and loading models. |
summary |
Model introspection. |
Functions:
| Name | Description |
|---|---|
load |
Load parameters from |
load_config |
Read the config sidecar written by |
load_state |
Restore a |
save |
Serialise |
save_state |
Serialise a full |
count_params |
Total number of inexact-array scalars in |
param_bytes |
Bytes occupied by the parameters, at their current dtypes. |
load
¶
Load parameters from path into a model with like's structure.
Build like exactly as the saved model was built (same sizes, same keys
are not required -- only the same shapes).
Source code in xwm/tools/checkpoint.py
load_config
¶
Read the config sidecar written by save.
Source code in xwm/tools/checkpoint.py
load_state
¶
Restore a TrainState.
Build like with Trainer.init() on a freshly constructed model, which
allocates the teacher and optimizer state with the right shapes.
Source code in xwm/tools/checkpoint.py
save
¶
Serialise model to path, optionally with a config sidecar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
destination file; parent directories are created. |
required |
config
|
dict[str, Any] | None
|
JSON-serialisable constructor arguments, written to
|
None
|
Source code in xwm/tools/checkpoint.py
save_state
¶
count_params
¶
Total number of inexact-array scalars in tree.
param_bytes
¶
Bytes occupied by the parameters, at their current dtypes.
summary¶
Note
xwm.tools.summary is both a submodule and the function it exports. The function
is documented here under its canonical path; xwm.tools.summary(...) is the way
to call it.
A parameter-count tree, in the spirit of torchinfo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_depth
|
int
|
how far to descend before summarising a subtree as a total. |
2
|
collapse_lists
|
bool
|
print |
True
|