Lightning-AI / Lightning-AI/pytorch-lightning

Support `xser` for saving checkpoints for XLA

Open
#7,969 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

accelerator: tpu feature
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

## 🚀 Feature

```python
import torch_xla.utils.serialization as xser

xser.save(model.state_dict(), path)
```

### Motivation

In case where memory is limited compared to the size of the model parameters, an API is provided that reduces the memory footprint on the host:

```python
import torch_xla.utils.serialization as xser

xser.save(model.state_dict(), path)
```

This API streams XLA tensors to CPU one at a time, reducing the amount of host memory used, but it requires a matching load API to restore:

```python
import torch_xla.utils.serialization as xser

state_dict = xser.load(path)
model.load_state_dict(state_dict)
```

### Pitch

### Alternatives

### Additional context

cc @borda @kaushikb11 @rohitgr7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the torch_xla.utils.serialization API shown in the issue and trace the existing checkpoint serialization path. The work is done when matching save and load APIs support model state dictionaries for XLA while streaming tensors to CPU one at a time to reduce host memory use.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.