recoilme commited on
Commit
c33ebd9
·
verified ·
1 Parent(s): dd118ba

Upload folder using huggingface_hub

Browse files
Untitled.ipynb CHANGED
@@ -2,61 +2,65 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 16,
6
  "id": "dca3239c-17d6-4284-a2cf-83237a55a7df",
7
  "metadata": {},
8
  "outputs": [
9
  {
10
  "data": {
11
  "application/vnd.jupyter.widget-view+json": {
12
- "model_id": "0314d609c09a4ad3b8c9d432e549330f",
13
  "version_major": 2,
14
  "version_minor": 0
15
  },
16
  "text/plain": [
17
- "pipeline_waifu.py: 0%| | 0.00/14.1k [00:00<?, ?B/s]"
18
  ]
19
  },
20
  "metadata": {},
21
  "output_type": "display_data"
22
  },
23
  {
24
- "ename": "NameError",
25
- "evalue": "name 'Union' is not defined",
26
- "output_type": "error",
27
- "traceback": [
28
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
29
- "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
30
- "Cell \u001b[0;32mIn[16], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m pipe_id \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAiArtLab/waifu-2b\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 5\u001b[0m variant \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfp16\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m----> 6\u001b[0m pipe \u001b[38;5;241m=\u001b[39m \u001b[43mDiffusionPipeline\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_pretrained\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43mpipe_id\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43mvariant\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mvariant\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[43m \u001b[49m\u001b[43mtrust_remote_code\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\n\u001b[1;32m 10\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;28mprint\u001b[39m(pipe)\n\u001b[1;32m 12\u001b[0m \u001b[38;5;66;03m#pipe_sd.to(\"cuda\")\u001b[39;00m\n",
31
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
32
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/diffusers/pipelines/pipeline_utils.py:731\u001b[0m, in \u001b[0;36mDiffusionPipeline.from_pretrained\u001b[0;34m(cls, pretrained_model_name_or_path, **kwargs)\u001b[0m\n\u001b[1;32m 726\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m pretrained_model_name_or_path\u001b[38;5;241m.\u001b[39mcount(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 727\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 728\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe provided pretrained_model_name_or_path \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpretrained_model_name_or_path\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 729\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m is neither a valid local path nor a valid repo id. Please check the parameter.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 730\u001b[0m )\n\u001b[0;32m--> 731\u001b[0m cached_folder \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdownload\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 732\u001b[0m \u001b[43m \u001b[49m\u001b[43mpretrained_model_name_or_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 733\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 734\u001b[0m \u001b[43m \u001b[49m\u001b[43mforce_download\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mforce_download\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 735\u001b[0m \u001b[43m \u001b[49m\u001b[43mproxies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 736\u001b[0m \u001b[43m \u001b[49m\u001b[43mlocal_files_only\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlocal_files_only\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 737\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 738\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 739\u001b[0m \u001b[43m \u001b[49m\u001b[43mfrom_flax\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfrom_flax\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 740\u001b[0m \u001b[43m \u001b[49m\u001b[43muse_safetensors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muse_safetensors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 741\u001b[0m \u001b[43m \u001b[49m\u001b[43muse_onnx\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muse_onnx\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 742\u001b[0m \u001b[43m \u001b[49m\u001b[43mcustom_pipeline\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcustom_pipeline\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 743\u001b[0m \u001b[43m \u001b[49m\u001b[43mcustom_revision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcustom_revision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 744\u001b[0m \u001b[43m \u001b[49m\u001b[43mvariant\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mvariant\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 745\u001b[0m \u001b[43m \u001b[49m\u001b[43mload_connected_pipeline\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mload_connected_pipeline\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 746\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 747\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 748\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 749\u001b[0m cached_folder \u001b[38;5;241m=\u001b[39m pretrained_model_name_or_path\n",
33
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
34
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/diffusers/pipelines/pipeline_utils.py:1381\u001b[0m, in \u001b[0;36mDiffusionPipeline.download\u001b[0;34m(cls, pretrained_model_name, **kwargs)\u001b[0m\n\u001b[1;32m 1374\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 1375\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe repository for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpretrained_model_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m contains custom code in \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.py, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin([os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(k,\u001b[38;5;250m \u001b[39mv)\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mfor\u001b[39;00m\u001b[38;5;250m \u001b[39mk,v\u001b[38;5;250m \u001b[39m\u001b[38;5;129;01min\u001b[39;00m\u001b[38;5;250m \u001b[39mcustom_components\u001b[38;5;241m.\u001b[39mitems()])\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m which must be executed to correctly \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1376\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mload the model. You can inspect the repository content at \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mjoin([\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhttps://hf.co/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpretrained_model_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mk\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mv\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.py\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mfor\u001b[39;00m\u001b[38;5;250m \u001b[39mk,v\u001b[38;5;250m \u001b[39m\u001b[38;5;129;01min\u001b[39;00m\u001b[38;5;250m \u001b[39mcustom_components\u001b[38;5;241m.\u001b[39mitems()])\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1377\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPlease pass the argument `trust_remote_code=True` to allow custom code to be run.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1378\u001b[0m )\n\u001b[1;32m 1380\u001b[0m \u001b[38;5;66;03m# retrieve passed components that should not be downloaded\u001b[39;00m\n\u001b[0;32m-> 1381\u001b[0m pipeline_class \u001b[38;5;241m=\u001b[39m \u001b[43m_get_pipeline_class\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1382\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mcls\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1383\u001b[0m \u001b[43m \u001b[49m\u001b[43mconfig_dict\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1384\u001b[0m \u001b[43m \u001b[49m\u001b[43mload_connected_pipeline\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mload_connected_pipeline\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1385\u001b[0m \u001b[43m \u001b[49m\u001b[43mcustom_pipeline\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcustom_pipeline\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1386\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpretrained_model_name\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mload_pipe_from_hub\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 1387\u001b[0m \u001b[43m \u001b[49m\u001b[43mhub_revision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1388\u001b[0m \u001b[43m \u001b[49m\u001b[43mclass_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcustom_class_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1389\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1390\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcustom_revision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1391\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1392\u001b[0m expected_components, _ \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39m_get_signature_keys(pipeline_class)\n\u001b[1;32m 1393\u001b[0m passed_components \u001b[38;5;241m=\u001b[39m [k \u001b[38;5;28;01mfor\u001b[39;00m k \u001b[38;5;129;01min\u001b[39;00m expected_components \u001b[38;5;28;01mif\u001b[39;00m k \u001b[38;5;129;01min\u001b[39;00m kwargs]\n",
35
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/diffusers/pipelines/pipeline_loading_utils.py:370\u001b[0m, in \u001b[0;36m_get_pipeline_class\u001b[0;34m(class_obj, config, load_connected_pipeline, custom_pipeline, repo_id, hub_revision, class_name, cache_dir, revision)\u001b[0m\n\u001b[1;32m 358\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_get_pipeline_class\u001b[39m(\n\u001b[1;32m 359\u001b[0m class_obj,\n\u001b[1;32m 360\u001b[0m config\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 367\u001b[0m revision\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 368\u001b[0m ):\n\u001b[1;32m 369\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m custom_pipeline \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 370\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_get_custom_pipeline_class\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 371\u001b[0m \u001b[43m \u001b[49m\u001b[43mcustom_pipeline\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 372\u001b[0m \u001b[43m \u001b[49m\u001b[43mrepo_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrepo_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 373\u001b[0m \u001b[43m \u001b[49m\u001b[43mhub_revision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mhub_revision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 374\u001b[0m \u001b[43m \u001b[49m\u001b[43mclass_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclass_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 375\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 376\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 377\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 379\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m class_obj\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDiffusionPipeline\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 380\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m class_obj\n",
36
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/diffusers/pipelines/pipeline_loading_utils.py:349\u001b[0m, in \u001b[0;36m_get_custom_pipeline_class\u001b[0;34m(custom_pipeline, repo_id, hub_revision, class_name, cache_dir, revision)\u001b[0m\n\u001b[1;32m 344\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m repo_id \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m hub_revision \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 345\u001b[0m \u001b[38;5;66;03m# if we load the pipeline code from the Hub\u001b[39;00m\n\u001b[1;32m 346\u001b[0m \u001b[38;5;66;03m# make sure to overwrite the `revision`\u001b[39;00m\n\u001b[1;32m 347\u001b[0m revision \u001b[38;5;241m=\u001b[39m hub_revision\n\u001b[0;32m--> 349\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mget_class_from_dynamic_module\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 350\u001b[0m \u001b[43m \u001b[49m\u001b[43mcustom_pipeline\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 351\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodule_file\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfile_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 352\u001b[0m \u001b[43m \u001b[49m\u001b[43mclass_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclass_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 353\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 354\u001b[0m \u001b[43m \u001b[49m\u001b[43mrevision\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrevision\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 355\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
37
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
38
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/diffusers/utils/dynamic_modules_utils.py:457\u001b[0m, in \u001b[0;36mget_class_from_dynamic_module\u001b[0;34m(pretrained_model_name_or_path, module_file, class_name, cache_dir, force_download, proxies, token, revision, local_files_only, **kwargs)\u001b[0m\n\u001b[1;32m 446\u001b[0m \u001b[38;5;66;03m# And lastly we get the class inside our newly created module\u001b[39;00m\n\u001b[1;32m 447\u001b[0m final_module \u001b[38;5;241m=\u001b[39m get_cached_module_file(\n\u001b[1;32m 448\u001b[0m pretrained_model_name_or_path,\n\u001b[1;32m 449\u001b[0m module_file,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 455\u001b[0m local_files_only\u001b[38;5;241m=\u001b[39mlocal_files_only,\n\u001b[1;32m 456\u001b[0m )\n\u001b[0;32m--> 457\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mget_class_in_module\u001b[49m\u001b[43m(\u001b[49m\u001b[43mclass_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfinal_module\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mreplace\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m.py\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
39
- "File \u001b[0;32m~/.local/lib/python3.11/site-packages/diffusers/utils/dynamic_modules_utils.py:162\u001b[0m, in \u001b[0;36mget_class_in_module\u001b[0;34m(class_name, module_path)\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 159\u001b[0m \u001b[38;5;124;03mImport a module on the cache directory for modules and extract a class from it.\u001b[39;00m\n\u001b[1;32m 160\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 161\u001b[0m module_path \u001b[38;5;241m=\u001b[39m module_path\u001b[38;5;241m.\u001b[39mreplace(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39msep, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 162\u001b[0m module \u001b[38;5;241m=\u001b[39m \u001b[43mimportlib\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimport_module\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodule_path\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 164\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m class_name \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 165\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m find_pipeline_class(module)\n",
40
- "File \u001b[0;32m/usr/lib/python3.11/importlib/__init__.py:126\u001b[0m, in \u001b[0;36mimport_module\u001b[0;34m(name, package)\u001b[0m\n\u001b[1;32m 124\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m 125\u001b[0m level \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[0;32m--> 126\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_bootstrap\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_gcd_import\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m[\u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m:\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpackage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m)\u001b[49m\n",
41
- "File \u001b[0;32m<frozen importlib._bootstrap>:1204\u001b[0m, in \u001b[0;36m_gcd_import\u001b[0;34m(name, package, level)\u001b[0m\n",
42
- "File \u001b[0;32m<frozen importlib._bootstrap>:1176\u001b[0m, in \u001b[0;36m_find_and_load\u001b[0;34m(name, import_)\u001b[0m\n",
43
- "File \u001b[0;32m<frozen importlib._bootstrap>:1147\u001b[0m, in \u001b[0;36m_find_and_load_unlocked\u001b[0;34m(name, import_)\u001b[0m\n",
44
- "File \u001b[0;32m<frozen importlib._bootstrap>:690\u001b[0m, in \u001b[0;36m_load_unlocked\u001b[0;34m(spec)\u001b[0m\n",
45
- "File \u001b[0;32m<frozen importlib._bootstrap_external>:940\u001b[0m, in \u001b[0;36mexec_module\u001b[0;34m(self, module)\u001b[0m\n",
46
- "File \u001b[0;32m<frozen importlib._bootstrap>:241\u001b[0m, in \u001b[0;36m_call_with_frames_removed\u001b[0;34m(f, *args, **kwds)\u001b[0m\n",
47
- "File \u001b[0;32m~/.cache/huggingface/modules/diffusers_modules/local/AiArtLab--waifu-2b/198e5ef5b8669576c07d632d8623f6da0f35d61e/pipeline_waifu.py:17\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;66;03m# Transformer\u001b[39;00m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mdiffusers\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SanaTransformer2DModel\n\u001b[0;32m---> 17\u001b[0m \u001b[38;5;28;43;01mclass\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;21;43;01mWaifuPipeline\u001b[39;49;00m\u001b[43m(\u001b[49m\u001b[43mDiffusionPipeline\u001b[49m\u001b[43m)\u001b[49m\u001b[43m:\u001b[49m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;250;43m \u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43;03m\"\"\"\u001b[39;49;00m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;124;43;03m Pipeline for text-to-image generation using [waifu](https://github.com/recoilme/waifu).\u001b[39;49;00m\n\u001b[1;32m 20\u001b[0m \u001b[38;5;124;43;03m \"\"\"\u001b[39;49;00m\n\u001b[1;32m 22\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodel_cpu_offload_seq\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtext_encoder->transformer->vae\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
48
- "File \u001b[0;32m~/.cache/huggingface/modules/diffusers_modules/local/AiArtLab--waifu-2b/198e5ef5b8669576c07d632d8623f6da0f35d61e/pipeline_waifu.py:45\u001b[0m, in \u001b[0;36mWaifuPipeline\u001b[0;34m()\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvae_scale_factor \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m8\u001b[39m\n\u001b[1;32m 40\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mimage_processor \u001b[38;5;241m=\u001b[39m PixArtImageProcessor(vae_scale_factor\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvae_scale_factor)\n\u001b[1;32m 42\u001b[0m \u001b[38;5;129m@torch\u001b[39m\u001b[38;5;241m.\u001b[39mno_grad()\n\u001b[1;32m 43\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\n\u001b[1;32m 44\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m---> 45\u001b[0m prompt: \u001b[43mUnion\u001b[49m[\u001b[38;5;28mstr\u001b[39m, List[\u001b[38;5;28mstr\u001b[39m]] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 46\u001b[0m negative_prompt: \u001b[38;5;28mstr\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 47\u001b[0m num_inference_steps: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m20\u001b[39m,\n\u001b[1;32m 48\u001b[0m timesteps: List[\u001b[38;5;28mint\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 49\u001b[0m sigmas: List[\u001b[38;5;28mfloat\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 50\u001b[0m guidance_scale: \u001b[38;5;28mfloat\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m4.5\u001b[39m,\n\u001b[1;32m 51\u001b[0m num_images_per_prompt: Optional[\u001b[38;5;28mint\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m,\n\u001b[1;32m 52\u001b[0m height: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m512\u001b[39m,\n\u001b[1;32m 53\u001b[0m width: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m512\u001b[39m,\n\u001b[1;32m 54\u001b[0m eta: \u001b[38;5;28mfloat\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0.0\u001b[39m,\n\u001b[1;32m 55\u001b[0m generator: Optional[Union[torch\u001b[38;5;241m.\u001b[39mGenerator, List[torch\u001b[38;5;241m.\u001b[39mGenerator]]] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 56\u001b[0m latents: Optional[torch\u001b[38;5;241m.\u001b[39mTensor] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 57\u001b[0m prompt_embeds: Optional[torch\u001b[38;5;241m.\u001b[39mTensor] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 58\u001b[0m prompt_attention_mask: Optional[torch\u001b[38;5;241m.\u001b[39mTensor] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 59\u001b[0m negative_prompt_embeds: Optional[torch\u001b[38;5;241m.\u001b[39mTensor] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 60\u001b[0m negative_prompt_attention_mask: Optional[torch\u001b[38;5;241m.\u001b[39mTensor] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 61\u001b[0m output_type: Optional[\u001b[38;5;28mstr\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpil\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 62\u001b[0m return_dict: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m 63\u001b[0m callback_on_step_end: Optional[Callable[[\u001b[38;5;28mint\u001b[39m, \u001b[38;5;28mint\u001b[39m, Dict], \u001b[38;5;28;01mNone\u001b[39;00m]] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 64\u001b[0m callback_on_step_end_tensor_inputs: List[\u001b[38;5;28mstr\u001b[39m] \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlatents\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 65\u001b[0m max_sequence_length: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m512\u001b[39m,\n\u001b[1;32m 66\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Union[SanaPipelineOutput, Tuple]:\n\u001b[1;32m 67\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 68\u001b[0m \u001b[38;5;124;03m Function invoked when calling the pipeline for generation.\u001b[39;00m\n\u001b[1;32m 69\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 142\u001b[0m \u001b[38;5;124;03m otherwise a `tuple` is returned where the first element is a list with the generated images\u001b[39;00m\n\u001b[1;32m 143\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 145\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(callback_on_step_end, (PipelineCallback, MultiPipelineCallbacks)):\n",
49
- "\u001b[0;31mNameError\u001b[0m: name 'Union' is not defined"
 
 
 
50
  ]
51
  }
52
  ],
53
  "source": [
54
  "import torch\n",
55
  "from diffusers import DiffusionPipeline\n",
 
56
  "\n",
57
- "pipe_id = \"AiArtLab/waifu-2b\"\n",
58
  "variant = \"fp16\"\n",
59
- "pipe = DiffusionPipeline.from_pretrained(\n",
60
  " pipe_id, \n",
61
  " variant=variant,\n",
62
  " trust_remote_code=True\n",
@@ -67,37 +71,89 @@
67
  },
68
  {
69
  "cell_type": "code",
70
- "execution_count": null,
71
  "id": "b6ebc579-0eb2-4828-89d5-b40f6d5e758e",
72
  "metadata": {},
73
  "outputs": [],
74
  "source": [
75
- "SanaPipeline {\n",
76
- " \"_class_name\": \"SanaPipeline\",\n",
77
- " \"_diffusers_version\": \"0.32.0.dev0\",\n",
78
- " \"_name_or_path\": \"AiArtLab/waifu-2b\",\n",
79
- " \"scheduler\": [\n",
80
- " \"diffusers\",\n",
81
- " \"FlowMatchEulerDiscreteScheduler\"\n",
82
- " ],\n",
83
- " \"text_encoder\": [\n",
84
- " \"transformers\",\n",
85
- " \"XLMRobertaModel\"\n",
86
- " ],\n",
87
- " \"tokenizer\": [\n",
88
- " \"transformers\",\n",
89
- " \"XLMRobertaTokenizerFast\"\n",
90
- " ],\n",
91
- " \"transformer\": [\n",
92
- " \"diffusers\",\n",
93
- " \"SanaTransformer2DModel\"\n",
94
- " ],\n",
95
- " \"vae\": [\n",
96
- " \"diffusers\",\n",
97
- " \"AutoencoderKL\"\n",
98
- " ]\n",
99
- "}\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  ]
 
 
 
 
 
 
 
 
101
  }
102
  ],
103
  "metadata": {
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 2,
6
  "id": "dca3239c-17d6-4284-a2cf-83237a55a7df",
7
  "metadata": {},
8
  "outputs": [
9
  {
10
  "data": {
11
  "application/vnd.jupyter.widget-view+json": {
12
+ "model_id": "add6682df5934d75bee02c59c4507a43",
13
  "version_major": 2,
14
  "version_minor": 0
15
  },
16
  "text/plain": [
17
+ "Loading pipeline components...: 0%| | 0/5 [00:00<?, ?it/s]"
18
  ]
19
  },
20
  "metadata": {},
21
  "output_type": "display_data"
22
  },
23
  {
24
+ "name": "stdout",
25
+ "output_type": "stream",
26
+ "text": [
27
+ "WaifuPipeline {\n",
28
+ " \"_class_name\": \"WaifuPipeline\",\n",
29
+ " \"_diffusers_version\": \"0.32.0.dev0\",\n",
30
+ " \"_name_or_path\": \"/home/recoilme/models/waifu-2b\",\n",
31
+ " \"scheduler\": [\n",
32
+ " \"diffusers\",\n",
33
+ " \"FlowMatchEulerDiscreteScheduler\"\n",
34
+ " ],\n",
35
+ " \"text_encoder\": [\n",
36
+ " \"transformers\",\n",
37
+ " \"XLMRobertaModel\"\n",
38
+ " ],\n",
39
+ " \"tokenizer\": [\n",
40
+ " \"transformers\",\n",
41
+ " \"XLMRobertaTokenizerFast\"\n",
42
+ " ],\n",
43
+ " \"transformer\": [\n",
44
+ " \"diffusers\",\n",
45
+ " \"SanaTransformer2DModel\"\n",
46
+ " ],\n",
47
+ " \"vae\": [\n",
48
+ " \"diffusers\",\n",
49
+ " \"AutoencoderKL\"\n",
50
+ " ]\n",
51
+ "}\n",
52
+ "\n"
53
  ]
54
  }
55
  ],
56
  "source": [
57
  "import torch\n",
58
  "from diffusers import DiffusionPipeline\n",
59
+ "from pipeline_waifu import WaifuPipeline\n",
60
  "\n",
61
+ "pipe_id = \"/home/recoilme/models/waifu-2b\"\n",
62
  "variant = \"fp16\"\n",
63
+ "pipe = WaifuPipeline.from_pretrained(\n",
64
  " pipe_id, \n",
65
  " variant=variant,\n",
66
  " trust_remote_code=True\n",
 
71
  },
72
  {
73
  "cell_type": "code",
74
+ "execution_count": 3,
75
  "id": "b6ebc579-0eb2-4828-89d5-b40f6d5e758e",
76
  "metadata": {},
77
  "outputs": [],
78
  "source": [
79
+ "def txt_embeds(prompt):\n",
80
+ " max_length = 512\n",
81
+ " select_index = [0] + list(range(-max_length + 1, 0))\n",
82
+ " \n",
83
+ " text_inputs = tokenizer(\n",
84
+ " prompt,\n",
85
+ " padding=\"max_length\",\n",
86
+ " max_length=max_length,\n",
87
+ " truncation=True,\n",
88
+ " add_special_tokens=True,\n",
89
+ " return_tensors=\"pt\",\n",
90
+ " )\n",
91
+ " text_input_ids = text_inputs.input_ids\n",
92
+ " prompt_attention_mask = text_inputs.attention_mask\n",
93
+ " device = \"cuda\"\n",
94
+ " prompt_attention_mask = prompt_attention_mask.to(device)\n",
95
+ " \n",
96
+ " prompt_embeds = text_encoder(input_ids=text_input_ids.to(device), attention_mask=prompt_attention_mask)[0][:, select_index]\n",
97
+ " #print(prompt_embeds.shape)\n",
98
+ " #prompt_embeds = prompt_embeds[0][:, select_index]\n",
99
+ " prompt_attention_mask = prompt_attention_mask[:, select_index]\n",
100
+ " #print(prompt_attention_mask.shape)\n",
101
+ " return prompt_embeds, prompt_attention_mask"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": 4,
107
+ "id": "3704e4a3-6855-4a32-a682-7ec307a668a0",
108
+ "metadata": {},
109
+ "outputs": [
110
+ {
111
+ "ename": "NameError",
112
+ "evalue": "name 'tokenizer' is not defined",
113
+ "output_type": "error",
114
+ "traceback": [
115
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
116
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
117
+ "Cell \u001b[0;32mIn[4], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m prompt \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mA young girl with long brown hair and brown eyes is standing against a brick wall, wearing a white shirt with a black sailor collar and a black pleated skirt. She is smiling and looking directly at the viewer, with sunlight filtering through the green vines behind her\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m#prompt = 'нарядная новогодняя елка, красивые игрушки, звезда сверху, огоньки, на тёмном фоне' \u001b[39;00m\n\u001b[0;32m----> 4\u001b[0m prompt_embeds, prompt_attention_mask \u001b[38;5;241m=\u001b[39m \u001b[43mtxt_embeds\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 5\u001b[0m negative_prompt_embeds, negative_prompt_attention_mask\u001b[38;5;241m=\u001b[39mtxt_embeds(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(prompt_embeds\u001b[38;5;241m.\u001b[39mshape)\n",
118
+ "Cell \u001b[0;32mIn[3], line 5\u001b[0m, in \u001b[0;36mtxt_embeds\u001b[0;34m(prompt)\u001b[0m\n\u001b[1;32m 2\u001b[0m max_length \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m512\u001b[39m\n\u001b[1;32m 3\u001b[0m select_index \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m-\u001b[39mmax_length \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m0\u001b[39m))\n\u001b[0;32m----> 5\u001b[0m text_inputs \u001b[38;5;241m=\u001b[39m \u001b[43mtokenizer\u001b[49m(\n\u001b[1;32m 6\u001b[0m prompt,\n\u001b[1;32m 7\u001b[0m padding\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmax_length\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 8\u001b[0m max_length\u001b[38;5;241m=\u001b[39mmax_length,\n\u001b[1;32m 9\u001b[0m truncation\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m 10\u001b[0m add_special_tokens\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m 11\u001b[0m return_tensors\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpt\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 12\u001b[0m )\n\u001b[1;32m 13\u001b[0m text_input_ids \u001b[38;5;241m=\u001b[39m text_inputs\u001b[38;5;241m.\u001b[39minput_ids\n\u001b[1;32m 14\u001b[0m prompt_attention_mask \u001b[38;5;241m=\u001b[39m text_inputs\u001b[38;5;241m.\u001b[39mattention_mask\n",
119
+ "\u001b[0;31mNameError\u001b[0m: name 'tokenizer' is not defined"
120
+ ]
121
+ }
122
+ ],
123
+ "source": [
124
+ "prompt = '1girl, solo, animal ears, bow, teeth, jacket, tail, open mouth, brown hair, orange background, bowtie, orange nails, simple background, cat ears, orange eyes, blue bow, animal ear fluff, cat tail, looking at viewer, upper body, shirt, school uniform, hood, striped bow, striped, white shirt, black jacket, blue bowtie, fingernails, long sleeves, cat girl, bangs, fangs, collared shirt, striped bowtie, short hair, tongue, hoodie, sharp teeth, facial mark, claw pose'\n",
125
+ "prompt = 'A young girl with long brown hair and brown eyes is standing against a brick wall, wearing a white shirt with a black sailor collar and a black pleated skirt. She is smiling and looking directly at the viewer, with sunlight filtering through the green vines behind her'\n",
126
+ "#prompt = 'нарядная новогодняя елка, красивые игрушки, звезда сверху, огоньки, на тёмном фоне' \n",
127
+ "prompt_embeds, prompt_attention_mask = txt_embeds(prompt)\n",
128
+ "negative_prompt_embeds, negative_prompt_attention_mask=txt_embeds(\"\")\n",
129
+ "print(prompt_embeds.shape)\n",
130
+ "\n",
131
+ "image = pipe(\n",
132
+ " prompt = None,\n",
133
+ " negative_prompt = None,\n",
134
+ " use_resolution_binning = False,\n",
135
+ " prompt_embeds=prompt_embeds,\n",
136
+ " prompt_attention_mask= prompt_attention_mask,\n",
137
+ " negative_prompt_embeds = negative_prompt_embeds,\n",
138
+ " negative_prompt_attention_mask = negative_prompt_attention_mask,\n",
139
+ " height=768,\n",
140
+ " width=768,\n",
141
+ " guidance_scale=4.5,\n",
142
+ " num_inference_steps=24,\n",
143
+ " generator=torch.Generator(device=\"cuda\").manual_seed(42),\n",
144
+ ")[0]\n",
145
+ "\n",
146
+ "for img in image:\n",
147
+ " img.show()"
148
  ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": null,
153
+ "id": "1b82a561-b93b-4261-9bc7-fe867168bdd2",
154
+ "metadata": {},
155
+ "outputs": [],
156
+ "source": []
157
  }
158
  ],
159
  "metadata": {
__pycache__/pipeline_waifu.cpython-311.pyc ADDED
Binary file (14.6 kB). View file
 
pipeline_waifu.py CHANGED
@@ -14,6 +14,9 @@ from diffusers.models import AutoencoderKL
14
  # Transformer
15
  from diffusers import SanaTransformer2DModel
16
 
 
 
 
17
 
18
  class WaifuPipeline(DiffusionPipeline):
19
  r"""
@@ -38,7 +41,7 @@ class WaifuPipeline(DiffusionPipeline):
38
  )
39
 
40
  self.vae_scale_factor = 8
41
- self.image_processor = PixArtImageProcessor(vae_scale_factor=self.vae_scale_factor)
42
 
43
  @torch.no_grad()
44
  def __call__(
@@ -64,7 +67,7 @@ class WaifuPipeline(DiffusionPipeline):
64
  callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
65
  callback_on_step_end_tensor_inputs: List[str] = ["latents"],
66
  max_sequence_length: int = 512,
67
- ) -> Union[SanaPipelineOutput, Tuple]:
68
  """
69
  Function invoked when calling the pipeline for generation.
70
 
@@ -285,4 +288,4 @@ class WaifuPipeline(DiffusionPipeline):
285
  if not return_dict:
286
  return (image,)
287
 
288
- return SanaPipelineOutput(images=image)
 
14
  # Transformer
15
  from diffusers import SanaTransformer2DModel
16
 
17
+ import numpy as np
18
+ import PIL.Image
19
+
20
 
21
  class WaifuPipeline(DiffusionPipeline):
22
  r"""
 
41
  )
42
 
43
  self.vae_scale_factor = 8
44
+ #self.image_processor = PixArtImageProcessor(vae_scale_factor=self.vae_scale_factor)
45
 
46
  @torch.no_grad()
47
  def __call__(
 
67
  callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
68
  callback_on_step_end_tensor_inputs: List[str] = ["latents"],
69
  max_sequence_length: int = 512,
70
+ ) -> Union[List[PIL.Image.Image], np.ndarray]:
71
  """
72
  Function invoked when calling the pipeline for generation.
73
 
 
288
  if not return_dict:
289
  return (image,)
290
 
291
+ return Union[List[PIL.Image.Image], np.ndarray]