-
Notifications
You must be signed in to change notification settings - Fork 453
[Distributed] Extend QuantizationModifier to support distributed activation calibration #2391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Etelis
wants to merge
22
commits into
vllm-project:main
Choose a base branch
from
Etelis:feature/quantization-modifier-ddp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+471
−5
Open
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f60200a
[Distributed] Add distributed utilities for DDP calibration
EtelisIBM c4d630d
[Distributed] Add recompute_qparams_from_observer helper
EtelisIBM 89d1ade
[Distributed] Partition weight calibration across DDP ranks
EtelisIBM ac0cc2a
[Tests] Add unit tests for distributed utilities
EtelisIBM 76cf40f
[Tests] Add multi-GPU integration tests for DDP quantization
EtelisIBM 0f3e1f9
[Examples] Add distributed W8A8 quantization example
EtelisIBM 9975edc
[Distributed] Fix broadcast_module_parameter for CPU-resident models
EtelisIBM 3320812
[Distributed] Refactor DDP activation sync per review feedback
EtelisIBM 87f4b0d
Merge branch 'main' into feature/quantization-modifier-ddp
Etelis 766a70c
Merge remote-tracking branch 'upstream/main' into feature/quantizatio…
EtelisIBM d44c4ab
[Distributed] Address review feedback for DDP activation observer sync
EtelisIBM 5fa31b2
Merge branch 'main' into feature/quantization-modifier-ddp
HDCharles 0e3a843
[Distributed] Use as_broadcastable and simplify moving-average sync
EtelisIBM 82d808c
Merge branch 'feature/quantization-modifier-ddp' of https://github.co…
EtelisIBM d6b3575
Update src/llmcompressor/observers/moving_base.py
Etelis 9680d9e
Merge branch 'main' into feature/quantization-modifier-ddp
Etelis 688b309
Merge branch 'main' into feature/quantization-modifier-ddp
kylesayrs 7f31744
Merge branch 'main' into feature/quantization-modifier-ddp
Etelis 4f80617
Merge branch 'main' into feature/quantization-modifier-ddp
Etelis f959d4b
fix formatting and moving-average test mock path
EtelisIBM 7baf545
Merge branch 'feature/quantization-modifier-ddp' of https://github.co…
EtelisIBM 09e817b
Merge branch 'main' into feature/quantization-modifier-ddp
HDCharles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
examples/big_models_with_sequential_onloading/llama3_8b_w8a8_distributed.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| ############################################################################# | ||
| # Distributed W8A8 quantization example with activation observer sync. | ||
| # run this with `torchrun --nproc_per_node=2 llama3_8b_w8a8_distributed.py` | ||
| # or change nproc_per_node to your desired configuration | ||
| ############################################################################# | ||
|
|
||
| import torch | ||
| from compressed_tensors.offload import dispatch_model, init_dist, load_offloaded_model | ||
| from datasets import load_dataset | ||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
| from llmcompressor import oneshot | ||
| from llmcompressor.datasets.utils import get_rank_partition | ||
| from llmcompressor.modifiers.quantization import QuantizationModifier | ||
|
|
||
| MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
|
|
||
| DATASET_ID = "HuggingFaceH4/ultrachat_200k" | ||
| DATASET_SPLIT = "train_sft" | ||
|
|
||
| NUM_CALIBRATION_SAMPLES = 256 | ||
| MAX_SEQUENCE_LENGTH = 2048 | ||
|
|
||
| ###### DDP MODEL LOAD CHANGE ##### | ||
| init_dist() | ||
| with load_offloaded_model(): | ||
| model = AutoModelForCausalLM.from_pretrained( | ||
| MODEL_ID, dtype="auto", device_map="auto_offload" | ||
| ) | ||
| ################################## | ||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained(MODEL_ID) | ||
|
|
||
| ###### DDP DATA LOAD CHANGE ##### | ||
| ds = load_dataset( | ||
| DATASET_ID, split=get_rank_partition(DATASET_SPLIT, NUM_CALIBRATION_SAMPLES) | ||
| ) | ||
| ################################## | ||
|
|
||
| ds = ds.shuffle(seed=42) | ||
|
|
||
|
|
||
| def preprocess(example): | ||
| return { | ||
| "text": tokenizer.apply_chat_template( | ||
| example["messages"], | ||
| tokenize=False, | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| ds = ds.map(preprocess) | ||
|
|
||
|
|
||
| def tokenize(sample): | ||
| return tokenizer( | ||
| sample["text"], | ||
| padding=False, | ||
| max_length=MAX_SEQUENCE_LENGTH, | ||
| truncation=True, | ||
| add_special_tokens=False, | ||
| ) | ||
|
|
||
|
|
||
| ds = ds.map(tokenize, remove_columns=ds.column_names) | ||
|
|
||
| # QuantizationModifier automatically detects torch.distributed and | ||
| # all-reduces activation observer statistics at layer boundaries | ||
| recipe = [ | ||
| QuantizationModifier(targets="Linear", scheme="W8A8", ignore=["lm_head"]), | ||
| ] | ||
|
|
||
| oneshot( | ||
| model=model, | ||
| dataset=ds, | ||
| recipe=recipe, | ||
| max_seq_length=MAX_SEQUENCE_LENGTH, | ||
| num_calibration_samples=NUM_CALIBRATION_SAMPLES, | ||
| ) | ||
|
|
||
| # Confirm generations of the quantized model look sane. | ||
| print("\n\n") | ||
| print("========== SAMPLE GENERATION ==============") | ||
| dispatch_model(model) | ||
| sample = tokenizer("Hello my name is", return_tensors="pt") | ||
| sample = {key: value.to(model.device) for key, value in sample.items()} | ||
| output = model.generate(**sample, max_new_tokens=100) | ||
| print(tokenizer.decode(output[0])) | ||
| print("==========================================\n\n") | ||
|
|
||
| print("Saving...") | ||
| SAVE_DIR = ( | ||
| MODEL_ID.rstrip("/").split("/")[-1] | ||
| + "-W8A8-DDP" | ||
| + str(torch.distributed.get_world_size()) | ||
| ) | ||
| model.save_pretrained(SAVE_DIR, save_compressed=True) | ||
| tokenizer.save_pretrained(SAVE_DIR) | ||
|
|
||
| torch.distributed.destroy_process_group() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.