Skip to content

Commit

Permalink
Add readme and license
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmed92 committed Nov 6, 2023
1 parent 0f6f543 commit 9944a65
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2023 Softwired Technologies Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Stable Diffusion on [tinygrad](https://github.com/tinygrad/tinygrad) WebGPU

This is a WebGPU port of Stable Diffusion in [tinygrad](https://github.com/tinygrad/tinygrad).<br>
The python code I wrote to compile and export the model can be found [here](https://github.com/tinygrad/tinygrad/blob/master/examples/webgpu/stable_diffusion/compile.py)

## How it works

The Stable Diffusion model is exported in three parts:
- textModel
- diffusor
- decoder

If you open [net.js](./net.js) you can see all the WebGPU kernels that are involved in the inference.<br>
When you open the page for the first time, the model will be downloaded from [huggingface](https://huggingface.co/wpmed/tinygrad-sd-f16/resolve/main) in tinygrad's safetensor format. The model is in f16 to optimize download speed.<br>
Since the computation is done in `f32` in the model, and since `shader-f16` is not yet supported in production Chrome, the model is decompressed to `f32` using [f16_to_f32.js](./f16_to_f32.js).<br>
When you open the site a second time, the model will be loaded from the `IndexedDB` cache into which it was saved on first visit. If you have a full cache hit, the model will be decompressed, compiled and ready to use. If you have a cache miss (usually due to `QuotaExceededError`), the model will be redownloaded.

## License

MIT

0 comments on commit 9944a65

Please sign in to comment.