[`pipeline`] Fix str device issue (#24396)
* fix str device issue
* fixup
* adapt from suggestions
* forward contrib credits from suggestions
* better fix
* added backward compatibility for older PT versions
* final fixes
* oops
* Attempting something with less branching.
---------
Co-authored-by: amyeroberts <amyeroberts@users.noreply.github.com>
Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>