Skip to content

Instantly share code, notes, and snippets.

@takuma104
Last active May 15, 2023 17:23
Show Gist options
  • Save takuma104/de3045680f9647209303695b0d959cb5 to your computer and use it in GitHub Desktop.
Save takuma104/de3045680f9647209303695b0d959cb5 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)}')
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