{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# GPU Environment PyTorch" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "This tutorial is available as an IPython notebook at [malaya-speech/example/gpu-environment-pytorch](https://github.com/huseinzol05/malaya-speech/tree/master/example/gpu-environment-pytorch).\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ['CUDA_VISIBLE_DEVICES'] = '1'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "`pyaudio` is not available, `malaya_speech.streaming.stream` is not able to use.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 3.29 s, sys: 3.78 s, total: 7.08 s\n", "Wall time: 3.09 s\n" ] } ], "source": [ "%%time\n", "\n", "import malaya_speech\n", "import logging\n", "logging.basicConfig(level = logging.INFO)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### List available GPU\n", "\n", "**You must install Pytorch GPU version first to enable GPU hardware acceleration**." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import torch\n", "\n", "torch.cuda.device_count()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Run model inside GPU\n", "\n", "Once you initiate `cuda` method from pytorch object, all inputs will auto cast to `cuda`." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO:malaya_speech.stt:for `malay-fleur102` language, tested on FLEURS102 `ms_my` test set, https://github.com/huseinzol05/malaya-speech/tree/master/pretrained-model/prepare-stt\n", "INFO:malaya_speech.stt:for `malay-malaya` language, tested on malaya-speech test set, https://github.com/huseinzol05/malaya-speech/tree/master/pretrained-model/prepare-stt\n", "INFO:malaya_speech.stt:for `singlish` language, tested on IMDA malaya-speech test set, https://github.com/huseinzol05/malaya-speech/tree/master/pretrained-model/prepare-stt\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Size (MB)malay-malayamalay-fleur102singlishLanguage
mesolitica/wav2vec2-xls-r-300m-mixed1180{'WER': 0.194655128, 'CER': 0.04775798, 'WER-L...{'WER': 0.2373861259, 'CER': 0.07055478, 'WER-...{'WER': 0.127588595, 'CER': 0.0494924979, 'WER...[malay, singlish]
mesolitica/wav2vec2-xls-r-300m-mixed-v21180{'WER': 0.154782923, 'CER': 0.035164031, 'WER-...{'WER': 0.2013994374, 'CER': 0.0518170369, 'WE...{'WER': 0.2258822139, 'CER': 0.082982312, 'WER...[malay, singlish]
mesolitica/wav2vec2-xls-r-300m-12layers-ms657{'WER': 0.1494983789, 'CER': 0.0342059992, 'WE...{'WER': 0.217107489, 'CER': 0.0546614199, 'WER...NaN[malay]
mesolitica/wav2vec2-xls-r-300m-6layers-ms339{'WER': 0.22481538553, 'CER': 0.0484392694, 'W...{'WER': 0.38642364985, 'CER': 0.0928960677, 'W...NaN[malay]
\n", "
" ], "text/plain": [ " Size (MB) \\\n", "mesolitica/wav2vec2-xls-r-300m-mixed 1180 \n", "mesolitica/wav2vec2-xls-r-300m-mixed-v2 1180 \n", "mesolitica/wav2vec2-xls-r-300m-12layers-ms 657 \n", "mesolitica/wav2vec2-xls-r-300m-6layers-ms 339 \n", "\n", " malay-malaya \\\n", "mesolitica/wav2vec2-xls-r-300m-mixed {'WER': 0.194655128, 'CER': 0.04775798, 'WER-L... \n", "mesolitica/wav2vec2-xls-r-300m-mixed-v2 {'WER': 0.154782923, 'CER': 0.035164031, 'WER-... \n", "mesolitica/wav2vec2-xls-r-300m-12layers-ms {'WER': 0.1494983789, 'CER': 0.0342059992, 'WE... \n", "mesolitica/wav2vec2-xls-r-300m-6layers-ms {'WER': 0.22481538553, 'CER': 0.0484392694, 'W... \n", "\n", " malay-fleur102 \\\n", "mesolitica/wav2vec2-xls-r-300m-mixed {'WER': 0.2373861259, 'CER': 0.07055478, 'WER-... \n", "mesolitica/wav2vec2-xls-r-300m-mixed-v2 {'WER': 0.2013994374, 'CER': 0.0518170369, 'WE... \n", "mesolitica/wav2vec2-xls-r-300m-12layers-ms {'WER': 0.217107489, 'CER': 0.0546614199, 'WER... \n", "mesolitica/wav2vec2-xls-r-300m-6layers-ms {'WER': 0.38642364985, 'CER': 0.0928960677, 'W... \n", "\n", " singlish \\\n", "mesolitica/wav2vec2-xls-r-300m-mixed {'WER': 0.127588595, 'CER': 0.0494924979, 'WER... \n", "mesolitica/wav2vec2-xls-r-300m-mixed-v2 {'WER': 0.2258822139, 'CER': 0.082982312, 'WER... \n", "mesolitica/wav2vec2-xls-r-300m-12layers-ms NaN \n", "mesolitica/wav2vec2-xls-r-300m-6layers-ms NaN \n", "\n", " Language \n", "mesolitica/wav2vec2-xls-r-300m-mixed [malay, singlish] \n", "mesolitica/wav2vec2-xls-r-300m-mixed-v2 [malay, singlish] \n", "mesolitica/wav2vec2-xls-r-300m-12layers-ms [malay] \n", "mesolitica/wav2vec2-xls-r-300m-6layers-ms [malay] " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "malaya_speech.stt.ctc.available_huggingface()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "model = malaya_speech.stt.ctc.huggingface(model = 'mesolitica/wav2vec2-xls-r-300m-6layers-ms')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "_ = model.cuda()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "y, _ = malaya_speech.load('speech/example-speaker/husein-zolkepli.wav')" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['testing nama saya husin bin zokapli']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.predict([y])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 2 }