Sampling grid - use vector field as input

I have a vector field given by dx, dy changes.
My field has shape [batch, H, W, 2], where 2 corresponds to dx and dy. How can I use this together with grid_sample to warp the image? I can use affine_grid, but not with the field directly. I need to convert the field to mappings, but I don’t know exactly how (without iterating the field value by value and computing position manually, which is slow).

field = some field given by dx, dy

# ?? transform field to be usable with grid_sample ??

out = F.grid_sample(input, field, mode="bilinear", padding_mode="zeros", align_corners=False)

I have also found this extension - GitHub - seung-lab/torchfields: A PyTorch add-on for working with image mappings and displacement fields, including Spatial Transformers, but I am not sure how to use it correctly.