#!/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}") | |