Every of the functions seems to be batcheable or have batcheable equivalents, so you could just convert it line by line.
But then, it seems that the computation by explicitly constructing the diagonal matrices is excessively inefficient – logdet or inverse are easy for diagonal matrices and hard for general ones – and I would recommend revisiting the maths here. (The GP people do a lot of these calculations, so GPyTorch 1 or my ancient CandleGP 1 will have plenty of examples, even if the latter doesn’t quite have what you want.
It may be convenient to use einsum for the summations.
Best regards
Thomas