The repeat calls are to emulate your input matrices. For the actual subtraction, you don’t need repeat, only these lines:
a = tensor_1
b = tensor_2
aT = a.unsqueeze(0) # adds a z-dimension
bTR = b.T.reshape(m, 1, k) 
result = aT - bTR # [m,n,k]