for reference, here is the code I have written:

After training the model (on my pc):

encoder = encoder.to(cpu).eval()
mock_encoder_input = torch.tensor(np.random.rand(1, 1, 138, 80), dtype=torch.float)
traced_encoder = torch.jit.trace(encoder, mock_encoder_input)
traced_encoder.save(colab_data + "/spectrograms/encoder.pt")


Checking the model outputs on the pc:

encoder(torch.zeros(1, 1, 138, 80, dtype=test_spectrograms.dtype))

with the first 5 scalars in the output tensor being: -7.5927e-01,  1.1893e-02, -6.2612e-03,  5.3497e-03, -3.3745e-02

Checking the model outputs on my Android phone:

IValue spectroTensor = IValue.from(Tensor.fromBlob(new float[(int)(dim0 * dim1 * dim2 * dim3)], tensorShape));
IValue[] encoderResults = encoder.forward(spectroTensor)

with the first 5 scalars in the output tensor being: 0.23662394, -0.41967326, 0.21712059, -0.312757, 0.29841155,