Solved by googlebot in post #2 
              
              
                batched matmul pre-expands all “batch” dimensions to same sizes, so w tensor is replicated 1000 times. 
There are two scenarios: 

the operation is expressible with 3d tensors and torch.bmm (backend of matmul)
you’re out of luck, and processing by parts may be required

stub dimension in b suggests …