Whisker and hillock formation are a stress relaxation response in Sn thin films and have become a critical reliability problem in Pb-free electronics. Whiskers grow by diffusion of atoms driven by stress gradients and usually have shallow grains at their roots. Therefore, the local conditions under which surface grains form need to be understood to mitigate whisker growth in Sn thin films. Two possible mechanisms for the nucleation of shallow grains are investigated using finite element simulations: grain boundary migration and pinch-off, and subgrain formation by local lattice rotation. By incorporating the role of localized plasticity, we find that shallow grains do not form by motion and bowing of grain boundaries. The simulations show that deformation-induced lattice rotation creates subgrains close to the thin film surface. These shallow grains form by the local heterogeneity of the strain in Sn polycrystals leading to high dislocation densities that subdivide grains into subgrains that may be potential sites for whisker formation.