|
45 | 45 | "outputs": [], |
46 | 46 | "source": [ |
47 | 47 | "# install neural-compressor from source\n", |
| 48 | + "import sys\n", |
48 | 49 | "!git clone https://github.com/intel/neural-compressor.git\n", |
49 | 50 | "%cd ./neural-compressor\n", |
50 | | - "!pip install -r requirements.txt\n", |
51 | | - "!python setup.py install\n", |
| 51 | + "!{sys.executable} -m pip install -r requirements.txt\n", |
| 52 | + "!{sys.executable} setup.py install\n", |
52 | 53 | "%cd ..\n", |
53 | 54 | "\n", |
54 | 55 | "# or install stable basic version from pypi\n", |
55 | | - "!pip install neural-compressor" |
| 56 | + "!{sys.executable} -m pip install neural-compressor\n" |
56 | 57 | ] |
57 | 58 | }, |
58 | 59 | { |
|
62 | 63 | "outputs": [], |
63 | 64 | "source": [ |
64 | 65 | "# install other packages used in this notebook.\n", |
65 | | - "!pip install torch>=1.9.0 transformers>=4.16.0 accelerate sympy numpy sentencepiece!=0.1.92 protobuf<=3.20.3 datasets>=1.1.3 scipy scikit-learn Keras-Preprocessing" |
| 66 | + "!{sys.executable} -m pip install -r requirements.txt\n" |
66 | 67 | ] |
67 | 68 | }, |
68 | 69 | { |
|
102 | 103 | " AutoTokenizer,\n", |
103 | 104 | " EvalPrediction,\n", |
104 | 105 | " Trainer,\n", |
105 | | - ")" |
| 106 | + ")\n" |
106 | 107 | ] |
107 | 108 | }, |
108 | 109 | { |
|
114 | 115 | "task_name = 'mrpc'\n", |
115 | 116 | "raw_datasets = load_dataset(\"glue\", task_name)\n", |
116 | 117 | "label_list = raw_datasets[\"train\"].features[\"label\"].names\n", |
117 | | - "num_labels = len(label_list)" |
| 118 | + "num_labels = len(label_list)\n" |
118 | 119 | ] |
119 | 120 | }, |
120 | 121 | { |
|
150 | 151 | " from_tf=False,\n", |
151 | 152 | " config=config,\n", |
152 | 153 | " use_auth_token=None,\n", |
153 | | - ")" |
| 154 | + ")\n" |
154 | 155 | ] |
155 | 156 | }, |
156 | 157 | { |
|
179 | 180 | " result = tokenizer(*args, padding=padding, max_length=max_seq_length, truncation=True)\n", |
180 | 181 | " return result\n", |
181 | 182 | "\n", |
182 | | - "raw_datasets = raw_datasets.map(preprocess_function, batched=True)" |
| 183 | + "raw_datasets = raw_datasets.map(preprocess_function, batched=True)\n" |
183 | 184 | ] |
184 | 185 | }, |
185 | 186 | { |
|
260 | 261 | " assert False, \"No metric returned, Please check inference metric!\"\n", |
261 | 262 | "\n", |
262 | 263 | "def eval_func(model):\n", |
263 | | - " return take_eval_steps(model, trainer)" |
| 264 | + " return take_eval_steps(model, trainer)\n" |
264 | 265 | ] |
265 | 266 | }, |
266 | 267 | { |
|
284 | 285 | "from neural_compressor.config import PostTrainingQuantConfig, TuningCriterion\n", |
285 | 286 | "tuning_criterion = TuningCriterion(max_trials=600)\n", |
286 | 287 | "conf = PostTrainingQuantConfig(approach=\"static\", tuning_criterion=tuning_criterion)\n", |
287 | | - "q_model = fit(model, conf=conf, calib_dataloader=eval_dataloader, eval_func=eval_func)" |
| 288 | + "q_model = fit(model, conf=conf, calib_dataloader=eval_dataloader, eval_func=eval_func)\n" |
288 | 289 | ] |
289 | 290 | }, |
290 | 291 | { |
|
303 | 304 | "outputs": [], |
304 | 305 | "source": [ |
305 | 306 | "# fp32 benchmark\n", |
306 | | - "!python benchmark.py --input_model ./pytorch_model.bin 2>&1|tee fp32_benchmark.log\n", |
| 307 | + "!{sys.executable} benchmark.py --input_model ./pytorch_model.bin 2>&1|tee fp32_benchmark.log\n", |
307 | 308 | "\n", |
308 | 309 | "# int8 benchmark\n", |
309 | | - "!python benchmark.py --input_model ./saved_results/best_model.pt 2>&1|tee int8_benchmark.log\n" |
| 310 | + "!{sys.executable} benchmark.py --input_model ./saved_results/best_model.pt 2>&1|tee int8_benchmark.log\n" |
310 | 311 | ] |
311 | 312 | } |
312 | 313 | ], |
|
0 commit comments