File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 6
6
import torch
7
7
import torch .functional as F
8
8
import transformers
9
+ import tqdm
9
10
from datasets import load_dataset
10
11
from transformers import AutoModelForCausalLM , AutoTokenizer
11
12
@@ -162,7 +163,7 @@ def forward(self, x):
162
163
def replace_module (model , name , new_module ):
163
164
if "." in name :
164
165
parent_name = name .rsplit ("." , 1 )[0 ]
165
- child_name = name [len (parent_name ) + 1 :]
166
+ child_name = name [len (parent_name ) + 1 :]
166
167
parent = model .model .get_submodule (parent_name )
167
168
else :
168
169
parent_name = ""
@@ -197,8 +198,11 @@ def quantize_activations(model, calibration_tokens):
197
198
cleanup_memory ()
198
199
199
200
# Calibration.
200
- for row_idx in range (calibration_tokens .shape [0 ]):
201
- _ = model (calibration_tokens [row_idx ].reshape (1 , - 1 ))
201
+ with tqdm .tqdm (total = calibration_tokens .shape [0 ], desc = "Calibrating" ) as pbar :
202
+ for row_idx in range (calibration_tokens .shape [0 ]):
203
+ model (calibration_tokens [row_idx ].reshape (1 , - 1 ))
204
+ torch .cuda .empty_cache ()
205
+ pbar .update (1 )
202
206
203
207
# Replace quantizer with StaticLayer.
204
208
for name , quantizer in model .model .named_modules ():
You can’t perform that action at this time.
0 commit comments