Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rf.set_default_device (torch.set_default_device?) before model creation? #1687

Open
albertz opened this issue Feb 10, 2025 · 0 comments
Open

Comments

@albertz
Copy link
Member

albertz commented Feb 10, 2025

Currently rf.set_default_device is called after the model was created. Specifically, we only use rf.set_default_device_ctx(self._device) around the run step, and not otherwise. The model creation happens on CPU, and then we call model.to(device).

I'm not 100% sure anymore about the reasoning for this. I think I did it this way to make sure the initialization stays mostly deterministic and independent of what device you use (e.g. on CUDA, the RNG behaves different, maybe even across CUDA versions). Maybe there could also be other issues.

Note, somewhat related to rf.set_default_device is also torch.set_default_device.

Changing this could potentially break some code now, and the concern about deterministic init still stays valid. But anyway, I want to discuss this. For bigger models, this can be quite some unnecessary overhead at startup.

Maybe some option for this, like global_set_default_device: bool, and if True, it will call rf.set_default_device (and maybe also torch.set_default_device) right in Engine.__init__?

And then also the question: We could introduce a new behavior version and make this enabled by default for the new behavior version?

(cc @NeoLegends)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant