Debian Codegraph @

examples/inference/pippy/README.md

raw
1 # Distributed inference examples with PiPPy
2
3 This repo contains a variety of tutorials for using the [PiPPy](https://github.com/PyTorch/PiPPy) pipeline parallelism library with accelerate. You will find examples covering:
4
5 1. How to trace the model using `accelerate.prepare_pippy`
6 2. How to specify inputs based on what the model expects (when to use `kwargs`, `args`, and such)
7 3. How to gather the results at the end.
8
9 ## Installation
10
11 This requires the `main` branch of accelerate (or a version at least 0.27.0), `pippy` version of 0.2.0 or greater, and at least python 3.9. Please install using `pip install .` to pull from the `setup.py` in this repo, or run manually:
12
13 ```bash
14 pip install 'accelerate>=0.27.0' 'torchpippy>=0.2.0'
15 ```
16
17 ## Running code
18
19 You can either use `torchrun` or the recommended way of `accelerate launch` (without needing to run `accelerate config`) on each script:
20
21 ```bash
22 accelerate launch bert.py
23 ```
24
25 Or:
26
27 ```bash
28 accelerate launch --num_processes {NUM_GPUS} bert.py
29 ```
30
31 Or:
32
33 ```bash
34 torchrun --nproc-per-node {NUM_GPUS} bert.py
35 ```
36
37 ## General speedups
38
39 One can expect that PiPPy will outperform native model parallism by a multiplicative factor since all GPUs are running at all times with inputs, rather than one input being passed through a GPU at a time waiting for the prior to finish.
40
41 Below are some benchmarks we have found when using the accelerate-pippy integration for a few models when running on 2x4090's:
42
43 ### Bert
44
45 | | Accelerate/Sequential | PiPPy + Accelerate |
46 |---|---|---|
47 | First batch | 0.2137s | 0.3119s |
48 | Average of 5 batches | 0.0099s | **0.0062s** |
49
50 ### GPT2
51
52 | | Accelerate/Sequential | PiPPy + Accelerate |
53 |---|---|---|
54 | First batch | 0.1959s | 0.4189s |
55 | Average of 5 batches | 0.0205s | **0.0126s** |
56
57 ### T5
58
59 | | Accelerate/Sequential | PiPPy + Accelerate |
60 |---|---|---|
61 | First batch | 0.2789s | 0.3809s |
62 | Average of 5 batches | 0.0198s | **0.0166s** |