Kernelize refactor (#46520)
* refactor: create kernelize function to refactor code
* fix: patch proper function in kernels test
* refactor: full refactor of the function
* fix: address rocm regression
* doc: update relevant docs
* doc: add missing ref to kernelize
* fix: broken import without torch
* style: ruff format