Automatic Differentiation Based Multi-Mode Ptychography