Last active
November 14, 2022 00:49
-
-
Save josephrocca/320fd77316bd09cef52c3fc8cb657a14 to your computer and use it in GitHub Desktop.
lyra-v2-soundstream split quantizer into its two subgraphs.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"collapsed_sections": [], | |
"name": "lyra-v2-soundstream split quantizer into its two subgraphs.ipynb", | |
"authorship_tag": "ABX9TyPYIuStrMU+dyIHd76uhnid", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
}, | |
"gpuClass": "standard" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/josephrocca/320fd77316bd09cef52c3fc8cb657a14/notebook.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!pip install git+https://github.com/onnx/tensorflow-onnx.git\n", | |
"!wget https://raw.githubusercontent.com/tensorflow/tensorflow/ee9a169b669e0e5804810eb631df11c3b7ecb1c2/tensorflow/lite/tools/flatbuffer_utils.py\n", | |
"!wget https://huggingface.co/rocca/lyra-v2-soundstream/resolve/main/tflite/quantizer.tflite" | |
], | |
"metadata": { | |
"id": "_Our00mFGN_J" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# extract the encoder and decoder subgraphs:\n", | |
"import flatbuffer_utils as fbu\n", | |
"model = fbu.read_model('quantizer.tflite')\n", | |
"encoder_subgraph = model.subgraphs[1]\n", | |
"decoder_subgraph = model.subgraphs[0]\n", | |
"\n", | |
"model.subgraphs = [encoder_subgraph]\n", | |
"fbu.write_model(model, 'quantizer_encoder.tflite')\n", | |
"model.subgraphs = [decoder_subgraph]\n", | |
"fbu.write_model(model, 'quantizer_decoder.tflite')" | |
], | |
"metadata": { | |
"id": "XaWcl61phzVN" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!python -m tf2onnx.convert --opset 17 --tflite quantizer_encoder.tflite --output quantizer_encoder.onnx --verbose --debug" | |
], | |
"metadata": { | |
"id": "BC4yz6N-MhzZ" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"!python -m tf2onnx.convert --opset 17 --tflite quantizer_decoder.tflite --output quantizer_decoder.onnx --verbose --debug" | |
], | |
"metadata": { | |
"id": "aznyk5z-lCZm" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment