Skip to content

Commit

Permalink
Step 2.4 Fine Tune model
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Murdaca <[email protected]>
  • Loading branch information
Francesco Murdaca committed Mar 16, 2022
1 parent ef29347 commit 079d001
Show file tree
Hide file tree
Showing 3 changed files with 1,635 additions and 0 deletions.
96 changes: 96 additions & 0 deletions notebooks/demo-nm/fine-tune-model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fine Tune Model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Neural Magic hosts many models, including BERT models sparsified on an English text corpus with a masked language modeling training scheme. These sparse models can then finetune to your dataset like you normally would with a dense model using SparseML and recipes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This import will install a sparsification compatible version of transformers for SparseML.\n",
"from sparseml.transformers import question_answering"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load Dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#TODO: Load dataset."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Fine Tune Model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"question_answering(\n",
" output_dir=\"sparse_quantized_bert-question_answering_squad\",\n",
" model_name_or_path=\"zoo:nlp/masked_language_modeling/bert-base/pytorch/huggingface/wikipedia_bookcorpus/12layer_pruned80_quant-none-vnni\",\n",
" recipe=\"zoo:nlp/masked_language_modeling/bert-base/pytorch/huggingface/wikipedia_bookcorpus/12layer_pruned80_quant-none-vnni?recipe_type=transfer-question_answering\",\n",
" distill_teacher=\"path/to/dense-teacher-trained\",\n",
" dataset_name=\"custom-dataset\",\n",
" do_train=True,\n",
" do_eval=True,\n",
" evaluation_strategy=\"epoch\",\n",
" fp16=True,\n",
" seed=21636,\n",
" per_device_train_batch_size=16,\n",
" per_device_eval_batch_size=24,\n",
" preprocessing_num_workers=6,\n",
" save_strategy=\"epoch\",\n",
" save_total_limit=1\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Store model in ONNX format for deepsparse engine"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
15 changes: 15 additions & 0 deletions overlays/nm-fine-tune/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
sparsezoo = "*"
sparseml = "*"
torch = "<1.9"
boto3 = "*"

[dev-packages]

[requires]
python_version = "3.8"
Loading

0 comments on commit 079d001

Please sign in to comment.