diff --git a/notebooks/02_quant_activation_overview.ipynb b/notebooks/02_quant_activation_overview.ipynb index 7bb97f46f..e929c56c8 100644 --- a/notebooks/02_quant_activation_overview.ipynb +++ b/notebooks/02_quant_activation_overview.ipynb @@ -343,7 +343,7 @@ "source": [ "return_disabled_quant_relu = QuantReLU(act_quant=None, return_quant_tensor=True)\n", "relu_out_tensor = return_disabled_quant_relu(out_tensor)\n", - "assert_with_message((relu_out_tensor.is_valid==True))\n", + "assert_with_message(relu_out_tensor.is_valid)\n", "assert_with_message(relu_out_tensor.scale == out_tensor.scale)\n", "assert_with_message(relu_out_tensor.zero_point == out_tensor.zero_point)\n", "assert_with_message(relu_out_tensor.bit_width == out_tensor.bit_width)" diff --git a/notebooks/Brevitas_TVMCon2021.ipynb b/notebooks/Brevitas_TVMCon2021.ipynb index 998d4b228..85b347722 100644 --- a/notebooks/Brevitas_TVMCon2021.ipynb +++ b/notebooks/Brevitas_TVMCon2021.ipynb @@ -73,6 +73,11 @@ "from brevitas.nn import QuantLinear\n", "from IPython.display import Markdown, display\n", "\n", + "# helpers\n", + "def assert_with_message(condition):\n", + " assert condition\n", + " print(condition)\n", + "\n", "def pretty_print_source(source):\n", " display(Markdown('```python\\n' + source + '\\n```'))\n", " \n", @@ -866,7 +871,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_61612/661358273.py:7: UserWarning: Defining your `__torch_function__` as a plain method is deprecated and will be an error in future, please define it as a classmethod. (Triggered internally at /opt/conda/conda-bld/pytorch_1699449183005/work/torch/csrc/utils/python_arg_parser.cpp:368.)\n", + "/tmp/ipykernel_86658/661358273.py:7: UserWarning: Defining your `__torch_function__` as a plain method is deprecated and will be an error in future, please define it as a classmethod. (Triggered internally at /opt/conda/conda-bld/pytorch_1699449183005/work/torch/csrc/utils/python_arg_parser.cpp:368.)\n", " quant_output = torch.tanh(quant_input)\n" ] } @@ -919,9 +924,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_61612/3932472163.py:8: UserWarning: Defining your `__torch_function__` as a plain method is deprecated and will be an error in future, please define it as a classmethod. (Triggered internally at /opt/conda/conda-bld/pytorch_1699449183005/work/torch/csrc/utils/python_arg_parser.cpp:368.)\n", + "/tmp/ipykernel_86658/3932472163.py:8: UserWarning: Defining your `__torch_function__` as a plain method is deprecated and will be an error in future, please define it as a classmethod. (Triggered internally at /opt/conda/conda-bld/pytorch_1699449183005/work/torch/csrc/utils/python_arg_parser.cpp:368.)\n", " train_mode_cat = torch.cat([quant_identity(float_inp1), quant_identity(float_inp2)], dim=1)\n", - "/tmp/ipykernel_61612/3932472163.py:14: UserWarning: Defining your `__torch_function__` as a plain method is deprecated and will be an error in future, please define it as a classmethod. (Triggered internally at /opt/conda/conda-bld/pytorch_1699449183005/work/torch/csrc/utils/python_arg_parser.cpp:368.)\n", + "/tmp/ipykernel_86658/3932472163.py:14: UserWarning: Defining your `__torch_function__` as a plain method is deprecated and will be an error in future, please define it as a classmethod. (Triggered internally at /opt/conda/conda-bld/pytorch_1699449183005/work/torch/csrc/utils/python_arg_parser.cpp:368.)\n", " eval_mode_cat = torch.cat([eval_quant_inp1, eval_quant_inp2], dim=1)\n" ] } @@ -1813,14 +1818,11 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] } ], "source": [ @@ -1836,7 +1838,7 @@ "quant_identity_bit_width = quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.msb_clamp_bit_width_impl\n", "quant_linear_bit_width = quant_linear.weight_quant.tensor_quant.msb_clamp_bit_width_impl\n", "\n", - "quant_identity_bit_width is quant_linear_bit_width" + "assert_with_message(quant_identity_bit_width is quant_linear_bit_width)" ] }, { @@ -2160,7 +2162,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 40, @@ -2555,7 +2557,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 42, @@ -2801,7 +2803,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 44, @@ -2895,7 +2897,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 46, diff --git a/notebooks/quantized_recurrent.ipynb b/notebooks/quantized_recurrent.ipynb index 20cfc8fee..dbca4c578 100644 --- a/notebooks/quantized_recurrent.ipynb +++ b/notebooks/quantized_recurrent.ipynb @@ -146,18 +146,15 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] } ], "source": [ - "quant_rnn_0_left_to_right.gate_params.input_weight.weight_quant is quant_rnn_1_right_to_left.gate_params.input_weight.weight_quant" + "assert_with_message(not quant_rnn_0_left_to_right.gate_params.input_weight.weight_quant is quant_rnn_1_right_to_left.gate_params.input_weight.weight_quant)" ] }, { @@ -166,18 +163,15 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] } ], "source": [ - "quant_rnn_0_left_to_right.cell.gate_acc_quant is quant_rnn_1_right_to_left.cell.gate_acc_quant" + "assert_with_message(not quant_rnn_0_left_to_right.cell.gate_acc_quant is quant_rnn_1_right_to_left.cell.gate_acc_quant)" ] }, { @@ -186,18 +180,15 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] } ], "source": [ - "quant_rnn_0_left_to_right.gate_params.bias_quant is quant_rnn_1_right_to_left.gate_params.bias_quant" + "assert_with_message(not quant_rnn_0_left_to_right.gate_params.bias_quant is quant_rnn_1_right_to_left.gate_params.bias_quant)" ] }, { @@ -214,18 +205,15 @@ "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] } ], "source": [ - "quant_rnn_0_left_to_right.io_quant is quant_rnn_1_right_to_left.io_quant" + "assert_with_message(quant_rnn_0_left_to_right.io_quant is quant_rnn_1_right_to_left.io_quant)" ] }, { @@ -966,7 +954,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 19, @@ -995,7 +983,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "2024-02-15 10:20:15.222259670 [W:onnxruntime:, graph.cc:1283 Graph] Initializer onnx::LSTM_93 appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.\n" + "2024-02-19 02:23:40.184678458 [W:onnxruntime:, graph.cc:1283 Graph] Initializer onnx::LSTM_93 appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.\n" ] } ], @@ -1042,37 +1030,7 @@ "skip-execution" ] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Serving 'quant_lstm_weight_only_cifg_4b.onnx' at http://localhost:8082\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "show_netron(export_path, 8082)" ] @@ -1094,7 +1052,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "2024-02-15 10:20:22.930760716 [W:onnxruntime:, graph.cc:1283 Graph] Initializer onnx::LSTM_87 appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.\n" + "2024-02-19 02:23:47.615422725 [W:onnxruntime:, graph.cc:1283 Graph] Initializer onnx::LSTM_87 appears in graph inputs and will not be treated as constant value/weight. This may prevent some of the graph optimizations, like const folding. Move it out of graph inputs if there is no need to override it, by either re-generating the model with latest exporter/converter or with the tool onnxruntime/tools/python/remove_initializer_from_input.py.\n" ] } ], @@ -1150,37 +1108,7 @@ "skip-execution" ] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Serving 'quant_lstm_weight_only_bidirectional_2_layers.onnx' at http://localhost:8083\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "show_netron(export_path, 8083)" ] @@ -1226,37 +1154,7 @@ "skip-execution" ] }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Serving 'quant_lstm_weight_only_bidirectional_2_layers_shared_ih.onnx' at http://localhost:8085\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "show_netron(export_path, 8085)" ] @@ -1326,7 +1224,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 29, @@ -1404,7 +1302,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 31, @@ -1482,7 +1380,7 @@ " " ], "text/plain": [ - "" + "" ] }, "execution_count": 33,