-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add block_mask & retrain_free features (#775)
Signed-off-by: Zhang, Weiwei1 <[email protected]> Co-authored-by: wenhuach21 <[email protected]>
- Loading branch information
1 parent
e45c022
commit d29aa0f
Showing
10 changed files
with
2,878 additions
and
122 deletions.
There are no files selected for viewing
924 changes: 924 additions & 0 deletions
924
...ples/pytorch/nlp/huggingface_models/language-modeling/pruning/eager/run_clm_no_trainer.py
Large diffs are not rendered by default.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
examples/pytorch/nlp/huggingface_models/language-modeling/pruning/eager/run_llm_pruning.sh
This file contains 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,17 @@ | ||
#!/bin/bash | ||
set -x | ||
python \ | ||
examples/pytorch/nlp/huggingface_models/language-modeling/pruning/eager/run_clm_no_trainer.py \ | ||
--model_name_or_path /path/to/your/model \ | ||
--dataset_name lambada \ | ||
--per_device_train_batch_size 2 \ | ||
--per_device_eval_batch_size 16 \ | ||
--max_train_steps 3002 \ | ||
--weight_decay 0 \ | ||
--block_size 512 \ | ||
--do_prune \ | ||
--auto_slim \ | ||
--output_dir sparse_clm_models/ \ | ||
--target_sparsity 0.2 \ | ||
--pruning_pattern channelx1 \ | ||
--pruning_frequency 500 \ |
33 changes: 33 additions & 0 deletions
33
examples/pytorch/nlp/huggingface_models/language-modeling/pruning/eager/timers.py
This file contains 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,33 @@ | ||
import time | ||
import torch | ||
class CPUTimer: | ||
def __init__(self, timelogs): | ||
self.timelogs = timelogs | ||
|
||
def __enter__(self): | ||
self.start = time.time() | ||
|
||
def __exit__(self): | ||
end = time.time() | ||
self.timelogs.append((end - self.start) * 1000) # ms | ||
|
||
def get_avg_time(self): | ||
return sum(self.timelogs) / len(self.timelogs) | ||
|
||
class GPUTimer: | ||
def __init__(self, timelogs): | ||
self.timelogs = timelogs | ||
|
||
def __enter__(self): | ||
self.start_event = torch.cuda.Event(enable_timing=True) | ||
self.end_event = torch.cuda.Event(enable_timing=True) | ||
self.start_event.record() | ||
|
||
def __exit__(self): | ||
self.end_event.record() | ||
self.end_event.synchronize() | ||
elapsed_time = self.start_event.elapsed_time(self.end_event) | ||
self.timelogs.append(elapsed_time) | ||
|
||
def get_avg_time(self): | ||
return sum(self.timelogs) / len(self.timelogs) |
Oops, something went wrong.