Hi,
You can use .view() on your 4D input to make it a 3D tensor with a batch size of BATCHSIZE * NLAYERS:
A = Variable(FloatTensor(BATCHSIZE,NLAYERS,100,100).normal_(std=1))
A = A.view(BATCHSIZE * NLAYERS, 100, 100)
B = bmm(data,A) # BATCHSIZE * NLAYERS x 42 x 100
B = B.view(BATCHSIZE, NLAYERS, 42, 100) # BATCHSIZE x NLAYERS x 42 x 100