File size: 767 Bytes
b9dffb2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#!/bin/env python
# Define 2 pickletensor files as args.
# Read in keys from the first.
# Compare contents. Print results, for each key
import torch
import sys
import numpy
if len(sys.argv) != 3:
print("Error: expect two filenames")
exit(1)
filename1=sys.argv[1]
filename2=sys.argv[2]
print("loading "+filename1)
model1=torch.load(filename1)
print("loading "+filename2)
model2=torch.load(filename2)
print("done")
def compare_tensor(t1,t2):
if t1.shape != t2.shape:
return "Shape mismatch"
if not numpy.array_equal(t1, t2):
return "NOT equal"
return "equal"
for key in model1.keys():
if key in model2:
print(key,compare_tensor(model1[key],model2[key]))
else:
print(f"{key} only in {filename1}")
|