Skip to content

Commit

Permalink
feat: Update conversion notebook to include task
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithKyrian committed Sep 4, 2024
1 parent 69089b1 commit ca6fc3b
Showing 1 changed file with 28 additions and 55 deletions.
83 changes: 28 additions & 55 deletions scripts/convert_upload_hf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
"cells": [
{
"cell_type": "markdown",
"source": [
"### Download and Install Dependencies"
],
"metadata": {
"id": "fwxJqHJiiYHX"
}
},
"source": [
"### Download and Install Dependencies"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "_7D67c3Sc7Aa"
},
"outputs": [],
Expand Down Expand Up @@ -49,6 +50,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "foOxhxatc7Ad"
},
"outputs": [],
Expand Down Expand Up @@ -79,6 +81,7 @@
"outputs": [],
"source": [
"model = \"textattack/bert-base-uncased-rotten-tomatoes\" # @param {type:\"string\"}\n",
"task = \"text-classification\" # @param {type:\"string\"}\n",
"user = \"codewithkyrian\" # @param {type:\"string\"}"
]
},
Expand All @@ -96,42 +99,31 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"id": "AZgFlpvdc7Ae"
},
"outputs": [],
"source": [
"os.makedirs(\"models\", exist_ok=True)\n",
"!python convert.py --quantize --model_id $model"
"!python convert.py --quantize --model_id $model --task $task"
]
},
{
"cell_type": "markdown",
"source": [
"### Upload Converted model to 🤗 Hub"
],
"metadata": {
"id": "sZ6Hna1xikyk"
}
},
"source": [
"### Upload Converted model to 🤗 Hub"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "6TWHZV29c7Ae",
"outputId": "06171614-95a7-48c1-822f-5cbbf20ec260"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Repo ID: codewithkyrian/bert-base-uncased-rotten-tomatoes\n"
]
}
],
"id": "6TWHZV29c7Ae"
},
"outputs": [],
"source": [
"model_name = model.split(\"/\")[-1]\n",
"repo_id = f\"{user}/{model_name}\" # new repo id with user\n",
Expand Down Expand Up @@ -178,6 +170,7 @@
"card_meta['library_name'] = \"Transformers PHP\"\n",
"card_meta.setdefault('tags', []) # sometimes, tags key doesn't exist\n",
"card_meta['tags'] += [\"onnx\"]\n",
"card_meta['pipeline_tag'] = task\n",
"card_meta = ModelCardData(**card_meta)"
]
},
Expand All @@ -200,54 +193,34 @@
"{card.text}\n",
"---\n",
"\n",
"Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).\n",
"Note: Having a separate repo for ONNX weights is intended to be a temporary solution until ONNXRuntime gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 69
},
"id": "t364cswtc7Af",
"outputId": "1d4eef30-db03-4c71-baae-de17ee2adef7"
},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"CommitInfo(commit_url='https://huggingface.co/codewithkyrian/bert-base-uncased-rotten-tomatoes/commit/2a2a5c72c5b6365ff17a01c4ec3330566fea3855', commit_message='Upload README.md with huggingface_hub', commit_description='', oid='2a2a5c72c5b6365ff17a01c4ec3330566fea3855', pr_url=None, pr_revision=None, pr_num=None)"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 22
}
],
"id": "t364cswtc7Af"
},
"outputs": [],
"source": [
"ModelCard(content).push_to_hub(repo_id) # push the new model card to the hub"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"colab": {
"provenance": [],
"toc_visible": true
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
}

0 comments on commit ca6fc3b

Please sign in to comment.