Skip to content

Instantly share code, notes, and snippets.

@josephrocca
Last active November 14, 2022 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephrocca/320fd77316bd09cef52c3fc8cb657a14 to your computer and use it in GitHub Desktop.
Save josephrocca/320fd77316bd09cef52c3fc8cb657a14 to your computer and use it in GitHub Desktop.
lyra-v2-soundstream split quantizer into its two subgraphs.ipynb
Display the source blob
Display the rendered blob
Raw
{
"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