It works just fine for me:
import torch
batch_size, N, M, D, P = 2, 2, 2, 2, 3
A = torch.arange(16).view(batch_size, N, M, D)
B = torch.arange(16, 28).view(batch_size, P, D)
C = torch.zeros(batch_size, N, M, P)
for i in range(batch_size):
    for j in range(N):
        C[i,j] = torch.mm(A[i,j],B[i].transpose(0,1))

F = torch.einsum('bnmd,bpd -> bnmp', [A, B])

print(F.equal(C.long())) # Prints True