Commit 5f63d7a
authored
[GPTQ][ddp] enabling DDP for GPTQ (vllm-project#2333)
After the changes in
vllm-project/compressed-tensors#572
vllm-project/compressed-tensors#534
vllm-project#2340 we're ready to
start rolling out DDP implementations of various modifiers
# API:
The Api we've landed on attempts to maintain the normal flow with
minimal changes necessary to enable DDP:
1) the user will call torchrun --nproc_per_node==<num_threads> script.py
to start the script
2) the user will initialize the distributed context, (they can use the
helper init_dist to do this)
3) the user will load the model using the new context manager, setting
the device map as outlined
[here](vllm-project/compressed-tensors#572).
(For most users this will be "auto_offload")
4) (optional) the user can partition the dataset at load time using
get_rank_partition or just load as normal and oneshot will partition the
data later (will load 1 copy of dataset into cpu memory for each rank
which may be onerous)
```python
from compressed_tensors.offload import load_offloaded_model, init_dist
init_dist()
with load_offloaded_model():
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, device_map="auto_offload")
...
ds = load_dataset(
DATASET_ID, split=get_rank_partition(DATASET_SPLIT, NUM_CALIBRATION_SAMPLES)
```
# Implementation
Adding the DDP process to GPTQ has relatively straightforward though
optimizing it for speed was a bit trickier. There are 4 steps
1) assigning each module to a rank which it will be compressed by
2) for each module assigned to a rank, having all hessian information
sent by other ranks to the assigned rank
3) each rank compresses the modules that it was assigned
4) broadcast the final quantized values to all ranks
Step 1 required the largest optimization, without any load balancing, we
ran into situations where 1 rank could be doing twice as much work as
another. Thus we implemented basic load balancing and time estimation
that seems to be working well in practice. The other major optimization
was using asynchronous ops for thread to thread communication. Before
these optimizations, 2 thread GPTQ was as fast as 1 thread GPTQ for
llama3-8B, afterward it results in a 27% speedup despite being a
relatively small model.
| model_id | world_size | max_time | max_memory | save_time |
flex_extract | eval_time |
|----------|-------------|----------|------------|-----------|--------------|-----------|
| Meta-Llama-3-8B-Instruct | 1 | 745.03 | 5.82 | 19.57 | 0.7066 | 95.28
|
| Meta-Llama-3-8B-Instruct | 2 | 372.20 | 5.57 | 49.10 | 0.7089 | 95.24
|
| Meta-Llama-3-8B-Instruct | 4 | 264.07 | 5.82 | 52.50 | 0.7180 | 96.74
|
| Qwen3-30B-A3B | 1 | 14207.53 | 6.56 | 748.23 | 0.8704 | 209.93 |
| Qwen3-30B-A3B | 2 | 7018.25 | 6.36 | 696.65 | 0.8810 | 205.89 |
| Qwen3-30B-A3B | 4 | 3694.46 | 6.36 | 723.05 | 0.8832 | 217.62 |
# GPTQ Changes
while validating numerical accuracy of the DDP technique, we noticed
that accuracy improved significantly for each thread added. After some
debugging we realized this was because the existing [hessian
calculation](https://github.com/vllm-project/llm-compressor/pull/2333/changes#diff-18d1319f01629ca65cc54f955dc6177f6dd025f057013932b2ed29842854f3ecL61-L65)
was causing an accumulation of floating point errors. By rewriting the
hessian calculation to sum the intermediate hessians and only divide by
num_samples at the end, we improved the GSM8K evaluation from (.67, .66)
to (.71, .71). You can repro these results
[here](https://github.com/vllm-project/llm-compressor/pull/2333/changes#diff-d31ce0453051853c17ba2a5225b3d1bfab548e095bab0967d6acfd1b3ce1b35d)
---------
Signed-off-by: HDCharles <charlesdavidhernandez@gmail.com>1 parent 881dd46 commit 5f63d7a
6 files changed
Lines changed: 278 additions & 40 deletions
File tree
- examples/quantization_w4a16
- src/llmcompressor
- modifiers/quantization/gptq
- transformers/compression
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
38 | 43 | | |
| |||
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
126 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
127 | 134 | | |
128 | 135 | | |
129 | 136 | | |
| |||
248 | 255 | | |
249 | 256 | | |
250 | 257 | | |
251 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
252 | 261 | | |
253 | 262 | | |
254 | 263 | | |
| |||
263 | 272 | | |
264 | 273 | | |
265 | 274 | | |
266 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
267 | 301 | | |
268 | 302 | | |
269 | 303 | | |
| |||
275 | 309 | | |
276 | 310 | | |
277 | 311 | | |
278 | | - | |
| 312 | + | |
279 | 313 | | |
280 | 314 | | |
281 | | - | |
| 315 | + | |
282 | 316 | | |
283 | 317 | | |
284 | 318 | | |
285 | 319 | | |
286 | 320 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
295 | 365 | | |
296 | 366 | | |
297 | 367 | | |
| |||
Lines changed: 13 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
| 37 | + | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | | - | |
| 64 | + | |
66 | 65 | | |
67 | 66 | | |
68 | 67 | | |
| |||
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
74 | | - | |
| 73 | + | |
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
| |||
91 | 90 | | |
92 | 91 | | |
93 | 92 | | |
94 | | - | |
95 | | - | |
| 93 | + | |
96 | 94 | | |
97 | 95 | | |
98 | 96 | | |
| |||
279 | 277 | | |
280 | 278 | | |
281 | 279 | | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
289 | 288 | | |
290 | 289 | | |
291 | 290 | | |
| |||
Lines changed: 15 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
97 | 99 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | | - | |
103 | | - | |
| 104 | + | |
| 105 | + | |
104 | 106 | | |
105 | | - | |
106 | | - | |
| 107 | + | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
0 commit comments