Thank you very much for your help. Your suggestion was correct; I have to call contiguous for the input used inside F.batch_norm in order for the codes to work.
Do you know why using channels_last would require the use of contiguous? Thank you.