# Intel GPU

[TrainingArguments](/docs/transformers/v5.20.0/en/main_classes/trainer#transformers.TrainingArguments), [Trainer](/docs/transformers/v5.20.0/en/main_classes/trainer#transformers.Trainer), and [Pipeline](/docs/transformers/v5.20.0/en/main_classes/pipelines#transformers.Pipeline) detect Intel GPUs and set the backend to `xpu` automatically.

## Select and order XPUs

You can control which XPUs PyTorch sees and in what order. Prioritize faster XPUs or limit a run to a subset of available XPUs. It works with both [DistributedDataParallel](https://pytorch.org/docs/stable/generated/torch.nn.parallel.DistributedDataParallel.html) and [DataParallel](https://pytorch.org/docs/stable/generated/torch.nn.DataParallel.html), and doesn't require Accelerate or the [DeepSpeed integration](./main_classes/deepspeed).

Use the `ZE_AFFINITY_MASK` environment variable to select XPUs and set their order. Set it on the command line per run, or add it to `~/.bashrc` or another startup config file.

> [!WARNING]
> Avoid exporting environment variables because if you forget how an environment variable was set up, you may silently train on the wrong XPUs. Set the environment variable on the same command line as the training run.

For example, to select XPUs 0 and 2 out of four:

```cli
ZE_AFFINITY_MASK=0,2 torchrun trainer-program.py ...
```

PyTorch sees only XPUs 0 and 2, which are mapped to `xpu:0` and `xpu:1`. To reverse the order (use XPU 2 as `xpu:0` and XPU 0 as `xpu:1`):

```cli
ZE_AFFINITY_MASK=2,0 torchrun trainer-program.py ...
```

Control the order of Intel XPUs with:

```cli
export ZE_ENABLE_PCI_ID_DEVICE_ORDER=1
```

For more on device enumeration and sorting on Intel XPU, see the [Level Zero](https://github.com/oneapi-src/level-zero/blob/master/README.md?plain=1#L87) documentation.

