{
    "componentChunkName": "component---src-templates-post-js",
    "path": "/stable-diffusionwodockerdedong-kasu-with-cpu/",
    "result": {"data":{"ghostPost":{"id":"Ghost__Post__6315bcefa35ab30001cac2e2","title":"Stable DiffusionをDockerで動かす on CPU","slug":"stable-diffusionwodockerdedong-kasu-with-cpu","featured":false,"feature_image":"https://ghost.tech.anti-pattern.co.jp/content/images/2022/09/test-3.png","excerpt":"Stable Diffusion\n今何かと話題なStable Diffusionをローカルで動かしてみたい。\n\n商用利用も可能とのことで、広告素材にも使えたら熱いと思い試してみる。\n\n※GPUを使って動かそうとすると少し準備が大変そうだったので、また次回\n\nGitHub - CompVis/stable-diffusionContribute to CompVis/stable-diffusion\ndevelopment by creating an account on GitHub.GitHubCompVis\n[https://github.com/CompVis/stable-diffusion]作ったもの\nGitHub - kooooohe/stable-diffusionContribute to kooooohe/stable-diffusion\ndevelopment by creating an account on GitHub.GitHubkooooohe\n[https://github.com/kooooohe/stable-diffusion]環境\nUbuntu","custom_excerpt":null,"visibility":"public","created_at_pretty":"05 September, 2022","published_at_pretty":"07 September, 2022","updated_at_pretty":"07 September, 2022","created_at":"2022-09-05T18:10:07.000+09:00","published_at":"2022-09-07T16:17:13.000+09:00","updated_at":"2022-09-07T16:17:19.000+09:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"name":"Kohei Kondo","slug":"kooooohe","bio":null,"profile_image":"https://ghost.tech.anti-pattern.co.jp/content/images/2022/04/MVIMG_20180910_102813.png","twitter":"@kooooohe_","facebook":null,"website":null}],"primary_author":{"name":"Kohei Kondo","slug":"kooooohe","bio":null,"profile_image":"https://ghost.tech.anti-pattern.co.jp/content/images/2022/04/MVIMG_20180910_102813.png","twitter":"@kooooohe_","facebook":null,"website":null},"primary_tag":null,"tags":[],"plaintext":"Stable Diffusion\n今何かと話題なStable Diffusionをローカルで動かしてみたい。\n\n商用利用も可能とのことで、広告素材にも使えたら熱いと思い試してみる。\n\n※GPUを使って動かそうとすると少し準備が大変そうだったので、また次回\n\nGitHub - CompVis/stable-diffusionContribute to CompVis/stable-diffusion\ndevelopment by creating an account on GitHub.GitHubCompVis\n[https://github.com/CompVis/stable-diffusion]作ったもの\nGitHub - kooooohe/stable-diffusionContribute to kooooohe/stable-diffusion\ndevelopment by creating an account on GitHub.GitHubkooooohe\n[https://github.com/kooooohe/stable-diffusion]環境\nUbuntu 20.04.5 LTS\nAMD® Ryzen 7 pro 5850u with radeon graphics × 16 \nAMD® Renoir\nmemory: 48GB\n\n\n\ndocker composeで動かす\n\n\nservices:\n  stable-diffusion:\n    build: .\n    volumes:\n      - ./app:/app\n      - .cache/huggingface:/root/.cache/huggingface\n    working_dir: /app\n    tty: true\n\nFROM pytorch/pytorch:latest\n\nRUN pip3 install --upgrade diffusers transformers scipy\n\n\n\n初回実行時に\n\ngit clone https://github.com/kooooohe/stable-diffusion app\n\nとして、volume先にcloneしておく。\n\ndocker compose up\n\ndocker compose stable-diffusion exec bash\n\nでコンテナに入り、下記プログラムを実行する。\n\nimport torch\nfrom diffusers import StableDiffusionPipeline\nfrom torch import autocast\n \nMODEL_ID = \"CompVis/stable-diffusion-v1-4\"\nDEVICE = \"cpu\"\nYOUR_TOKEN = \"YOUR TOKEN\"\n \npipe = StableDiffusionPipeline.from_pretrained(MODEL_ID,  use_auth_token=YOUR_TOKEN)\npipe.to(DEVICE)\n\nprompt = \"A digital Illustration of Cloud\"\n \nimage = pipe(prompt, guidance_scale=7.5)[\"sample\"][0]\nimage.save(\"test.png\")\n\n※公式のGitHubのsampleプログラムを実行するとGPUを使おうとしてエラーを吐いたので、とりあえず今の環境（CPU)でも動くように改変しています。\n\n※tokenは予め公式の情報をみて取得しておいてください。\n\n結果\n実行時間: 約14分\n\nftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [10:59, 12.94s/it]\nroot@f3ef6ab788c6:/app# python3 sample.py \nftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [11:12, 13.19s/it]\nroot@f3ef6ab788c6:/app# python3 sample.py \nftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [14:05, 16.57s/it]\nroot@f3ef6ab788c6:/app# python3 sapmle.py \nftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [12:13, 14.39s/it]\n\n終わりに\n機械でできた雲を出力しようとしましたが、なかなか難しかったです。\n\nグーグル検索をして目的の情報を探すスキルのように、AIに期待する画像を出力させる文言選択のスキルが必要だなと感じました。","html":"<h1 id=\"stable-diffusion\">Stable Diffusion</h1><p>今何かと話題なStable Diffusionをローカルで動かしてみたい。</p><p>商用利用も可能とのことで、広告素材にも使えたら熱いと思い試してみる。</p><p>※GPUを使って動かそうとすると少し準備が大変そうだったので、また次回</p><figure class=\"kg-card kg-bookmark-card\"><a class=\"kg-bookmark-container\" href=\"https://github.com/CompVis/stable-diffusion\"><div class=\"kg-bookmark-content\"><div class=\"kg-bookmark-title\">GitHub - CompVis/stable-diffusion</div><div class=\"kg-bookmark-description\">Contribute to CompVis/stable-diffusion development by creating an account on GitHub.</div><div class=\"kg-bookmark-metadata\"><img class=\"kg-bookmark-icon\" src=\"https://github.githubassets.com/favicons/favicon.svg\"><span class=\"kg-bookmark-author\">GitHub</span><span class=\"kg-bookmark-publisher\">CompVis</span></div></div><div class=\"kg-bookmark-thumbnail\"><img src=\"https://opengraph.githubassets.com/3d9ba20bf2675cd4d9b1937557adfef78cd7bf29609a12f6054629c5e7363e4a/CompVis/stable-diffusion\"></div></a></figure><h2 id=\"%E4%BD%9C%E3%81%A3%E3%81%9F%E3%82%82%E3%81%AE\">作ったもの</h2><figure class=\"kg-card kg-bookmark-card\"><a class=\"kg-bookmark-container\" href=\"https://github.com/kooooohe/stable-diffusion\"><div class=\"kg-bookmark-content\"><div class=\"kg-bookmark-title\">GitHub - kooooohe/stable-diffusion</div><div class=\"kg-bookmark-description\">Contribute to kooooohe/stable-diffusion development by creating an account on GitHub.</div><div class=\"kg-bookmark-metadata\"><img class=\"kg-bookmark-icon\" src=\"https://github.githubassets.com/favicons/favicon.svg\"><span class=\"kg-bookmark-author\">GitHub</span><span class=\"kg-bookmark-publisher\">kooooohe</span></div></div><div class=\"kg-bookmark-thumbnail\"><img src=\"https://opengraph.githubassets.com/ee2a1e83cdc8bfc0a4f5dc099bc7f3b420633f7ff23e874f02b722f293dcb9ee/kooooohe/stable-diffusion\"></div></a></figure><h1 id=\"%E7%92%B0%E5%A2%83\">環境</h1><pre><code>Ubuntu 20.04.5 LTS\nAMD® Ryzen 7 pro 5850u with radeon graphics × 16 \nAMD® Renoir\nmemory: 48GB</code></pre><p></p><h1 id=\"docker-compose%E3%81%A7%E5%8B%95%E3%81%8B%E3%81%99\">docker composeで動かす</h1><p></p><pre><code class=\"language-yaml\">services:\n  stable-diffusion:\n    build: .\n    volumes:\n      - ./app:/app\n      - .cache/huggingface:/root/.cache/huggingface\n    working_dir: /app\n    tty: true</code></pre><pre><code class=\"language-Dockerfile\">FROM pytorch/pytorch:latest\n\nRUN pip3 install --upgrade diffusers transformers scipy</code></pre><p></p><p>初回実行時に</p><p><code>git clone <a href=\"https://github.com/kooooohe/stable-diffusion\">https://github.com/kooooohe/stable-diffusion</a> app</code></p><p>として、volume先にcloneしておく。</p><p><code>docker compose up</code></p><p><code>docker compose stable-diffusion exec bash</code></p><p>でコンテナに入り、下記プログラムを実行する。</p><pre><code class=\"language-python\">import torch\nfrom diffusers import StableDiffusionPipeline\nfrom torch import autocast\n \nMODEL_ID = \"CompVis/stable-diffusion-v1-4\"\nDEVICE = \"cpu\"\nYOUR_TOKEN = \"YOUR TOKEN\"\n \npipe = StableDiffusionPipeline.from_pretrained(MODEL_ID,  use_auth_token=YOUR_TOKEN)\npipe.to(DEVICE)\n\nprompt = \"A digital Illustration of Cloud\"\n \nimage = pipe(prompt, guidance_scale=7.5)[\"sample\"][0]\nimage.save(\"test.png\")</code></pre><p>※公式のGitHubのsampleプログラムを実行するとGPUを使おうとしてエラーを吐いたので、とりあえず今の環境（CPU)でも動くように改変しています。</p><p>※tokenは予め公式の情報をみて取得しておいてください。</p><h2 id=\"%E7%B5%90%E6%9E%9C\">結果</h2><p>実行時間: 約14分</p><pre><code>ftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [10:59, 12.94s/it]\nroot@f3ef6ab788c6:/app# python3 sample.py \nftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [11:12, 13.19s/it]\nroot@f3ef6ab788c6:/app# python3 sample.py \nftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [14:05, 16.57s/it]\nroot@f3ef6ab788c6:/app# python3 sapmle.py \nftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.\n51it [12:13, 14.39s/it]</code></pre><figure class=\"kg-card kg-image-card\"><img src=\"https://ghost.tech.anti-pattern.co.jp/content/images/2022/09/test.png\" class=\"kg-image\" alt loading=\"lazy\" width=\"512\" height=\"512\"></figure><figure class=\"kg-card kg-image-card\"><img src=\"https://ghost.tech.anti-pattern.co.jp/content/images/2022/09/test3.png\" class=\"kg-image\" alt loading=\"lazy\" width=\"512\" height=\"512\"></figure><figure class=\"kg-card kg-image-card\"><img src=\"https://ghost.tech.anti-pattern.co.jp/content/images/2022/09/test4.png\" class=\"kg-image\" alt loading=\"lazy\" width=\"512\" height=\"512\"></figure><figure class=\"kg-card kg-image-card\"><img src=\"https://ghost.tech.anti-pattern.co.jp/content/images/2022/09/test5.png\" class=\"kg-image\" alt loading=\"lazy\" width=\"512\" height=\"512\"></figure><figure class=\"kg-card kg-image-card\"><img src=\"https://ghost.tech.anti-pattern.co.jp/content/images/2022/09/test6.png\" class=\"kg-image\" alt loading=\"lazy\" width=\"512\" height=\"512\"></figure><figure class=\"kg-card kg-image-card\"><img src=\"https://ghost.tech.anti-pattern.co.jp/content/images/2022/09/test-2.png\" class=\"kg-image\" alt loading=\"lazy\" width=\"512\" height=\"512\"></figure><h1 id=\"%E7%B5%82%E3%82%8F%E3%82%8A%E3%81%AB\">終わりに</h1><p>機械でできた雲を出力しようとしましたが、なかなか難しかったです。</p><p>グーグル検索をして目的の情報を探すスキルのように、AIに期待する画像を出力させる文言選択のスキルが必要だなと感じました。</p>","url":"https://ghost.tech.anti-pattern.co.jp/stable-diffusionwodockerdedong-kasu-with-cpu/","canonical_url":null,"uuid":"87a68107-15b8-4347-9e3a-6d821ba3ea24","page":null,"codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"6315bcefa35ab30001cac2e2","reading_time":3}},"pageContext":{"slug":"stable-diffusionwodockerdedong-kasu-with-cpu"}},
    "staticQueryHashes": ["176528973","2358152166","2561578252","2731221146","4145280475"]}