You could either cherry-pick all PRs for this feature into your 1.5.1 branch, solve all merge conflicts, and rebuild PyTorch or alternatively try to copy-paste the code for this feature into custom classes and treat it as custom functions.
However, what’s the reason you cannot update PyTorch, which seems to be easier?