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
And, of course, if statements are not options due to the project complexity.