Automatic Differentiation based Multi-Mode Ptychography