How to got opencv warpaffine M from torch affine_grid theta?

I found some discussions about converting known opencv warpaffine matrix to pytorch affine_grid theta, and tried some give solutions (though none of them worked). However, given a known affine_grid, how to transform this theta to the opencv warpaffine M matrix? Any help or suggestions are appreciated.