Accessing model attributes from within DataParallel object

This question may seem a duplicate. I know one can accomplish the question text by using DataParallel.module.attribute. However, If I chose to do so, my code won’t be dynamic enough to accept customized gpu id. For example, consider we have an gpu_id option that defaults to None if the user wants to do DataParallel or the gpu_id otherwise. How can I accept both options if one of them forces me to write the code as DataParallel.module.attribute.

And, of course, if statements are not options due to the project complexity.

Can you give a use case where you are needing this?
I did face such scenarios, but in my case, it was possible to rewrite the model in such a way that all the operations are self-contained within the model so that I didn’t need to use DataParallel.module.attribute. So, I think it depends on your use case.