Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,47 @@ with the [contributors guide](https://github.com/pytorch/xla/blob/master/CONTRIB

## Getting Started

Following here are guides for a simple single process, and multi process application.
Multi processing is more complex, and is not compatible with SPMD.
This tutorial does not dive into SPMD. For more on that, check our
[SPMD guide](https://github.com/pytorch/xla/blob/master/docs/source/perf/spmd_basic.md).

### Simple single process

To update your exisitng training loop, make the following changes:

```diff
+import torch_xla as xla
+import torch_xla.core.xla_model as xm

def train(model, training_data, ...):
...
for inputs, labels in train_loader:
+ with xla.step():
inputs, labels = training_data[i]
+ # Transfer data to the XLA device. This happens asynchronously.
+ inputs, labels = training_data.to(inputs.xla.device()), labels.to(xla.device())
optimizer.zero_grad()
outputs = model(inputs)
loss = loss_fn(outputs, labels)
loss.backward()
optimizer.step()

+ xm.mark_step()
...

if __name__ == '__main__':
...
+ # Move the model paramters to your XLA device
+ model.to(xla.device())
train(model, training_data, ...)
...
```

The changes above should get your model to train on the TPU.

### Multi processing

To update your existing training loop, make the following changes:

```diff
Expand Down
Loading