Since I asked this, I have learned that what I am trying to do is called Sobolev training, and I have indeed found a couple of illustrative implementations using pytorch.
For those interested, see [1706.04859] Sobolev Training for Neural Networks, and two simple applications: GitHub - Tony-Y/PotFit: A PyTorch Example of Potential Fitting, Amit Parag / Sobolev Experiments · GitLab.