diff --git a/notebooks/openvino/stable_diffusion_hybrid_quantization.ipynb b/notebooks/openvino/stable_diffusion_hybrid_quantization.ipynb index b5d9ae7001..41969b162a 100644 --- a/notebooks/openvino/stable_diffusion_hybrid_quantization.ipynb +++ b/notebooks/openvino/stable_diffusion_hybrid_quantization.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "id": "dffab375-a730-4015-8d17-360b76a0718d", "metadata": {}, "outputs": [], @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "0407fc92-c052-47b7-8721-01836adf3b54", "metadata": { "execution": { @@ -70,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "id": "c32f9a76-414b-43d9-9769-af131223f1c1", "metadata": { "execution": { @@ -125,14 +125,14 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "id": "92a3f434", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "caab335ab7b146bba41c81e8688759f9", + "model_id": "31afdad1b284494aa51e668f5d8fc5c8", "version_major": 2, "version_minor": 0 }, @@ -147,7 +147,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'image': , 'filename': 'COCO_train2014_000000494175.jpg', 'cocoid': 494175, 'caption': 'A crowded arena filled with people and confetti.'}\n" + "{'image': , 'filename': 'COCO_train2014_000000494175.jpg', 'cocoid': 494175, 'caption': 'A crowded arena filled with people and confetti.'}\n" ] } ], @@ -158,24 +158,18 @@ }, { "cell_type": "code", - "execution_count": 9, - "id": "8be68958-ce5e-4cc6-b8e7-2867feaf084b", - "metadata": { - "execution": { - "iopub.execute_input": "2022-12-04T14:40:31.358230Z", - "iopub.status.busy": "2022-12-04T14:40:31.358053Z", - "iopub.status.idle": "2022-12-04T14:40:31.360666Z", - "shell.execute_reply": "2022-12-04T14:40:31.360301Z", - "shell.execute_reply.started": "2022-12-04T14:40:31.358218Z" - }, - "tags": [] - }, + "execution_count": 5, + "id": "1036fe23", + "metadata": {}, "outputs": [], "source": [ "def preprocess_fn(example):\n", " return {\"prompt\": example[\"caption\"]}\n", "\n", - "calibration_dataset = dataset.map(lambda x: preprocess_fn(x), remove_columns=dataset.column_names)" + "NUM_SAMPLES = 200\n", + "dataset = dataset.take(NUM_SAMPLES)\n", + "dataset = dataset.map(lambda x: preprocess_fn(x), remove_columns=dataset.column_names)\n", + "calibration_dataset = list(dataset)" ] }, { @@ -190,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "31c5415e-e22b-4ab9-b903-8791e80b188d", "metadata": { "execution": { @@ -204,7 +198,6 @@ }, "outputs": [], "source": [ - "NUM_SAMPLES = 200\n", "quantization_config = OVWeightQuantizationConfig(bits=8, dataset=calibration_dataset, num_samples=NUM_SAMPLES)\n", "int8_pipe = OVStableDiffusionPipeline.from_pretrained(model_id=MODEL_ID, export=True, quantization_config=quantization_config)\n", "int8_pipe.save_pretrained(int8_model_path)" @@ -251,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "6c2f615a-19e3-4ee2-9309-2ae1392c7f62", "metadata": { "execution": { @@ -290,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "id": "90902149", "metadata": {}, "outputs": [], @@ -311,7 +304,36 @@ "execution_count": null, "id": "02f01fc1", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "eb96ea3ef90f4b7488cb7b92853b5ef7", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0/50 [00:00" ] @@ -350,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "1eeaa81f-7fc5-49ba-80b8-2d95a1310a0c", "metadata": { "execution": { @@ -388,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "id": "91134d48", "metadata": {}, "outputs": [ @@ -397,7 +419,7 @@ "output_type": "stream", "text": [ "FP32 model size: 4920.93 MB\n", - "INT8 model size: 1240.23 MB\n", + "INT8 model size: 1240.29 MB\n", "INT8 size decrease: 3.97x\n" ] } @@ -424,7 +446,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "8806da79-0b3b-403e-a40c-61db6a0f482d", "metadata": { "execution": { @@ -447,7 +469,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "6816982d5d7e412fb02d1efcf972a95d", + "model_id": "bdf72f14022b4944b2fe6f5e482b01f2", "version_major": 2, "version_minor": 0 }, @@ -461,7 +483,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "7c51ada2ecb84e6398f82c10acd523ae", + "model_id": "fd9c55cebb4646b7b606a4d6b177889b", "version_major": 2, "version_minor": 0 }, @@ -475,7 +497,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "7bf9616672ef4743a5e05f519e47ccae", + "model_id": "2599d0b1599a4bedac510cd0382262d0", "version_major": 2, "version_minor": 0 }, @@ -490,13 +512,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Latency of original FP32 model: 355705.40 ms\n" + "Latency of original FP32 model: 212177.56 ms\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2a8db52629c7434da87864707e1c8023", + "model_id": "8ca3ba9b0dca486dbc5fa6c5b508f1b8", "version_major": 2, "version_minor": 0 }, @@ -510,7 +532,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "f65d645f05464727bb05b7a0028353fb", + "model_id": "27a597e75cc44a3db5360bbde7b613e8", "version_major": 2, "version_minor": 0 }, @@ -524,7 +546,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "f1452100a86443e29f4d6f62473cfecf", + "model_id": "f15ec840672b4568aea1882539d7bb33", "version_major": 2, "version_minor": 0 }, @@ -539,14 +561,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "Latency of quantized model: 315484.52 ms\n", - "Speedup: 1.13x\n" + "Latency of quantized model: 162504.42 ms\n", + "Speedup: 1.31x\n" ] } ], "source": [ "def get_val_dataset(num_items=3):\n", - " return [item[\"caption\"] for item in dataset.take(num_items)]\n", + " return [item[\"prompt\"] for item in dataset.take(num_items)]\n", "\n", "def benchmark(pipeline, dataset):\n", " \"\"\"\n",