Ensured multi-gpu math does not divide by 0 or overshoot n_layers
#1358
+68
−2
n_layers
#1358