xlm.utils.saving_utils
mkdir_rank_zero_only(dir, exist_ok=True)
Create directory only on rank 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir
|
Path
|
Directory path. |
required |
exist_ok
|
bool
|
If True, do not raise an exception if the directory already exists. Default to True. |
True
|
process_state_dict(state_dict, symbols=0, exceptions=None)
Filter and map model state dict keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_dict
|
Union[OrderedDict, dict]
|
State dict. |
required |
symbols
|
int
|
Determines how many symbols should be cut in the beginning of state dict keys. Default to 0. |
0
|
exceptions
|
Union[str, List[str]]
|
Determines exceptions, i.e. substrings, which keys should not contain. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
OrderedDict |
OrderedDict
|
Filtered state dict. |
save_predictions_from_dataloader(predictions, path)
Save predictions returned by Trainer.predict method for single
dataloader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[Any]
|
Predictions returned by |
required |
path
|
Path
|
Path to predictions. |
required |
save_predictions(predictions, dirname, output_format='json')
Save predictions returned by Trainer.predict method.
Due to LightningDataModule.predict_dataloader return type is
Union[DataLoader, List[DataLoader]], so Trainer.predict method can return
a list of dictionaries, one for each provided batch containing their
respective predictions, or a list of lists, one for each provided dataloader
containing their respective predictions, where each list contains dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
List[Any]
|
Predictions returned by |
required |
dirname
|
str
|
Dirname for predictions. |
required |
output_format
|
str
|
Output file format. It could be |
'json'
|