Well parameters_to_vector is doing the same thing as your cat operator. So that will be as efficient.
I don’t think you can do anything better really and manual bookkeeping of the values will most likely end up being more expensive that these few large ops.
I am not sure why you need this to be a generator though as you can directly update all the p.grad inplace from this function no?