You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To get the model ready for `int8` quantization, use the utility function [`prepare_model_for_int8_training`](https://github.com/huggingface/peft/blob/34027fe813756897767b9a6f19ae7f1c4c7b418c/src/peft/utils/other.py#L35) to handle the following:
180
180
181
-
- casts the `LayerNorm` to full precision (`fp32`) for stability
181
+
- casts all the non `int8` modules to full precision (`fp32`) for stability
182
182
- adds a forward hook to the input embedding layer to calculate the gradients of the input hidden states
183
183
- enables gradient checkpointing for more memory-efficient training
184
-
- casts the output logits to `fp32` for smoother sampling
185
184
186
185
```py
187
186
from peft import prepare_model_for_int8_training
188
187
189
-
model = prepare_model_for_int8_training(model, output_embedding_layer_name="proj_out")
188
+
model = prepare_model_for_int8_training(model)
190
189
```
191
190
192
191
Let's also apply LoRA to the training to make it even more efficient. Load a [`~peft.LoraConfig`] and configure the following parameters:
Copy file name to clipboardexpand all lines: examples/int8_training/Finetune_flan_t5_large_bnb_peft.ipynb
+2-3
Original file line number
Diff line number
Diff line change
@@ -328,10 +328,9 @@
328
328
},
329
329
"source": [
330
330
"Some pre-processing needs to be done before training such an int8 model using `peft`, therefore let's import an utiliy function `prepare_model_for_int8_training` that will: \n",
331
-
"- Cast the layer norm in `float32` for stability purposes\n",
331
+
"- Casts all the non `int8` modules to full precision (`fp32`) for stability\n",
332
332
"- Add a `forward_hook` to the input embedding layer to enable gradient computation of the input hidden states\n",
333
-
"- Enable gradient checkpointing for more memory-efficient training\n",
334
-
"- Cast the output logits in `float32` for smoother sampling during the sampling procedure"
333
+
"- Enable gradient checkpointing for more memory-efficient training"
Copy file name to clipboardexpand all lines: examples/int8_training/Finetune_opt_bnb_peft.ipynb
+2-3
Original file line number
Diff line number
Diff line change
@@ -377,10 +377,9 @@
377
377
"### Prepare model for training\n",
378
378
"\n",
379
379
"Some pre-processing needs to be done before training such an int8 model using `peft`, therefore let's import an utiliy function `prepare_model_for_int8_training` that will: \n",
380
-
"- Cast the layer norm in `float32` for stability purposes\n",
380
+
"- Casts all the non `int8` modules to full precision (`fp32`) for stability\n",
381
381
"- Add a `forward_hook` to the input embedding layer to enable gradient computation of the input hidden states\n",
382
-
"- Enable gradient checkpointing for more memory-efficient training\n",
383
-
"- Cast the output logits in `float32` for smoother sampling during the sampling procedure"
382
+
"- Enable gradient checkpointing for more memory-efficient training"
Copy file name to clipboardexpand all lines: examples/int8_training/peft_bnb_whisper_large_v2_training.ipynb
+3-2
Original file line number
Diff line number
Diff line change
@@ -1133,6 +1133,7 @@
1133
1133
]
1134
1134
},
1135
1135
{
1136
+
"attachments": {},
1136
1137
"cell_type": "markdown",
1137
1138
"id": "bR-_yaEOPsfQ",
1138
1139
"metadata": {
@@ -1141,7 +1142,7 @@
1141
1142
"source": [
1142
1143
"### Post-processing on the model\n",
1143
1144
"\n",
1144
-
"Finally, we need to apply some post-processing on the 8-bit model to enable training, let's freeze all our layers, and cast the layer-norm in `float32` for stability. We also cast the output of the last layer in `float32` for the same reasons."
1145
+
"Finally, we need to apply some post-processing on the 8-bit model to enable training, let's freeze all our layers, and cast all non `int8` layers in `float32` for stability."
0 commit comments