[docs] add xpu device check (#34684)
* add XPU path * use accelerate API * Update docs/source/en/tasks/semantic_segmentation.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> * update more places with accelerate API --------- Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
This commit is contained in:
@@ -689,7 +689,9 @@ Reload the dataset and load an image for inference.
|
||||
We will now see how to infer without a pipeline. Process the image with an image processor and place the `pixel_values` on a GPU:
|
||||
|
||||
```py
|
||||
>>> device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # use GPU if available, otherwise use a CPU
|
||||
>>> from accelerate.test_utils.testing import get_backend
|
||||
# automatically detects the underlying device type (CUDA, CPU, XPU, MPS, etc.)
|
||||
>>> device, _, _ = get_backend()
|
||||
>>> encoding = image_processor(image, return_tensors="pt")
|
||||
>>> pixel_values = encoding.pixel_values.to(device)
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user