Data-Efficient Training of CNNs and Transformers with Coresets: A Stability Perspective