Closed mar-muel closed 3 years ago
Hello! This is weird, you indeed get a significantly different output. Running your exact code sample above, only changing the device to cuda
yields the same results for me:
tensor([[0.0769]])
tensor([[0.0769]])
Tried it a few times, and I always get the same results - I've added an additional statement to ensure we get the exact same output:
print(torch.allclose(pred1, pred2))
And we do!
I feel this may be a setup issue - would you mind opening trying it on Colab and sharing it if you get the same results so that I can investigate?
Thanks a lot @LysandreJik - Yes, indeed there's no issues on Colab.
I turns out the problem only occurs with PyTorch versions
# pip freeze | grep torch
torch==1.8.1+cu111
torchaudio==0.8.1
torchvision==0.9.1+cu111
But using torch==1.8.1
works fine.
This is the output of my nvidia-smi
:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.80.02 Driver Version: 450.80.02 CUDA Version: 11.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla K80 Off | 00000000:00:04.0 Off | 0 |
| N/A 49C P0 70W / 149W | 0MiB / 11441MiB | 100% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
I created my environment like this:
conda create -n ml python==3.8
conda activate ml
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
pip install transformers
Would you mind checking whether you can reproduce with the above?
I'd really like to understand what's going on here π
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Environment info
transformers
version: 4.5.1Who can help
Information
Model I am using (Bert, XLNet ...): AutoModel
To reproduce
Steps to reproduce the behavior:
Hi all - I've been struggling with inconsistent behavior on CPU vs. GPU.
When running on CPU the following code works as expected:
Output:
But when I change the to cuda by changing the device
I get a significantly different output:
Weirdly the above doesn't happen if I increase the length of my test string:
I'm pretty sure I'm missing something obvious - any help is appreciated! π
Expected behavior
I expect the output of the loaded model to be identical not only on CPU but also on GPU.