Skip to content

Commit

Permalink
add block_mask & retrain_free features (#775)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang, Weiwei1 <weiwei1.zhang@intel.com>
Co-authored-by: wenhuach21 <108330088+wenhuach21@users.noreply.github.com>
  • Loading branch information
WeiweiZhang1 and wenhuach21 committed Apr 12, 2023
1 parent e45c022 commit d29aa0f
Show file tree
Hide file tree
Showing 10 changed files with 2,878 additions and 122 deletions.

Large diffs are not rendered by default.

@@ -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 \
@@ -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)

0 comments on commit d29aa0f

Please sign in to comment.