pipe.vae.to(memory_format=torch.channels_last) Since dynamic quantization is only limited to the linear layers, convert the appropriate pointwise convolution layers into linear layers to maximize its benefit.   Copied from torchao import swap_conv2d_1x1_to_linear