├── .gitignore ├── LICENSE ├── README.md ├── notebooks ├── README.md ├── imgs │ ├── cover.png │ ├── gradio_app.png │ ├── infer-results.png │ ├── neb.jpg │ ├── neb_x_gradio.png │ ├── output-stable-diffusion.png │ ├── sd-benchmarks.png │ ├── sd-cover.png │ ├── speedster-results.png │ ├── speedsterdoc.png │ ├── stab1.jpg │ ├── stab2.jpg │ ├── thanos.png │ ├── tome-arch.png │ ├── tome-impl.png │ ├── tome-results.png │ ├── tome.png │ ├── tomeintro.png │ └── total-results.png └── notebooks │ ├── stable-diffusion.ipynb │ └── token-merging.ipynb └── notes ├── README.md └── files └── MIT6.S965 └── Lecture_02.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![cover_lh](https://user-images.githubusercontent.com/53374883/225739546-cf303981-7a31-4cb9-9f53-4c553083b76b.png) 3 |
4 |
5 | 6 |
7 | 8 | 9 | 10 |   11 |   12 |   13 | 14 | 15 | 16 |   17 |   18 |   19 | 20 | 21 | 22 |   23 |   24 |   25 | 26 | 27 | 28 |
29 |
30 | 31 | ## Hey there and welcome! 🌈 32 | This repository is a collection of learning resources, which includes two folders: the [`notes`](https://github.com/nebuly-ai/learning-hub/tree/main/notes) folder consisting of handwritten notes from courses or reading papers, and the [`notebooks`](https://github.com/mfumanelli/learning-hub/tree/main/notebooks) folder providing notebooks to experiment with the latest techniques or utilize Nebuly tools. 33 | 34 | This is still a work in progress, and we welcome any contributions. Let's keep learning! 35 | -------------------------------------------------------------------------------- /notebooks/README.md: -------------------------------------------------------------------------------- 1 | 2 | ![cover_notebooks](https://user-images.githubusercontent.com/53374883/225739935-671cdbed-dcff-49b6-aeac-3e0c736aa192.png) 3 | 4 |
5 | 6 |
7 | 8 |
9 | 10 | 11 | 12 |   13 |   14 |   15 | 16 | 17 | 18 |   19 |   20 |   21 | 22 | 23 | 24 |   25 |   26 |   27 | 28 | 29 | 30 |
31 |
32 | 33 | ## 🚀 Hi! 34 | In this repository we collect notebooks with examples, analysis, and use cases focused on artificial intelligence optimization. The repository is still under construction 👷‍♀️ 35 | 36 | ### Use Cases 37 | 38 | | **notebook** | **open in colab or kaggle** | **supplementary materials** | **references** | 39 | |:------------:|:------------------------------------:|:----------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------:| 40 | | [Accelerate Stable Diffusion Model Using Speedster + New TensorRT 8.6 Release and Gradio App Creation](https://github.com/nebuly-ai/learning-hub/blob/main/notebooks/notebooks/stable-diffusion.ipynb) | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1ihtoUeJ3fLpEuh4_njfohw7hs0lXXaMV?usp=sharing) | | | 41 | | [Token Merging (ToMe) - Meta AI's New Optimization Technique to Make ViT Faster by 2x. But Can ViT be Even Faster?](https://github.com/nebuly-ai/learning-hub/blob/main/notebooks/notebooks/token-merging.ipynb) | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1dd8JENS8HudfPz_cA-Mc5oN90nYJUBND?usp=sharing) [![Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://www.kaggle.com/code/serquet/token-merging-your-vit-but-faster) |[Blog post](https://www.nebuly.com/blog/token-merging-tome-meta-ais-new-optimization-technique-to-make-vit-faster)| [![GitHub](https://badges.aleen42.com/src/github.svg)](https://github.com/facebookresearch/ToMe) | 42 | 43 | ### Speedster Quickstarts 44 | | **notebook** | **description** | **open in colab** | 45 | |:------------:|:------------:|:------------:| 46 | |[Accelerate Diffusers Stable Diffusion](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/diffusers/Accelerate_Stable_Diffusion_with_Speedster.ipynb)|Show how to optimize with Speedster the Stable Diffusion models from Diffusers.| [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/diffusers/Accelerate_Stable_Diffusion_with_Speedster.ipynb) | 47 | | [Accelerate Hugging Face PyTorch GPT2](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_GPT2_with_Speedster.ipynb) | Show how to optimize with Speedster the GPT2 model from Hugging Face with PyTorch backend. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_GPT2_with_Speedster.ipynb) | 48 | |[Accelerate PyTorch ViT](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_ViT_with_Speedster.ipynb) | Show how to optimize with Speedster a PyTorch ViT model. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_ViT_with_Speedster.ipynb)| 49 | | [Accelerate Hugging Face PyTorch BERT](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_BERT_with_Speedster.ipynb) | Show how to optimize with Speedster the BERT model from Hugging Face with PyTorch backend. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_BERT_with_Speedster.ipynb) | 50 | | [Accelerate Hugging Face PyTorch DistilBERT](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_DistilBERT_with_Speedster.ipynb) | Show how to optimize with Speedster the DistilBERT model from Hugging Face with PyTorch backend. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_DistilBERT_with_Speedster.ipynb) | | 51 | | [Accelerate Hugging Face TensorFlow BERT](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_TensorFlow_BERT_with_Speedster.ipynb) | Show how to optimize with Speedster the BERT model from Hugging Face with TensorFlow backend. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_TensorFlow_BERT_with_Speedster.ipynb) | 52 | | [Accelerate Hugging Face PyTorch T5](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_T5_with_Speedster.ipynb) | Show how to optimize with Speedster the T5 model from Hugging Face with PyTorch backend. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/huggingface/Accelerate_Hugging_Face_PyTorch_T5_with_Speedster.ipynb) | 53 | | [Accelerate ONNX Resnet50](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/onnx/Accelerate_ONNX_ResNet50_with_Speedster.ipynb) | Show how to optimize with Speedster a Resnet50 model in ONNX format. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/onnx/Accelerate_ONNX_ResNet50_with_Speedster.ipynb) | 54 | | [Accelerate Torchvision Resnet50](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_ResNet50_with_Speedster.ipynb) | Show how to optimize with Speedster a Resnet50 model loaded from Torchvision. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_ResNet50_with_Speedster.ipynb) | 55 | | [Accelerate Fast AI Resnet34](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_fast_ai_Resnet34_with_Speedster.ipynb) | Show how to optimize with Speedster a Resnet34 model loaded from Fast AI. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_fast_ai_Resnet34_with_Speedster.ipynb) | 56 | | [Accelerate Ultralytics YOLOv5](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_YOLOv5_with_Speedster.ipynb) | Show how to optimize with Speedster a YOLOv5 model from Ultralytics. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_YOLOv5_with_Speedster.ipynb) | 57 | | [Accelerate Ultralytics YOLOv8](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_YOLOv8_with_Speedster.ipynb) | Show how to optimize with Speedster a YOLOv8 model from Ultralytics. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/pytorch/Accelerate_PyTorch_YOLOv8_with_Speedster.ipynb) | 58 | | [Accelerate Keras Resnet50](https://github.com/nebuly-ai/nebullvm/blob/main/notebooks/speedster/tensorflow/Accelerate_Tensorflow_ResNet50_with_Speedster.ipynb) | Show how to optimize with Speedster a Resnet50 model loaded from keras. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nebuly-ai/nebullvm/blob/main/notebooks/speedster/tensorflow/Accelerate_Tensorflow_ResNet50_with_Speedster.ipynb) | 59 | -------------------------------------------------------------------------------- /notebooks/imgs/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/cover.png -------------------------------------------------------------------------------- /notebooks/imgs/gradio_app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/gradio_app.png -------------------------------------------------------------------------------- /notebooks/imgs/infer-results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/infer-results.png -------------------------------------------------------------------------------- /notebooks/imgs/neb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/neb.jpg -------------------------------------------------------------------------------- /notebooks/imgs/neb_x_gradio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/neb_x_gradio.png -------------------------------------------------------------------------------- /notebooks/imgs/output-stable-diffusion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/output-stable-diffusion.png -------------------------------------------------------------------------------- /notebooks/imgs/sd-benchmarks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/sd-benchmarks.png -------------------------------------------------------------------------------- /notebooks/imgs/sd-cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/sd-cover.png -------------------------------------------------------------------------------- /notebooks/imgs/speedster-results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/speedster-results.png -------------------------------------------------------------------------------- /notebooks/imgs/speedsterdoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/speedsterdoc.png -------------------------------------------------------------------------------- /notebooks/imgs/stab1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/stab1.jpg -------------------------------------------------------------------------------- /notebooks/imgs/stab2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/stab2.jpg -------------------------------------------------------------------------------- /notebooks/imgs/thanos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/thanos.png -------------------------------------------------------------------------------- /notebooks/imgs/tome-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/tome-arch.png -------------------------------------------------------------------------------- /notebooks/imgs/tome-impl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/tome-impl.png -------------------------------------------------------------------------------- /notebooks/imgs/tome-results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/tome-results.png -------------------------------------------------------------------------------- /notebooks/imgs/tome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/tome.png -------------------------------------------------------------------------------- /notebooks/imgs/tomeintro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/tomeintro.png -------------------------------------------------------------------------------- /notebooks/imgs/total-results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notebooks/imgs/total-results.png -------------------------------------------------------------------------------- /notebooks/notebooks/stable-diffusion.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "b8e4382d", 6 | "metadata": {}, 7 | "source": [ 8 | "\"cover\"" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "36df534b", 14 | "metadata": {}, 15 | "source": [ 16 | "# Accelerate Stable Diffusion Model Using Speedster + New TensorRT 8.6 Release and Gradio App Creation" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "618b51be-63e5-4fc3-bfc1-70dd947cd79a", 22 | "metadata": {}, 23 | "source": [ 24 | "#### 🚀 Welcome to this notebook focused on optimizing Stable Diffusion using Speedster 🚀\n", 25 | "\n", 26 | "### Goal\n", 27 | "The goal is to optimize the performance of a Stable Diffusion model using Speedster and the latest TensorRT version, to obtain an inference model that runs ~2-3 times faster than the original one. After that, we will show you how easy it is to integrate an optimized model in a Gradio application, so we will develop a game using Gradio and the accelerated model. The game we create will be called *guess the Pokémon*, the user will have to identify the name of the Pokémon generated using the optimized Stable Diffusion model." 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "id": "8f3ca852-9e20-440c-a073-029ad0baf663", 33 | "metadata": {}, 34 | "source": [ 35 | "\"cover\"\n", 36 | "
Results obtained on a 3090Ti GPU for the Stable Diffusion 2.1 model.
" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "id": "6bd4102f", 42 | "metadata": {}, 43 | "source": [ 44 | "### Stable Diffusion" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "id": "562dced5", 50 | "metadata": {}, 51 | "source": [ 52 | "Stable Diffusion, which was released in 2022, is a text-to-image model that is mainly utilized for generating images based on textual descriptions.\n", 53 | "\n", 54 | "Stable Diffusion consists of three main components: \n", 55 | "* **a text-understanding component** that uses a Transformer language model to translate text into a numeric representation\n", 56 | "* **an image generator** that includes an image information creator and an image decoder \n", 57 | "* **an autoencoder decoder** that produces the final image\n", 58 | "\n", 59 | "The image generator works in the latent space and gradually processes the information to generate high-quality images, with the UNet neural network and scheduling algorithm as its components. The image decoder uses the processed information array to produce the final pixel image. Speedster's main focus for model acceleration is the conditional U-Net architecture utilized for denoising the latent component of the encoded image. The reason for this emphasis is that UNet is executed multiple times based on the num_inference_steps hyperparameter, which is usually set to 50 by default. As a result, the computational cost of UNet far outweighs the impact of the other two model components, which are only executed once." 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "id": "87325a48-409c-4ec1-aa8a-67ffb75ae716", 65 | "metadata": {}, 66 | "source": [ 67 | "
\"stab1\"
" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "id": "dda1ba83-8353-472b-abfc-e447c43420f7", 73 | "metadata": {}, 74 | "source": [ 75 | "
Image taken from The Illustrated Stable Diffusionb log by Jay Alammar.
" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "id": "7fb78874-d878-4bb7-ba0b-1d6095072498", 81 | "metadata": {}, 82 | "source": [ 83 | "
\"stab2\"
" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "id": "f86ba113-108e-4537-8197-9c59662864b4", 89 | "metadata": {}, 90 | "source": [ 91 | "
Image taken from The Illustrated Stable Diffusion blog by Jay Alammar.
" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "id": "8b088504", 97 | "metadata": {}, 98 | "source": [ 99 | "### Speedster" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "id": "7758a909-fdda-40d0-947a-9da41ab8ffce", 105 | "metadata": {}, 106 | "source": [ 107 | "Nebuly's [Speedster](https://github.com/nebuly-ai/nebullvm/tree/main/apps/accelerate/speedster) is an **open-source** module that enables fast AI inference through just a few lines of code. The module automatically applies state-of-the-art optimization techniques to maximize the hardware's physical inference speed-up, including latency, throughput, and model size on a single machine.\n", 108 | "\n", 109 | "To get started, you can refer to the [getting started guide](https://github.com/nebuly-ai/nebullvm/tree/main/apps/accelerate/speedster) for five different input model frameworks supported by Speedster, which are PyTorch, Hugging Face Transformers, Hugging Face Diffusers, TensorFlow/Keras, and ONNX.\n", 110 | "\n", 111 | "In this notebook, we will delve into the details of Stable Diffusion and the Speedster algorithm. We will learn how to implement Speedster in Python and use it to optimize Stable Diffusion.\n", 112 | "\n", 113 | "In addition to optimization techniques, we will also create a Gradio application to interact with our accelerated model." 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "id": "10752f50-4f7f-452b-ab07-e5eaba2fa5b7", 119 | "metadata": {}, 120 | "source": [ 121 | "
\"nebuly\"
" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "id": "857b4230-6e54-474b-a521-d0a5a58b06e0", 127 | "metadata": {}, 128 | "source": [ 129 | "
Image taken from Nebuly's website.
" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "id": "b8e71c6f", 135 | "metadata": {}, 136 | "source": [ 137 | "## Install and Imports" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "id": "a44e3366-38a5-4f02-880f-d339437ef492", 143 | "metadata": {}, 144 | "source": [ 145 | "Before we dive into the analysis, we need to make sure that we have all the necessary tools to execute the code. In this section, we will install the required packages and libraries to ensure a smooth and error-free run of the notebook. These packages include torch, Speedster and some Hugging Face libraries. Once we have installed the packages, we will import them into the notebook and get ready to use them in our analysis." 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "d872948e-bff3-462d-b3d5-c18daff6305e", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "! pip install accelerate torch datasets diffusers gradio speedster --quiet " 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": null, 161 | "id": "b0ea8891", 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "! python -m nebullvm.installers.auto_installer --frameworks diffusers --compilers all" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": null, 171 | "id": "65b5cbfa-b4d7-4913-90a0-7dbf8898f146", 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "import torch\n", 176 | "\n", 177 | "import pandas as pd\n", 178 | "\n", 179 | "from diffusers import StableDiffusionPipeline\n", 180 | "from datasets import load_dataset\n", 181 | "\n", 182 | "from speedster import optimize_model, save_model, load_model\n", 183 | "\n", 184 | "import gradio as gr\n", 185 | "\n", 186 | "from random import randrange\n", 187 | "import os" 188 | ] 189 | }, 190 | { 191 | "cell_type": "markdown", 192 | "id": "7b906350-54e1-468e-a186-8de10fb6400d", 193 | "metadata": {}, 194 | "source": [ 195 | "## Environment Check" 196 | ] 197 | }, 198 | { 199 | "cell_type": "markdown", 200 | "id": "2ed1ed43-a961-49c6-b63f-d3294123539c", 201 | "metadata": {}, 202 | "source": [ 203 | "![ChessUrl](https://media.giphy.com/media/rAm0u2k17rM3e/giphy.gif \"env\")" 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "id": "5451bf78", 209 | "metadata": {}, 210 | "source": [ 211 | "In order to make everything work, we need to check that the environment meets the necessary requirements. In particular, to optimize a model of the Hugging Face Diffusers library you need to have `CUDA>=12` and `tensorrt>=8.6.0`." 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "id": "92eb8ff0", 217 | "metadata": {}, 218 | "source": [ 219 | "From TensorRT 8.6, all the tensorrt pre-built wheels released by nvidia support only `CUDA>=12.0`. Speedster will install `tensorrt>=8.6.0` automatically in the auto-installer only if it detects `CUDA>=12.0`, otherwise it will install `tensorrt==8.5.3.1`. In that case, you will have to upgrade your CUDA version and then to upgarde tensorrt to 8.6.0 or above to execute this notebook." 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "id": "58e53514", 225 | "metadata": {}, 226 | "source": [ 227 | "First of all, Let's check the CUDA version installed on the machine:" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 2, 233 | "id": "ecc389f0", 234 | "metadata": {}, 235 | "outputs": [], 236 | "source": [ 237 | "import subprocess\n", 238 | "\n", 239 | "if torch.cuda.is_available():\n", 240 | " cuda_version = subprocess.check_output([\"nvidia-smi\"])\n", 241 | " cuda_version = int(cuda_version.decode(\"utf-8\").split(\"\\n\")[2].split(\"|\")[-2].split(\":\")[-1].strip().split(\".\")[0])\n", 242 | " assert cuda_version >= 12, (\"This notebook requires CUDA>=12.0 to be executed, please upgrade your CUDA version.\")" 243 | ] 244 | }, 245 | { 246 | "cell_type": "markdown", 247 | "id": "aa7c09c9", 248 | "metadata": {}, 249 | "source": [ 250 | "If you have `CUDA<12.0`, you can upgrade it at this link: https://developer.nvidia.com/cuda-downloads. The installation is very simple, you only have to select the characteristics of your environment and copy and paste the commands provided by Nvidia." 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "id": "eec5858a", 256 | "metadata": {}, 257 | "source": [ 258 | "Then, let's check the tensorrt version installed on the platform. Stable Diffusion optimization is supported starting from `tensorrt==8.6.0`" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 3, 264 | "id": "81f2ed3f", 265 | "metadata": {}, 266 | "outputs": [], 267 | "source": [ 268 | "import tensorrt\n", 269 | "from nebullvm.tools.utils import check_module_version\n", 270 | "\n", 271 | "assert check_module_version(tensorrt, \"8.6.0\"), (\"This notebook can be run only with tensorrt>=8.6.0, if using an older version you could have issues during the optimization.\")" 272 | ] 273 | }, 274 | { 275 | "cell_type": "markdown", 276 | "id": "c697ded2", 277 | "metadata": {}, 278 | "source": [ 279 | "If you have an older version, after ensuring you have `CUDA>=12.0` installed, you can upgrade your TensorRT version by running:\n", 280 | "```\n", 281 | "! pip install -U tensorrt\n", 282 | "```" 283 | ] 284 | }, 285 | { 286 | "cell_type": "markdown", 287 | "id": "6a0638a5-19cc-4e5b-b4d4-766c197358da", 288 | "metadata": {}, 289 | "source": [ 290 | "## Load Data" 291 | ] 292 | }, 293 | { 294 | "cell_type": "markdown", 295 | "id": "6eddf854-012e-49fb-9b2f-0234decc91b3", 296 | "metadata": {}, 297 | "source": [ 298 | "The data that will be used for analysis and modeling are derived from the [Bulbagarden](https://bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_name) website and consists of a small dataset with two columns, one with the names of the Pokémon and the other with their descriptions.\n", 299 | "\n", 300 | "You can get the data from [Hugging Face](https://huggingface.co/datasets/mfumanelli/pokemon-description-xs)." 301 | ] 302 | }, 303 | { 304 | "cell_type": "code", 305 | "execution_count": null, 306 | "id": "d19474b8-b2b8-4c0e-94e1-46852b841d95", 307 | "metadata": {}, 308 | "outputs": [], 309 | "source": [ 310 | "dataset = load_dataset(\"mfumanelli/pokemon-description-xs\")" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": 5, 316 | "id": "c4b76565-9cc7-47c3-be93-790d4c198041", 317 | "metadata": {}, 318 | "outputs": [], 319 | "source": [ 320 | "data = dataset['train'].to_pandas()" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 6, 326 | "id": "3b91619e", 327 | "metadata": {}, 328 | "outputs": [ 329 | { 330 | "data": { 331 | "text/html": [ 332 | "
\n", 333 | "\n", 346 | "\n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | "
namedescription
0Bulbasaurit's a blue and green Pokémon. It has a seed o...
1Pikachuit's a yellow and black Pokémon. It's a creatu...
\n", 367 | "
" 368 | ], 369 | "text/plain": [ 370 | " name description\n", 371 | "0 Bulbasaur it's a blue and green Pokémon. It has a seed o...\n", 372 | "1 Pikachu it's a yellow and black Pokémon. It's a creatu..." 373 | ] 374 | }, 375 | "execution_count": 6, 376 | "metadata": {}, 377 | "output_type": "execute_result" 378 | } 379 | ], 380 | "source": [ 381 | "data.head(2)" 382 | ] 383 | }, 384 | { 385 | "cell_type": "markdown", 386 | "id": "bbef81d6-d439-4892-8760-16571eb206ff", 387 | "metadata": {}, 388 | "source": [ 389 | "![ChessUrl](https://media.giphy.com/media/I2nZMy0sI0ySA/giphy.gif \"chess\")" 390 | ] 391 | }, 392 | { 393 | "cell_type": "markdown", 394 | "id": "575f597f-ef20-411f-b241-6c57343debe2", 395 | "metadata": {}, 396 | "source": [ 397 | "## Model" 398 | ] 399 | }, 400 | { 401 | "cell_type": "markdown", 402 | "id": "67523b45-08df-4170-89c2-758cc3e1d14d", 403 | "metadata": {}, 404 | "source": [ 405 | "First of all we have to choose the version of the Stable Diffusion model we want to optimize, Speedster officially supports the most used versions:\n", 406 | "\n", 407 | "* [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4)\n", 408 | "* [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5)\n", 409 | "* [stabilityai/stable-diffusion-2-1-base](https://huggingface.co/stabilityai/stable-diffusion-2-1-base)\n", 410 | "* [stabilityai/stable-diffusion-2-1](https://huggingface.co/stabilityai/stable-diffusion-2-1)\n", 411 | "\n", 412 | "Other Stable Diffusion versions from the [Diffusers library](https://github.com/huggingface/diffusers) should work but have never been officially tested. \n", 413 | "\n", 414 | "⚠️ If you try a version not included among these and it works, please feel free to report it to us on [Discord](https://discord.com/invite/RbeQMu886J) so we can add it to the list of supported versions. If you try a version that does not work, you can open an issue and possibly a PR on [GitHub](https://github.com/nebuly-ai/nebullvm/tree/main/apps/accelerate/speedster) ⚠️\n", 415 | "\n", 416 | "In this notebook, we'll be utilizing the `Stable-Diffusion-v1-4` checkpoint. This checkpoint was initially based on the `Stable-Diffusion-v1-2` checkpoint's weights and subsequently fine-tuned for 225k steps at a resolution of 512x512 using \"laion-aesthetics v2 5+\" dataset, with 10% of text-conditioning removed to enhance classifier-free guidance sampling.\n", 417 | "\n", 418 | "**NOTE**: If you want to run the `stable-diffusion-2-1` version of Stable Diffusion, you need a GPU with a minimum of 22GB memory. If your GPU has less than 22GB memory, you can opt for other versions of the model, such as `stable-diffusion-2-1-base`." 419 | ] 420 | }, 421 | { 422 | "cell_type": "code", 423 | "execution_count": 7, 424 | "id": "60d40675-f2d6-466b-873b-fedff54ada67", 425 | "metadata": {}, 426 | "outputs": [], 427 | "source": [ 428 | "model_id = \"CompVis/stable-diffusion-v1-4\"" 429 | ] 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "id": "4bdbb1ac-c0a7-4449-9874-0a4047a31570", 434 | "metadata": { 435 | "tags": [] 436 | }, 437 | "source": [ 438 | "## Model Optimization" 439 | ] 440 | }, 441 | { 442 | "cell_type": "markdown", 443 | "id": "5a87ba42-851e-4dd3-b257-2384cf1cb272", 444 | "metadata": {}, 445 | "source": [ 446 | "Using Speedster's latest API, there are two options to enhance the speed of your models. The first option allows you to accelerate your models without compromising accuracy, whereas the second option lets you further increase their speed by specifying a desired level of accuracy or precision to trade-off. To achieve this acceleration, Speedster utilizes several optimization techniques, including deep learning compilers (in both options), quantization, and half accuracy, among others (in the second option).\n", 447 | "\n", 448 | "Here are the outcomes achieved for Stable Diffusion on the A10 GPU (the GPU that we will use) and on the 3090Ti:" 449 | ] 450 | }, 451 | { 452 | "cell_type": "markdown", 453 | "id": "3cd15de3-bd42-4d48-8000-9893f66151ac", 454 | "metadata": {}, 455 | "source": [ 456 | "\"cover\"" 457 | ] 458 | }, 459 | { 460 | "cell_type": "markdown", 461 | "id": "5f6448eb-ba8d-42ae-bedc-aa0ec1fd41d5", 462 | "metadata": {}, 463 | "source": [ 464 | "We conducted tests on each GPU, evaluating the performance of the four most commonly utilized versions of Stable Diffusion. We compared the performance of the base version in fp16 with the version utilizing xformers and the speedster-compiled model. Our findings demonstrate that the optimized attention algorithm implemented within xformers delivers considerably better performance than the base model, particularly for the most complex model (the 2.1). Moreover, Speedster enhances the model's speed even further. In fact, the latest version of TensorRT outperforms both the base version and the one that utilizes xformers in all tested cases." 465 | ] 466 | }, 467 | { 468 | "cell_type": "markdown", 469 | "id": "5acf8c77-76df-4b9a-aca6-518513b44745", 470 | "metadata": {}, 471 | "source": [ 472 | "When utilizing Speedster to optimize Stable Diffusion models from Hugging Face's Diffusers library, two easy steps must be followed:" 473 | ] 474 | }, 475 | { 476 | "cell_type": "markdown", 477 | "id": "6589671e-74bb-4599-a4ac-70a54f027379", 478 | "metadata": {}, 479 | "source": [ 480 | "1) Once you have selected and downloaded the desired model, generate a small set of sample input data:" 481 | ] 482 | }, 483 | { 484 | "cell_type": "code", 485 | "execution_count": 8, 486 | "id": "4a0c899f-8990-4fb2-b790-6605e0738069", 487 | "metadata": {}, 488 | "outputs": [], 489 | "source": [ 490 | "input_data = data.description[0:5].tolist()" 491 | ] 492 | }, 493 | { 494 | "cell_type": "markdown", 495 | "id": "1f2c6577-fe6f-4625-a8d7-57b9a08eb553", 496 | "metadata": {}, 497 | "source": [ 498 | "2) Run the optimization by specifying as arguments: \n", 499 | "* **Model**\n", 500 | "* **Input data**\n", 501 | "* **Optimization time** specify whether to limit or not\n", 502 | "* **Compilers to exclude** depending on hardware and model, certain compilers may be unsuitable\n", 503 | "* **Acceptable level of accuracy loss** during optimization, can be set to zero as well" 504 | ] 505 | }, 506 | { 507 | "cell_type": "markdown", 508 | "id": "387df72a-bbf7-4555-830a-f47f60031cd0", 509 | "metadata": {}, 510 | "source": [ 511 | "**Please note**: Optimization of stable diffusion requires **a lot of RAM**. If you are running this notebook on google colab, make sure to use the high RAM option, otherwise the kernel may crash. If the kernel crashes also when using the high RAM option, please try adding \"torchscript\" to the ignore_compilers list." 512 | ] 513 | }, 514 | { 515 | "cell_type": "markdown", 516 | "id": "d5f3c30a-094d-4db7-a767-869095e13fc3", 517 | "metadata": {}, 518 | "source": [ 519 | "### Optimization" 520 | ] 521 | }, 522 | { 523 | "cell_type": "markdown", 524 | "id": "025537b7-dab7-48e9-8ffd-7d8f99981198", 525 | "metadata": {}, 526 | "source": [ 527 | "Let's optimize the model on a single **A10 GPU**, note that on GPU we load by default the model in half precision, because it's faster and lighter:" 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": 9, 533 | "id": "f4d798f3", 534 | "metadata": {}, 535 | "outputs": [], 536 | "source": [ 537 | "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"" 538 | ] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "execution_count": null, 543 | "id": "4a63b5af-c43b-4b09-9fae-44d6bd93e40d", 544 | "metadata": {}, 545 | "outputs": [], 546 | "source": [ 547 | "if device == \"cuda\":\n", 548 | " pipe = StableDiffusionPipeline.from_pretrained(model_id, revision='fp16', torch_dtype=torch.float16)\n", 549 | "else:\n", 550 | " pipe = StableDiffusionPipeline.from_pretrained(model_id)\n", 551 | "\n", 552 | "pipe.to(device)" 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": null, 558 | "id": "809bfd2f-75b4-45f0-90c1-bc122810e8cf", 559 | "metadata": { 560 | "scrolled": true, 561 | "tags": [] 562 | }, 563 | "outputs": [], 564 | "source": [ 565 | "optimized_model = optimize_model(\n", 566 | " model=pipe,\n", 567 | " input_data=input_data,\n", 568 | " optimization_time=\"unconstrained\",\n", 569 | " ignore_compilers=[\"torch_tensor_rt\", \"tvm\"], # TensorRT from the torch pipeline has some issues with Stable Diffusion, so we are going to skip it.\n", 570 | " metric_drop_ths=0.2,\n", 571 | " device=device\n", 572 | ")" 573 | ] 574 | }, 575 | { 576 | "cell_type": "markdown", 577 | "id": "86ee4f47-a67b-4307-ad97-69e0582028e9", 578 | "metadata": {}, 579 | "source": [ 580 | "\"cover\"" 581 | ] 582 | }, 583 | { 584 | "cell_type": "markdown", 585 | "id": "d3f06958-0610-48dd-88db-72faff400aa1", 586 | "metadata": {}, 587 | "source": [ 588 | "As can be seen, the compiler that allows for greater acceleration of the model is TensorRT. Speedster has integrated the latest release of TensorRT, [**TensorRT v8.6.0**](https://github.com/NVIDIA/TensorRT/releases/tag/v8.6.0), which was recently made available by Nvidia.\n", 589 | "\n", 590 | "In essence, TensorRT optimizes a model's mathematical coordinates to strike a balance between the smallest possible size and highest achievable accuracy for the intended system. In the latest release, one of the key updates is that now the demoDiffusion acceleration is supported out of the box in TensorRT without requiring the installation of additional plugins.\n", 591 | "\n", 592 | "Using Speedster for diffusion models has enormous advantages over using TensorRT: \n", 593 | "1. Speedster takes as input directly the diffusers pipeline and automatically optimize and replace the diffusion model components. There is no need for the user to manually scan the model implementation looking for the UNet component, intercept the UNet inputs for checking the loss in precision after the optimization, compile it with TensorRT and wrap the output (a TensorRT engine) into a diffusers compatible format (pytorch-like model). All this complexity is abstracted away by Speedster, you just have to enjoy the speedup.\n", 594 | "2. Support for multiple HW devices: TensorRT is Nvidia’s proprietary compiler and it runs just on Nvidia GPUs. With Speedster, you can take advantage of faster optimizations on a wide variety of hardware devices, from CPUs to GPUs. \n", 595 | "\n", 596 | "The model has ~2 times acceleration. This value refers only to the speedup on the UNet. To actually see how the latency times change let's calculate benchmarks using the original model and the optimized one." 597 | ] 598 | }, 599 | { 600 | "cell_type": "markdown", 601 | "id": "11757fc6-de4b-42dc-a79e-a7685bd1c8cd", 602 | "metadata": {}, 603 | "source": [ 604 | "## Benchmarks" 605 | ] 606 | }, 607 | { 608 | "cell_type": "markdown", 609 | "id": "ed256ccb-ca4f-416a-bc80-f0893dc750b3", 610 | "metadata": {}, 611 | "source": [ 612 | "Let's run the prediction 10 times to calculate the average response time of the original model." 613 | ] 614 | }, 615 | { 616 | "cell_type": "code", 617 | "execution_count": 12, 618 | "id": "65720eee", 619 | "metadata": {}, 620 | "outputs": [], 621 | "source": [ 622 | "test_prompt = \"futuristic llama with a cyberpunk city on the background\"" 623 | ] 624 | }, 625 | { 626 | "cell_type": "code", 627 | "execution_count": null, 628 | "id": "b886630f", 629 | "metadata": {}, 630 | "outputs": [], 631 | "source": [ 632 | "if device == \"cuda\":\n", 633 | " pipe = StableDiffusionPipeline.from_pretrained(model_id, revision='fp16', torch_dtype=torch.float16)\n", 634 | "else:\n", 635 | " pipe = StableDiffusionPipeline.from_pretrained(model_id)\n", 636 | "\n", 637 | "pipe.to(device)" 638 | ] 639 | }, 640 | { 641 | "cell_type": "code", 642 | "execution_count": null, 643 | "id": "5ee63316-1d8f-43be-bf4d-5c58a264e504", 644 | "metadata": {}, 645 | "outputs": [], 646 | "source": [ 647 | "import time\n", 648 | "\n", 649 | "times = []\n", 650 | "\n", 651 | "# Warmup for 2 iterations\n", 652 | "for _ in range(2):\n", 653 | " with torch.no_grad():\n", 654 | " final_out = pipe(test_prompt).images[0]\n", 655 | "\n", 656 | "# Benchmark\n", 657 | "for _ in range(8):\n", 658 | " st = time.time()\n", 659 | " with torch.no_grad():\n", 660 | " final_out = pipe(test_prompt).images[0]\n", 661 | " times.append(time.time()-st)\n", 662 | "original_model_time = sum(times)/len(times)" 663 | ] 664 | }, 665 | { 666 | "cell_type": "code", 667 | "execution_count": 15, 668 | "id": "0ffb3c00-fc85-4e20-8044-0af25e8eb45a", 669 | "metadata": {}, 670 | "outputs": [ 671 | { 672 | "name": "stdout", 673 | "output_type": "stream", 674 | "text": [ 675 | "Average response time for original Stable Diffusion 1.4 on a A10 GPU: 4.100552409887314 s\n" 676 | ] 677 | } 678 | ], 679 | "source": [ 680 | "print(f\"Average response time for original Stable Diffusion 1.4 on a A10 GPU: {original_model_time} s\")" 681 | ] 682 | }, 683 | { 684 | "cell_type": "markdown", 685 | "id": "b060416d-1f65-487c-9dc0-66bf82d14346", 686 | "metadata": {}, 687 | "source": [ 688 | "While the average response of the optimized model turns out to be:" 689 | ] 690 | }, 691 | { 692 | "cell_type": "code", 693 | "execution_count": null, 694 | "id": "8d3bb530-34f0-443e-be3a-0889632aed10", 695 | "metadata": {}, 696 | "outputs": [], 697 | "source": [ 698 | "times = []\n", 699 | "\n", 700 | "for _ in range(2):\n", 701 | " with torch.no_grad():\n", 702 | " final_out = optimized_model(test_prompt).images[0]\n", 703 | "\n", 704 | "# Benchmark\n", 705 | "for _ in range(8):\n", 706 | " st = time.time()\n", 707 | " with torch.no_grad():\n", 708 | " final_out = optimized_model(test_prompt).images[0]\n", 709 | " times.append(time.time()-st)\n", 710 | "optimized_model_time = sum(times)/len(times)" 711 | ] 712 | }, 713 | { 714 | "cell_type": "code", 715 | "execution_count": 17, 716 | "id": "489beaeb-f26e-4197-9e7a-3bd0c5b7daa9", 717 | "metadata": {}, 718 | "outputs": [ 719 | { 720 | "name": "stdout", 721 | "output_type": "stream", 722 | "text": [ 723 | "Average response time for optimized Stable Diffusion 1.4: 2.160187304019928 s\n" 724 | ] 725 | } 726 | ], 727 | "source": [ 728 | "print(f\"Average response time for optimized Stable Diffusion 1.4: {optimized_model_time} s\")" 729 | ] 730 | }, 731 | { 732 | "cell_type": "markdown", 733 | "id": "d620e672-12fd-453a-931e-4925ae702bf6", 734 | "metadata": {}, 735 | "source": [ 736 | "The entire model has been sped up by roughly two times, reducing the average response time from around 4 seconds to approximately 2 seconds." 737 | ] 738 | }, 739 | { 740 | "cell_type": "markdown", 741 | "id": "d8e5d445-3b1a-4379-9a21-ff82b4cda08e", 742 | "metadata": {}, 743 | "source": [ 744 | "## Gradio App" 745 | ] 746 | }, 747 | { 748 | "cell_type": "markdown", 749 | "id": "cf13c459-6143-4815-9c3c-e8b4bb1b5767", 750 | "metadata": {}, 751 | "source": [ 752 | "\"neb_gradio\"" 753 | ] 754 | }, 755 | { 756 | "cell_type": "markdown", 757 | "id": "9780baf8-968c-4feb-9ea2-c4d242cd6233", 758 | "metadata": {}, 759 | "source": [ 760 | "In this section, we will show how to create a Gradio application that utilizes the **optimized Stable Diffusion model generated using Speedster**. \n", 761 | "\n", 762 | "This Gradio application will allow users to generate images of Pokémon based on the descriptions provided in the previously loaded dataset. Let's dive in and create our very own Pokémon generator using Stable Diffusion and Gradio!" 763 | ] 764 | }, 765 | { 766 | "cell_type": "markdown", 767 | "id": "586fd5e1-80c5-44e3-b713-f8cac6858a76", 768 | "metadata": {}, 769 | "source": [ 770 | "The initial stage involves creating an inference function that enables the generation of images based on a prompt" 771 | ] 772 | }, 773 | { 774 | "cell_type": "code", 775 | "execution_count": 18, 776 | "id": "183475c2-a3d9-4454-ace0-264e99d81293", 777 | "metadata": {}, 778 | "outputs": [], 779 | "source": [ 780 | "def infer(prompt, steps, scale):\n", 781 | " generator = torch.Generator(device=device)\n", 782 | "\n", 783 | " if device == 'cuda':\n", 784 | " with torch.autocast(device):\n", 785 | " image = optimized_model(\n", 786 | " f\"\"\"Cutest cartoon ever created: {prompt}\"\"\",\n", 787 | " num_inference_steps=steps,\n", 788 | " guidance_scale=scale,\n", 789 | " generator=generator,\n", 790 | " )\n", 791 | " else:\n", 792 | " image = optimized_model(\n", 793 | " f\"\"\"Cutest cartoon ever created: {prompt}\"\"\",\n", 794 | " num_inference_steps=steps,\n", 795 | " guidance_scale=scale,\n", 796 | " generator=generator,\n", 797 | " )\n", 798 | "\n", 799 | " return image" 800 | ] 801 | }, 802 | { 803 | "cell_type": "markdown", 804 | "id": "939efbcd-8325-46f8-83d9-7e57b05c4271", 805 | "metadata": {}, 806 | "source": [ 807 | "The function needs to be invoked with a randomly selected Pokémon description from the dataset as its input" 808 | ] 809 | }, 810 | { 811 | "cell_type": "code", 812 | "execution_count": 19, 813 | "id": "f3564c05-1402-4ee8-a52b-21ccb0d23ad9", 814 | "metadata": {}, 815 | "outputs": [], 816 | "source": [ 817 | "def generate_pokemon():\n", 818 | " seed = randrange(data.shape[0])\n", 819 | " random_description = data.iloc[seed][\"description\"]\n", 820 | " image = infer(random_description, 50, 7)\n", 821 | "\n", 822 | " return image[0][0], seed" 823 | ] 824 | }, 825 | { 826 | "cell_type": "markdown", 827 | "id": "1aa2b03a-c194-4145-93cc-690777fd6a2a", 828 | "metadata": {}, 829 | "source": [ 830 | "last but not least, let's make a function to get the name of the generated Pokémon" 831 | ] 832 | }, 833 | { 834 | "cell_type": "code", 835 | "execution_count": 20, 836 | "id": "3db5f847-45d3-4584-9cf7-55ab1a24862a", 837 | "metadata": {}, 838 | "outputs": [], 839 | "source": [ 840 | "def pokemon_name(seed):\n", 841 | " return data.iloc[int(seed)][\"name\"]" 842 | ] 843 | }, 844 | { 845 | "cell_type": "markdown", 846 | "id": "1b96f511-ce6e-47c5-91dd-18e2fd75be0e", 847 | "metadata": {}, 848 | "source": [ 849 | "Here is some CSS code to improve the visual appearance of our application:" 850 | ] 851 | }, 852 | { 853 | "cell_type": "code", 854 | "execution_count": 21, 855 | "id": "5622bfea-ee45-409e-ba25-43fa567a25f5", 856 | "metadata": {}, 857 | "outputs": [], 858 | "source": [ 859 | "css = \"\"\"\n", 860 | " .gradio-container {\n", 861 | " font-family: 'IBM Plex Sans', sans-serif;\n", 862 | " }\n", 863 | " .gr-button {\n", 864 | " color: white;\n", 865 | " border-color: black;\n", 866 | " background: black;\n", 867 | " }\n", 868 | " input[type='range'] {\n", 869 | " accent-color: black;\n", 870 | " }\n", 871 | " .dark input[type='range'] {\n", 872 | " accent-color: #dfdfdf;\n", 873 | " }\n", 874 | " .container {\n", 875 | " max-width: 730px;\n", 876 | " margin: auto;\n", 877 | " padding-top: 1.5rem;\n", 878 | " }\n", 879 | " #iamge {\n", 880 | " min-height: 22rem;\n", 881 | " margin-bottom: 15px;\n", 882 | " margin-left: auto;\n", 883 | " margin-right: auto;\n", 884 | " border-bottom-right-radius: .5rem !important;\n", 885 | " border-bottom-left-radius: .5rem !important;\n", 886 | " }\n", 887 | " #iamge>div>.h-full {\n", 888 | " min-height: 20rem;\n", 889 | " }\n", 890 | " .details:hover {\n", 891 | " text-decoration: underline;\n", 892 | " }\n", 893 | " .gr-button {\n", 894 | " white-space: nowrap;\n", 895 | " }\n", 896 | " .gr-button:focus {\n", 897 | " border-color: rgb(147 197 253 / var(--tw-border-opacity));\n", 898 | " outline: none;\n", 899 | " box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);\n", 900 | " --tw-border-opacity: 1;\n", 901 | " --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);\n", 902 | " --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);\n", 903 | " --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));\n", 904 | " --tw-ring-opacity: .5;\n", 905 | " }\n", 906 | " .footer {\n", 907 | " margin-bottom: 45px;\n", 908 | " margin-top: 35px;\n", 909 | " text-align: center;\n", 910 | " border-bottom: 1px solid #e5e5e5;\n", 911 | " }\n", 912 | " .footer>p {\n", 913 | " font-size: .8rem;\n", 914 | " display: inline-block;\n", 915 | " padding: 0 10px;\n", 916 | " transform: translateY(10px);\n", 917 | " background: white;\n", 918 | " }\n", 919 | " .dark .footer {\n", 920 | " border-color: #303030;\n", 921 | " }\n", 922 | " .dark .footer>p {\n", 923 | " background: #0b0f19;\n", 924 | " }\n", 925 | " .acknowledgments h4{\n", 926 | " margin: 1.25em 0 .25em 0;\n", 927 | " font-weight: bold;\n", 928 | " font-size: 115%;\n", 929 | " }\n", 930 | "\"\"\"" 931 | ] 932 | }, 933 | { 934 | "cell_type": "markdown", 935 | "id": "712447db-65a3-4f0c-b302-3f96375a3616", 936 | "metadata": {}, 937 | "source": [ 938 | "Lastly, we will develop and deploy the application. Moreover, it can be hosted on Hugging Face for a duration of 72 hours using:

demo.launch(share=True)

" 939 | ] 940 | }, 941 | { 942 | "cell_type": "code", 943 | "execution_count": null, 944 | "id": "153aaf85-f77d-49c8-bf55-8e25706bdb55", 945 | "metadata": {}, 946 | "outputs": [], 947 | "source": [ 948 | "with gr.Blocks(css=css) as demo:\n", 949 | " gr.HTML(\n", 950 | " \"\"\"\n", 951 | "
\n", 952 | " \n", 960 | " >\n", 961 | "\t\n", 968 | "\t\n", 974 | "\t\n", 981 | "\n", 982 | "

\n", 983 | " Stable Diffusion Loves Pokémon\n", 984 | "

\n", 985 | "
\n", 986 | "

\n", 987 | " Stable Diffusion is a state-of-the-art text-to-image model that generates images from text, \n", 988 | " in this demo it is used to generate Pokèmon from their description.

\n", 989 | "
\n", 990 | "
\n", 991 | "

\n", 992 | " Instructions: press the \"Generate a Pokémon!\" button to generate an image and try to see if you can guess the movie.\n", 993 | " You can see if you guessed right by pressing the \"Tell me the name\" button.\n", 994 | "

\n", 995 | "
\n", 996 | " NOTE: If a completely black image is generated, it means that the NSFW checker has blocked the display of the output.\n", 997 | " \n", 998 | " \"\"\"\n", 999 | " )\n", 1000 | " with gr.Group():\n", 1001 | " with gr.Box():\n", 1002 | " with gr.Row().style(mobile_collapse=False, equal_height=True):\n", 1003 | " b1 = gr.Button(\"Generate a Pokémon\")\n", 1004 | " b2 = gr.Button(\"Tell me the name\")\n", 1005 | " text = gr.Textbox(label=\"Name:\")\n", 1006 | " image = gr.Image(\n", 1007 | " label=\"Generated images\", show_label=False, elem_id=\"image\"\n", 1008 | " ).style(height=\"auto\")\n", 1009 | "\n", 1010 | " seed = gr.Number(visible=False)\n", 1011 | "\n", 1012 | " b1.click(generate_pokemon, inputs=None, outputs=[image, seed])\n", 1013 | " b2.click(pokemon_name, inputs=seed, outputs=text)\n", 1014 | "\n", 1015 | "demo.launch(share=False)" 1016 | ] 1017 | }, 1018 | { 1019 | "cell_type": "markdown", 1020 | "id": "48bd3be9-c1dc-42f0-bc6f-1ca9d1f9d8c7", 1021 | "metadata": {}, 1022 | "source": [ 1023 | "\"cover\"" 1024 | ] 1025 | }, 1026 | { 1027 | "cell_type": "markdown", 1028 | "id": "cdd69a59-a5ac-4b98-b658-aac14917fe13", 1029 | "metadata": {}, 1030 | "source": [ 1031 | "## Conclusions" 1032 | ] 1033 | }, 1034 | { 1035 | "cell_type": "markdown", 1036 | "id": "f4a21ded-8aa7-4dfb-a460-315bec08b4d6", 1037 | "metadata": {}, 1038 | "source": [ 1039 | "And here we are, Let's summarize what we saw in this notebook:\n", 1040 | "* Stable Diffusion is a text-to-image model mainly used to generate images based on textual descriptions\n", 1041 | "* Accelerating this model with Speedster is very simple and fast\n", 1042 | "* Speedster also integrates the latest version of TensorRT for 🚀🚀🚀🚀 performance and ease of use\n", 1043 | "* Using Speedster we achieve 2x faster model latency\n", 1044 | "* Using a Speedster-optimized model within a Gradio application is straightforward, as we showed in our example with the **guess the Pokémon** application\n", 1045 | "\n", 1046 | "We hope this notebook will be useful to you, also you can find many more speedster use cases in [this repository](https://github.com/nebuly-ai/learning-hub/notebooks).\n", 1047 | "\n", 1048 | "Remember to join our [Discord community](https://discord.com/invite/RbeQMu886J) and if you are interested in AI optimization or if you liked this notebook please leave a star at our repo [Speedster](https://github.com/nebuly-ai/nebullvm/tree/main/apps/accelerate/speedster) 💕🌟!" 1049 | ] 1050 | }, 1051 | { 1052 | "cell_type": "markdown", 1053 | "id": "27de5970-a8cc-4f04-a3d6-6d273252f84d", 1054 | "metadata": {}, 1055 | "source": [ 1056 | "![ChessUrl](https://media.giphy.com/media/slVWEctHZKvWU/giphy.gif \"env\")" 1057 | ] 1058 | }, 1059 | { 1060 | "cell_type": "code", 1061 | "execution_count": null, 1062 | "id": "7e4c72f5-5a9b-4bd5-838c-72971348a131", 1063 | "metadata": {}, 1064 | "outputs": [], 1065 | "source": [] 1066 | } 1067 | ], 1068 | "metadata": { 1069 | "kernelspec": { 1070 | "display_name": "Python 3 (ipykernel)", 1071 | "language": "python", 1072 | "name": "python3" 1073 | }, 1074 | "language_info": { 1075 | "codemirror_mode": { 1076 | "name": "ipython", 1077 | "version": 3 1078 | }, 1079 | "file_extension": ".py", 1080 | "mimetype": "text/x-python", 1081 | "name": "python", 1082 | "nbconvert_exporter": "python", 1083 | "pygments_lexer": "ipython3", 1084 | "version": "3.9.13" 1085 | } 1086 | }, 1087 | "nbformat": 4, 1088 | "nbformat_minor": 5 1089 | } 1090 | -------------------------------------------------------------------------------- /notes/README.md: -------------------------------------------------------------------------------- 1 | ![cover_notes](https://user-images.githubusercontent.com/53374883/225740129-1f08691b-9263-45cc-a8e3-f5739f2ceaf1.png) 2 | 3 |
4 | 5 |
6 | 7 |
8 | 9 | 10 | 11 |   12 |   13 |   14 | 15 | 16 | 17 |   18 |   19 |   20 | 21 | 22 | 23 |   24 |   25 |   26 | 27 | 28 | 29 |
30 |
31 | 32 | ## ❤️ Hi! 33 | In this repository, you can find notes on various topics including AI, optimization, and others, which have been taken from lectures, videos, or articles. The repository is still under construction 👷‍♀️ and we welcome contributions in all forms! 34 | 35 | 36 | | **topic** | **notes** | **references** | 37 | |:------------:|:------------:|:--------------:| 38 | |Basics of Neural Networks|[MIT 6.S965 Lecture 02](https://github.com/nebuly-ai/learning-hub/blob/main/notes/files/MIT6.S965/Lecture_02.pdf) | [![YouTube](https://badges.aleen42.com/src/youtube.svg)](https://www.youtube.com/watch?v=5HpLyZd1h0Q)| 39 | -------------------------------------------------------------------------------- /notes/files/MIT6.S965/Lecture_02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nebuly-ai/learning-hub/b5d5a2392466bb21d3c38cad524f236bc83e5d41/notes/files/MIT6.S965/Lecture_02.pdf --------------------------------------------------------------------------------