Get different scores in different machine with the same torch version

Cause the same model and code to get different output on different machines.

Who has encountered the same problem? Or told me why this happens. Thank you.

NumPy gets the right value.

1 Like

This is interesting. I wonder if it could be due to different vectorization implementations being available on the different machines yielding different results.

Can you give us some information about the processor(s) of each machine (e.g., the output of cat /proc/cpuinfo)?
I’m also curious if manually writing the sum to force it to proceed without vectorization produces different results (e.g.,

a = torch.ones(512, 512)
a = a/255
s = 0.0
for i in range(512):
    for j in range(512):
        s += a[i, j]
print(s)
1 Like

Thanks for your reply.

This code:

a = torch.ones(512, 512)
a = a/255
s = 0.0
for i in range(512):
    for j in range(512):
        s += a[i, j]
print(s)

gets the same value(1026.9807) in two machine,but different from (512*512)/255(1028.0156862745098)

The processor information of machine one is:

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 79
model name	: Intel(R) Core(TM) i7-6850K CPU @ 3.60GHz
stepping	: 1
microcode	: 0xb000038
cpu MHz		: 1199.605
cache size	: 15360 KB
physical id	: 0
siblings	: 12
core id		: 0
cpu cores	: 6
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 20
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit
bogomips	: 7195.69
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits physical, 48 bits virtual
power management:

The second machine:

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 85
model name	: Intel(R) Xeon(R) Silver 4114 CPU @ 2.20GHz
stepping	: 4
microcode	: 0x2006a08
cpu MHz		: 800.234
cache size	: 14080 KB
physical id	: 0
siblings	: 20
core id		: 0
cpu cores	: 10
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke md_clear flush_l1d
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa itlb_multihit
bogomips	: 4400.00
clflush size	: 64
cache_alignment	: 64
address sizes	: 46 bits physical, 48 bits virtual
power management:

Interesting, both CPUs have avx2 support and I’m not sure if PyTorch has any avx512 capabilities upstreamed (or in 1.6.0, for that matter). Can you try to see if using double precision initially is a usable workaround? a = torch.ones(512, 512, dtype=torch.float64)

Thanks, looks like a precision issue. The values are very close when using double precision to calculate. 1028.0156862745062 vs 1028.0156862745064.

There is still a problem. I trained my network with float32. The model output is different in the second decimal place in some image (e.g. -0.7769964337348938 vs -0.7643359303474426). Is there any other solution besides modifying the precision?

Are you applying the standard tricks to try to make sure your model training is deterministic/starts from the same random seed etc. across the two machines?

The model was trained once and inference in two different machines(GPU is P100 and K80). Most images have a close output but some of them are different. However, the output is the same when run multi times on the same machine. Does this mean that the reason is not a random seed?Is this caused by the GPU?

If the model is already trained, then it doesn’t sound like the difference is due to random seeds. Are the outputs far enough apart to affect model accuracy measurably? P100 and K80 are different enough that I would expect cuDNN to use different algorithms for operations like convolution which will likely have different numerical behavior.

1 Like

Thank you for all your assistance! I know why this happens.