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

Attack on an HF model split into multiple GPUs #798

Open
RealPolitiX opened this issue Aug 2, 2024 · 1 comment
Open

Attack on an HF model split into multiple GPUs #798

RealPolitiX opened this issue Aug 2, 2024 · 1 comment

Comments

@RealPolitiX
Copy link

RealPolitiX commented Aug 2, 2024

Does textattack allow running the attack calculation on a single model doing distributed inference across multiple GPUs?

For example, one can use the argument device_map="auto", which distributes a large model to multiple GPUs, on HuggingFaceModelWrapper. However, it seems that if you split a single instance of a large model onto multiple GPUs, then when doing the attack, such as using attacker.attack_dataset(), then there will be a RuntimeError similar to the following (if two GPUs are present)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cuda:1!

@RealPolitiX RealPolitiX changed the title Attack on HF models split into multiple GPUs Attack on an HF model split into multiple GPUs Aug 2, 2024
@RealPolitiX
Copy link
Author

RealPolitiX commented Aug 11, 2024

Solved this problem by commenting out the following two lines

if torch.cuda.is_available():
     self.attack.cuda_()

in the attacker.py file. It seems that cuda_() is enforcing a specific mapping of the neural network to GPU memory.

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