# Getting different sentence embeddings when using model on CPU and GPU

**URL:** <https://discuss.huggingface.co/t/getting-different-sentence-embeddings-when-using-model-on-cpu-and-gpu/22159>\
**Category:** Beginners\
**Created:** [August 26, 2022, 12:05pm UTC](https://discuss.huggingface.co/t/getting-different-sentence-embeddings-when-using-model-on-cpu-and-gpu/22159 "2022-08-26T12:05:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![torcher](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@torcher](https://discuss.huggingface.co/u/torcher)\
**Post date:** [August 26, 2022, 12:05pm UTC](https://discuss.huggingface.co/t/getting-different-sentence-embeddings-when-using-model-on-cpu-and-gpu/22159/1 "2022-08-26T12:05:15Z")

</div>

I am trying to get sentence embedding from pretrained Roberta. When I use the model on CPU and GPU, I get two different sentence embeddings. Following is the code snippet:

```auto
from transformers import RobertaConfig, RobertaModel, RobertaTokenizer
import torch
import numpy as np
device = ("cuda" if torch.cuda.is_available() else "cpu")
# Initializing tokenizer
tokenizer = RobertaTokenizer.from_pretrained("roberta-base")

# Initializing a RoBERTa configuration
configuration = RobertaConfig()
configuration.vocab_size = tokenizer.vocab_size

# Initializing a model from the configuration
model = RobertaModel(configuration)
model = model.to(device)
model = model.eval()

with torch.no_grad():
    tokenized_task = tokenizer('random_sentence_check_v000', return_tensors="pt")
    outputs = model(**tokenized_task.to(device))
    embedding = outputs.pooler_output.squeeze(0).cpu().numpy().tolist()

```

I use colab for my experiments. Shouldn’t the embedding be the same as the weights are pretrained?
