Skip to content

Commit

Permalink
add scripted greedy decode test
Browse files Browse the repository at this point in the history
  • Loading branch information
evanarlian committed Oct 20, 2022
1 parent 0841cf2 commit 800c964
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
{
"data": {
"text/plain": [
"' And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.'"
"'And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.'"
]
},
"execution_count": 11,
Expand All @@ -254,8 +254,9 @@
}
],
"source": [
"modded_transcribed = modded.greedy_decode(tokens, mel, suppress_blanks, suppress_nonspeech)\n",
"tokenizer.batch_decode(modded_transcribed, skip_special_tokens=True)[0]"
"options = whisper.DecodingOptions(language=\"en\", fp16=False)\n",
"ori_transcribed = whisper.decode(ori, mel, options)\n",
"ori_transcribed[0].text"
]
},
{
Expand All @@ -266,7 +267,7 @@
{
"data": {
"text/plain": [
"'And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.'"
"' And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.'"
]
},
"execution_count": 12,
Expand All @@ -275,17 +276,38 @@
}
],
"source": [
"options = whisper.DecodingOptions(language=\"en\", fp16=False)\n",
"ori_transcribed = whisper.decode(ori, mel, options)\n",
"ori_transcribed[0].text"
"modded_transcribed = modded.greedy_decode(tokens, mel, suppress_blanks, suppress_nonspeech)\n",
"tokenizer.batch_decode(modded_transcribed, skip_special_tokens=True)[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_35928/3722662783.py:1: UserWarning: operator() sees varying value in profiling, ignoring and this should be handled by GUARD logic (Triggered internally at /opt/conda/conda-bld/pytorch_1659484806139/work/torch/csrc/jit/codegen/cuda/parser.cpp:3513.)\n",
" scripted_transcribed = scripted.greedy_decode(tokens, mel, suppress_blanks, suppress_nonspeech)\n"
]
},
{
"data": {
"text/plain": [
"' And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scripted_transcribed = scripted.greedy_decode(tokens, mel, suppress_blanks, suppress_nonspeech)\n",
"tokenizer.batch_decode(scripted_transcribed, skip_special_tokens=True)[0]"
]
},
{
"cell_type": "code",
Expand All @@ -310,7 +332,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -342,7 +364,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -360,7 +382,7 @@
" [0., 0., 0., 0.]], grad_fn=<SubBackward0>)"
]
},
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -371,7 +393,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand All @@ -389,7 +411,7 @@
" [0., 0., 0., 0.]], grad_fn=<SubBackward0>)"
]
},
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -400,7 +422,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -410,7 +432,7 @@
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/evan/Documents/whisper-torchscript/tests.ipynb Cell 25\u001b[0m in \u001b[0;36m<cell line: 12>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/evan/Documents/whisper-torchscript/tests.ipynb#X40sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m \u001b[39mreturn\u001b[39;00m x\n\u001b[1;32m <a href='vscode-notebook-cell:/home/evan/Documents/whisper-torchscript/tests.ipynb#X40sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m net \u001b[39m=\u001b[39m Net()\n\u001b[0;32m---> <a href='vscode-notebook-cell:/home/evan/Documents/whisper-torchscript/tests.ipynb#X40sZmlsZQ%3D%3D?line=11'>12</a>\u001b[0m net\u001b[39m.\u001b[39;49meval()\n",
"\u001b[1;32m/home/evan/Documents/whisper-torchscript/tests.ipynb Cell 25\u001b[0m in \u001b[0;36m<cell line: 12>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/evan/Documents/whisper-torchscript/tests.ipynb#Y134sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m \u001b[39mreturn\u001b[39;00m x\n\u001b[1;32m <a href='vscode-notebook-cell:/home/evan/Documents/whisper-torchscript/tests.ipynb#Y134sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m net \u001b[39m=\u001b[39m Net()\n\u001b[0;32m---> <a href='vscode-notebook-cell:/home/evan/Documents/whisper-torchscript/tests.ipynb#Y134sZmlsZQ%3D%3D?line=11'>12</a>\u001b[0m net\u001b[39m.\u001b[39;49meval()\n",
"File \u001b[0;32m~/miniconda3/envs/ml/lib/python3.9/site-packages/torch/nn/modules/module.py:1858\u001b[0m, in \u001b[0;36mModule.eval\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1842\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39meval\u001b[39m(\u001b[39mself\u001b[39m: T) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m T:\n\u001b[1;32m 1843\u001b[0m \u001b[39mr\u001b[39m\u001b[39m\"\"\"Sets the module in evaluation mode.\u001b[39;00m\n\u001b[1;32m 1844\u001b[0m \n\u001b[1;32m 1845\u001b[0m \u001b[39m This has any effect only on certain modules. See documentations of\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1856\u001b[0m \u001b[39m Module: self\u001b[39;00m\n\u001b[1;32m 1857\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m-> 1858\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtrain(\u001b[39mFalse\u001b[39;49;00m)\n",
"File \u001b[0;32m~/miniconda3/envs/ml/lib/python3.9/site-packages/torch/nn/modules/module.py:1837\u001b[0m, in \u001b[0;36mModule.train\u001b[0;34m(self, mode)\u001b[0m\n\u001b[1;32m 1835\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(mode, \u001b[39mbool\u001b[39m):\n\u001b[1;32m 1836\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mtraining mode is expected to be boolean\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m-> 1837\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtraining \u001b[39m=\u001b[39m mode\n\u001b[1;32m 1838\u001b[0m \u001b[39mfor\u001b[39;00m module \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mchildren():\n\u001b[1;32m 1839\u001b[0m module\u001b[39m.\u001b[39mtrain(mode)\n",
"File \u001b[0;32m~/miniconda3/envs/ml/lib/python3.9/site-packages/torch/nn/modules/module.py:1242\u001b[0m, in \u001b[0;36mModule.__setattr__\u001b[0;34m(self, name, value)\u001b[0m\n\u001b[1;32m 1240\u001b[0m \u001b[39melif\u001b[39;00m modules \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m name \u001b[39min\u001b[39;00m modules:\n\u001b[1;32m 1241\u001b[0m \u001b[39mif\u001b[39;00m value \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m-> 1242\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mcannot assign \u001b[39m\u001b[39m'\u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m as child module \u001b[39m\u001b[39m'\u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 1243\u001b[0m \u001b[39m\"\u001b[39m\u001b[39m(torch.nn.Module or None expected)\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 1244\u001b[0m \u001b[39m.\u001b[39mformat(torch\u001b[39m.\u001b[39mtypename(value), name))\n\u001b[1;32m 1245\u001b[0m modules[name] \u001b[39m=\u001b[39m value\n\u001b[1;32m 1246\u001b[0m \u001b[39melse\u001b[39;00m:\n",
Expand Down

0 comments on commit 800c964

Please sign in to comment.