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

Inefficient usage of torch.randn() in vision/model_factory.py #2555

Open
perfNerdJK opened this issue Dec 11, 2024 · 0 comments
Open

Inefficient usage of torch.randn() in vision/model_factory.py #2555

perfNerdJK opened this issue Dec 11, 2024 · 0 comments

Comments

@perfNerdJK
Copy link

torch.randn() used here first allocates space for self.batch_size in the host memory and then copies it to the device memory, wasting host-device bandwidth.

As self.batch_size contains random values, we can directly create self.batch_size on the device to bypass this non-sense host-device data copy. The proposed patch is as follows.

-torch.randn((self.batch_size, 3, 224, 224)).to(self.device)
+torch.randn((self.batch_size, 3, 224, 224), device=self.device)

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