r/pytorch • u/AlternativeCUDA101 • 8h ago
Differentiable simulations, one per sample, on the GPU, feeding PyTorch without writing them as tensors
Putting physics in a training loop often means running many small simulations that end at different times. Written as tensor code, every simulation keeps running until the last one finishes.
hawk lets you write the step for one sample as a typed Python function. It compiles it for the GPU and the CPU, and gives you its forward and reverse derivatives. eagle then runs a million of them and drops the ones that finish. The result plugs into torch.autograd, and tensors move to and from PyTorch without copies.
It is deliberately not a tensor framework: no layers, no training stack. PyTorch keeps doing that part. With a million samples in double precision that stop at different steps, the simulation part runs 9.8× to 130× faster than the same step written for torch.compile (130× on an H100, 11× on a free Colab T4), and 2.5× to 4.2× faster than an NVIDIA Warp kernel. JAX support is being certified for one of the next patch releases, and I have not benchmarked Triton yet.
Personal project; I work at ESA. There is a notebook that simulates, takes derivatives, and fits a drag coefficient with PyTorch: https://amasat01.github.io