10000 Quantization stable diffusion by thliang01 · Pull Request #84 · huggingface/cookbook · GitHub
[go: up one dir, main page]

Skip to content

Quantization stable diffusion #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
05c429c
feat: initial notebook
thliang01 Apr 25, 2024
a61c958
feat: add title to _toctree file
thliang01 Apr 25, 2024
60433d9
feat: add base sdxl model
thliang01 Apr 25, 2024
a9a74bc
fix: clear all outputs
thliang01 Apr 25, 2024
476e139
feat: add evaluation
thliang01 Apr 25, 2024
f508c9d
feat: add Quantitative Evaluation
thliang01 Apr 26, 2024
f04848d
feat: install quanto
thliang01 Apr 26, 2024
2b20e2a
doc: rewrite selection title name
thliang01 Apr 27, 2024
6451982
docs: add desciption about evaluating diffusion model
thliang01 Apr 28, 2024
77e3e8e
feat: remove broken quantization code blocks
thliang01 Apr 29, 2024
04389f8
feat: add Post Training Quantization method W8A16
thliang01 Apr 29, 2024
d7d2a67
chore: remove unused library & change default pipeline from pipe to p…
thliang01 Apr 29, 2024
0fc2066
feat: add evaluating PTQ diffusion model
thliang01 Apr 29, 2024
7af2d0c
feat: add messure time & memory & Conclusion & References
thliang01 Apr 29, 2024
64e4ef3
docs: add description about quantization (post training quantization)
thliang01 Apr 29, 2024
0eaa6ec
docs: add empty images link
thliang01 Apr 29, 2024
a5c15e9
docs: change title name
thliang01 Apr 30, 2024
984eae8
chore: rename notebook
thliang01 Apr 30, 2024
e3ae110
Revert "chore: rename notebook"
thliang01 Apr 30, 2024
4f194bd
chore: rename notebook name
thliang01 Apr 30, 2024
9bc56dd
docs: remove unread doc
thliang01 May 1, 2024
9eb2458
feat: serval bugs
thliang01 May 1, 2024
bbf0d9c
feat: add import VAE
thliang01 May 1, 2024
91f525d
feat: add vae
thliang01 May 1, 2024
fe25434
chore: remove fuse_qkv_projections
thliang01 May 3, 2024
a84afab
feat: fix bugs
thliang01 May 4, 2024
d17867d
feat: add ptq vae
thliang01 May 5, 2024
4b81bb4
feat: add new conclusion score
thliang01 May 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add evaluation
* CLIP score
  • Loading branch information
thliang01 committed Apr 25, 2024
commit 476e139c206380730a53c86c72ec7d8ee6a9a76b
62 changes: 59 additions & 3 deletions notebooks/en/quantization_stable_diffusion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"outputs": [],
"source": [
"! pip install --upgrade diffusers accelerate transformers safetensors\n",
"! pip install -q numpy Pillow"
"! pip install -q numpy Pillow torchmetrics"
]
},
{
Expand Down Expand Up @@ -113,9 +113,65 @@
"outputs": [],
"source": [
"prompt = \"a photo of an astronaut riding a horse on mars\"\n",
"image = pipe(prompt).images[0]\n",
"image"
"images = pipe(prompt).images[0]\n",
"images"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Quantitative Evaluation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"prompts = [\n",
" \"a photo of an astronaut riding a horse on mars\",\n",
" \"A high tech solarpunk utopia in the Amazon rainforest\",\n",
" # \"A pikachu fine dining with a view to the Eiffel Tower\",\n",
" # \"A mecha robot in a favela in expressionist style\",\n",
" # \"an insect robot preparing a delicious meal\",\n",
" # \"A small cabin on top of a snowy mountain in the style of Disney, artstation\",\n",
"]\n",
"\n",
"images = pipe(prompts, num_images_per_prompt=1, output_type=\"np\").images\n",
"\n",
"print(images.shape)\n",
"# (6, 512, 512, 3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from torchmetrics.functional.multimodal import clip_score\n",
"from functools import partial\n",
"\n",
"clip_score_fn = partial(clip_score, model_name_or_path=\"openai/clip-vit-base-patch16\")\n",
"\n",
"def calculate_clip_score(images, prompts):\n",
" images_int = (images * 255).astype(\"uint8\")\n",
" clip_score = clip_score_fn(torch.from_numpy(images_int).permute(0, 3, 1, 2), prompts).detach()\n",
" return round(float(clip_score), 4)\n",
"\n",
"sd_clip_score = calculate_clip_score(images, prompts)\n",
"print(f\"CLIP score: {sd_clip_score}\")\n",
"# CLIP score: 35.7038"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
0