Skip to content

Commit

Permalink
Remove usage of SparseAutoModel.log_model_load
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoin authored Apr 9, 2024
1 parent d636d35 commit 25c6795
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,11 @@
"model_kwargs = {\"config\": model_config}\n",
"model_kwargs[\"state_dict\"], s_delayed = SparseAutoModel._loadable_state_dict(model_path)\n",
"model = AutoModelForSequenceClassification.from_pretrained(model_path,**model_kwargs,)\n",
"SparseAutoModel.log_model_load(model, model_path, \"student\", s_delayed) # prints metrics on sparsity profile\n",
"\n",
"# initialize teacher using familiar HF AutoModel\n",
"teacher_kwargs = {\"config\": teacher_config}\n",
"teacher_kwargs[\"state_dict\"], t_delayed = SparseAutoModel._loadable_state_dict(teacher_path)\n",
"teacher = AutoModelForSequenceClassification.from_pretrained(teacher_path,**teacher_kwargs,)\n",
"SparseAutoModel.log_model_load(teacher, teacher_path, \"teacher\", t_delayed)"
"teacher = AutoModelForSequenceClassification.from_pretrained(teacher_path,**teacher_kwargs,)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,7 @@
"\n",
"teacher_kwargs = {'config':teacher_config}\n",
"teacher_kwargs[\"state_dict\"], t_delayed = SparseAutoModel._loadable_state_dict(teacher_path)\n",
"teacher = AutoModelForSequenceClassification.from_pretrained(teacher_path, **teacher_kwargs,)\n",
"\n",
"# optional - prints metrics about sparsity profiles of the models\n",
"SparseAutoModel.log_model_load(model, model_path, \"student\", s_delayed)\n",
"SparseAutoModel.log_model_load(teacher, teacher_path, \"teacher\", t_delayed)"
"teacher = AutoModelForSequenceClassification.from_pretrained(teacher_path, **teacher_kwargs,)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,7 @@
"# initialize model using familiar HF AutoModel\n",
"model_kwargs = {\"config\": config}\n",
"model_kwargs[\"state_dict\"], s_delayed = SparseAutoModel._loadable_state_dict(model_path)\n",
"model = AutoModelForSequenceClassification.from_pretrained(model_path, **model_kwargs,)\n",
"\n",
"# prints metrics on sparsity profile\n",
"SparseAutoModel.log_model_load(model, model_path, \"student\", s_delayed)"
"model = AutoModelForSequenceClassification.from_pretrained(model_path, **model_kwargs,)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,11 @@
"model_kwargs = {\"config\": model_config}\n",
"model_kwargs[\"state_dict\"], s_delayed = SparseAutoModel._loadable_state_dict(model_path)\n",
"model = AutoModelForSequenceClassification.from_pretrained(model_path, **model_kwargs,)\n",
"SparseAutoModel.log_model_load(model, model_path, \"student\", s_delayed) # prints metrics on sparsity profile\n",
"\n",
"# initialize teacher using familiar HF AutoModel\n",
"teacher_kwargs = {\"config\": teacher_config}\n",
"teacher_kwargs[\"state_dict\"], t_delayed = SparseAutoModel._loadable_state_dict(teacher_path)\n",
"teacher = AutoModelForSequenceClassification.from_pretrained(teacher_path, **teacher_kwargs,)\n",
"SparseAutoModel.log_model_load(teacher, teacher_path, \"teacher\", t_delayed) # prints metrics on sparsity profile"
"teacher = AutoModelForSequenceClassification.from_pretrained(teacher_path, **teacher_kwargs,)\n"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@
"model_kwargs = {\"config\": config}\n",
"model_kwargs[\"state_dict\"], s_delayed = SparseAutoModel._loadable_state_dict(model_path)\n",
"model = AutoModelForSequenceClassification.from_pretrained(model_path,**model_kwargs,)\n",
"SparseAutoModel.log_model_load(model, model_path, \"student\", s_delayed) # prints metrics on sparsity profile\n",
"\n",
"# FYI: there is a factory function called SparseAutoModel that does the same as above\n",
"# model, teacher = SparseAutoModel.text_classification_from_pretrained_distil(\n",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,7 @@
"# initialize model\n",
"model_kwargs = {\"config\": config}\n",
"model_kwargs[\"state_dict\"], s_delayed = SparseAutoModel._loadable_state_dict(model_path)\n",
"model = AutoModelForTokenClassification.from_pretrained(model_path, **model_kwargs,)\n",
"SparseAutoModel.log_model_load(model, model_path, \"student\", s_delayed) # prints metrics on sparsity profile"
"model = AutoModelForTokenClassification.from_pretrained(model_path, **model_kwargs,)"
]
},
{
Expand Down

0 comments on commit 25c6795

Please sign in to comment.