[docs] use device-agnostic API instead of cuda (#34913)

add device-agnostic API

Signed-off-by: Lin, Fanli <fanli.lin@intel.com>
This commit is contained in:
Fanli Lin 2024-11-27 01:23:34 +08:00 committed by GitHub
parent 64b73e61f8
commit 6bc0c219c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -73,8 +73,9 @@ Let's demonstrate this process with GPT-2.
```python
from transformers import GPT2LMHeadModel, GPT2TokenizerFast
from accelerate.test_utils.testing import get_backend
device = "cuda"
device, _, _ = get_backend() # automatically detects the underlying device type (CUDA, CPU, XPU, MPS, etc.)
model_id = "openai-community/gpt2-large"
model = GPT2LMHeadModel.from_pretrained(model_id).to(device)
tokenizer = GPT2TokenizerFast.from_pretrained(model_id)