{"id":76,"date":"2025-11-22T22:12:18","date_gmt":"2025-11-22T14:12:18","guid":{"rendered":"https:\/\/lowenfu.idv.tw\/wordpress\/?p=76"},"modified":"2025-11-22T22:44:43","modified_gmt":"2025-11-22T14:44:43","slug":"ai_optimum-intel-diffusers","status":"publish","type":"post","link":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/2025\/11\/22\/ai_optimum-intel-diffusers\/","title":{"rendered":"\u6587\u751f\u5716Optimum-Intel + Diffusers"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">\u50b3\u7d71\u7684Stable Diffusion WebUI\u53ea\u80fd\u7528Nvidia GPU,AMD GPU,\u5982\u679c\u8981\u4f7f\u7528Intel\u7684GPU\u6587\u751f\u5716,\u53ea\u80fd\u53e6\u627e\u65b9\u6cd5,google\u597d\u5e7e\u5929\u4e0d\u65b7\u8a66\u932f\u9084\u662f\u505a\u4e0d\u51fa\u4f86(\u7db2\u8def\u4e0a\u4e00\u5806\u7528linux\u7684\u4f5c\u6cd5\u61c9\u8a72\u662f\u4e0d\u80fd\u7528\u4e86),\u7a81\u7136\u60f3\u5230\u958bvscode\u554fAI,\u7d50\u679c\u4e00\u5929\u5c31\u505a\u597d,\u611f\u5606AI\u6642\u4ee3\u771f\u7684\u4e0d\u4e00\u6a23\u4e86<\/h5>\n\n\n\n<p>\u4e00. \u5148\u5b89\u88ddpython3.10, git<\/p>\n\n\n\n<p>\u4e8c. \u5efa\u7acb\u865b\u64ec\u9694\u96e2\u74b0\u5883 (\u70ba\u4e86\u5716\u7247\u653e\u5927\u529f\u80fd\u641e\u58de\u74b0\u5883,AI\u9084\u662f\u6703\u51fa\u932f\u554a,\u597d\u5728AI\u6709\u6c42\u5fc5\u61c9,\u8fc5\u901f\u7d66\u51fa\u6b65\u9a5f)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code> 1. \u5220\u9664\u65e7\u73af\u5883\ncd C:\\AI\\sd-openvino\nRemove-Item -Recurse -Force .\\venv\n\n 2. \u521b\u5efa\u65b0\u73af\u5883\npython -m venv venv\n.\\venv\\Scripts\\Activate.ps1\n\n 3. \u5347\u7ea7 pip\npython -m pip install --upgrade pip\n\n 4. \u5b89\u88c5\u6838\u5fc3\u4f9d\u8d56\npip install optimum&#91;openvino,nncf]\npip install diffusers transformers accelerate\npip install gradio\npip install pillow\npip install peft\n\n 5. \u9a8c\u8bc1\u5b89\u88c5\npython -c \"from optimum.intel import OVStableDiffusionPipeline; print('OK')\"\npython -c \"from openvino.runtime import Core; print('Devices:', Core().available_devices)\"\n\n 6. \u8fd0\u884c webui\npython webui.py<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u4e09. \u6a21\u578b\u9700\u5f9eHugging Face\u4e0b\u8f09\u4e26\u8f49\u63db\u6210OpenVINO\u683c\u5f0f, \u82b1\u5f88\u591a\u6642\u9593\u8a66\u5404\u7a2e\u6a21\u578b, \u8ddfstable diffusion\u7684\u6a21\u578b\u6bd4, \u540d\u7a31\u4e00\u6a23\u4f46\u6587\u751f\u5716\u6210\u679c\u4e0d\u592a\u4e00\u6a23, \u53ea\u80fd\u6162\u6162\u8a66<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from optimum.intel import OVStableDiffusionPipeline\nfrom pathlib import Path\nimport argparse\n\ndef download_and_convert(model_id, output_dir, device=\"GPU\"):\n    \"\"\"\u4e0b\u8f09\u4e26\u8f49\u63db\u6a21\u578b\u70ba OpenVINO \u683c\u5f0f\"\"\"\n    print(f\"\ud83d\udce5 \u4e0b\u8f09\u6a21\u578b: {model_id}\")\n    print(f\"\ud83d\udcbe \u8f38\u51fa\u76ee\u9304: {output_dir}\")\n    \n    # \u8f09\u5165\u4e26\u8f49\u63db\n    pipe = OVStableDiffusionPipeline.from_pretrained(\n        model_id,\n        export=True,\n        device=device,\n        compile=False  # \u9996\u6b21\u4e0d\u7de8\u8b6f\uff0c\u8b93\u9996\u6b21\u4f7f\u7528\u6642\u7de8\u8b6f\n    )\n    \n    # \u4fdd\u5b58\n    output_path = Path(output_dir)\n    pipe.save_pretrained(output_path)\n    print(f\"\u2705 \u6a21\u578b\u5df2\u4fdd\u5b58\u5230: {output_path}\")\n    \n    return output_path\n\ndef list_models(models_dir=\".\/models\"):\n    \"\"\"\u5217\u51fa\u5df2\u4e0b\u8f09\u7684\u6a21\u578b\"\"\"\n    models_path = Path(models_dir)\n    if not models_path.exists():\n        print(\"\u274c \u6a21\u578b\u76ee\u9304\u4e0d\u5b58\u5728\")\n        return\n    \n    print(\"\\n\ud83d\udce6 \u5df2\u5b89\u88dd\u7684\u6a21\u578b:\")\n    print(\"-\" * 60)\n    \n    for model_dir in models_path.iterdir():\n        if model_dir.is_dir() and (model_dir \/ \"model_index.json\").exists():\n            size = sum(f.stat().st_size for f in model_dir.rglob('*') if f.is_file())\n            size_gb = size \/ (1024**3)\n            print(f\"  \u2713 {model_dir.name} ({size_gb:.2f} GB)\")\n    \n    print(\"-\" * 60)\n\ndef main():\n    parser = argparse.ArgumentParser(description=\"Stable Diffusion \u6a21\u578b\u7ba1\u7406\u5de5\u5177\")\n    parser.add_argument(\"--download\", type=str, help=\"\u4e0b\u8f09\u6a21\u578b\uff08Hugging Face ID\uff09\")\n    parser.add_argument(\"--output\", type=str, default=\".\/models\", help=\"\u8f38\u51fa\u76ee\u9304\")\n    parser.add_argument(\"--name\", type=str, help=\"\u6a21\u578b\u540d\u7a31\")\n    parser.add_argument(\"--list\", action=\"store_true\", help=\"\u5217\u51fa\u5df2\u5b89\u88dd\u7684\u6a21\u578b\")\n    parser.add_argument(\"--device\", type=str, default=\"GPU\", help=\"\u8a2d\u5099\uff08GPU\/CPU\/NPU\uff09\")\n    \n    args = parser.parse_args()\n    \n    if args.list:\n        list_models(args.output)\n    elif args.download:\n        model_name = args.name or args.download.split(\"\/\")&#91;-1]\n        output_dir = Path(args.output) \/ f\"{model_name}-openvino\"\n        download_and_convert(args.download, output_dir, args.device)\n    else:\n        parser.print_help()\n\nif __name__ == \"__main__\":\n    main()<\/code><\/pre>\n\n\n\n<p>\u56db. VAE\u5f88\u91cd\u8981,\u4e0d\u7136\u4eba\u81c9\u4e0d\u80fd\u770b,\u597d\u5728AI\u5f88\u5feb\u7d66\u51fa\u4f5c\u6cd5,\u505a\u5728webui.py\u88e1,\u8b9a<\/p>\n\n\n\n<p>\u4e94. Lora\u5728openvino\u88e1\u4e0d\u662f\u5f88\u597d\u7528,\u5148\u66ab\u6642\u8df3\u904e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>powershell\ncd C:\\AI\\sd-openvino\n.\\venv\\Scripts\\Activate.ps1\npython webui.py\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"583\" src=\"https:\/\/lowenfu.idv.tw\/wordpress\/wp-content\/uploads\/2025\/11\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2025-11-22-221010-1024x583.png\" alt=\"\" class=\"wp-image-77\" srcset=\"https:\/\/lowenfu.idv.tw\/wordpress\/wp-content\/uploads\/2025\/11\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2025-11-22-221010-1024x583.png 1024w, https:\/\/lowenfu.idv.tw\/wordpress\/wp-content\/uploads\/2025\/11\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2025-11-22-221010-300x171.png 300w, https:\/\/lowenfu.idv.tw\/wordpress\/wp-content\/uploads\/2025\/11\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2025-11-22-221010-768x438.png 768w, https:\/\/lowenfu.idv.tw\/wordpress\/wp-content\/uploads\/2025\/11\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2025-11-22-221010-1536x875.png 1536w, https:\/\/lowenfu.idv.tw\/wordpress\/wp-content\/uploads\/2025\/11\/\u87a2\u5e55\u64f7\u53d6\u756b\u9762-2025-11-22-221010-2048x1167.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u7528Intel GPU\u6587\u751f\u5716,\u901f\u5ea6\u5feb,\u518d\u4e5f\u4e0d\u7528\u62ffCPU\u6162\u6162\u8dd1\u4e86,\u8b9a\u5566<\/p>\n\n\n\n<p>\u552f\u4e00\u7684\u554f\u984c\u662fprompt\u6709\u5b57\u6578\u9650\u523672Tokens, prompt\u53ea\u80fd\u8b1b\u91cd\u9ede, \u82e5\u662f\u6709\u597d\u4e00\u9ede\u7684GPU\u7684\u8a71\u8dd1SDXL\u6a21\u578b,\u5b57\u6578\u53ef\u4ee5\u518d\u591a\u4e00\u9ede<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u50b3\u7d71\u7684Stable Diffusion WebUI\u53ea\u80fd\u7528Nvidia GPU,AMD GPU,\u5982\u679c\u8981\u4f7f\u7528Int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-aitxt2img"],"_links":{"self":[{"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":6,"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":84,"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions\/84"}],"wp:attachment":[{"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lowenfu.idv.tw\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}