Skip to content

Instantly share code, notes, and snippets.

@takuma104
Last active May 22, 2023 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuma104/dd7855909af17f3792b3704578c63a26 to your computer and use it in GitHub Desktop.
Save takuma104/dd7855909af17f3792b3704578c63a26 to your computer and use it in GitHub Desktop.
import torch
import safetensors.torch
import sys
def dump_keys(parent, suffix=''):
for k in sorted(parent.keys()):
if isinstance(parent[k], torch.Tensor):
print(f'{suffix}{k} {list(parent[k].shape)} mean={torch.mean(parent[k]):.3g} std={torch.std(parent[k]):.3g}')
else:
dump_keys(parent[k], f'{suffix}{k}.')
if __name__ == '__main__':
fn = sys.argv[1]
if fn.endswith('.safetensors'):
checkpoint = safetensors.torch.load_file(fn)
else:
checkpoint = torch.load(fn)
dump_keys(checkpoint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment