Fix compilation error for torch 2.12+ (#8238)