does this pytorch code have to be fixed so that it gets sent to CUDA? textembeddings =…
- User
does this pytorch code have to be fixed so that it gets sent to CUDA?
codetext_embeddings = self.model.get_text_features(**model_inputs).detach().numpy() - Assistant
Yes, if you want to run your PyTorch code on a GPU, you need to send your model and data to the GPU. Here's how you can modify your code:
First, you need to check if CUDA is available and set your device accordingly:
pythondevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")Then, you need to send your model to the device:
pythonself.model = self.model.to(device)After that, you need to ensure that your input data is also on the same device:
pythonmodel_inputs = {name: tensor.to(device) for name, tensor in model_inputs.items()}Finally, you can get your text embeddings:
pythontext_embeddings = self.model.get_text_features(**model_inputs).detach().cpu().numpy()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.