NRDK CLI¶
Usage
The CLI tools use tyro:
- Positional arguments ("required") are passed as positional command line arguments
- Named arguments are passed as flagged command line arguments
nrdk export¶
Export model weights from a full-service checkpoint.
Usage
Take the best checkpoint in results/experiment/version, and export
the model to results/experiment/version/weights.pth:
The model is assumed to be created by
NRDKLightningModule (via pytorch lightning), so has a
state_dict attribute that contains the model weights, where each key
has a leading .model prefix.
- If the
pathpoints to a file, export that checkpoint. - If the
pathis a directory, the directory should have acheckpoints.yamlwith abestkey which specifies the best checkpoint in acheckpoints/directory; the exported model is saved relative to thepath.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to the checkpoint. |
required |
output
|
str
|
path to save the exported weights. |
'weights.pth'
|
Source code in src/nrdk/_cli/export.py
nrdk inspect¶
Inspect a pytorch / pytorch lightning checkpoint.
If the path points to a file, inspect that checkpoint; if it points to a
directory, inspect the most recent checkpoint (by modification time).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to checkpoint file. |
required |
depth
|
int
|
maximum depth to print in the module/parameter tree. |
2
|
weights_only
|
bool
|
allow loading pytorch checkpoints containing custom objects. Note that this allows arbitrary code execution! |
False
|
Source code in src/nrdk/_cli/inspect.py
nrdk upgrade-config¶
Upgrade implementation references in hydra configs.
Usage
First test with a dry run:
If you're happy with what you see, you can then run the actual upgrade:Danger
This is a potentially destructive operation! Always run with
--dry-run first, and make sure that to does not overlap with
any other existing implementations in your configs.
You can also use the upgrade-config tool to check for this overlap
first:
For each valid results directory in the specified
path, search for all _target_ fields in the hydra config, and replace
any occurrences of from with to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
full path name of the implementation to replace. |
required |
to
|
str | None
|
full path name of the implementation to replace with. |
None
|
dry_run
|
bool
|
if |
False
|
path
|
str
|
path to search for results directories. |
'.'
|
follow_symlinks
|
bool
|
whether to follow symlinks when searching for results. |
False
|
Source code in src/nrdk/_cli/upgrade.py
nrdk validate¶
Validate results directories.
For each valid results directory in the specified
path, check that all expected files are present:
| File | Description |
|---|---|
.hydra/config.yaml |
Hydra configuration used for the run. |
checkpoints/last.ckpt |
Last model checkpoint saved during training. |
eval/ |
Directory containing evaluation outputs. |
checkpoints.yaml |
Checkpoint index; absence indicates a crashed run. |
events.out.tfevents.* |
Tensorboard log files. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
path to search for results directories. |
required |
follow_symlinks
|
bool
|
whether to follow symlinks when searching for results. |
False
|
show_all
|
bool
|
show all results instead of just results with missing files. |
False
|