Upload with huggingface_hub
Browse files- .config/.last_opt_in_prompt.yaml +1 -0
- .config/.last_survey_prompt.yaml +1 -0
- .config/.last_update_check.json +1 -0
- .config/active_config +1 -0
- .config/config_sentinel +0 -0
- .config/configurations/config_default +6 -0
- .config/gce +1 -0
- .config/logs/2022.12.20/20.17.35.236470.log +592 -0
- .config/logs/2022.12.20/20.18.05.031957.log +4 -0
- .config/logs/2022.12.20/20.18.33.478842.log +165 -0
- .config/logs/2022.12.20/20.18.48.288023.log +4 -0
- .config/logs/2022.12.20/20.19.18.730018.log +7 -0
- .config/logs/2022.12.20/20.19.19.661684.log +7 -0
- .gitattributes +2 -0
- README.md +13 -0
- convert_original_stable_diffusion_to_diffusers.py +752 -0
- convert_original_stable_diffusion_to_diffusers.py.1 +752 -0
- convert_original_stable_diffusion_to_diffusers.py.2 +752 -0
- feature_extractor/preprocessor_config.json +20 -0
- kanianime-finetune.ckpt +3 -0
- kanianime-finetune/model_index.json +25 -0
- kanianime-finetune/scheduler/scheduler_config.json +12 -0
- kanianime-finetune/text_encoder/config.json +25 -0
- kanianime-finetune/text_encoder/pytorch_model.bin +3 -0
- kanianime-finetune/tokenizer/merges.txt +0 -0
- kanianime-finetune/tokenizer/special_tokens_map.json +24 -0
- kanianime-finetune/tokenizer/tokenizer_config.json +34 -0
- kanianime-finetune/tokenizer/vocab.json +0 -0
- kanianime-finetune/unet/config.json +40 -0
- kanianime-finetune/unet/diffusion_pytorch_model.bin +3 -0
- kanianime-finetune/vae/config.json +29 -0
- kanianime-finetune/vae/diffusion_pytorch_model.bin +3 -0
- model_index.json +32 -0
- safety_checker/config.json +179 -0
- safety_checker/pytorch_model.bin +3 -0
- sample_data/README.md +19 -0
- sample_data/anscombe.json +49 -0
- sample_data/california_housing_test.csv +0 -0
- sample_data/california_housing_train.csv +0 -0
- sample_data/mnist_test.csv +3 -0
- sample_data/mnist_train_small.csv +3 -0
- train_dreambooth.py +695 -0
- v1-inference.yaml +70 -0
- v1-inference.yaml.1 +70 -0
.config/.last_opt_in_prompt.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|
.config/.last_survey_prompt.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
last_prompt_time: 1671567512.6059277
|
.config/.last_update_check.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"last_update_check_time": 1671567527.5556612, "last_update_check_revision": 20221209155815, "notifications": [], "last_nag_times": {}}
|
.config/active_config
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
default
|
.config/config_sentinel
ADDED
|
File without changes
|
.config/configurations/config_default
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[component_manager]
|
| 2 |
+
disable_update_check = true
|
| 3 |
+
|
| 4 |
+
[compute]
|
| 5 |
+
gce_metadata_read_timeout_sec = 0
|
| 6 |
+
|
.config/gce
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
False
|
.config/logs/2022.12.20/20.17.35.236470.log
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2022-12-20 20:17:35,242 DEBUG root Loaded Command Group: ['gcloud', 'components']
|
| 2 |
+
2022-12-20 20:17:35,246 DEBUG root Loaded Command Group: ['gcloud', 'components', 'update']
|
| 3 |
+
2022-12-20 20:17:35,249 DEBUG root Running [gcloud.components.update] with arguments: [--allow-no-backup: "True", --quiet: "True", COMPONENT-IDS:7: "['core', 'gcloud-deps', 'bq', 'gcloud', 'gcloud-crc32c', 'gsutil', 'anthoscli']"]
|
| 4 |
+
2022-12-20 20:17:35,250 INFO ___FILE_ONLY___ Beginning update. This process may take several minutes.
|
| 5 |
+
|
| 6 |
+
2022-12-20 20:17:47,278 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 7 |
+
2022-12-20 20:17:47,352 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components-2.json HTTP/1.1" 200 203441
|
| 8 |
+
2022-12-20 20:17:47,367 INFO ___FILE_ONLY___
|
| 9 |
+
|
| 10 |
+
2022-12-20 20:17:47,368 INFO ___FILE_ONLY___
|
| 11 |
+
Your current Google Cloud CLI version is: 412.0.0
|
| 12 |
+
|
| 13 |
+
2022-12-20 20:17:47,368 INFO ___FILE_ONLY___ Installing components from version: 412.0.0
|
| 14 |
+
|
| 15 |
+
2022-12-20 20:17:47,368 INFO ___FILE_ONLY___
|
| 16 |
+
|
| 17 |
+
2022-12-20 20:17:47,376 INFO ___FILE_ONLY___ ┌─────────────────────────────────────────────────────────────────────────────┐
|
| 18 |
+
2022-12-20 20:17:47,376 INFO ___FILE_ONLY___
|
| 19 |
+
|
| 20 |
+
2022-12-20 20:17:47,376 INFO ___FILE_ONLY___ │ These components will be installed. │
|
| 21 |
+
2022-12-20 20:17:47,376 INFO ___FILE_ONLY___
|
| 22 |
+
|
| 23 |
+
2022-12-20 20:17:47,376 INFO ___FILE_ONLY___ ├─────────────────────────────────────────────────────┬────────────┬──────────┤
|
| 24 |
+
2022-12-20 20:17:47,376 INFO ___FILE_ONLY___
|
| 25 |
+
|
| 26 |
+
2022-12-20 20:17:47,377 INFO ___FILE_ONLY___ │ Name │ Version │ Size │
|
| 27 |
+
2022-12-20 20:17:47,377 INFO ___FILE_ONLY___
|
| 28 |
+
|
| 29 |
+
2022-12-20 20:17:47,377 INFO ___FILE_ONLY___ ├─────────────────────────────────────────────────────┼────────────┼──────────┤
|
| 30 |
+
2022-12-20 20:17:47,377 INFO ___FILE_ONLY___
|
| 31 |
+
|
| 32 |
+
2022-12-20 20:17:47,377 INFO ___FILE_ONLY___ │
|
| 33 |
+
2022-12-20 20:17:47,377 INFO ___FILE_ONLY___ BigQuery Command Line Tool
|
| 34 |
+
2022-12-20 20:17:47,377 INFO ___FILE_ONLY___
|
| 35 |
+
2022-12-20 20:17:47,378 INFO ___FILE_ONLY___ │
|
| 36 |
+
2022-12-20 20:17:47,378 INFO ___FILE_ONLY___ 2.0.83
|
| 37 |
+
2022-12-20 20:17:47,378 INFO ___FILE_ONLY___
|
| 38 |
+
2022-12-20 20:17:47,378 INFO ___FILE_ONLY___ │
|
| 39 |
+
2022-12-20 20:17:47,378 INFO ___FILE_ONLY___ 1.6 MiB
|
| 40 |
+
2022-12-20 20:17:47,379 INFO ___FILE_ONLY___
|
| 41 |
+
2022-12-20 20:17:47,379 INFO ___FILE_ONLY___ │
|
| 42 |
+
2022-12-20 20:17:47,379 INFO ___FILE_ONLY___
|
| 43 |
+
|
| 44 |
+
2022-12-20 20:17:47,379 INFO ___FILE_ONLY___ │
|
| 45 |
+
2022-12-20 20:17:47,379 INFO ___FILE_ONLY___ BigQuery Command Line Tool (Platform Specific)
|
| 46 |
+
2022-12-20 20:17:47,379 INFO ___FILE_ONLY___
|
| 47 |
+
2022-12-20 20:17:47,380 INFO ___FILE_ONLY___ │
|
| 48 |
+
2022-12-20 20:17:47,380 INFO ___FILE_ONLY___ 2.0.77
|
| 49 |
+
2022-12-20 20:17:47,380 INFO ___FILE_ONLY___
|
| 50 |
+
2022-12-20 20:17:47,380 INFO ___FILE_ONLY___ │
|
| 51 |
+
2022-12-20 20:17:47,380 INFO ___FILE_ONLY___ < 1 MiB
|
| 52 |
+
2022-12-20 20:17:47,380 INFO ___FILE_ONLY___
|
| 53 |
+
2022-12-20 20:17:47,381 INFO ___FILE_ONLY___ │
|
| 54 |
+
2022-12-20 20:17:47,381 INFO ___FILE_ONLY___
|
| 55 |
+
|
| 56 |
+
2022-12-20 20:17:47,381 INFO ___FILE_ONLY___ │
|
| 57 |
+
2022-12-20 20:17:47,381 INFO ___FILE_ONLY___ Bundled Python 3.9
|
| 58 |
+
2022-12-20 20:17:47,381 INFO ___FILE_ONLY___
|
| 59 |
+
2022-12-20 20:17:47,381 INFO ___FILE_ONLY___ │
|
| 60 |
+
2022-12-20 20:17:47,382 INFO ___FILE_ONLY___ 3.9.12
|
| 61 |
+
2022-12-20 20:17:47,382 INFO ___FILE_ONLY___
|
| 62 |
+
2022-12-20 20:17:47,382 INFO ___FILE_ONLY___ │
|
| 63 |
+
2022-12-20 20:17:47,382 INFO ___FILE_ONLY___ 62.2 MiB
|
| 64 |
+
2022-12-20 20:17:47,382 INFO ___FILE_ONLY___
|
| 65 |
+
2022-12-20 20:17:47,382 INFO ___FILE_ONLY___ │
|
| 66 |
+
2022-12-20 20:17:47,383 INFO ___FILE_ONLY___
|
| 67 |
+
|
| 68 |
+
2022-12-20 20:17:47,383 INFO ___FILE_ONLY___ │
|
| 69 |
+
2022-12-20 20:17:47,383 INFO ___FILE_ONLY___ Cloud Storage Command Line Tool
|
| 70 |
+
2022-12-20 20:17:47,383 INFO ___FILE_ONLY___
|
| 71 |
+
2022-12-20 20:17:47,383 INFO ___FILE_ONLY___ │
|
| 72 |
+
2022-12-20 20:17:47,383 INFO ___FILE_ONLY___ 5.17
|
| 73 |
+
2022-12-20 20:17:47,384 INFO ___FILE_ONLY___
|
| 74 |
+
2022-12-20 20:17:47,384 INFO ___FILE_ONLY___ │
|
| 75 |
+
2022-12-20 20:17:47,384 INFO ___FILE_ONLY___ 15.5 MiB
|
| 76 |
+
2022-12-20 20:17:47,384 INFO ___FILE_ONLY___
|
| 77 |
+
2022-12-20 20:17:47,384 INFO ___FILE_ONLY___ │
|
| 78 |
+
2022-12-20 20:17:47,384 INFO ___FILE_ONLY___
|
| 79 |
+
|
| 80 |
+
2022-12-20 20:17:47,384 INFO ___FILE_ONLY___ │
|
| 81 |
+
2022-12-20 20:17:47,385 INFO ___FILE_ONLY___ Cloud Storage Command Line Tool (Platform Specific)
|
| 82 |
+
2022-12-20 20:17:47,385 INFO ___FILE_ONLY___
|
| 83 |
+
2022-12-20 20:17:47,385 INFO ___FILE_ONLY___ │
|
| 84 |
+
2022-12-20 20:17:47,385 INFO ___FILE_ONLY___ 5.13
|
| 85 |
+
2022-12-20 20:17:47,385 INFO ___FILE_ONLY___
|
| 86 |
+
2022-12-20 20:17:47,385 INFO ___FILE_ONLY___ │
|
| 87 |
+
2022-12-20 20:17:47,386 INFO ___FILE_ONLY___ < 1 MiB
|
| 88 |
+
2022-12-20 20:17:47,386 INFO ___FILE_ONLY___
|
| 89 |
+
2022-12-20 20:17:47,386 INFO ___FILE_ONLY___ │
|
| 90 |
+
2022-12-20 20:17:47,386 INFO ___FILE_ONLY___
|
| 91 |
+
|
| 92 |
+
2022-12-20 20:17:47,386 INFO ___FILE_ONLY___ │
|
| 93 |
+
2022-12-20 20:17:47,386 INFO ___FILE_ONLY___ Google Cloud CLI Core Libraries (Platform Specific)
|
| 94 |
+
2022-12-20 20:17:47,387 INFO ___FILE_ONLY___
|
| 95 |
+
2022-12-20 20:17:47,387 INFO ___FILE_ONLY___ │
|
| 96 |
+
2022-12-20 20:17:47,387 INFO ___FILE_ONLY___ 2022.09.20
|
| 97 |
+
2022-12-20 20:17:47,387 INFO ___FILE_ONLY___
|
| 98 |
+
2022-12-20 20:17:47,387 INFO ___FILE_ONLY___ │
|
| 99 |
+
2022-12-20 20:17:47,387 INFO ___FILE_ONLY___ < 1 MiB
|
| 100 |
+
2022-12-20 20:17:47,388 INFO ___FILE_ONLY___
|
| 101 |
+
2022-12-20 20:17:47,388 INFO ___FILE_ONLY___ │
|
| 102 |
+
2022-12-20 20:17:47,388 INFO ___FILE_ONLY___
|
| 103 |
+
|
| 104 |
+
2022-12-20 20:17:47,388 INFO ___FILE_ONLY___ │
|
| 105 |
+
2022-12-20 20:17:47,388 INFO ___FILE_ONLY___ Google Cloud CRC32C Hash Tool
|
| 106 |
+
2022-12-20 20:17:47,388 INFO ___FILE_ONLY___
|
| 107 |
+
2022-12-20 20:17:47,389 INFO ___FILE_ONLY___ │
|
| 108 |
+
2022-12-20 20:17:47,389 INFO ___FILE_ONLY___ 1.0.0
|
| 109 |
+
2022-12-20 20:17:47,389 INFO ___FILE_ONLY___
|
| 110 |
+
2022-12-20 20:17:47,389 INFO ___FILE_ONLY___ │
|
| 111 |
+
2022-12-20 20:17:47,389 INFO ___FILE_ONLY___ 1.2 MiB
|
| 112 |
+
2022-12-20 20:17:47,390 INFO ___FILE_ONLY___
|
| 113 |
+
2022-12-20 20:17:47,390 INFO ___FILE_ONLY___ │
|
| 114 |
+
2022-12-20 20:17:47,390 INFO ___FILE_ONLY___
|
| 115 |
+
|
| 116 |
+
2022-12-20 20:17:47,390 INFO ___FILE_ONLY___ │
|
| 117 |
+
2022-12-20 20:17:47,390 INFO ___FILE_ONLY___ anthoscli
|
| 118 |
+
2022-12-20 20:17:47,390 INFO ___FILE_ONLY___
|
| 119 |
+
2022-12-20 20:17:47,391 INFO ___FILE_ONLY___ │
|
| 120 |
+
2022-12-20 20:17:47,391 INFO ___FILE_ONLY___ 0.2.30
|
| 121 |
+
2022-12-20 20:17:47,391 INFO ___FILE_ONLY___
|
| 122 |
+
2022-12-20 20:17:47,391 INFO ___FILE_ONLY___ │
|
| 123 |
+
2022-12-20 20:17:47,391 INFO ___FILE_ONLY___ 39.1 MiB
|
| 124 |
+
2022-12-20 20:17:47,391 INFO ___FILE_ONLY___
|
| 125 |
+
2022-12-20 20:17:47,392 INFO ___FILE_ONLY___ │
|
| 126 |
+
2022-12-20 20:17:47,392 INFO ___FILE_ONLY___
|
| 127 |
+
|
| 128 |
+
2022-12-20 20:17:47,392 INFO ___FILE_ONLY___ │
|
| 129 |
+
2022-12-20 20:17:47,392 INFO ___FILE_ONLY___ gcloud cli dependencies
|
| 130 |
+
2022-12-20 20:17:47,392 INFO ___FILE_ONLY___
|
| 131 |
+
2022-12-20 20:17:47,392 INFO ___FILE_ONLY___ │
|
| 132 |
+
2022-12-20 20:17:47,393 INFO ___FILE_ONLY___ 2021.04.16
|
| 133 |
+
2022-12-20 20:17:47,393 INFO ___FILE_ONLY___
|
| 134 |
+
2022-12-20 20:17:47,393 INFO ___FILE_ONLY___ │
|
| 135 |
+
2022-12-20 20:17:47,393 INFO ___FILE_ONLY___ < 1 MiB
|
| 136 |
+
2022-12-20 20:17:47,393 INFO ___FILE_ONLY___
|
| 137 |
+
2022-12-20 20:17:47,393 INFO ___FILE_ONLY___ │
|
| 138 |
+
2022-12-20 20:17:47,394 INFO ___FILE_ONLY___
|
| 139 |
+
|
| 140 |
+
2022-12-20 20:17:47,394 INFO ___FILE_ONLY___ └─────────────────────────────────────────────────────┴────────────┴──────────┘
|
| 141 |
+
2022-12-20 20:17:47,394 INFO ___FILE_ONLY___
|
| 142 |
+
|
| 143 |
+
2022-12-20 20:17:47,394 INFO ___FILE_ONLY___
|
| 144 |
+
|
| 145 |
+
2022-12-20 20:17:47,397 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 146 |
+
2022-12-20 20:17:47,423 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/RELEASE_NOTES HTTP/1.1" 200 916325
|
| 147 |
+
2022-12-20 20:17:47,454 INFO ___FILE_ONLY___ For the latest full release notes, please visit:
|
| 148 |
+
https://cloud.google.com/sdk/release_notes
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
2022-12-20 20:17:47,462 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 152 |
+
|
| 153 |
+
2022-12-20 20:17:47,462 INFO ___FILE_ONLY___ ╠═ Creating update staging area ═╣
|
| 154 |
+
|
| 155 |
+
2022-12-20 20:17:47,462 INFO ___FILE_ONLY___ ╚
|
| 156 |
+
2022-12-20 20:17:47,463 INFO ___FILE_ONLY___ ══════
|
| 157 |
+
2022-12-20 20:17:47,463 INFO ___FILE_ONLY___ ══════
|
| 158 |
+
2022-12-20 20:17:47,463 INFO ___FILE_ONLY___ ══════
|
| 159 |
+
2022-12-20 20:17:47,646 INFO ___FILE_ONLY___ ═
|
| 160 |
+
2022-12-20 20:17:47,749 INFO ___FILE_ONLY___ ═
|
| 161 |
+
2022-12-20 20:17:47,843 INFO ___FILE_ONLY___ ═
|
| 162 |
+
2022-12-20 20:17:47,931 INFO ___FILE_ONLY___ ═
|
| 163 |
+
2022-12-20 20:17:48,043 INFO ___FILE_ONLY___ ═
|
| 164 |
+
2022-12-20 20:17:48,173 INFO ___FILE_ONLY___ ═
|
| 165 |
+
2022-12-20 20:17:48,273 INFO ___FILE_ONLY___ ═
|
| 166 |
+
2022-12-20 20:17:48,371 INFO ___FILE_ONLY___ ═
|
| 167 |
+
2022-12-20 20:17:48,460 INFO ___FILE_ONLY___ ═
|
| 168 |
+
2022-12-20 20:17:48,562 INFO ___FILE_ONLY___ ═
|
| 169 |
+
2022-12-20 20:17:48,672 INFO ___FILE_ONLY___ ═
|
| 170 |
+
2022-12-20 20:17:48,781 INFO ___FILE_ONLY___ ═
|
| 171 |
+
2022-12-20 20:17:48,878 INFO ___FILE_ONLY___ ═
|
| 172 |
+
2022-12-20 20:17:48,967 INFO ___FILE_ONLY___ ═
|
| 173 |
+
2022-12-20 20:17:49,075 INFO ___FILE_ONLY___ ═
|
| 174 |
+
2022-12-20 20:17:49,218 INFO ___FILE_ONLY___ ═
|
| 175 |
+
2022-12-20 20:17:49,329 INFO ___FILE_ONLY___ ═
|
| 176 |
+
2022-12-20 20:17:49,460 INFO ___FILE_ONLY___ ═
|
| 177 |
+
2022-12-20 20:17:49,513 INFO ___FILE_ONLY___ ═
|
| 178 |
+
2022-12-20 20:17:49,565 INFO ___FILE_ONLY___ ═
|
| 179 |
+
2022-12-20 20:17:49,631 INFO ___FILE_ONLY___ ═
|
| 180 |
+
2022-12-20 20:17:49,691 INFO ___FILE_ONLY___ ═
|
| 181 |
+
2022-12-20 20:17:49,741 INFO ___FILE_ONLY___ ═
|
| 182 |
+
2022-12-20 20:17:49,794 INFO ___FILE_ONLY___ ═
|
| 183 |
+
2022-12-20 20:17:50,024 INFO ___FILE_ONLY___ ═
|
| 184 |
+
2022-12-20 20:17:50,102 INFO ___FILE_ONLY___ ═
|
| 185 |
+
2022-12-20 20:17:50,411 INFO ___FILE_ONLY___ ═
|
| 186 |
+
2022-12-20 20:17:50,581 INFO ___FILE_ONLY___ ═
|
| 187 |
+
2022-12-20 20:17:50,656 INFO ___FILE_ONLY___ ═
|
| 188 |
+
2022-12-20 20:17:50,743 INFO ___FILE_ONLY___ ═
|
| 189 |
+
2022-12-20 20:17:50,832 INFO ___FILE_ONLY___ ═
|
| 190 |
+
2022-12-20 20:17:50,936 INFO ___FILE_ONLY___ ═
|
| 191 |
+
2022-12-20 20:17:51,027 INFO ___FILE_ONLY___ ═
|
| 192 |
+
2022-12-20 20:17:51,131 INFO ___FILE_ONLY___ ═
|
| 193 |
+
2022-12-20 20:17:51,279 INFO ___FILE_ONLY___ ═
|
| 194 |
+
2022-12-20 20:17:51,391 INFO ___FILE_ONLY___ ═
|
| 195 |
+
2022-12-20 20:17:51,489 INFO ___FILE_ONLY___ ═
|
| 196 |
+
2022-12-20 20:17:51,613 INFO ___FILE_ONLY___ ═
|
| 197 |
+
2022-12-20 20:17:51,722 INFO ___FILE_ONLY___ ═
|
| 198 |
+
2022-12-20 20:17:51,823 INFO ___FILE_ONLY___ ═
|
| 199 |
+
2022-12-20 20:17:52,065 INFO ___FILE_ONLY___ ═
|
| 200 |
+
2022-12-20 20:17:52,149 INFO ___FILE_ONLY___ ═
|
| 201 |
+
2022-12-20 20:17:52,150 INFO ___FILE_ONLY___ ╝
|
| 202 |
+
|
| 203 |
+
2022-12-20 20:17:52,504 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 204 |
+
|
| 205 |
+
2022-12-20 20:17:52,505 INFO ___FILE_ONLY___ ╠═ Installing: BigQuery Command Line Tool ═╣
|
| 206 |
+
|
| 207 |
+
2022-12-20 20:17:52,505 INFO ___FILE_ONLY___ ╚
|
| 208 |
+
2022-12-20 20:17:52,509 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 209 |
+
2022-12-20 20:17:52,579 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-bq-20221205224721.tar.gz HTTP/1.1" 200 1694761
|
| 210 |
+
2022-12-20 20:17:52,596 INFO ___FILE_ONLY___ ═
|
| 211 |
+
2022-12-20 20:17:52,596 INFO ___FILE_ONLY___ ═
|
| 212 |
+
2022-12-20 20:17:52,597 INFO ___FILE_ONLY___ ═
|
| 213 |
+
2022-12-20 20:17:52,597 INFO ___FILE_ONLY___ ═
|
| 214 |
+
2022-12-20 20:17:52,597 INFO ___FILE_ONLY___ ═
|
| 215 |
+
2022-12-20 20:17:52,597 INFO ___FILE_ONLY___ ═
|
| 216 |
+
2022-12-20 20:17:52,598 INFO ___FILE_ONLY___ ═
|
| 217 |
+
2022-12-20 20:17:52,598 INFO ___FILE_ONLY___ ═
|
| 218 |
+
2022-12-20 20:17:52,598 INFO ___FILE_ONLY___ ═
|
| 219 |
+
2022-12-20 20:17:52,599 INFO ___FILE_ONLY___ ═
|
| 220 |
+
2022-12-20 20:17:52,599 INFO ___FILE_ONLY___ ═
|
| 221 |
+
2022-12-20 20:17:52,599 INFO ___FILE_ONLY___ ═
|
| 222 |
+
2022-12-20 20:17:52,599 INFO ___FILE_ONLY___ ═
|
| 223 |
+
2022-12-20 20:17:52,600 INFO ___FILE_ONLY___ ═
|
| 224 |
+
2022-12-20 20:17:52,600 INFO ___FILE_ONLY___ ═
|
| 225 |
+
2022-12-20 20:17:52,600 INFO ___FILE_ONLY___ ═
|
| 226 |
+
2022-12-20 20:17:52,600 INFO ___FILE_ONLY___ ═
|
| 227 |
+
2022-12-20 20:17:52,601 INFO ___FILE_ONLY___ ═
|
| 228 |
+
2022-12-20 20:17:52,601 INFO ___FILE_ONLY___ ═
|
| 229 |
+
2022-12-20 20:17:52,601 INFO ___FILE_ONLY___ ═
|
| 230 |
+
2022-12-20 20:17:52,601 INFO ___FILE_ONLY___ ═
|
| 231 |
+
2022-12-20 20:17:52,602 INFO ___FILE_ONLY___ ═
|
| 232 |
+
2022-12-20 20:17:52,602 INFO ___FILE_ONLY___ ═
|
| 233 |
+
2022-12-20 20:17:52,602 INFO ___FILE_ONLY___ ═
|
| 234 |
+
2022-12-20 20:17:52,602 INFO ___FILE_ONLY___ ═
|
| 235 |
+
2022-12-20 20:17:52,603 INFO ___FILE_ONLY___ ═
|
| 236 |
+
2022-12-20 20:17:52,603 INFO ___FILE_ONLY___ ═
|
| 237 |
+
2022-12-20 20:17:52,603 INFO ___FILE_ONLY___ ═
|
| 238 |
+
2022-12-20 20:17:52,603 INFO ___FILE_ONLY___ ═
|
| 239 |
+
2022-12-20 20:17:52,604 INFO ___FILE_ONLY___ ═
|
| 240 |
+
2022-12-20 20:17:52,738 INFO ___FILE_ONLY___ ═
|
| 241 |
+
2022-12-20 20:17:52,745 INFO ___FILE_ONLY___ ═
|
| 242 |
+
2022-12-20 20:17:52,752 INFO ___FILE_ONLY___ ═
|
| 243 |
+
2022-12-20 20:17:52,761 INFO ___FILE_ONLY___ ═
|
| 244 |
+
2022-12-20 20:17:52,768 INFO ___FILE_ONLY___ ═
|
| 245 |
+
2022-12-20 20:17:52,774 INFO ___FILE_ONLY___ ═
|
| 246 |
+
2022-12-20 20:17:52,780 INFO ___FILE_ONLY___ ═
|
| 247 |
+
2022-12-20 20:17:52,789 INFO ___FILE_ONLY___ ═
|
| 248 |
+
2022-12-20 20:17:52,796 INFO ___FILE_ONLY___ ═
|
| 249 |
+
2022-12-20 20:17:52,802 INFO ___FILE_ONLY___ ═
|
| 250 |
+
2022-12-20 20:17:52,809 INFO ___FILE_ONLY___ ═
|
| 251 |
+
2022-12-20 20:17:52,816 INFO ___FILE_ONLY___ ═
|
| 252 |
+
2022-12-20 20:17:52,825 INFO ___FILE_ONLY___ ═
|
| 253 |
+
2022-12-20 20:17:52,833 INFO ___FILE_ONLY___ ═
|
| 254 |
+
2022-12-20 20:17:52,841 INFO ___FILE_ONLY___ ═
|
| 255 |
+
2022-12-20 20:17:52,848 INFO ___FILE_ONLY___ ═
|
| 256 |
+
2022-12-20 20:17:52,854 INFO ___FILE_ONLY___ ═
|
| 257 |
+
2022-12-20 20:17:52,860 INFO ___FILE_ONLY___ ═
|
| 258 |
+
2022-12-20 20:17:52,867 INFO ___FILE_ONLY___ ═
|
| 259 |
+
2022-12-20 20:17:52,874 INFO ___FILE_ONLY___ ═
|
| 260 |
+
2022-12-20 20:17:52,883 INFO ___FILE_ONLY___ ═
|
| 261 |
+
2022-12-20 20:17:52,889 INFO ___FILE_ONLY___ ═
|
| 262 |
+
2022-12-20 20:17:52,896 INFO ___FILE_ONLY___ ═
|
| 263 |
+
2022-12-20 20:17:52,902 INFO ___FILE_ONLY___ ═
|
| 264 |
+
2022-12-20 20:17:52,909 INFO ___FILE_ONLY___ ═
|
| 265 |
+
2022-12-20 20:17:52,916 INFO ___FILE_ONLY___ ═
|
| 266 |
+
2022-12-20 20:17:52,922 INFO ___FILE_ONLY___ ═
|
| 267 |
+
2022-12-20 20:17:52,929 INFO ___FILE_ONLY___ ═
|
| 268 |
+
2022-12-20 20:17:52,936 INFO ___FILE_ONLY___ ═
|
| 269 |
+
2022-12-20 20:17:52,943 INFO ___FILE_ONLY___ ═
|
| 270 |
+
2022-12-20 20:17:52,943 INFO ___FILE_ONLY___ ╝
|
| 271 |
+
|
| 272 |
+
2022-12-20 20:17:52,961 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 273 |
+
|
| 274 |
+
2022-12-20 20:17:52,962 INFO ___FILE_ONLY___ ╠═ Installing: BigQuery Command Line Tool (Platform Spec... ═╣
|
| 275 |
+
|
| 276 |
+
2022-12-20 20:17:52,962 INFO ___FILE_ONLY___ ╚
|
| 277 |
+
2022-12-20 20:17:52,966 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 278 |
+
2022-12-20 20:17:53,037 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-bq-nix-20220920185015.tar.gz HTTP/1.1" 200 1837
|
| 279 |
+
2022-12-20 20:17:53,038 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 280 |
+
2022-12-20 20:17:53,040 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 281 |
+
2022-12-20 20:17:53,040 INFO ___FILE_ONLY___ ╝
|
| 282 |
+
|
| 283 |
+
2022-12-20 20:17:53,052 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 284 |
+
|
| 285 |
+
2022-12-20 20:17:53,053 INFO ___FILE_ONLY___ ╠═ Installing: Bundled Python 3.9 ═╣
|
| 286 |
+
|
| 287 |
+
2022-12-20 20:17:53,053 INFO ___FILE_ONLY___ ╚
|
| 288 |
+
2022-12-20 20:17:53,057 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 289 |
+
2022-12-20 20:17:53,083 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-bundled-python3-unix-linux-x86_64-20220506143240.tar.gz HTTP/1.1" 200 65223088
|
| 290 |
+
2022-12-20 20:17:53,462 INFO ___FILE_ONLY___ ═
|
| 291 |
+
2022-12-20 20:17:53,468 INFO ___FILE_ONLY___ ═
|
| 292 |
+
2022-12-20 20:17:53,473 INFO ___FILE_ONLY___ ═
|
| 293 |
+
2022-12-20 20:17:53,478 INFO ___FILE_ONLY___ ═
|
| 294 |
+
2022-12-20 20:17:53,483 INFO ___FILE_ONLY___ ═
|
| 295 |
+
2022-12-20 20:17:53,488 INFO ___FILE_ONLY___ ═
|
| 296 |
+
2022-12-20 20:17:53,493 INFO ___FILE_ONLY___ ═
|
| 297 |
+
2022-12-20 20:17:53,498 INFO ___FILE_ONLY___ ═
|
| 298 |
+
2022-12-20 20:17:53,504 INFO ___FILE_ONLY___ ═
|
| 299 |
+
2022-12-20 20:17:53,509 INFO ___FILE_ONLY___ ═
|
| 300 |
+
2022-12-20 20:17:53,514 INFO ___FILE_ONLY___ ═
|
| 301 |
+
2022-12-20 20:17:53,519 INFO ___FILE_ONLY___ ═
|
| 302 |
+
2022-12-20 20:17:53,525 INFO ___FILE_ONLY___ ═
|
| 303 |
+
2022-12-20 20:17:53,531 INFO ___FILE_ONLY___ ═
|
| 304 |
+
2022-12-20 20:17:53,536 INFO ___FILE_ONLY___ ═
|
| 305 |
+
2022-12-20 20:17:53,542 INFO ___FILE_ONLY___ ═
|
| 306 |
+
2022-12-20 20:17:53,547 INFO ___FILE_ONLY___ ═
|
| 307 |
+
2022-12-20 20:17:53,553 INFO ___FILE_ONLY___ ═
|
| 308 |
+
2022-12-20 20:17:53,558 INFO ___FILE_ONLY___ ═
|
| 309 |
+
2022-12-20 20:17:53,563 INFO ___FILE_ONLY___ ═
|
| 310 |
+
2022-12-20 20:17:53,568 INFO ___FILE_ONLY___ ═
|
| 311 |
+
2022-12-20 20:17:53,574 INFO ___FILE_ONLY___ ═
|
| 312 |
+
2022-12-20 20:17:53,579 INFO ___FILE_ONLY___ ═
|
| 313 |
+
2022-12-20 20:17:53,584 INFO ___FILE_ONLY___ ═
|
| 314 |
+
2022-12-20 20:17:53,590 INFO ___FILE_ONLY___ ═
|
| 315 |
+
2022-12-20 20:17:53,595 INFO ___FILE_ONLY___ ═
|
| 316 |
+
2022-12-20 20:17:53,601 INFO ___FILE_ONLY___ ═
|
| 317 |
+
2022-12-20 20:17:53,606 INFO ___FILE_ONLY___ ═
|
| 318 |
+
2022-12-20 20:17:53,612 INFO ___FILE_ONLY___ ═
|
| 319 |
+
2022-12-20 20:17:53,617 INFO ___FILE_ONLY___ ═
|
| 320 |
+
2022-12-20 20:17:55,655 INFO ___FILE_ONLY___ ═
|
| 321 |
+
2022-12-20 20:17:55,683 INFO ___FILE_ONLY___ ═
|
| 322 |
+
2022-12-20 20:17:55,711 INFO ___FILE_ONLY___ ═
|
| 323 |
+
2022-12-20 20:17:55,737 INFO ___FILE_ONLY___ ═
|
| 324 |
+
2022-12-20 20:17:55,763 INFO ___FILE_ONLY___ ═
|
| 325 |
+
2022-12-20 20:17:55,797 INFO ___FILE_ONLY___ ═
|
| 326 |
+
2022-12-20 20:17:55,843 INFO ___FILE_ONLY___ ═
|
| 327 |
+
2022-12-20 20:17:55,879 INFO ___FILE_ONLY___ ═
|
| 328 |
+
2022-12-20 20:17:55,906 INFO ___FILE_ONLY___ ═
|
| 329 |
+
2022-12-20 20:17:55,933 INFO ___FILE_ONLY___ ═
|
| 330 |
+
2022-12-20 20:17:55,965 INFO ___FILE_ONLY___ ═
|
| 331 |
+
2022-12-20 20:17:55,996 INFO ___FILE_ONLY___ ═
|
| 332 |
+
2022-12-20 20:17:56,126 INFO ___FILE_ONLY___ ═
|
| 333 |
+
2022-12-20 20:17:56,151 INFO ___FILE_ONLY___ ═
|
| 334 |
+
2022-12-20 20:17:56,261 INFO ___FILE_ONLY___ ═
|
| 335 |
+
2022-12-20 20:17:56,295 INFO ___FILE_ONLY___ ═
|
| 336 |
+
2022-12-20 20:17:56,319 INFO ___FILE_ONLY___ ═
|
| 337 |
+
2022-12-20 20:17:56,352 INFO ___FILE_ONLY___ ═
|
| 338 |
+
2022-12-20 20:17:56,382 INFO ___FILE_ONLY___ ═
|
| 339 |
+
2022-12-20 20:17:56,437 INFO ___FILE_ONLY___ ═
|
| 340 |
+
2022-12-20 20:17:56,463 INFO ___FILE_ONLY___ ═
|
| 341 |
+
2022-12-20 20:17:56,487 INFO ___FILE_ONLY___ ═
|
| 342 |
+
2022-12-20 20:17:56,514 INFO ___FILE_ONLY___ ═
|
| 343 |
+
2022-12-20 20:17:56,545 INFO ___FILE_ONLY___ ═
|
| 344 |
+
2022-12-20 20:17:56,576 INFO ___FILE_ONLY___ ═
|
| 345 |
+
2022-12-20 20:17:56,606 INFO ___FILE_ONLY___ ═
|
| 346 |
+
2022-12-20 20:17:57,388 INFO ___FILE_ONLY___ ═
|
| 347 |
+
2022-12-20 20:17:57,769 INFO ___FILE_ONLY___ ═
|
| 348 |
+
2022-12-20 20:17:57,792 INFO ___FILE_ONLY___ ═
|
| 349 |
+
2022-12-20 20:17:57,816 INFO ___FILE_ONLY___ ═
|
| 350 |
+
2022-12-20 20:17:57,816 INFO ___FILE_ONLY___ ╝
|
| 351 |
+
|
| 352 |
+
2022-12-20 20:17:57,882 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 353 |
+
|
| 354 |
+
2022-12-20 20:17:57,883 INFO ___FILE_ONLY___ ╠═ Installing: Bundled Python 3.9 ═╣
|
| 355 |
+
|
| 356 |
+
2022-12-20 20:17:57,883 INFO ___FILE_ONLY___ ╚
|
| 357 |
+
2022-12-20 20:17:57,888 INFO ___FILE_ONLY___ ════════════════════════════════════════════════════════════
|
| 358 |
+
2022-12-20 20:17:57,888 INFO ___FILE_ONLY___ ╝
|
| 359 |
+
|
| 360 |
+
2022-12-20 20:17:57,894 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 361 |
+
|
| 362 |
+
2022-12-20 20:17:57,895 INFO ___FILE_ONLY___ ╠═ Installing: Cloud Storage Command Line Tool ═╣
|
| 363 |
+
|
| 364 |
+
2022-12-20 20:17:57,895 INFO ___FILE_ONLY___ ╚
|
| 365 |
+
2022-12-20 20:17:57,899 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 366 |
+
2022-12-20 20:17:57,972 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-gsutil-20221205224721.tar.gz HTTP/1.1" 200 16292401
|
| 367 |
+
2022-12-20 20:17:58,074 INFO ___FILE_ONLY___ ═
|
| 368 |
+
2022-12-20 20:17:58,075 INFO ___FILE_ONLY___ ═
|
| 369 |
+
2022-12-20 20:17:58,077 INFO ___FILE_ONLY___ ═
|
| 370 |
+
2022-12-20 20:17:58,078 INFO ___FILE_ONLY___ ═
|
| 371 |
+
2022-12-20 20:17:58,080 INFO ___FILE_ONLY___ ═
|
| 372 |
+
2022-12-20 20:17:58,081 INFO ___FILE_ONLY___ ═
|
| 373 |
+
2022-12-20 20:17:58,082 INFO ___FILE_ONLY___ ═
|
| 374 |
+
2022-12-20 20:17:58,084 INFO ___FILE_ONLY___ ═
|
| 375 |
+
2022-12-20 20:17:58,085 INFO ___FILE_ONLY___ ═
|
| 376 |
+
2022-12-20 20:17:58,086 INFO ___FILE_ONLY___ ═
|
| 377 |
+
2022-12-20 20:17:58,088 INFO ___FILE_ONLY___ ═
|
| 378 |
+
2022-12-20 20:17:58,089 INFO ___FILE_ONLY___ ═
|
| 379 |
+
2022-12-20 20:17:58,091 INFO ___FILE_ONLY___ ═
|
| 380 |
+
2022-12-20 20:17:58,092 INFO ___FILE_ONLY___ ═
|
| 381 |
+
2022-12-20 20:17:58,093 INFO ___FILE_ONLY___ ═
|
| 382 |
+
2022-12-20 20:17:58,095 INFO ___FILE_ONLY___ ═
|
| 383 |
+
2022-12-20 20:17:58,096 INFO ___FILE_ONLY___ ═
|
| 384 |
+
2022-12-20 20:17:58,098 INFO ___FILE_ONLY___ ═
|
| 385 |
+
2022-12-20 20:17:58,099 INFO ___FILE_ONLY___ ═
|
| 386 |
+
2022-12-20 20:17:58,100 INFO ___FILE_ONLY___ ═
|
| 387 |
+
2022-12-20 20:17:58,102 INFO ___FILE_ONLY___ ═
|
| 388 |
+
2022-12-20 20:17:58,103 INFO ___FILE_ONLY___ ═
|
| 389 |
+
2022-12-20 20:17:58,105 INFO ___FILE_ONLY___ ═
|
| 390 |
+
2022-12-20 20:17:58,106 INFO ___FILE_ONLY___ ═
|
| 391 |
+
2022-12-20 20:17:58,108 INFO ___FILE_ONLY___ ═
|
| 392 |
+
2022-12-20 20:17:58,109 INFO ___FILE_ONLY___ ═
|
| 393 |
+
2022-12-20 20:17:58,110 INFO ___FILE_ONLY___ ═
|
| 394 |
+
2022-12-20 20:17:58,112 INFO ___FILE_ONLY___ ═
|
| 395 |
+
2022-12-20 20:17:58,113 INFO ___FILE_ONLY___ ═
|
| 396 |
+
2022-12-20 20:17:58,115 INFO ___FILE_ONLY___ ═
|
| 397 |
+
2022-12-20 20:17:59,411 INFO ___FILE_ONLY___ ═
|
| 398 |
+
2022-12-20 20:17:59,488 INFO ___FILE_ONLY___ ═
|
| 399 |
+
2022-12-20 20:17:59,564 INFO ___FILE_ONLY___ ═
|
| 400 |
+
2022-12-20 20:17:59,639 INFO ___FILE_ONLY___ ═
|
| 401 |
+
2022-12-20 20:17:59,744 INFO ___FILE_ONLY___ ═
|
| 402 |
+
2022-12-20 20:17:59,833 INFO ___FILE_ONLY___ ═
|
| 403 |
+
2022-12-20 20:17:59,940 INFO ___FILE_ONLY___ ═
|
| 404 |
+
2022-12-20 20:18:00,026 INFO ___FILE_ONLY___ ═
|
| 405 |
+
2022-12-20 20:18:00,093 INFO ___FILE_ONLY___ ═
|
| 406 |
+
2022-12-20 20:18:00,214 INFO ___FILE_ONLY___ ═
|
| 407 |
+
2022-12-20 20:18:00,284 INFO ___FILE_ONLY___ ═
|
| 408 |
+
2022-12-20 20:18:00,372 INFO ___FILE_ONLY___ ═
|
| 409 |
+
2022-12-20 20:18:00,449 INFO ___FILE_ONLY___ ═
|
| 410 |
+
2022-12-20 20:18:00,532 INFO ___FILE_ONLY___ ═
|
| 411 |
+
2022-12-20 20:18:00,609 INFO ___FILE_ONLY___ ═
|
| 412 |
+
2022-12-20 20:18:00,680 INFO ___FILE_ONLY___ ═
|
| 413 |
+
2022-12-20 20:18:00,757 INFO ___FILE_ONLY___ ═
|
| 414 |
+
2022-12-20 20:18:00,842 INFO ___FILE_ONLY___ ═
|
| 415 |
+
2022-12-20 20:18:00,913 INFO ___FILE_ONLY___ ═
|
| 416 |
+
2022-12-20 20:18:00,990 INFO ___FILE_ONLY___ ═
|
| 417 |
+
2022-12-20 20:18:01,068 INFO ___FILE_ONLY___ ═
|
| 418 |
+
2022-12-20 20:18:01,145 INFO ___FILE_ONLY___ ═
|
| 419 |
+
2022-12-20 20:18:01,233 INFO ___FILE_ONLY___ ═
|
| 420 |
+
2022-12-20 20:18:01,309 INFO ___FILE_ONLY___ ═
|
| 421 |
+
2022-12-20 20:18:01,396 INFO ___FILE_ONLY___ ═
|
| 422 |
+
2022-12-20 20:18:01,484 INFO ___FILE_ONLY___ ═
|
| 423 |
+
2022-12-20 20:18:01,561 INFO ___FILE_ONLY___ ═
|
| 424 |
+
2022-12-20 20:18:01,634 INFO ___FILE_ONLY___ ═
|
| 425 |
+
2022-12-20 20:18:01,708 INFO ___FILE_ONLY___ ═
|
| 426 |
+
2022-12-20 20:18:01,800 INFO ___FILE_ONLY___ ═
|
| 427 |
+
2022-12-20 20:18:01,800 INFO ___FILE_ONLY___ ╝
|
| 428 |
+
|
| 429 |
+
2022-12-20 20:18:01,899 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 430 |
+
|
| 431 |
+
2022-12-20 20:18:01,900 INFO ___FILE_ONLY___ ╠═ Installing: Cloud Storage Command Line Tool (Platform... ═╣
|
| 432 |
+
|
| 433 |
+
2022-12-20 20:18:01,900 INFO ___FILE_ONLY___ ╚
|
| 434 |
+
2022-12-20 20:18:01,904 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 435 |
+
2022-12-20 20:18:01,973 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-gsutil-nix-20220920185015.tar.gz HTTP/1.1" 200 1851
|
| 436 |
+
2022-12-20 20:18:01,974 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 437 |
+
2022-12-20 20:18:01,976 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 438 |
+
2022-12-20 20:18:01,976 INFO ___FILE_ONLY___ ╝
|
| 439 |
+
|
| 440 |
+
2022-12-20 20:18:02,025 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 441 |
+
|
| 442 |
+
2022-12-20 20:18:02,025 INFO ___FILE_ONLY___ ╠═ Installing: Default set of gcloud commands ═╣
|
| 443 |
+
|
| 444 |
+
2022-12-20 20:18:02,025 INFO ___FILE_ONLY___ ╚
|
| 445 |
+
2022-12-20 20:18:02,030 INFO ___FILE_ONLY___ ════════════════════════════════════════════════════════════
|
| 446 |
+
2022-12-20 20:18:02,030 INFO ___FILE_ONLY___ ╝
|
| 447 |
+
|
| 448 |
+
2022-12-20 20:18:02,037 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 449 |
+
|
| 450 |
+
2022-12-20 20:18:02,037 INFO ___FILE_ONLY___ ╠═ Installing: Google Cloud CLI Core Libraries (Platform... ═╣
|
| 451 |
+
|
| 452 |
+
2022-12-20 20:18:02,037 INFO ___FILE_ONLY___ ╚
|
| 453 |
+
2022-12-20 20:18:02,042 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 454 |
+
2022-12-20 20:18:02,115 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-core-nix-20220920185015.tar.gz HTTP/1.1" 200 2221
|
| 455 |
+
2022-12-20 20:18:02,116 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 456 |
+
2022-12-20 20:18:02,118 INFO ___FILE_ONLY___ ═══════════════
|
| 457 |
+
2022-12-20 20:18:02,118 INFO ___FILE_ONLY___ ═══════════════
|
| 458 |
+
2022-12-20 20:18:02,118 INFO ___FILE_ONLY___ ╝
|
| 459 |
+
|
| 460 |
+
2022-12-20 20:18:02,132 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 461 |
+
|
| 462 |
+
2022-12-20 20:18:02,132 INFO ___FILE_ONLY___ ╠═ Installing: Google Cloud CRC32C Hash Tool ═╣
|
| 463 |
+
|
| 464 |
+
2022-12-20 20:18:02,132 INFO ___FILE_ONLY___ ╚
|
| 465 |
+
2022-12-20 20:18:02,137 INFO ___FILE_ONLY___ ════════════════════════════════════════════════════════════
|
| 466 |
+
2022-12-20 20:18:02,138 INFO ___FILE_ONLY___ ╝
|
| 467 |
+
|
| 468 |
+
2022-12-20 20:18:02,144 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 469 |
+
|
| 470 |
+
2022-12-20 20:18:02,144 INFO ___FILE_ONLY___ ╠═ Installing: Google Cloud CRC32C Hash Tool ═╣
|
| 471 |
+
|
| 472 |
+
2022-12-20 20:18:02,144 INFO ___FILE_ONLY___ ╚
|
| 473 |
+
2022-12-20 20:18:02,149 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 474 |
+
2022-12-20 20:18:02,177 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-gcloud-crc32c-linux-x86_64-20221205224721.tar.gz HTTP/1.1" 200 1235322
|
| 475 |
+
2022-12-20 20:18:02,194 INFO ___FILE_ONLY___ ═
|
| 476 |
+
2022-12-20 20:18:02,196 INFO ___FILE_ONLY___ ═
|
| 477 |
+
2022-12-20 20:18:02,196 INFO ___FILE_ONLY___ ═
|
| 478 |
+
2022-12-20 20:18:02,197 INFO ___FILE_ONLY___ ═
|
| 479 |
+
2022-12-20 20:18:02,197 INFO ___FILE_ONLY___ ═
|
| 480 |
+
2022-12-20 20:18:02,198 INFO ___FILE_ONLY___ ═
|
| 481 |
+
2022-12-20 20:18:02,199 INFO ___FILE_ONLY___ ═
|
| 482 |
+
2022-12-20 20:18:02,200 INFO ___FILE_ONLY___ ═
|
| 483 |
+
2022-12-20 20:18:02,200 INFO ___FILE_ONLY___ ═
|
| 484 |
+
2022-12-20 20:18:02,201 INFO ___FILE_ONLY___ ═
|
| 485 |
+
2022-12-20 20:18:02,201 INFO ___FILE_ONLY___ ═
|
| 486 |
+
2022-12-20 20:18:02,201 INFO ___FILE_ONLY___ ═
|
| 487 |
+
2022-12-20 20:18:02,202 INFO ___FILE_ONLY___ ═
|
| 488 |
+
2022-12-20 20:18:02,202 INFO ___FILE_ONLY___ ═
|
| 489 |
+
2022-12-20 20:18:02,202 INFO ___FILE_ONLY___ ═
|
| 490 |
+
2022-12-20 20:18:02,202 INFO ___FILE_ONLY___ ═
|
| 491 |
+
2022-12-20 20:18:02,203 INFO ___FILE_ONLY___ ═
|
| 492 |
+
2022-12-20 20:18:02,203 INFO ___FILE_ONLY___ ═
|
| 493 |
+
2022-12-20 20:18:02,203 INFO ___FILE_ONLY___ ═
|
| 494 |
+
2022-12-20 20:18:02,203 INFO ___FILE_ONLY___ ═
|
| 495 |
+
2022-12-20 20:18:02,203 INFO ___FILE_ONLY___ ═
|
| 496 |
+
2022-12-20 20:18:02,204 INFO ___FILE_ONLY___ ═
|
| 497 |
+
2022-12-20 20:18:02,204 INFO ___FILE_ONLY___ ═
|
| 498 |
+
2022-12-20 20:18:02,204 INFO ___FILE_ONLY___ ═
|
| 499 |
+
2022-12-20 20:18:02,204 INFO ___FILE_ONLY___ ═
|
| 500 |
+
2022-12-20 20:18:02,204 INFO ___FILE_ONLY___ ═
|
| 501 |
+
2022-12-20 20:18:02,205 INFO ___FILE_ONLY___ ═
|
| 502 |
+
2022-12-20 20:18:02,205 INFO ___FILE_ONLY___ ═
|
| 503 |
+
2022-12-20 20:18:02,205 INFO ___FILE_ONLY___ ═
|
| 504 |
+
2022-12-20 20:18:02,205 INFO ___FILE_ONLY___ ═
|
| 505 |
+
2022-12-20 20:18:02,243 INFO ___FILE_ONLY___ ═══════════════
|
| 506 |
+
2022-12-20 20:18:02,244 INFO ___FILE_ONLY___ ═══════════════
|
| 507 |
+
2022-12-20 20:18:02,244 INFO ___FILE_ONLY___ ╝
|
| 508 |
+
|
| 509 |
+
2022-12-20 20:18:02,257 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 510 |
+
|
| 511 |
+
2022-12-20 20:18:02,257 INFO ___FILE_ONLY___ ╠═ Installing: anthoscli ═╣
|
| 512 |
+
|
| 513 |
+
2022-12-20 20:18:02,257 INFO ___FILE_ONLY___ ╚
|
| 514 |
+
2022-12-20 20:18:02,262 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 515 |
+
2022-12-20 20:18:02,337 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-anthoscli-linux-x86_64-20221017194419.tar.gz HTTP/1.1" 200 41007646
|
| 516 |
+
2022-12-20 20:18:02,584 INFO ___FILE_ONLY___ ═
|
| 517 |
+
2022-12-20 20:18:02,587 INFO ___FILE_ONLY___ ═
|
| 518 |
+
2022-12-20 20:18:02,591 INFO ___FILE_ONLY___ ═
|
| 519 |
+
2022-12-20 20:18:02,594 INFO ___FILE_ONLY___ ═
|
| 520 |
+
2022-12-20 20:18:02,597 INFO ___FILE_ONLY___ ═
|
| 521 |
+
2022-12-20 20:18:02,601 INFO ___FILE_ONLY___ ═
|
| 522 |
+
2022-12-20 20:18:02,604 INFO ___FILE_ONLY___ ═
|
| 523 |
+
2022-12-20 20:18:02,608 INFO ___FILE_ONLY___ ═
|
| 524 |
+
2022-12-20 20:18:02,611 INFO ___FILE_ONLY___ ═
|
| 525 |
+
2022-12-20 20:18:02,614 INFO ___FILE_ONLY___ ═
|
| 526 |
+
2022-12-20 20:18:02,618 INFO ___FILE_ONLY___ ═
|
| 527 |
+
2022-12-20 20:18:02,621 INFO ___FILE_ONLY___ ═
|
| 528 |
+
2022-12-20 20:18:02,624 INFO ___FILE_ONLY___ ═
|
| 529 |
+
2022-12-20 20:18:02,628 INFO ___FILE_ONLY___ ═
|
| 530 |
+
2022-12-20 20:18:02,631 INFO ___FILE_ONLY___ ═
|
| 531 |
+
2022-12-20 20:18:02,634 INFO ___FILE_ONLY___ ═
|
| 532 |
+
2022-12-20 20:18:02,638 INFO ___FILE_ONLY___ ═
|
| 533 |
+
2022-12-20 20:18:02,641 INFO ___FILE_ONLY___ ═
|
| 534 |
+
2022-12-20 20:18:02,644 INFO ___FILE_ONLY___ ═
|
| 535 |
+
2022-12-20 20:18:02,648 INFO ___FILE_ONLY___ ═
|
| 536 |
+
2022-12-20 20:18:02,651 INFO ___FILE_ONLY___ ═
|
| 537 |
+
2022-12-20 20:18:02,654 INFO ___FILE_ONLY___ ═
|
| 538 |
+
2022-12-20 20:18:02,657 INFO ___FILE_ONLY___ ═
|
| 539 |
+
2022-12-20 20:18:02,661 INFO ___FILE_ONLY___ ═
|
| 540 |
+
2022-12-20 20:18:02,664 INFO ___FILE_ONLY___ ═
|
| 541 |
+
2022-12-20 20:18:02,668 INFO ___FILE_ONLY___ ═
|
| 542 |
+
2022-12-20 20:18:02,671 INFO ___FILE_ONLY___ ═
|
| 543 |
+
2022-12-20 20:18:02,675 INFO ___FILE_ONLY___ ═
|
| 544 |
+
2022-12-20 20:18:02,678 INFO ___FILE_ONLY___ ═
|
| 545 |
+
2022-12-20 20:18:02,682 INFO ___FILE_ONLY___ ═
|
| 546 |
+
2022-12-20 20:18:04,120 INFO ___FILE_ONLY___ ══════════
|
| 547 |
+
2022-12-20 20:18:04,126 INFO ___FILE_ONLY___ ═════════
|
| 548 |
+
2022-12-20 20:18:04,154 INFO ___FILE_ONLY___ ═══════════
|
| 549 |
+
2022-12-20 20:18:04,154 INFO ___FILE_ONLY___ ╝
|
| 550 |
+
|
| 551 |
+
2022-12-20 20:18:04,185 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 552 |
+
|
| 553 |
+
2022-12-20 20:18:04,185 INFO ___FILE_ONLY___ ╠═ Installing: anthoscli ═╣
|
| 554 |
+
|
| 555 |
+
2022-12-20 20:18:04,185 INFO ___FILE_ONLY___ ╚
|
| 556 |
+
2022-12-20 20:18:04,190 INFO ___FILE_ONLY___ ════════════════════════════════════════════════════════════
|
| 557 |
+
2022-12-20 20:18:04,190 INFO ___FILE_ONLY___ ╝
|
| 558 |
+
|
| 559 |
+
2022-12-20 20:18:04,197 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 560 |
+
|
| 561 |
+
2022-12-20 20:18:04,197 INFO ___FILE_ONLY___ ╠═ Installing: gcloud cli dependencies ═╣
|
| 562 |
+
|
| 563 |
+
2022-12-20 20:18:04,197 INFO ___FILE_ONLY___ ╚
|
| 564 |
+
2022-12-20 20:18:04,201 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 565 |
+
2022-12-20 20:18:04,276 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-gcloud-deps-linux-x86_64-20210416153011.tar.gz HTTP/1.1" 200 104
|
| 566 |
+
2022-12-20 20:18:04,277 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 567 |
+
2022-12-20 20:18:04,277 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 568 |
+
2022-12-20 20:18:04,277 INFO ___FILE_ONLY___ ╝
|
| 569 |
+
|
| 570 |
+
2022-12-20 20:18:04,291 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 571 |
+
|
| 572 |
+
2022-12-20 20:18:04,291 INFO ___FILE_ONLY___ ╠═ Creating backup and activating new installation ═╣
|
| 573 |
+
|
| 574 |
+
2022-12-20 20:18:04,291 INFO ___FILE_ONLY___ ╚
|
| 575 |
+
2022-12-20 20:18:04,292 DEBUG root Attempting to move directory [/tools/google-cloud-sdk] to [/tools/google-cloud-sdk.staging/.install/.backup]
|
| 576 |
+
2022-12-20 20:18:04,292 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 577 |
+
2022-12-20 20:18:04,292 DEBUG root Attempting to move directory [/tools/google-cloud-sdk.staging] to [/tools/google-cloud-sdk]
|
| 578 |
+
2022-12-20 20:18:04,292 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 579 |
+
2022-12-20 20:18:04,292 INFO ___FILE_ONLY___ ╝
|
| 580 |
+
|
| 581 |
+
2022-12-20 20:18:04,298 DEBUG root Updating notification cache...
|
| 582 |
+
2022-12-20 20:18:04,299 INFO ___FILE_ONLY___
|
| 583 |
+
|
| 584 |
+
2022-12-20 20:18:04,305 INFO ___FILE_ONLY___ Performing post processing steps...
|
| 585 |
+
2022-12-20 20:18:04,306 DEBUG root Executing command: ['python3', '-S', '/tools/google-cloud-sdk/lib/gcloud.py', 'components', 'post-process']
|
| 586 |
+
2022-12-20 20:18:32,586 DEBUG ___FILE_ONLY___
|
| 587 |
+
2022-12-20 20:18:32,587 DEBUG ___FILE_ONLY___
|
| 588 |
+
2022-12-20 20:18:32,597 INFO ___FILE_ONLY___
|
| 589 |
+
Update done!
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
2022-12-20 20:18:32,604 INFO root Display format: "none"
|
.config/logs/2022.12.20/20.18.05.031957.log
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2022-12-20 20:18:05,033 DEBUG root Loaded Command Group: ['gcloud', 'components']
|
| 2 |
+
2022-12-20 20:18:05,035 DEBUG root Loaded Command Group: ['gcloud', 'components', 'post_process']
|
| 3 |
+
2022-12-20 20:18:05,038 DEBUG root Running [gcloud.components.post-process] with arguments: []
|
| 4 |
+
2022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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2022-12-20 20:18:33,480 DEBUG root Loaded Command Group: ['gcloud', 'components']
|
| 2 |
+
2022-12-20 20:18:33,483 DEBUG root Loaded Command Group: ['gcloud', 'components', 'update']
|
| 3 |
+
2022-12-20 20:18:33,486 DEBUG root Running [gcloud.components.update] with arguments: [--quiet: "True", COMPONENT-IDS:8: "['gcloud', 'core', 'bq', 'gsutil', 'compute', 'preview', 'alpha', 'beta']"]
|
| 4 |
+
2022-12-20 20:18:33,487 INFO ___FILE_ONLY___ Beginning update. This process may take several minutes.
|
| 5 |
+
|
| 6 |
+
2022-12-20 20:18:33,492 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 7 |
+
2022-12-20 20:18:33,571 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components-2.json HTTP/1.1" 200 203441
|
| 8 |
+
2022-12-20 20:18:33,590 WARNING root Component [compute] no longer exists.
|
| 9 |
+
2022-12-20 20:18:33,590 WARNING root Component [preview] no longer exists.
|
| 10 |
+
2022-12-20 20:18:33,591 INFO ___FILE_ONLY___
|
| 11 |
+
|
| 12 |
+
2022-12-20 20:18:33,592 INFO ___FILE_ONLY___
|
| 13 |
+
Your current Google Cloud CLI version is: 412.0.0
|
| 14 |
+
|
| 15 |
+
2022-12-20 20:18:33,592 INFO ___FILE_ONLY___ Installing components from version: 412.0.0
|
| 16 |
+
|
| 17 |
+
2022-12-20 20:18:33,592 INFO ___FILE_ONLY___
|
| 18 |
+
|
| 19 |
+
2022-12-20 20:18:33,595 INFO ___FILE_ONLY___ ┌──────────────────────────────────────────────┐
|
| 20 |
+
2022-12-20 20:18:33,595 INFO ___FILE_ONLY___
|
| 21 |
+
|
| 22 |
+
2022-12-20 20:18:33,595 INFO ___FILE_ONLY___ │ These components will be installed. │
|
| 23 |
+
2022-12-20 20:18:33,595 INFO ___FILE_ONLY___
|
| 24 |
+
|
| 25 |
+
2022-12-20 20:18:33,595 INFO ___FILE_ONLY___ ├───────────────────────┬────────────┬─────────┤
|
| 26 |
+
2022-12-20 20:18:33,595 INFO ___FILE_ONLY___
|
| 27 |
+
|
| 28 |
+
2022-12-20 20:18:33,595 INFO ___FILE_ONLY___ │ Name │ Version │ Size │
|
| 29 |
+
2022-12-20 20:18:33,596 INFO ___FILE_ONLY___
|
| 30 |
+
|
| 31 |
+
2022-12-20 20:18:33,596 INFO ___FILE_ONLY___ ├───────────────────────┼────────────┼─────────┤
|
| 32 |
+
2022-12-20 20:18:33,596 INFO ___FILE_ONLY___
|
| 33 |
+
|
| 34 |
+
2022-12-20 20:18:33,596 INFO ___FILE_ONLY___ │
|
| 35 |
+
2022-12-20 20:18:33,596 INFO ___FILE_ONLY___ gcloud Alpha Commands
|
| 36 |
+
2022-12-20 20:18:33,596 INFO ___FILE_ONLY___
|
| 37 |
+
2022-12-20 20:18:33,596 INFO ___FILE_ONLY___ │
|
| 38 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___ 2022.12.09
|
| 39 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___
|
| 40 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___ │
|
| 41 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___ < 1 MiB
|
| 42 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___
|
| 43 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___ │
|
| 44 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___
|
| 45 |
+
|
| 46 |
+
2022-12-20 20:18:33,597 INFO ___FILE_ONLY___ │
|
| 47 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___ gcloud Beta Commands
|
| 48 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___
|
| 49 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___ │
|
| 50 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___ 2022.12.09
|
| 51 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___
|
| 52 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___ │
|
| 53 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___ < 1 MiB
|
| 54 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___
|
| 55 |
+
2022-12-20 20:18:33,598 INFO ___FILE_ONLY___ │
|
| 56 |
+
2022-12-20 20:18:33,599 INFO ___FILE_ONLY___
|
| 57 |
+
|
| 58 |
+
2022-12-20 20:18:33,599 INFO ___FILE_ONLY___ └───────────────────────┴────────────┴─────────┘
|
| 59 |
+
2022-12-20 20:18:33,599 INFO ___FILE_ONLY___
|
| 60 |
+
|
| 61 |
+
2022-12-20 20:18:33,599 INFO ___FILE_ONLY___
|
| 62 |
+
|
| 63 |
+
2022-12-20 20:18:33,601 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 64 |
+
2022-12-20 20:18:33,674 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/RELEASE_NOTES HTTP/1.1" 200 916325
|
| 65 |
+
2022-12-20 20:18:33,705 INFO ___FILE_ONLY___ For the latest full release notes, please visit:
|
| 66 |
+
https://cloud.google.com/sdk/release_notes
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
2022-12-20 20:18:33,712 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 70 |
+
|
| 71 |
+
2022-12-20 20:18:33,712 INFO ___FILE_ONLY___ ╠═ Creating update staging area ═╣
|
| 72 |
+
|
| 73 |
+
2022-12-20 20:18:33,713 INFO ___FILE_ONLY___ ╚
|
| 74 |
+
2022-12-20 20:18:33,713 INFO ___FILE_ONLY___ ══════
|
| 75 |
+
2022-12-20 20:18:35,027 INFO ___FILE_ONLY___ ══════
|
| 76 |
+
2022-12-20 20:18:35,028 INFO ___FILE_ONLY___ ══════
|
| 77 |
+
2022-12-20 20:18:35,444 INFO ___FILE_ONLY___ ═
|
| 78 |
+
2022-12-20 20:18:35,635 INFO ___FILE_ONLY___ ═
|
| 79 |
+
2022-12-20 20:18:35,807 INFO ___FILE_ONLY___ ═
|
| 80 |
+
2022-12-20 20:18:35,991 INFO ___FILE_ONLY___ ═
|
| 81 |
+
2022-12-20 20:18:36,218 INFO ___FILE_ONLY___ ═
|
| 82 |
+
2022-12-20 20:18:36,415 INFO ___FILE_ONLY___ ═
|
| 83 |
+
2022-12-20 20:18:36,553 INFO ___FILE_ONLY___ ═
|
| 84 |
+
2022-12-20 20:18:36,673 INFO ___FILE_ONLY___ ═
|
| 85 |
+
2022-12-20 20:18:36,947 INFO ___FILE_ONLY___ ═
|
| 86 |
+
2022-12-20 20:18:37,118 INFO ___FILE_ONLY___ ═
|
| 87 |
+
2022-12-20 20:18:37,265 INFO ___FILE_ONLY___ ═
|
| 88 |
+
2022-12-20 20:18:37,471 INFO ___FILE_ONLY___ ═
|
| 89 |
+
2022-12-20 20:18:37,607 INFO ___FILE_ONLY___ ═
|
| 90 |
+
2022-12-20 20:18:37,768 INFO ___FILE_ONLY___ ═
|
| 91 |
+
2022-12-20 20:18:38,035 INFO ___FILE_ONLY___ ═
|
| 92 |
+
2022-12-20 20:18:38,407 INFO ___FILE_ONLY___ ═
|
| 93 |
+
2022-12-20 20:18:38,670 INFO ___FILE_ONLY___ ═
|
| 94 |
+
2022-12-20 20:18:39,369 INFO ___FILE_ONLY___ ═
|
| 95 |
+
2022-12-20 20:18:39,493 INFO ___FILE_ONLY___ ═
|
| 96 |
+
2022-12-20 20:18:39,635 INFO ___FILE_ONLY___ ═
|
| 97 |
+
2022-12-20 20:18:39,746 INFO ___FILE_ONLY___ ═
|
| 98 |
+
2022-12-20 20:18:39,861 INFO ___FILE_ONLY___ ═
|
| 99 |
+
2022-12-20 20:18:39,970 INFO ___FILE_ONLY___ ═
|
| 100 |
+
2022-12-20 20:18:40,113 INFO ___FILE_ONLY___ ═
|
| 101 |
+
2022-12-20 20:18:40,280 INFO ___FILE_ONLY___ ═
|
| 102 |
+
2022-12-20 20:18:40,416 INFO ___FILE_ONLY___ ═
|
| 103 |
+
2022-12-20 20:18:40,532 INFO ___FILE_ONLY___ ═
|
| 104 |
+
2022-12-20 20:18:40,647 INFO ___FILE_ONLY___ ═
|
| 105 |
+
2022-12-20 20:18:40,774 INFO ___FILE_ONLY___ ═
|
| 106 |
+
2022-12-20 20:18:40,875 INFO ___FILE_ONLY___ ═
|
| 107 |
+
2022-12-20 20:18:41,007 INFO ___FILE_ONLY___ ═
|
| 108 |
+
2022-12-20 20:18:41,125 INFO ___FILE_ONLY___ ═
|
| 109 |
+
2022-12-20 20:18:41,246 INFO ___FILE_ONLY___ ═
|
| 110 |
+
2022-12-20 20:18:41,358 INFO ___FILE_ONLY___ ═
|
| 111 |
+
2022-12-20 20:18:41,476 INFO ___FILE_ONLY___ ═
|
| 112 |
+
2022-12-20 20:18:41,585 INFO ___FILE_ONLY___ ═
|
| 113 |
+
2022-12-20 20:18:41,679 INFO ___FILE_ONLY___ ═
|
| 114 |
+
2022-12-20 20:18:41,807 INFO ___FILE_ONLY___ ═
|
| 115 |
+
2022-12-20 20:18:41,935 INFO ___FILE_ONLY___ ═
|
| 116 |
+
2022-12-20 20:18:42,098 INFO ___FILE_ONLY___ ═
|
| 117 |
+
2022-12-20 20:18:42,367 INFO ___FILE_ONLY___ ═
|
| 118 |
+
2022-12-20 20:18:42,530 INFO ___FILE_ONLY___ ═
|
| 119 |
+
2022-12-20 20:18:42,530 INFO ___FILE_ONLY___ ╝
|
| 120 |
+
|
| 121 |
+
2022-12-20 20:18:47,407 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 122 |
+
|
| 123 |
+
2022-12-20 20:18:47,407 INFO ___FILE_ONLY___ ╠═ Installing: gcloud Alpha Commands ═╣
|
| 124 |
+
|
| 125 |
+
2022-12-20 20:18:47,407 INFO ___FILE_ONLY___ ╚
|
| 126 |
+
2022-12-20 20:18:47,412 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 127 |
+
2022-12-20 20:18:47,483 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-alpha-20221209155815.tar.gz HTTP/1.1" 200 800
|
| 128 |
+
2022-12-20 20:18:47,484 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 129 |
+
2022-12-20 20:18:47,487 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 130 |
+
2022-12-20 20:18:47,487 INFO ___FILE_ONLY___ ╝
|
| 131 |
+
|
| 132 |
+
2022-12-20 20:18:47,502 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 133 |
+
|
| 134 |
+
2022-12-20 20:18:47,503 INFO ___FILE_ONLY___ ╠═ Installing: gcloud Beta Commands ═╣
|
| 135 |
+
|
| 136 |
+
2022-12-20 20:18:47,503 INFO ___FILE_ONLY___ ╚
|
| 137 |
+
2022-12-20 20:18:47,508 DEBUG urllib3.connectionpool Starting new HTTPS connection (1): dl.google.com:443
|
| 138 |
+
2022-12-20 20:18:47,533 DEBUG urllib3.connectionpool https://dl.google.com:443 "GET /dl/cloudsdk/channels/rapid/components/google-cloud-sdk-beta-20221209155815.tar.gz HTTP/1.1" 200 797
|
| 139 |
+
2022-12-20 20:18:47,534 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 140 |
+
2022-12-20 20:18:47,535 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 141 |
+
2022-12-20 20:18:47,535 INFO ___FILE_ONLY___ ╝
|
| 142 |
+
|
| 143 |
+
2022-12-20 20:18:47,548 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
|
| 144 |
+
|
| 145 |
+
2022-12-20 20:18:47,548 INFO ___FILE_ONLY___ ╠═ Creating backup and activating new installation ═╣
|
| 146 |
+
|
| 147 |
+
2022-12-20 20:18:47,548 INFO ___FILE_ONLY___ ╚
|
| 148 |
+
2022-12-20 20:18:47,549 DEBUG root Attempting to move directory [/tools/google-cloud-sdk] to [/tools/google-cloud-sdk.staging/.install/.backup]
|
| 149 |
+
2022-12-20 20:18:47,549 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 150 |
+
2022-12-20 20:18:47,549 DEBUG root Attempting to move directory [/tools/google-cloud-sdk.staging] to [/tools/google-cloud-sdk]
|
| 151 |
+
2022-12-20 20:18:47,549 INFO ___FILE_ONLY___ ══════════════════════════════
|
| 152 |
+
2022-12-20 20:18:47,549 INFO ___FILE_ONLY___ ╝
|
| 153 |
+
|
| 154 |
+
2022-12-20 20:18:47,555 DEBUG root Updating notification cache...
|
| 155 |
+
2022-12-20 20:18:47,556 INFO ___FILE_ONLY___
|
| 156 |
+
|
| 157 |
+
2022-12-20 20:18:47,563 INFO ___FILE_ONLY___ Performing post processing steps...
|
| 158 |
+
2022-12-20 20:18:47,563 DEBUG root Executing command: ['python3', '-S', '/tools/google-cloud-sdk/lib/gcloud.py', 'components', 'post-process']
|
| 159 |
+
2022-12-20 20:19:17,822 DEBUG ___FILE_ONLY___
|
| 160 |
+
2022-12-20 20:19:17,823 DEBUG ___FILE_ONLY___
|
| 161 |
+
2022-12-20 20:19:17,856 INFO ___FILE_ONLY___
|
| 162 |
+
Update done!
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
2022-12-20 20:19:17,862 INFO root Display format: "none"
|
.config/logs/2022.12.20/20.18.48.288023.log
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2022-12-20 20:18:48,289 DEBUG root Loaded Command Group: ['gcloud', 'components']
|
| 2 |
+
2022-12-20 20:18:48,292 DEBUG root Loaded Command Group: ['gcloud', 'components', 'post_process']
|
| 3 |
+
2022-12-20 20:18:48,294 DEBUG root Running [gcloud.components.post-process] with arguments: []
|
| 4 |
+
2022-12-20 20:19:17,710 INFO root Display format: "none"
|
.config/logs/2022.12.20/20.19.18.730018.log
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2022-12-20 20:19:18,732 DEBUG root Loaded Command Group: ['gcloud', 'config']
|
| 2 |
+
2022-12-20 20:19:18,766 DEBUG root Loaded Command Group: ['gcloud', 'config', 'set']
|
| 3 |
+
2022-12-20 20:19:18,769 DEBUG root Running [gcloud.config.set] with arguments: [SECTION/PROPERTY: "component_manager/disable_update_check", VALUE: "true"]
|
| 4 |
+
2022-12-20 20:19:18,803 INFO ___FILE_ONLY___ Updated property [component_manager/disable_update_check].
|
| 5 |
+
|
| 6 |
+
2022-12-20 20:19:18,804 INFO root Display format: "default"
|
| 7 |
+
2022-12-20 20:19:18,805 DEBUG root SDK update checks are disabled.
|
.config/logs/2022.12.20/20.19.19.661684.log
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2022-12-20 20:19:19,663 DEBUG root Loaded Command Group: ['gcloud', 'config']
|
| 2 |
+
2022-12-20 20:19:19,697 DEBUG root Loaded Command Group: ['gcloud', 'config', 'set']
|
| 3 |
+
2022-12-20 20:19:19,700 DEBUG root Running [gcloud.config.set] with arguments: [SECTION/PROPERTY: "compute/gce_metadata_read_timeout_sec", VALUE: "0"]
|
| 4 |
+
2022-12-20 20:19:19,701 INFO ___FILE_ONLY___ Updated property [compute/gce_metadata_read_timeout_sec].
|
| 5 |
+
|
| 6 |
+
2022-12-20 20:19:19,702 INFO root Display format: "default"
|
| 7 |
+
2022-12-20 20:19:19,703 DEBUG root SDK update checks are disabled.
|
.gitattributes
CHANGED
|
@@ -32,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
sample_data/mnist_train_small.csv filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
sample_data/mnist_test.csv filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: creativeml-openrail-m
|
| 3 |
+
tags:
|
| 4 |
+
- text-to-image
|
| 5 |
+
- stable-diffusion
|
| 6 |
+
---
|
| 7 |
+
### Model Dreambooth concept Model-diffuser được train bởi tranmc bằng [Shinja Zero SoTA DreamBooth_Stable_Diffusion](https://colab.research.google.com/drive/1G7qx6M_S1PDDlsWIMdbZXwdZik6sUlEh) notebook <br>
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
Test concept bằng [Shinja Zero no Notebook](https://colab.research.google.com/drive/1Hp1ZIjPbsZKlCtomJVmt2oX7733W44b0) <br>
|
| 11 |
+
Hoặc test bằng `diffusers` [Colab Notebook for Inference](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/sd_dreambooth_inference.ipynb)
|
| 12 |
+
|
| 13 |
+
Ảnh mẫu của concept: WIP
|
convert_original_stable_diffusion_to_diffusers.py
ADDED
|
@@ -0,0 +1,752 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2022 The HuggingFace Inc. team.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
""" Conversion script for the LDM checkpoints. """
|
| 16 |
+
|
| 17 |
+
import argparse
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
import torch
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
from omegaconf import OmegaConf
|
| 25 |
+
except ImportError:
|
| 26 |
+
raise ImportError(
|
| 27 |
+
"OmegaConf is required to convert the LDM checkpoints. Please install it with `pip install OmegaConf`."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
from diffusers import (
|
| 31 |
+
AutoencoderKL,
|
| 32 |
+
DDIMScheduler,
|
| 33 |
+
DPMSolverMultistepScheduler,
|
| 34 |
+
EulerAncestralDiscreteScheduler,
|
| 35 |
+
EulerDiscreteScheduler,
|
| 36 |
+
LDMTextToImagePipeline,
|
| 37 |
+
LMSDiscreteScheduler,
|
| 38 |
+
PNDMScheduler,
|
| 39 |
+
StableDiffusionPipeline,
|
| 40 |
+
UNet2DConditionModel,
|
| 41 |
+
)
|
| 42 |
+
from diffusers.pipelines.latent_diffusion.pipeline_latent_diffusion import LDMBertConfig, LDMBertModel
|
| 43 |
+
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
|
| 44 |
+
from transformers import AutoFeatureExtractor, BertTokenizerFast, CLIPTextModel, CLIPTokenizer
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def shave_segments(path, n_shave_prefix_segments=1):
|
| 48 |
+
"""
|
| 49 |
+
Removes segments. Positive values shave the first segments, negative shave the last segments.
|
| 50 |
+
"""
|
| 51 |
+
if n_shave_prefix_segments >= 0:
|
| 52 |
+
return ".".join(path.split(".")[n_shave_prefix_segments:])
|
| 53 |
+
else:
|
| 54 |
+
return ".".join(path.split(".")[:n_shave_prefix_segments])
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def renew_resnet_paths(old_list, n_shave_prefix_segments=0):
|
| 58 |
+
"""
|
| 59 |
+
Updates paths inside resnets to the new naming scheme (local renaming)
|
| 60 |
+
"""
|
| 61 |
+
mapping = []
|
| 62 |
+
for old_item in old_list:
|
| 63 |
+
new_item = old_item.replace("in_layers.0", "norm1")
|
| 64 |
+
new_item = new_item.replace("in_layers.2", "conv1")
|
| 65 |
+
|
| 66 |
+
new_item = new_item.replace("out_layers.0", "norm2")
|
| 67 |
+
new_item = new_item.replace("out_layers.3", "conv2")
|
| 68 |
+
|
| 69 |
+
new_item = new_item.replace("emb_layers.1", "time_emb_proj")
|
| 70 |
+
new_item = new_item.replace("skip_connection", "conv_shortcut")
|
| 71 |
+
|
| 72 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 73 |
+
|
| 74 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 75 |
+
|
| 76 |
+
return mapping
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def renew_vae_resnet_paths(old_list, n_shave_prefix_segments=0):
|
| 80 |
+
"""
|
| 81 |
+
Updates paths inside resnets to the new naming scheme (local renaming)
|
| 82 |
+
"""
|
| 83 |
+
mapping = []
|
| 84 |
+
for old_item in old_list:
|
| 85 |
+
new_item = old_item
|
| 86 |
+
|
| 87 |
+
new_item = new_item.replace("nin_shortcut", "conv_shortcut")
|
| 88 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 89 |
+
|
| 90 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 91 |
+
|
| 92 |
+
return mapping
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def renew_attention_paths(old_list, n_shave_prefix_segments=0):
|
| 96 |
+
"""
|
| 97 |
+
Updates paths inside attentions to the new naming scheme (local renaming)
|
| 98 |
+
"""
|
| 99 |
+
mapping = []
|
| 100 |
+
for old_item in old_list:
|
| 101 |
+
new_item = old_item
|
| 102 |
+
|
| 103 |
+
# new_item = new_item.replace('norm.weight', 'group_norm.weight')
|
| 104 |
+
# new_item = new_item.replace('norm.bias', 'group_norm.bias')
|
| 105 |
+
|
| 106 |
+
# new_item = new_item.replace('proj_out.weight', 'proj_attn.weight')
|
| 107 |
+
# new_item = new_item.replace('proj_out.bias', 'proj_attn.bias')
|
| 108 |
+
|
| 109 |
+
# new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 110 |
+
|
| 111 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 112 |
+
|
| 113 |
+
return mapping
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def renew_vae_attention_paths(old_list, n_shave_prefix_segments=0):
|
| 117 |
+
"""
|
| 118 |
+
Updates paths inside attentions to the new naming scheme (local renaming)
|
| 119 |
+
"""
|
| 120 |
+
mapping = []
|
| 121 |
+
for old_item in old_list:
|
| 122 |
+
new_item = old_item
|
| 123 |
+
|
| 124 |
+
new_item = new_item.replace("norm.weight", "group_norm.weight")
|
| 125 |
+
new_item = new_item.replace("norm.bias", "group_norm.bias")
|
| 126 |
+
|
| 127 |
+
new_item = new_item.replace("q.weight", "query.weight")
|
| 128 |
+
new_item = new_item.replace("q.bias", "query.bias")
|
| 129 |
+
|
| 130 |
+
new_item = new_item.replace("k.weight", "key.weight")
|
| 131 |
+
new_item = new_item.replace("k.bias", "key.bias")
|
| 132 |
+
|
| 133 |
+
new_item = new_item.replace("v.weight", "value.weight")
|
| 134 |
+
new_item = new_item.replace("v.bias", "value.bias")
|
| 135 |
+
|
| 136 |
+
new_item = new_item.replace("proj_out.weight", "proj_attn.weight")
|
| 137 |
+
new_item = new_item.replace("proj_out.bias", "proj_attn.bias")
|
| 138 |
+
|
| 139 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 140 |
+
|
| 141 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 142 |
+
|
| 143 |
+
return mapping
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def assign_to_checkpoint(
|
| 147 |
+
paths, checkpoint, old_checkpoint, attention_paths_to_split=None, additional_replacements=None, config=None
|
| 148 |
+
):
|
| 149 |
+
"""
|
| 150 |
+
This does the final conversion step: take locally converted weights and apply a global renaming
|
| 151 |
+
to them. It splits attention layers, and takes into account additional replacements
|
| 152 |
+
that may arise.
|
| 153 |
+
|
| 154 |
+
Assigns the weights to the new checkpoint.
|
| 155 |
+
"""
|
| 156 |
+
assert isinstance(paths, list), "Paths should be a list of dicts containing 'old' and 'new' keys."
|
| 157 |
+
|
| 158 |
+
# Splits the attention layers into three variables.
|
| 159 |
+
if attention_paths_to_split is not None:
|
| 160 |
+
for path, path_map in attention_paths_to_split.items():
|
| 161 |
+
old_tensor = old_checkpoint[path]
|
| 162 |
+
channels = old_tensor.shape[0] // 3
|
| 163 |
+
|
| 164 |
+
target_shape = (-1, channels) if len(old_tensor.shape) == 3 else (-1)
|
| 165 |
+
|
| 166 |
+
num_heads = old_tensor.shape[0] // config["num_head_channels"] // 3
|
| 167 |
+
|
| 168 |
+
old_tensor = old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:])
|
| 169 |
+
query, key, value = old_tensor.split(channels // num_heads, dim=1)
|
| 170 |
+
|
| 171 |
+
checkpoint[path_map["query"]] = query.reshape(target_shape)
|
| 172 |
+
checkpoint[path_map["key"]] = key.reshape(target_shape)
|
| 173 |
+
checkpoint[path_map["value"]] = value.reshape(target_shape)
|
| 174 |
+
|
| 175 |
+
for path in paths:
|
| 176 |
+
new_path = path["new"]
|
| 177 |
+
|
| 178 |
+
# These have already been assigned
|
| 179 |
+
if attention_paths_to_split is not None and new_path in attention_paths_to_split:
|
| 180 |
+
continue
|
| 181 |
+
|
| 182 |
+
# Global renaming happens here
|
| 183 |
+
new_path = new_path.replace("middle_block.0", "mid_block.resnets.0")
|
| 184 |
+
new_path = new_path.replace("middle_block.1", "mid_block.attentions.0")
|
| 185 |
+
new_path = new_path.replace("middle_block.2", "mid_block.resnets.1")
|
| 186 |
+
|
| 187 |
+
if additional_replacements is not None:
|
| 188 |
+
for replacement in additional_replacements:
|
| 189 |
+
new_path = new_path.replace(replacement["old"], replacement["new"])
|
| 190 |
+
|
| 191 |
+
# proj_attn.weight has to be converted from conv 1D to linear
|
| 192 |
+
if "proj_attn.weight" in new_path:
|
| 193 |
+
checkpoint[new_path] = old_checkpoint[path["old"]][:, :, 0]
|
| 194 |
+
else:
|
| 195 |
+
checkpoint[new_path] = old_checkpoint[path["old"]]
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def conv_attn_to_linear(checkpoint):
|
| 199 |
+
keys = list(checkpoint.keys())
|
| 200 |
+
attn_keys = ["query.weight", "key.weight", "value.weight"]
|
| 201 |
+
for key in keys:
|
| 202 |
+
if ".".join(key.split(".")[-2:]) in attn_keys:
|
| 203 |
+
if checkpoint[key].ndim > 2:
|
| 204 |
+
checkpoint[key] = checkpoint[key][:, :, 0, 0]
|
| 205 |
+
elif "proj_attn.weight" in key:
|
| 206 |
+
if checkpoint[key].ndim > 2:
|
| 207 |
+
checkpoint[key] = checkpoint[key][:, :, 0]
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def create_unet_diffusers_config(original_config):
|
| 211 |
+
"""
|
| 212 |
+
Creates a config for the diffusers based on the config of the LDM model.
|
| 213 |
+
"""
|
| 214 |
+
model_params = original_config.model.params
|
| 215 |
+
unet_params = original_config.model.params.unet_config.params
|
| 216 |
+
|
| 217 |
+
block_out_channels = [unet_params.model_channels * mult for mult in unet_params.channel_mult]
|
| 218 |
+
|
| 219 |
+
down_block_types = []
|
| 220 |
+
resolution = 1
|
| 221 |
+
for i in range(len(block_out_channels)):
|
| 222 |
+
block_type = "CrossAttnDownBlock2D" if resolution in unet_params.attention_resolutions else "DownBlock2D"
|
| 223 |
+
down_block_types.append(block_type)
|
| 224 |
+
if i != len(block_out_channels) - 1:
|
| 225 |
+
resolution *= 2
|
| 226 |
+
|
| 227 |
+
up_block_types = []
|
| 228 |
+
for i in range(len(block_out_channels)):
|
| 229 |
+
block_type = "CrossAttnUpBlock2D" if resolution in unet_params.attention_resolutions else "UpBlock2D"
|
| 230 |
+
up_block_types.append(block_type)
|
| 231 |
+
resolution //= 2
|
| 232 |
+
|
| 233 |
+
config = dict(
|
| 234 |
+
sample_size=model_params.image_size,
|
| 235 |
+
in_channels=unet_params.in_channels,
|
| 236 |
+
out_channels=unet_params.out_channels,
|
| 237 |
+
down_block_types=tuple(down_block_types),
|
| 238 |
+
up_block_types=tuple(up_block_types),
|
| 239 |
+
block_out_channels=tuple(block_out_channels),
|
| 240 |
+
layers_per_block=unet_params.num_res_blocks,
|
| 241 |
+
cross_attention_dim=unet_params.context_dim,
|
| 242 |
+
attention_head_dim=unet_params.num_heads,
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
return config
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def create_vae_diffusers_config(original_config):
|
| 249 |
+
"""
|
| 250 |
+
Creates a config for the diffusers based on the config of the LDM model.
|
| 251 |
+
"""
|
| 252 |
+
vae_params = original_config.model.params.first_stage_config.params.ddconfig
|
| 253 |
+
_ = original_config.model.params.first_stage_config.params.embed_dim
|
| 254 |
+
|
| 255 |
+
block_out_channels = [vae_params.ch * mult for mult in vae_params.ch_mult]
|
| 256 |
+
down_block_types = ["DownEncoderBlock2D"] * len(block_out_channels)
|
| 257 |
+
up_block_types = ["UpDecoderBlock2D"] * len(block_out_channels)
|
| 258 |
+
|
| 259 |
+
config = dict(
|
| 260 |
+
sample_size=vae_params.resolution,
|
| 261 |
+
in_channels=vae_params.in_channels,
|
| 262 |
+
out_channels=vae_params.out_ch,
|
| 263 |
+
down_block_types=tuple(down_block_types),
|
| 264 |
+
up_block_types=tuple(up_block_types),
|
| 265 |
+
block_out_channels=tuple(block_out_channels),
|
| 266 |
+
latent_channels=vae_params.z_channels,
|
| 267 |
+
layers_per_block=vae_params.num_res_blocks,
|
| 268 |
+
)
|
| 269 |
+
return config
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
def create_diffusers_schedular(original_config):
|
| 273 |
+
schedular = DDIMScheduler(
|
| 274 |
+
num_train_timesteps=original_config.model.params.timesteps,
|
| 275 |
+
beta_start=original_config.model.params.linear_start,
|
| 276 |
+
beta_end=original_config.model.params.linear_end,
|
| 277 |
+
beta_schedule="scaled_linear",
|
| 278 |
+
)
|
| 279 |
+
return schedular
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def create_ldm_bert_config(original_config):
|
| 283 |
+
bert_params = original_config.model.parms.cond_stage_config.params
|
| 284 |
+
config = LDMBertConfig(
|
| 285 |
+
d_model=bert_params.n_embed,
|
| 286 |
+
encoder_layers=bert_params.n_layer,
|
| 287 |
+
encoder_ffn_dim=bert_params.n_embed * 4,
|
| 288 |
+
)
|
| 289 |
+
return config
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def convert_ldm_unet_checkpoint(checkpoint, config, path=None, extract_ema=False):
|
| 293 |
+
"""
|
| 294 |
+
Takes a state dict and a config, and returns a converted checkpoint.
|
| 295 |
+
"""
|
| 296 |
+
|
| 297 |
+
# extract state_dict for UNet
|
| 298 |
+
unet_state_dict = {}
|
| 299 |
+
keys = list(checkpoint.keys())
|
| 300 |
+
|
| 301 |
+
unet_key = "model.diffusion_model."
|
| 302 |
+
# at least a 100 parameters have to start with `model_ema` in order for the checkpoint to be EMA
|
| 303 |
+
if sum(k.startswith("model_ema") for k in keys) > 100:
|
| 304 |
+
print(f"Checkpoint {path} has both EMA and non-EMA weights.")
|
| 305 |
+
if extract_ema:
|
| 306 |
+
print(
|
| 307 |
+
"In this conversion only the EMA weights are extracted. If you want to instead extract the non-EMA"
|
| 308 |
+
" weights (useful to continue fine-tuning), please make sure to remove the `--extract_ema` flag."
|
| 309 |
+
)
|
| 310 |
+
for key in keys:
|
| 311 |
+
if key.startswith("model.diffusion_model"):
|
| 312 |
+
flat_ema_key = "model_ema." + "".join(key.split(".")[1:])
|
| 313 |
+
unet_state_dict[key.replace(unet_key, "")] = checkpoint.pop(flat_ema_key)
|
| 314 |
+
else:
|
| 315 |
+
print(
|
| 316 |
+
"In this conversion only the non-EMA weights are extracted. If you want to instead extract the EMA"
|
| 317 |
+
" weights (usually better for inference), please make sure to add the `--extract_ema` flag."
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
for key in keys:
|
| 321 |
+
if key.startswith(unet_key):
|
| 322 |
+
unet_state_dict[key.replace(unet_key, "")] = checkpoint.pop(key)
|
| 323 |
+
|
| 324 |
+
new_checkpoint = {}
|
| 325 |
+
|
| 326 |
+
new_checkpoint["time_embedding.linear_1.weight"] = unet_state_dict["time_embed.0.weight"]
|
| 327 |
+
new_checkpoint["time_embedding.linear_1.bias"] = unet_state_dict["time_embed.0.bias"]
|
| 328 |
+
new_checkpoint["time_embedding.linear_2.weight"] = unet_state_dict["time_embed.2.weight"]
|
| 329 |
+
new_checkpoint["time_embedding.linear_2.bias"] = unet_state_dict["time_embed.2.bias"]
|
| 330 |
+
|
| 331 |
+
new_checkpoint["conv_in.weight"] = unet_state_dict["input_blocks.0.0.weight"]
|
| 332 |
+
new_checkpoint["conv_in.bias"] = unet_state_dict["input_blocks.0.0.bias"]
|
| 333 |
+
|
| 334 |
+
new_checkpoint["conv_norm_out.weight"] = unet_state_dict["out.0.weight"]
|
| 335 |
+
new_checkpoint["conv_norm_out.bias"] = unet_state_dict["out.0.bias"]
|
| 336 |
+
new_checkpoint["conv_out.weight"] = unet_state_dict["out.2.weight"]
|
| 337 |
+
new_checkpoint["conv_out.bias"] = unet_state_dict["out.2.bias"]
|
| 338 |
+
|
| 339 |
+
# Retrieves the keys for the input blocks only
|
| 340 |
+
num_input_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "input_blocks" in layer})
|
| 341 |
+
input_blocks = {
|
| 342 |
+
layer_id: [key for key in unet_state_dict if f"input_blocks.{layer_id}" in key]
|
| 343 |
+
for layer_id in range(num_input_blocks)
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
# Retrieves the keys for the middle blocks only
|
| 347 |
+
num_middle_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "middle_block" in layer})
|
| 348 |
+
middle_blocks = {
|
| 349 |
+
layer_id: [key for key in unet_state_dict if f"middle_block.{layer_id}" in key]
|
| 350 |
+
for layer_id in range(num_middle_blocks)
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
# Retrieves the keys for the output blocks only
|
| 354 |
+
num_output_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "output_blocks" in layer})
|
| 355 |
+
output_blocks = {
|
| 356 |
+
layer_id: [key for key in unet_state_dict if f"output_blocks.{layer_id}" in key]
|
| 357 |
+
for layer_id in range(num_output_blocks)
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
for i in range(1, num_input_blocks):
|
| 361 |
+
block_id = (i - 1) // (config["layers_per_block"] + 1)
|
| 362 |
+
layer_in_block_id = (i - 1) % (config["layers_per_block"] + 1)
|
| 363 |
+
|
| 364 |
+
resnets = [
|
| 365 |
+
key for key in input_blocks[i] if f"input_blocks.{i}.0" in key and f"input_blocks.{i}.0.op" not in key
|
| 366 |
+
]
|
| 367 |
+
attentions = [key for key in input_blocks[i] if f"input_blocks.{i}.1" in key]
|
| 368 |
+
|
| 369 |
+
if f"input_blocks.{i}.0.op.weight" in unet_state_dict:
|
| 370 |
+
new_checkpoint[f"down_blocks.{block_id}.downsamplers.0.conv.weight"] = unet_state_dict.pop(
|
| 371 |
+
f"input_blocks.{i}.0.op.weight"
|
| 372 |
+
)
|
| 373 |
+
new_checkpoint[f"down_blocks.{block_id}.downsamplers.0.conv.bias"] = unet_state_dict.pop(
|
| 374 |
+
f"input_blocks.{i}.0.op.bias"
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
paths = renew_resnet_paths(resnets)
|
| 378 |
+
meta_path = {"old": f"input_blocks.{i}.0", "new": f"down_blocks.{block_id}.resnets.{layer_in_block_id}"}
|
| 379 |
+
assign_to_checkpoint(
|
| 380 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
if len(attentions):
|
| 384 |
+
paths = renew_attention_paths(attentions)
|
| 385 |
+
meta_path = {"old": f"input_blocks.{i}.1", "new": f"down_blocks.{block_id}.attentions.{layer_in_block_id}"}
|
| 386 |
+
assign_to_checkpoint(
|
| 387 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
resnet_0 = middle_blocks[0]
|
| 391 |
+
attentions = middle_blocks[1]
|
| 392 |
+
resnet_1 = middle_blocks[2]
|
| 393 |
+
|
| 394 |
+
resnet_0_paths = renew_resnet_paths(resnet_0)
|
| 395 |
+
assign_to_checkpoint(resnet_0_paths, new_checkpoint, unet_state_dict, config=config)
|
| 396 |
+
|
| 397 |
+
resnet_1_paths = renew_resnet_paths(resnet_1)
|
| 398 |
+
assign_to_checkpoint(resnet_1_paths, new_checkpoint, unet_state_dict, config=config)
|
| 399 |
+
|
| 400 |
+
attentions_paths = renew_attention_paths(attentions)
|
| 401 |
+
meta_path = {"old": "middle_block.1", "new": "mid_block.attentions.0"}
|
| 402 |
+
assign_to_checkpoint(
|
| 403 |
+
attentions_paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
for i in range(num_output_blocks):
|
| 407 |
+
block_id = i // (config["layers_per_block"] + 1)
|
| 408 |
+
layer_in_block_id = i % (config["layers_per_block"] + 1)
|
| 409 |
+
output_block_layers = [shave_segments(name, 2) for name in output_blocks[i]]
|
| 410 |
+
output_block_list = {}
|
| 411 |
+
|
| 412 |
+
for layer in output_block_layers:
|
| 413 |
+
layer_id, layer_name = layer.split(".")[0], shave_segments(layer, 1)
|
| 414 |
+
if layer_id in output_block_list:
|
| 415 |
+
output_block_list[layer_id].append(layer_name)
|
| 416 |
+
else:
|
| 417 |
+
output_block_list[layer_id] = [layer_name]
|
| 418 |
+
|
| 419 |
+
if len(output_block_list) > 1:
|
| 420 |
+
resnets = [key for key in output_blocks[i] if f"output_blocks.{i}.0" in key]
|
| 421 |
+
attentions = [key for key in output_blocks[i] if f"output_blocks.{i}.1" in key]
|
| 422 |
+
|
| 423 |
+
resnet_0_paths = renew_resnet_paths(resnets)
|
| 424 |
+
paths = renew_resnet_paths(resnets)
|
| 425 |
+
|
| 426 |
+
meta_path = {"old": f"output_blocks.{i}.0", "new": f"up_blocks.{block_id}.resnets.{layer_in_block_id}"}
|
| 427 |
+
assign_to_checkpoint(
|
| 428 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 429 |
+
)
|
| 430 |
+
|
| 431 |
+
if ["conv.weight", "conv.bias"] in output_block_list.values():
|
| 432 |
+
index = list(output_block_list.values()).index(["conv.weight", "conv.bias"])
|
| 433 |
+
new_checkpoint[f"up_blocks.{block_id}.upsamplers.0.conv.weight"] = unet_state_dict[
|
| 434 |
+
f"output_blocks.{i}.{index}.conv.weight"
|
| 435 |
+
]
|
| 436 |
+
new_checkpoint[f"up_blocks.{block_id}.upsamplers.0.conv.bias"] = unet_state_dict[
|
| 437 |
+
f"output_blocks.{i}.{index}.conv.bias"
|
| 438 |
+
]
|
| 439 |
+
|
| 440 |
+
# Clear attentions as they have been attributed above.
|
| 441 |
+
if len(attentions) == 2:
|
| 442 |
+
attentions = []
|
| 443 |
+
|
| 444 |
+
if len(attentions):
|
| 445 |
+
paths = renew_attention_paths(attentions)
|
| 446 |
+
meta_path = {
|
| 447 |
+
"old": f"output_blocks.{i}.1",
|
| 448 |
+
"new": f"up_blocks.{block_id}.attentions.{layer_in_block_id}",
|
| 449 |
+
}
|
| 450 |
+
assign_to_checkpoint(
|
| 451 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 452 |
+
)
|
| 453 |
+
else:
|
| 454 |
+
resnet_0_paths = renew_resnet_paths(output_block_layers, n_shave_prefix_segments=1)
|
| 455 |
+
for path in resnet_0_paths:
|
| 456 |
+
old_path = ".".join(["output_blocks", str(i), path["old"]])
|
| 457 |
+
new_path = ".".join(["up_blocks", str(block_id), "resnets", str(layer_in_block_id), path["new"]])
|
| 458 |
+
|
| 459 |
+
new_checkpoint[new_path] = unet_state_dict[old_path]
|
| 460 |
+
|
| 461 |
+
return new_checkpoint
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
def convert_ldm_vae_checkpoint(checkpoint, config):
|
| 465 |
+
# extract state dict for VAE
|
| 466 |
+
vae_state_dict = {}
|
| 467 |
+
vae_key = "first_stage_model."
|
| 468 |
+
keys = list(checkpoint.keys())
|
| 469 |
+
for key in keys:
|
| 470 |
+
if key.startswith(vae_key):
|
| 471 |
+
vae_state_dict[key.replace(vae_key, "")] = checkpoint.get(key)
|
| 472 |
+
|
| 473 |
+
new_checkpoint = {}
|
| 474 |
+
|
| 475 |
+
new_checkpoint["encoder.conv_in.weight"] = vae_state_dict["encoder.conv_in.weight"]
|
| 476 |
+
new_checkpoint["encoder.conv_in.bias"] = vae_state_dict["encoder.conv_in.bias"]
|
| 477 |
+
new_checkpoint["encoder.conv_out.weight"] = vae_state_dict["encoder.conv_out.weight"]
|
| 478 |
+
new_checkpoint["encoder.conv_out.bias"] = vae_state_dict["encoder.conv_out.bias"]
|
| 479 |
+
new_checkpoint["encoder.conv_norm_out.weight"] = vae_state_dict["encoder.norm_out.weight"]
|
| 480 |
+
new_checkpoint["encoder.conv_norm_out.bias"] = vae_state_dict["encoder.norm_out.bias"]
|
| 481 |
+
|
| 482 |
+
new_checkpoint["decoder.conv_in.weight"] = vae_state_dict["decoder.conv_in.weight"]
|
| 483 |
+
new_checkpoint["decoder.conv_in.bias"] = vae_state_dict["decoder.conv_in.bias"]
|
| 484 |
+
new_checkpoint["decoder.conv_out.weight"] = vae_state_dict["decoder.conv_out.weight"]
|
| 485 |
+
new_checkpoint["decoder.conv_out.bias"] = vae_state_dict["decoder.conv_out.bias"]
|
| 486 |
+
new_checkpoint["decoder.conv_norm_out.weight"] = vae_state_dict["decoder.norm_out.weight"]
|
| 487 |
+
new_checkpoint["decoder.conv_norm_out.bias"] = vae_state_dict["decoder.norm_out.bias"]
|
| 488 |
+
|
| 489 |
+
new_checkpoint["quant_conv.weight"] = vae_state_dict["quant_conv.weight"]
|
| 490 |
+
new_checkpoint["quant_conv.bias"] = vae_state_dict["quant_conv.bias"]
|
| 491 |
+
new_checkpoint["post_quant_conv.weight"] = vae_state_dict["post_quant_conv.weight"]
|
| 492 |
+
new_checkpoint["post_quant_conv.bias"] = vae_state_dict["post_quant_conv.bias"]
|
| 493 |
+
|
| 494 |
+
# Retrieves the keys for the encoder down blocks only
|
| 495 |
+
num_down_blocks = len({".".join(layer.split(".")[:3]) for layer in vae_state_dict if "encoder.down" in layer})
|
| 496 |
+
down_blocks = {
|
| 497 |
+
layer_id: [key for key in vae_state_dict if f"down.{layer_id}" in key] for layer_id in range(num_down_blocks)
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
# Retrieves the keys for the decoder up blocks only
|
| 501 |
+
num_up_blocks = len({".".join(layer.split(".")[:3]) for layer in vae_state_dict if "decoder.up" in layer})
|
| 502 |
+
up_blocks = {
|
| 503 |
+
layer_id: [key for key in vae_state_dict if f"up.{layer_id}" in key] for layer_id in range(num_up_blocks)
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
for i in range(num_down_blocks):
|
| 507 |
+
resnets = [key for key in down_blocks[i] if f"down.{i}" in key and f"down.{i}.downsample" not in key]
|
| 508 |
+
|
| 509 |
+
if f"encoder.down.{i}.downsample.conv.weight" in vae_state_dict:
|
| 510 |
+
new_checkpoint[f"encoder.down_blocks.{i}.downsamplers.0.conv.weight"] = vae_state_dict.pop(
|
| 511 |
+
f"encoder.down.{i}.downsample.conv.weight"
|
| 512 |
+
)
|
| 513 |
+
new_checkpoint[f"encoder.down_blocks.{i}.downsamplers.0.conv.bias"] = vae_state_dict.pop(
|
| 514 |
+
f"encoder.down.{i}.downsample.conv.bias"
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 518 |
+
meta_path = {"old": f"down.{i}.block", "new": f"down_blocks.{i}.resnets"}
|
| 519 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 520 |
+
|
| 521 |
+
mid_resnets = [key for key in vae_state_dict if "encoder.mid.block" in key]
|
| 522 |
+
num_mid_res_blocks = 2
|
| 523 |
+
for i in range(1, num_mid_res_blocks + 1):
|
| 524 |
+
resnets = [key for key in mid_resnets if f"encoder.mid.block_{i}" in key]
|
| 525 |
+
|
| 526 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 527 |
+
meta_path = {"old": f"mid.block_{i}", "new": f"mid_block.resnets.{i - 1}"}
|
| 528 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 529 |
+
|
| 530 |
+
mid_attentions = [key for key in vae_state_dict if "encoder.mid.attn" in key]
|
| 531 |
+
paths = renew_vae_attention_paths(mid_attentions)
|
| 532 |
+
meta_path = {"old": "mid.attn_1", "new": "mid_block.attentions.0"}
|
| 533 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 534 |
+
conv_attn_to_linear(new_checkpoint)
|
| 535 |
+
|
| 536 |
+
for i in range(num_up_blocks):
|
| 537 |
+
block_id = num_up_blocks - 1 - i
|
| 538 |
+
resnets = [
|
| 539 |
+
key for key in up_blocks[block_id] if f"up.{block_id}" in key and f"up.{block_id}.upsample" not in key
|
| 540 |
+
]
|
| 541 |
+
|
| 542 |
+
if f"decoder.up.{block_id}.upsample.conv.weight" in vae_state_dict:
|
| 543 |
+
new_checkpoint[f"decoder.up_blocks.{i}.upsamplers.0.conv.weight"] = vae_state_dict[
|
| 544 |
+
f"decoder.up.{block_id}.upsample.conv.weight"
|
| 545 |
+
]
|
| 546 |
+
new_checkpoint[f"decoder.up_blocks.{i}.upsamplers.0.conv.bias"] = vae_state_dict[
|
| 547 |
+
f"decoder.up.{block_id}.upsample.conv.bias"
|
| 548 |
+
]
|
| 549 |
+
|
| 550 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 551 |
+
meta_path = {"old": f"up.{block_id}.block", "new": f"up_blocks.{i}.resnets"}
|
| 552 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 553 |
+
|
| 554 |
+
mid_resnets = [key for key in vae_state_dict if "decoder.mid.block" in key]
|
| 555 |
+
num_mid_res_blocks = 2
|
| 556 |
+
for i in range(1, num_mid_res_blocks + 1):
|
| 557 |
+
resnets = [key for key in mid_resnets if f"decoder.mid.block_{i}" in key]
|
| 558 |
+
|
| 559 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 560 |
+
meta_path = {"old": f"mid.block_{i}", "new": f"mid_block.resnets.{i - 1}"}
|
| 561 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 562 |
+
|
| 563 |
+
mid_attentions = [key for key in vae_state_dict if "decoder.mid.attn" in key]
|
| 564 |
+
paths = renew_vae_attention_paths(mid_attentions)
|
| 565 |
+
meta_path = {"old": "mid.attn_1", "new": "mid_block.attentions.0"}
|
| 566 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 567 |
+
conv_attn_to_linear(new_checkpoint)
|
| 568 |
+
return new_checkpoint
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def convert_ldm_bert_checkpoint(checkpoint, config):
|
| 572 |
+
def _copy_attn_layer(hf_attn_layer, pt_attn_layer):
|
| 573 |
+
hf_attn_layer.q_proj.weight.data = pt_attn_layer.to_q.weight
|
| 574 |
+
hf_attn_layer.k_proj.weight.data = pt_attn_layer.to_k.weight
|
| 575 |
+
hf_attn_layer.v_proj.weight.data = pt_attn_layer.to_v.weight
|
| 576 |
+
|
| 577 |
+
hf_attn_layer.out_proj.weight = pt_attn_layer.to_out.weight
|
| 578 |
+
hf_attn_layer.out_proj.bias = pt_attn_layer.to_out.bias
|
| 579 |
+
|
| 580 |
+
def _copy_linear(hf_linear, pt_linear):
|
| 581 |
+
hf_linear.weight = pt_linear.weight
|
| 582 |
+
hf_linear.bias = pt_linear.bias
|
| 583 |
+
|
| 584 |
+
def _copy_layer(hf_layer, pt_layer):
|
| 585 |
+
# copy layer norms
|
| 586 |
+
_copy_linear(hf_layer.self_attn_layer_norm, pt_layer[0][0])
|
| 587 |
+
_copy_linear(hf_layer.final_layer_norm, pt_layer[1][0])
|
| 588 |
+
|
| 589 |
+
# copy attn
|
| 590 |
+
_copy_attn_layer(hf_layer.self_attn, pt_layer[0][1])
|
| 591 |
+
|
| 592 |
+
# copy MLP
|
| 593 |
+
pt_mlp = pt_layer[1][1]
|
| 594 |
+
_copy_linear(hf_layer.fc1, pt_mlp.net[0][0])
|
| 595 |
+
_copy_linear(hf_layer.fc2, pt_mlp.net[2])
|
| 596 |
+
|
| 597 |
+
def _copy_layers(hf_layers, pt_layers):
|
| 598 |
+
for i, hf_layer in enumerate(hf_layers):
|
| 599 |
+
if i != 0:
|
| 600 |
+
i += i
|
| 601 |
+
pt_layer = pt_layers[i : i + 2]
|
| 602 |
+
_copy_layer(hf_layer, pt_layer)
|
| 603 |
+
|
| 604 |
+
hf_model = LDMBertModel(config).eval()
|
| 605 |
+
|
| 606 |
+
# copy embeds
|
| 607 |
+
hf_model.model.embed_tokens.weight = checkpoint.transformer.token_emb.weight
|
| 608 |
+
hf_model.model.embed_positions.weight.data = checkpoint.transformer.pos_emb.emb.weight
|
| 609 |
+
|
| 610 |
+
# copy layer norm
|
| 611 |
+
_copy_linear(hf_model.model.layer_norm, checkpoint.transformer.norm)
|
| 612 |
+
|
| 613 |
+
# copy hidden layers
|
| 614 |
+
_copy_layers(hf_model.model.layers, checkpoint.transformer.attn_layers.layers)
|
| 615 |
+
|
| 616 |
+
_copy_linear(hf_model.to_logits, checkpoint.transformer.to_logits)
|
| 617 |
+
|
| 618 |
+
return hf_model
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def convert_ldm_clip_checkpoint(checkpoint):
|
| 622 |
+
text_model = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14")
|
| 623 |
+
|
| 624 |
+
keys = list(checkpoint.keys())
|
| 625 |
+
|
| 626 |
+
text_model_dict = {}
|
| 627 |
+
|
| 628 |
+
for key in keys:
|
| 629 |
+
if key.startswith("cond_stage_model.transformer"):
|
| 630 |
+
text_model_dict[key[len("cond_stage_model.transformer.") :]] = checkpoint[key]
|
| 631 |
+
|
| 632 |
+
text_model.load_state_dict(text_model_dict)
|
| 633 |
+
|
| 634 |
+
return text_model
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
if __name__ == "__main__":
|
| 638 |
+
parser = argparse.ArgumentParser()
|
| 639 |
+
|
| 640 |
+
parser.add_argument(
|
| 641 |
+
"--checkpoint_path", default=None, type=str, required=True, help="Path to the checkpoint to convert."
|
| 642 |
+
)
|
| 643 |
+
# !wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml
|
| 644 |
+
parser.add_argument(
|
| 645 |
+
"--original_config_file",
|
| 646 |
+
default=None,
|
| 647 |
+
type=str,
|
| 648 |
+
help="The YAML config file corresponding to the original architecture.",
|
| 649 |
+
)
|
| 650 |
+
parser.add_argument(
|
| 651 |
+
"--scheduler_type",
|
| 652 |
+
default="pndm",
|
| 653 |
+
type=str,
|
| 654 |
+
help="Type of scheduler to use. Should be one of ['pndm', 'lms', 'ddim', 'euler', 'euler-ancest', 'dpm']",
|
| 655 |
+
)
|
| 656 |
+
parser.add_argument(
|
| 657 |
+
"--extract_ema",
|
| 658 |
+
action="store_true",
|
| 659 |
+
help=(
|
| 660 |
+
"Only relevant for checkpoints that have both EMA and non-EMA weights. Whether to extract the EMA weights"
|
| 661 |
+
" or not. Defaults to `False`. Add `--extract_ema` to extract the EMA weights. EMA weights usually yield"
|
| 662 |
+
" higher quality images for inference. Non-EMA weights are usually better to continue fine-tuning."
|
| 663 |
+
),
|
| 664 |
+
)
|
| 665 |
+
parser.add_argument("--dump_path", default=None, type=str, required=True, help="Path to the output model.")
|
| 666 |
+
|
| 667 |
+
args = parser.parse_args()
|
| 668 |
+
|
| 669 |
+
if args.original_config_file is None:
|
| 670 |
+
os.system(
|
| 671 |
+
"wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
|
| 672 |
+
)
|
| 673 |
+
args.original_config_file = "./v1-inference.yaml"
|
| 674 |
+
|
| 675 |
+
original_config = OmegaConf.load(args.original_config_file)
|
| 676 |
+
|
| 677 |
+
checkpoint = torch.load(args.checkpoint_path)
|
| 678 |
+
checkpoint = checkpoint["state_dict"]
|
| 679 |
+
|
| 680 |
+
num_train_timesteps = original_config.model.params.timesteps
|
| 681 |
+
beta_start = original_config.model.params.linear_start
|
| 682 |
+
beta_end = original_config.model.params.linear_end
|
| 683 |
+
if args.scheduler_type == "pndm":
|
| 684 |
+
scheduler = PNDMScheduler(
|
| 685 |
+
beta_end=beta_end,
|
| 686 |
+
beta_schedule="scaled_linear",
|
| 687 |
+
beta_start=beta_start,
|
| 688 |
+
num_train_timesteps=num_train_timesteps,
|
| 689 |
+
skip_prk_steps=True,
|
| 690 |
+
)
|
| 691 |
+
elif args.scheduler_type == "lms":
|
| 692 |
+
scheduler = LMSDiscreteScheduler(beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear")
|
| 693 |
+
elif args.scheduler_type == "euler":
|
| 694 |
+
scheduler = EulerDiscreteScheduler(beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear")
|
| 695 |
+
elif args.scheduler_type == "euler-ancestral":
|
| 696 |
+
scheduler = EulerAncestralDiscreteScheduler(
|
| 697 |
+
beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear"
|
| 698 |
+
)
|
| 699 |
+
elif args.scheduler_type == "dpm":
|
| 700 |
+
scheduler = DPMSolverMultistepScheduler(
|
| 701 |
+
beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear"
|
| 702 |
+
)
|
| 703 |
+
elif args.scheduler_type == "ddim":
|
| 704 |
+
scheduler = DDIMScheduler(
|
| 705 |
+
beta_start=beta_start,
|
| 706 |
+
beta_end=beta_end,
|
| 707 |
+
beta_schedule="scaled_linear",
|
| 708 |
+
clip_sample=False,
|
| 709 |
+
set_alpha_to_one=False,
|
| 710 |
+
)
|
| 711 |
+
else:
|
| 712 |
+
raise ValueError(f"Scheduler of type {args.scheduler_type} doesn't exist!")
|
| 713 |
+
|
| 714 |
+
# Convert the UNet2DConditionModel model.
|
| 715 |
+
unet_config = create_unet_diffusers_config(original_config)
|
| 716 |
+
converted_unet_checkpoint = convert_ldm_unet_checkpoint(
|
| 717 |
+
checkpoint, unet_config, path=args.checkpoint_path, extract_ema=args.extract_ema
|
| 718 |
+
)
|
| 719 |
+
|
| 720 |
+
unet = UNet2DConditionModel(**unet_config)
|
| 721 |
+
unet.load_state_dict(converted_unet_checkpoint)
|
| 722 |
+
|
| 723 |
+
# Convert the VAE model.
|
| 724 |
+
vae_config = create_vae_diffusers_config(original_config)
|
| 725 |
+
converted_vae_checkpoint = convert_ldm_vae_checkpoint(checkpoint, vae_config)
|
| 726 |
+
|
| 727 |
+
vae = AutoencoderKL(**vae_config)
|
| 728 |
+
vae.load_state_dict(converted_vae_checkpoint)
|
| 729 |
+
|
| 730 |
+
# Convert the text model.
|
| 731 |
+
text_model_type = original_config.model.params.cond_stage_config.target.split(".")[-1]
|
| 732 |
+
if text_model_type == "FrozenCLIPEmbedder":
|
| 733 |
+
text_model = convert_ldm_clip_checkpoint(checkpoint)
|
| 734 |
+
tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14")
|
| 735 |
+
# safety_checker = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
|
| 736 |
+
# feature_extractor = AutoFeatureExtractor.from_pretrained("CompVis/stable-diffusion-safety-checker")
|
| 737 |
+
pipe = StableDiffusionPipeline(
|
| 738 |
+
vae=vae,
|
| 739 |
+
text_encoder=text_model,
|
| 740 |
+
tokenizer=tokenizer,
|
| 741 |
+
unet=unet,
|
| 742 |
+
scheduler=scheduler,
|
| 743 |
+
# safety_checker=safety_checker,
|
| 744 |
+
# feature_extractor=feature_extractor,
|
| 745 |
+
)
|
| 746 |
+
else:
|
| 747 |
+
text_config = create_ldm_bert_config(original_config)
|
| 748 |
+
text_model = convert_ldm_bert_checkpoint(checkpoint, text_config)
|
| 749 |
+
tokenizer = BertTokenizerFast.from_pretrained("bert-base-uncased")
|
| 750 |
+
pipe = LDMTextToImagePipeline(vqvae=vae, bert=text_model, tokenizer=tokenizer, unet=unet, scheduler=scheduler)
|
| 751 |
+
|
| 752 |
+
pipe.save_pretrained(args.dump_path)
|
convert_original_stable_diffusion_to_diffus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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2022 The HuggingFace Inc. team.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
""" Conversion script for the LDM checkpoints. """
|
| 16 |
+
|
| 17 |
+
import argparse
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
import torch
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
from omegaconf import OmegaConf
|
| 25 |
+
except ImportError:
|
| 26 |
+
raise ImportError(
|
| 27 |
+
"OmegaConf is required to convert the LDM checkpoints. Please install it with `pip install OmegaConf`."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
from diffusers import (
|
| 31 |
+
AutoencoderKL,
|
| 32 |
+
DDIMScheduler,
|
| 33 |
+
DPMSolverMultistepScheduler,
|
| 34 |
+
EulerAncestralDiscreteScheduler,
|
| 35 |
+
EulerDiscreteScheduler,
|
| 36 |
+
LDMTextToImagePipeline,
|
| 37 |
+
LMSDiscreteScheduler,
|
| 38 |
+
PNDMScheduler,
|
| 39 |
+
StableDiffusionPipeline,
|
| 40 |
+
UNet2DConditionModel,
|
| 41 |
+
)
|
| 42 |
+
from diffusers.pipelines.latent_diffusion.pipeline_latent_diffusion import LDMBertConfig, LDMBertModel
|
| 43 |
+
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
|
| 44 |
+
from transformers import AutoFeatureExtractor, BertTokenizerFast, CLIPTextModel, CLIPTokenizer
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def shave_segments(path, n_shave_prefix_segments=1):
|
| 48 |
+
"""
|
| 49 |
+
Removes segments. Positive values shave the first segments, negative shave the last segments.
|
| 50 |
+
"""
|
| 51 |
+
if n_shave_prefix_segments >= 0:
|
| 52 |
+
return ".".join(path.split(".")[n_shave_prefix_segments:])
|
| 53 |
+
else:
|
| 54 |
+
return ".".join(path.split(".")[:n_shave_prefix_segments])
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def renew_resnet_paths(old_list, n_shave_prefix_segments=0):
|
| 58 |
+
"""
|
| 59 |
+
Updates paths inside resnets to the new naming scheme (local renaming)
|
| 60 |
+
"""
|
| 61 |
+
mapping = []
|
| 62 |
+
for old_item in old_list:
|
| 63 |
+
new_item = old_item.replace("in_layers.0", "norm1")
|
| 64 |
+
new_item = new_item.replace("in_layers.2", "conv1")
|
| 65 |
+
|
| 66 |
+
new_item = new_item.replace("out_layers.0", "norm2")
|
| 67 |
+
new_item = new_item.replace("out_layers.3", "conv2")
|
| 68 |
+
|
| 69 |
+
new_item = new_item.replace("emb_layers.1", "time_emb_proj")
|
| 70 |
+
new_item = new_item.replace("skip_connection", "conv_shortcut")
|
| 71 |
+
|
| 72 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 73 |
+
|
| 74 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 75 |
+
|
| 76 |
+
return mapping
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def renew_vae_resnet_paths(old_list, n_shave_prefix_segments=0):
|
| 80 |
+
"""
|
| 81 |
+
Updates paths inside resnets to the new naming scheme (local renaming)
|
| 82 |
+
"""
|
| 83 |
+
mapping = []
|
| 84 |
+
for old_item in old_list:
|
| 85 |
+
new_item = old_item
|
| 86 |
+
|
| 87 |
+
new_item = new_item.replace("nin_shortcut", "conv_shortcut")
|
| 88 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 89 |
+
|
| 90 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 91 |
+
|
| 92 |
+
return mapping
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def renew_attention_paths(old_list, n_shave_prefix_segments=0):
|
| 96 |
+
"""
|
| 97 |
+
Updates paths inside attentions to the new naming scheme (local renaming)
|
| 98 |
+
"""
|
| 99 |
+
mapping = []
|
| 100 |
+
for old_item in old_list:
|
| 101 |
+
new_item = old_item
|
| 102 |
+
|
| 103 |
+
# new_item = new_item.replace('norm.weight', 'group_norm.weight')
|
| 104 |
+
# new_item = new_item.replace('norm.bias', 'group_norm.bias')
|
| 105 |
+
|
| 106 |
+
# new_item = new_item.replace('proj_out.weight', 'proj_attn.weight')
|
| 107 |
+
# new_item = new_item.replace('proj_out.bias', 'proj_attn.bias')
|
| 108 |
+
|
| 109 |
+
# new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 110 |
+
|
| 111 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 112 |
+
|
| 113 |
+
return mapping
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def renew_vae_attention_paths(old_list, n_shave_prefix_segments=0):
|
| 117 |
+
"""
|
| 118 |
+
Updates paths inside attentions to the new naming scheme (local renaming)
|
| 119 |
+
"""
|
| 120 |
+
mapping = []
|
| 121 |
+
for old_item in old_list:
|
| 122 |
+
new_item = old_item
|
| 123 |
+
|
| 124 |
+
new_item = new_item.replace("norm.weight", "group_norm.weight")
|
| 125 |
+
new_item = new_item.replace("norm.bias", "group_norm.bias")
|
| 126 |
+
|
| 127 |
+
new_item = new_item.replace("q.weight", "query.weight")
|
| 128 |
+
new_item = new_item.replace("q.bias", "query.bias")
|
| 129 |
+
|
| 130 |
+
new_item = new_item.replace("k.weight", "key.weight")
|
| 131 |
+
new_item = new_item.replace("k.bias", "key.bias")
|
| 132 |
+
|
| 133 |
+
new_item = new_item.replace("v.weight", "value.weight")
|
| 134 |
+
new_item = new_item.replace("v.bias", "value.bias")
|
| 135 |
+
|
| 136 |
+
new_item = new_item.replace("proj_out.weight", "proj_attn.weight")
|
| 137 |
+
new_item = new_item.replace("proj_out.bias", "proj_attn.bias")
|
| 138 |
+
|
| 139 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 140 |
+
|
| 141 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 142 |
+
|
| 143 |
+
return mapping
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def assign_to_checkpoint(
|
| 147 |
+
paths, checkpoint, old_checkpoint, attention_paths_to_split=None, additional_replacements=None, config=None
|
| 148 |
+
):
|
| 149 |
+
"""
|
| 150 |
+
This does the final conversion step: take locally converted weights and apply a global renaming
|
| 151 |
+
to them. It splits attention layers, and takes into account additional replacements
|
| 152 |
+
that may arise.
|
| 153 |
+
|
| 154 |
+
Assigns the weights to the new checkpoint.
|
| 155 |
+
"""
|
| 156 |
+
assert isinstance(paths, list), "Paths should be a list of dicts containing 'old' and 'new' keys."
|
| 157 |
+
|
| 158 |
+
# Splits the attention layers into three variables.
|
| 159 |
+
if attention_paths_to_split is not None:
|
| 160 |
+
for path, path_map in attention_paths_to_split.items():
|
| 161 |
+
old_tensor = old_checkpoint[path]
|
| 162 |
+
channels = old_tensor.shape[0] // 3
|
| 163 |
+
|
| 164 |
+
target_shape = (-1, channels) if len(old_tensor.shape) == 3 else (-1)
|
| 165 |
+
|
| 166 |
+
num_heads = old_tensor.shape[0] // config["num_head_channels"] // 3
|
| 167 |
+
|
| 168 |
+
old_tensor = old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:])
|
| 169 |
+
query, key, value = old_tensor.split(channels // num_heads, dim=1)
|
| 170 |
+
|
| 171 |
+
checkpoint[path_map["query"]] = query.reshape(target_shape)
|
| 172 |
+
checkpoint[path_map["key"]] = key.reshape(target_shape)
|
| 173 |
+
checkpoint[path_map["value"]] = value.reshape(target_shape)
|
| 174 |
+
|
| 175 |
+
for path in paths:
|
| 176 |
+
new_path = path["new"]
|
| 177 |
+
|
| 178 |
+
# These have already been assigned
|
| 179 |
+
if attention_paths_to_split is not None and new_path in attention_paths_to_split:
|
| 180 |
+
continue
|
| 181 |
+
|
| 182 |
+
# Global renaming happens here
|
| 183 |
+
new_path = new_path.replace("middle_block.0", "mid_block.resnets.0")
|
| 184 |
+
new_path = new_path.replace("middle_block.1", "mid_block.attentions.0")
|
| 185 |
+
new_path = new_path.replace("middle_block.2", "mid_block.resnets.1")
|
| 186 |
+
|
| 187 |
+
if additional_replacements is not None:
|
| 188 |
+
for replacement in additional_replacements:
|
| 189 |
+
new_path = new_path.replace(replacement["old"], replacement["new"])
|
| 190 |
+
|
| 191 |
+
# proj_attn.weight has to be converted from conv 1D to linear
|
| 192 |
+
if "proj_attn.weight" in new_path:
|
| 193 |
+
checkpoint[new_path] = old_checkpoint[path["old"]][:, :, 0]
|
| 194 |
+
else:
|
| 195 |
+
checkpoint[new_path] = old_checkpoint[path["old"]]
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def conv_attn_to_linear(checkpoint):
|
| 199 |
+
keys = list(checkpoint.keys())
|
| 200 |
+
attn_keys = ["query.weight", "key.weight", "value.weight"]
|
| 201 |
+
for key in keys:
|
| 202 |
+
if ".".join(key.split(".")[-2:]) in attn_keys:
|
| 203 |
+
if checkpoint[key].ndim > 2:
|
| 204 |
+
checkpoint[key] = checkpoint[key][:, :, 0, 0]
|
| 205 |
+
elif "proj_attn.weight" in key:
|
| 206 |
+
if checkpoint[key].ndim > 2:
|
| 207 |
+
checkpoint[key] = checkpoint[key][:, :, 0]
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def create_unet_diffusers_config(original_config):
|
| 211 |
+
"""
|
| 212 |
+
Creates a config for the diffusers based on the config of the LDM model.
|
| 213 |
+
"""
|
| 214 |
+
model_params = original_config.model.params
|
| 215 |
+
unet_params = original_config.model.params.unet_config.params
|
| 216 |
+
|
| 217 |
+
block_out_channels = [unet_params.model_channels * mult for mult in unet_params.channel_mult]
|
| 218 |
+
|
| 219 |
+
down_block_types = []
|
| 220 |
+
resolution = 1
|
| 221 |
+
for i in range(len(block_out_channels)):
|
| 222 |
+
block_type = "CrossAttnDownBlock2D" if resolution in unet_params.attention_resolutions else "DownBlock2D"
|
| 223 |
+
down_block_types.append(block_type)
|
| 224 |
+
if i != len(block_out_channels) - 1:
|
| 225 |
+
resolution *= 2
|
| 226 |
+
|
| 227 |
+
up_block_types = []
|
| 228 |
+
for i in range(len(block_out_channels)):
|
| 229 |
+
block_type = "CrossAttnUpBlock2D" if resolution in unet_params.attention_resolutions else "UpBlock2D"
|
| 230 |
+
up_block_types.append(block_type)
|
| 231 |
+
resolution //= 2
|
| 232 |
+
|
| 233 |
+
config = dict(
|
| 234 |
+
sample_size=model_params.image_size,
|
| 235 |
+
in_channels=unet_params.in_channels,
|
| 236 |
+
out_channels=unet_params.out_channels,
|
| 237 |
+
down_block_types=tuple(down_block_types),
|
| 238 |
+
up_block_types=tuple(up_block_types),
|
| 239 |
+
block_out_channels=tuple(block_out_channels),
|
| 240 |
+
layers_per_block=unet_params.num_res_blocks,
|
| 241 |
+
cross_attention_dim=unet_params.context_dim,
|
| 242 |
+
attention_head_dim=unet_params.num_heads,
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
return config
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def create_vae_diffusers_config(original_config):
|
| 249 |
+
"""
|
| 250 |
+
Creates a config for the diffusers based on the config of the LDM model.
|
| 251 |
+
"""
|
| 252 |
+
vae_params = original_config.model.params.first_stage_config.params.ddconfig
|
| 253 |
+
_ = original_config.model.params.first_stage_config.params.embed_dim
|
| 254 |
+
|
| 255 |
+
block_out_channels = [vae_params.ch * mult for mult in vae_params.ch_mult]
|
| 256 |
+
down_block_types = ["DownEncoderBlock2D"] * len(block_out_channels)
|
| 257 |
+
up_block_types = ["UpDecoderBlock2D"] * len(block_out_channels)
|
| 258 |
+
|
| 259 |
+
config = dict(
|
| 260 |
+
sample_size=vae_params.resolution,
|
| 261 |
+
in_channels=vae_params.in_channels,
|
| 262 |
+
out_channels=vae_params.out_ch,
|
| 263 |
+
down_block_types=tuple(down_block_types),
|
| 264 |
+
up_block_types=tuple(up_block_types),
|
| 265 |
+
block_out_channels=tuple(block_out_channels),
|
| 266 |
+
latent_channels=vae_params.z_channels,
|
| 267 |
+
layers_per_block=vae_params.num_res_blocks,
|
| 268 |
+
)
|
| 269 |
+
return config
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
def create_diffusers_schedular(original_config):
|
| 273 |
+
schedular = DDIMScheduler(
|
| 274 |
+
num_train_timesteps=original_config.model.params.timesteps,
|
| 275 |
+
beta_start=original_config.model.params.linear_start,
|
| 276 |
+
beta_end=original_config.model.params.linear_end,
|
| 277 |
+
beta_schedule="scaled_linear",
|
| 278 |
+
)
|
| 279 |
+
return schedular
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def create_ldm_bert_config(original_config):
|
| 283 |
+
bert_params = original_config.model.parms.cond_stage_config.params
|
| 284 |
+
config = LDMBertConfig(
|
| 285 |
+
d_model=bert_params.n_embed,
|
| 286 |
+
encoder_layers=bert_params.n_layer,
|
| 287 |
+
encoder_ffn_dim=bert_params.n_embed * 4,
|
| 288 |
+
)
|
| 289 |
+
return config
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def convert_ldm_unet_checkpoint(checkpoint, config, path=None, extract_ema=False):
|
| 293 |
+
"""
|
| 294 |
+
Takes a state dict and a config, and returns a converted checkpoint.
|
| 295 |
+
"""
|
| 296 |
+
|
| 297 |
+
# extract state_dict for UNet
|
| 298 |
+
unet_state_dict = {}
|
| 299 |
+
keys = list(checkpoint.keys())
|
| 300 |
+
|
| 301 |
+
unet_key = "model.diffusion_model."
|
| 302 |
+
# at least a 100 parameters have to start with `model_ema` in order for the checkpoint to be EMA
|
| 303 |
+
if sum(k.startswith("model_ema") for k in keys) > 100:
|
| 304 |
+
print(f"Checkpoint {path} has both EMA and non-EMA weights.")
|
| 305 |
+
if extract_ema:
|
| 306 |
+
print(
|
| 307 |
+
"In this conversion only the EMA weights are extracted. If you want to instead extract the non-EMA"
|
| 308 |
+
" weights (useful to continue fine-tuning), please make sure to remove the `--extract_ema` flag."
|
| 309 |
+
)
|
| 310 |
+
for key in keys:
|
| 311 |
+
if key.startswith("model.diffusion_model"):
|
| 312 |
+
flat_ema_key = "model_ema." + "".join(key.split(".")[1:])
|
| 313 |
+
unet_state_dict[key.replace(unet_key, "")] = checkpoint.pop(flat_ema_key)
|
| 314 |
+
else:
|
| 315 |
+
print(
|
| 316 |
+
"In this conversion only the non-EMA weights are extracted. If you want to instead extract the EMA"
|
| 317 |
+
" weights (usually better for inference), please make sure to add the `--extract_ema` flag."
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
for key in keys:
|
| 321 |
+
if key.startswith(unet_key):
|
| 322 |
+
unet_state_dict[key.replace(unet_key, "")] = checkpoint.pop(key)
|
| 323 |
+
|
| 324 |
+
new_checkpoint = {}
|
| 325 |
+
|
| 326 |
+
new_checkpoint["time_embedding.linear_1.weight"] = unet_state_dict["time_embed.0.weight"]
|
| 327 |
+
new_checkpoint["time_embedding.linear_1.bias"] = unet_state_dict["time_embed.0.bias"]
|
| 328 |
+
new_checkpoint["time_embedding.linear_2.weight"] = unet_state_dict["time_embed.2.weight"]
|
| 329 |
+
new_checkpoint["time_embedding.linear_2.bias"] = unet_state_dict["time_embed.2.bias"]
|
| 330 |
+
|
| 331 |
+
new_checkpoint["conv_in.weight"] = unet_state_dict["input_blocks.0.0.weight"]
|
| 332 |
+
new_checkpoint["conv_in.bias"] = unet_state_dict["input_blocks.0.0.bias"]
|
| 333 |
+
|
| 334 |
+
new_checkpoint["conv_norm_out.weight"] = unet_state_dict["out.0.weight"]
|
| 335 |
+
new_checkpoint["conv_norm_out.bias"] = unet_state_dict["out.0.bias"]
|
| 336 |
+
new_checkpoint["conv_out.weight"] = unet_state_dict["out.2.weight"]
|
| 337 |
+
new_checkpoint["conv_out.bias"] = unet_state_dict["out.2.bias"]
|
| 338 |
+
|
| 339 |
+
# Retrieves the keys for the input blocks only
|
| 340 |
+
num_input_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "input_blocks" in layer})
|
| 341 |
+
input_blocks = {
|
| 342 |
+
layer_id: [key for key in unet_state_dict if f"input_blocks.{layer_id}" in key]
|
| 343 |
+
for layer_id in range(num_input_blocks)
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
# Retrieves the keys for the middle blocks only
|
| 347 |
+
num_middle_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "middle_block" in layer})
|
| 348 |
+
middle_blocks = {
|
| 349 |
+
layer_id: [key for key in unet_state_dict if f"middle_block.{layer_id}" in key]
|
| 350 |
+
for layer_id in range(num_middle_blocks)
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
# Retrieves the keys for the output blocks only
|
| 354 |
+
num_output_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "output_blocks" in layer})
|
| 355 |
+
output_blocks = {
|
| 356 |
+
layer_id: [key for key in unet_state_dict if f"output_blocks.{layer_id}" in key]
|
| 357 |
+
for layer_id in range(num_output_blocks)
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
for i in range(1, num_input_blocks):
|
| 361 |
+
block_id = (i - 1) // (config["layers_per_block"] + 1)
|
| 362 |
+
layer_in_block_id = (i - 1) % (config["layers_per_block"] + 1)
|
| 363 |
+
|
| 364 |
+
resnets = [
|
| 365 |
+
key for key in input_blocks[i] if f"input_blocks.{i}.0" in key and f"input_blocks.{i}.0.op" not in key
|
| 366 |
+
]
|
| 367 |
+
attentions = [key for key in input_blocks[i] if f"input_blocks.{i}.1" in key]
|
| 368 |
+
|
| 369 |
+
if f"input_blocks.{i}.0.op.weight" in unet_state_dict:
|
| 370 |
+
new_checkpoint[f"down_blocks.{block_id}.downsamplers.0.conv.weight"] = unet_state_dict.pop(
|
| 371 |
+
f"input_blocks.{i}.0.op.weight"
|
| 372 |
+
)
|
| 373 |
+
new_checkpoint[f"down_blocks.{block_id}.downsamplers.0.conv.bias"] = unet_state_dict.pop(
|
| 374 |
+
f"input_blocks.{i}.0.op.bias"
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
paths = renew_resnet_paths(resnets)
|
| 378 |
+
meta_path = {"old": f"input_blocks.{i}.0", "new": f"down_blocks.{block_id}.resnets.{layer_in_block_id}"}
|
| 379 |
+
assign_to_checkpoint(
|
| 380 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
if len(attentions):
|
| 384 |
+
paths = renew_attention_paths(attentions)
|
| 385 |
+
meta_path = {"old": f"input_blocks.{i}.1", "new": f"down_blocks.{block_id}.attentions.{layer_in_block_id}"}
|
| 386 |
+
assign_to_checkpoint(
|
| 387 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
resnet_0 = middle_blocks[0]
|
| 391 |
+
attentions = middle_blocks[1]
|
| 392 |
+
resnet_1 = middle_blocks[2]
|
| 393 |
+
|
| 394 |
+
resnet_0_paths = renew_resnet_paths(resnet_0)
|
| 395 |
+
assign_to_checkpoint(resnet_0_paths, new_checkpoint, unet_state_dict, config=config)
|
| 396 |
+
|
| 397 |
+
resnet_1_paths = renew_resnet_paths(resnet_1)
|
| 398 |
+
assign_to_checkpoint(resnet_1_paths, new_checkpoint, unet_state_dict, config=config)
|
| 399 |
+
|
| 400 |
+
attentions_paths = renew_attention_paths(attentions)
|
| 401 |
+
meta_path = {"old": "middle_block.1", "new": "mid_block.attentions.0"}
|
| 402 |
+
assign_to_checkpoint(
|
| 403 |
+
attentions_paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
for i in range(num_output_blocks):
|
| 407 |
+
block_id = i // (config["layers_per_block"] + 1)
|
| 408 |
+
layer_in_block_id = i % (config["layers_per_block"] + 1)
|
| 409 |
+
output_block_layers = [shave_segments(name, 2) for name in output_blocks[i]]
|
| 410 |
+
output_block_list = {}
|
| 411 |
+
|
| 412 |
+
for layer in output_block_layers:
|
| 413 |
+
layer_id, layer_name = layer.split(".")[0], shave_segments(layer, 1)
|
| 414 |
+
if layer_id in output_block_list:
|
| 415 |
+
output_block_list[layer_id].append(layer_name)
|
| 416 |
+
else:
|
| 417 |
+
output_block_list[layer_id] = [layer_name]
|
| 418 |
+
|
| 419 |
+
if len(output_block_list) > 1:
|
| 420 |
+
resnets = [key for key in output_blocks[i] if f"output_blocks.{i}.0" in key]
|
| 421 |
+
attentions = [key for key in output_blocks[i] if f"output_blocks.{i}.1" in key]
|
| 422 |
+
|
| 423 |
+
resnet_0_paths = renew_resnet_paths(resnets)
|
| 424 |
+
paths = renew_resnet_paths(resnets)
|
| 425 |
+
|
| 426 |
+
meta_path = {"old": f"output_blocks.{i}.0", "new": f"up_blocks.{block_id}.resnets.{layer_in_block_id}"}
|
| 427 |
+
assign_to_checkpoint(
|
| 428 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 429 |
+
)
|
| 430 |
+
|
| 431 |
+
if ["conv.weight", "conv.bias"] in output_block_list.values():
|
| 432 |
+
index = list(output_block_list.values()).index(["conv.weight", "conv.bias"])
|
| 433 |
+
new_checkpoint[f"up_blocks.{block_id}.upsamplers.0.conv.weight"] = unet_state_dict[
|
| 434 |
+
f"output_blocks.{i}.{index}.conv.weight"
|
| 435 |
+
]
|
| 436 |
+
new_checkpoint[f"up_blocks.{block_id}.upsamplers.0.conv.bias"] = unet_state_dict[
|
| 437 |
+
f"output_blocks.{i}.{index}.conv.bias"
|
| 438 |
+
]
|
| 439 |
+
|
| 440 |
+
# Clear attentions as they have been attributed above.
|
| 441 |
+
if len(attentions) == 2:
|
| 442 |
+
attentions = []
|
| 443 |
+
|
| 444 |
+
if len(attentions):
|
| 445 |
+
paths = renew_attention_paths(attentions)
|
| 446 |
+
meta_path = {
|
| 447 |
+
"old": f"output_blocks.{i}.1",
|
| 448 |
+
"new": f"up_blocks.{block_id}.attentions.{layer_in_block_id}",
|
| 449 |
+
}
|
| 450 |
+
assign_to_checkpoint(
|
| 451 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 452 |
+
)
|
| 453 |
+
else:
|
| 454 |
+
resnet_0_paths = renew_resnet_paths(output_block_layers, n_shave_prefix_segments=1)
|
| 455 |
+
for path in resnet_0_paths:
|
| 456 |
+
old_path = ".".join(["output_blocks", str(i), path["old"]])
|
| 457 |
+
new_path = ".".join(["up_blocks", str(block_id), "resnets", str(layer_in_block_id), path["new"]])
|
| 458 |
+
|
| 459 |
+
new_checkpoint[new_path] = unet_state_dict[old_path]
|
| 460 |
+
|
| 461 |
+
return new_checkpoint
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
def convert_ldm_vae_checkpoint(checkpoint, config):
|
| 465 |
+
# extract state dict for VAE
|
| 466 |
+
vae_state_dict = {}
|
| 467 |
+
vae_key = "first_stage_model."
|
| 468 |
+
keys = list(checkpoint.keys())
|
| 469 |
+
for key in keys:
|
| 470 |
+
if key.startswith(vae_key):
|
| 471 |
+
vae_state_dict[key.replace(vae_key, "")] = checkpoint.get(key)
|
| 472 |
+
|
| 473 |
+
new_checkpoint = {}
|
| 474 |
+
|
| 475 |
+
new_checkpoint["encoder.conv_in.weight"] = vae_state_dict["encoder.conv_in.weight"]
|
| 476 |
+
new_checkpoint["encoder.conv_in.bias"] = vae_state_dict["encoder.conv_in.bias"]
|
| 477 |
+
new_checkpoint["encoder.conv_out.weight"] = vae_state_dict["encoder.conv_out.weight"]
|
| 478 |
+
new_checkpoint["encoder.conv_out.bias"] = vae_state_dict["encoder.conv_out.bias"]
|
| 479 |
+
new_checkpoint["encoder.conv_norm_out.weight"] = vae_state_dict["encoder.norm_out.weight"]
|
| 480 |
+
new_checkpoint["encoder.conv_norm_out.bias"] = vae_state_dict["encoder.norm_out.bias"]
|
| 481 |
+
|
| 482 |
+
new_checkpoint["decoder.conv_in.weight"] = vae_state_dict["decoder.conv_in.weight"]
|
| 483 |
+
new_checkpoint["decoder.conv_in.bias"] = vae_state_dict["decoder.conv_in.bias"]
|
| 484 |
+
new_checkpoint["decoder.conv_out.weight"] = vae_state_dict["decoder.conv_out.weight"]
|
| 485 |
+
new_checkpoint["decoder.conv_out.bias"] = vae_state_dict["decoder.conv_out.bias"]
|
| 486 |
+
new_checkpoint["decoder.conv_norm_out.weight"] = vae_state_dict["decoder.norm_out.weight"]
|
| 487 |
+
new_checkpoint["decoder.conv_norm_out.bias"] = vae_state_dict["decoder.norm_out.bias"]
|
| 488 |
+
|
| 489 |
+
new_checkpoint["quant_conv.weight"] = vae_state_dict["quant_conv.weight"]
|
| 490 |
+
new_checkpoint["quant_conv.bias"] = vae_state_dict["quant_conv.bias"]
|
| 491 |
+
new_checkpoint["post_quant_conv.weight"] = vae_state_dict["post_quant_conv.weight"]
|
| 492 |
+
new_checkpoint["post_quant_conv.bias"] = vae_state_dict["post_quant_conv.bias"]
|
| 493 |
+
|
| 494 |
+
# Retrieves the keys for the encoder down blocks only
|
| 495 |
+
num_down_blocks = len({".".join(layer.split(".")[:3]) for layer in vae_state_dict if "encoder.down" in layer})
|
| 496 |
+
down_blocks = {
|
| 497 |
+
layer_id: [key for key in vae_state_dict if f"down.{layer_id}" in key] for layer_id in range(num_down_blocks)
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
# Retrieves the keys for the decoder up blocks only
|
| 501 |
+
num_up_blocks = len({".".join(layer.split(".")[:3]) for layer in vae_state_dict if "decoder.up" in layer})
|
| 502 |
+
up_blocks = {
|
| 503 |
+
layer_id: [key for key in vae_state_dict if f"up.{layer_id}" in key] for layer_id in range(num_up_blocks)
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
for i in range(num_down_blocks):
|
| 507 |
+
resnets = [key for key in down_blocks[i] if f"down.{i}" in key and f"down.{i}.downsample" not in key]
|
| 508 |
+
|
| 509 |
+
if f"encoder.down.{i}.downsample.conv.weight" in vae_state_dict:
|
| 510 |
+
new_checkpoint[f"encoder.down_blocks.{i}.downsamplers.0.conv.weight"] = vae_state_dict.pop(
|
| 511 |
+
f"encoder.down.{i}.downsample.conv.weight"
|
| 512 |
+
)
|
| 513 |
+
new_checkpoint[f"encoder.down_blocks.{i}.downsamplers.0.conv.bias"] = vae_state_dict.pop(
|
| 514 |
+
f"encoder.down.{i}.downsample.conv.bias"
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 518 |
+
meta_path = {"old": f"down.{i}.block", "new": f"down_blocks.{i}.resnets"}
|
| 519 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 520 |
+
|
| 521 |
+
mid_resnets = [key for key in vae_state_dict if "encoder.mid.block" in key]
|
| 522 |
+
num_mid_res_blocks = 2
|
| 523 |
+
for i in range(1, num_mid_res_blocks + 1):
|
| 524 |
+
resnets = [key for key in mid_resnets if f"encoder.mid.block_{i}" in key]
|
| 525 |
+
|
| 526 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 527 |
+
meta_path = {"old": f"mid.block_{i}", "new": f"mid_block.resnets.{i - 1}"}
|
| 528 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 529 |
+
|
| 530 |
+
mid_attentions = [key for key in vae_state_dict if "encoder.mid.attn" in key]
|
| 531 |
+
paths = renew_vae_attention_paths(mid_attentions)
|
| 532 |
+
meta_path = {"old": "mid.attn_1", "new": "mid_block.attentions.0"}
|
| 533 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 534 |
+
conv_attn_to_linear(new_checkpoint)
|
| 535 |
+
|
| 536 |
+
for i in range(num_up_blocks):
|
| 537 |
+
block_id = num_up_blocks - 1 - i
|
| 538 |
+
resnets = [
|
| 539 |
+
key for key in up_blocks[block_id] if f"up.{block_id}" in key and f"up.{block_id}.upsample" not in key
|
| 540 |
+
]
|
| 541 |
+
|
| 542 |
+
if f"decoder.up.{block_id}.upsample.conv.weight" in vae_state_dict:
|
| 543 |
+
new_checkpoint[f"decoder.up_blocks.{i}.upsamplers.0.conv.weight"] = vae_state_dict[
|
| 544 |
+
f"decoder.up.{block_id}.upsample.conv.weight"
|
| 545 |
+
]
|
| 546 |
+
new_checkpoint[f"decoder.up_blocks.{i}.upsamplers.0.conv.bias"] = vae_state_dict[
|
| 547 |
+
f"decoder.up.{block_id}.upsample.conv.bias"
|
| 548 |
+
]
|
| 549 |
+
|
| 550 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 551 |
+
meta_path = {"old": f"up.{block_id}.block", "new": f"up_blocks.{i}.resnets"}
|
| 552 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 553 |
+
|
| 554 |
+
mid_resnets = [key for key in vae_state_dict if "decoder.mid.block" in key]
|
| 555 |
+
num_mid_res_blocks = 2
|
| 556 |
+
for i in range(1, num_mid_res_blocks + 1):
|
| 557 |
+
resnets = [key for key in mid_resnets if f"decoder.mid.block_{i}" in key]
|
| 558 |
+
|
| 559 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 560 |
+
meta_path = {"old": f"mid.block_{i}", "new": f"mid_block.resnets.{i - 1}"}
|
| 561 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 562 |
+
|
| 563 |
+
mid_attentions = [key for key in vae_state_dict if "decoder.mid.attn" in key]
|
| 564 |
+
paths = renew_vae_attention_paths(mid_attentions)
|
| 565 |
+
meta_path = {"old": "mid.attn_1", "new": "mid_block.attentions.0"}
|
| 566 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 567 |
+
conv_attn_to_linear(new_checkpoint)
|
| 568 |
+
return new_checkpoint
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def convert_ldm_bert_checkpoint(checkpoint, config):
|
| 572 |
+
def _copy_attn_layer(hf_attn_layer, pt_attn_layer):
|
| 573 |
+
hf_attn_layer.q_proj.weight.data = pt_attn_layer.to_q.weight
|
| 574 |
+
hf_attn_layer.k_proj.weight.data = pt_attn_layer.to_k.weight
|
| 575 |
+
hf_attn_layer.v_proj.weight.data = pt_attn_layer.to_v.weight
|
| 576 |
+
|
| 577 |
+
hf_attn_layer.out_proj.weight = pt_attn_layer.to_out.weight
|
| 578 |
+
hf_attn_layer.out_proj.bias = pt_attn_layer.to_out.bias
|
| 579 |
+
|
| 580 |
+
def _copy_linear(hf_linear, pt_linear):
|
| 581 |
+
hf_linear.weight = pt_linear.weight
|
| 582 |
+
hf_linear.bias = pt_linear.bias
|
| 583 |
+
|
| 584 |
+
def _copy_layer(hf_layer, pt_layer):
|
| 585 |
+
# copy layer norms
|
| 586 |
+
_copy_linear(hf_layer.self_attn_layer_norm, pt_layer[0][0])
|
| 587 |
+
_copy_linear(hf_layer.final_layer_norm, pt_layer[1][0])
|
| 588 |
+
|
| 589 |
+
# copy attn
|
| 590 |
+
_copy_attn_layer(hf_layer.self_attn, pt_layer[0][1])
|
| 591 |
+
|
| 592 |
+
# copy MLP
|
| 593 |
+
pt_mlp = pt_layer[1][1]
|
| 594 |
+
_copy_linear(hf_layer.fc1, pt_mlp.net[0][0])
|
| 595 |
+
_copy_linear(hf_layer.fc2, pt_mlp.net[2])
|
| 596 |
+
|
| 597 |
+
def _copy_layers(hf_layers, pt_layers):
|
| 598 |
+
for i, hf_layer in enumerate(hf_layers):
|
| 599 |
+
if i != 0:
|
| 600 |
+
i += i
|
| 601 |
+
pt_layer = pt_layers[i : i + 2]
|
| 602 |
+
_copy_layer(hf_layer, pt_layer)
|
| 603 |
+
|
| 604 |
+
hf_model = LDMBertModel(config).eval()
|
| 605 |
+
|
| 606 |
+
# copy embeds
|
| 607 |
+
hf_model.model.embed_tokens.weight = checkpoint.transformer.token_emb.weight
|
| 608 |
+
hf_model.model.embed_positions.weight.data = checkpoint.transformer.pos_emb.emb.weight
|
| 609 |
+
|
| 610 |
+
# copy layer norm
|
| 611 |
+
_copy_linear(hf_model.model.layer_norm, checkpoint.transformer.norm)
|
| 612 |
+
|
| 613 |
+
# copy hidden layers
|
| 614 |
+
_copy_layers(hf_model.model.layers, checkpoint.transformer.attn_layers.layers)
|
| 615 |
+
|
| 616 |
+
_copy_linear(hf_model.to_logits, checkpoint.transformer.to_logits)
|
| 617 |
+
|
| 618 |
+
return hf_model
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def convert_ldm_clip_checkpoint(checkpoint):
|
| 622 |
+
text_model = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14")
|
| 623 |
+
|
| 624 |
+
keys = list(checkpoint.keys())
|
| 625 |
+
|
| 626 |
+
text_model_dict = {}
|
| 627 |
+
|
| 628 |
+
for key in keys:
|
| 629 |
+
if key.startswith("cond_stage_model.transformer"):
|
| 630 |
+
text_model_dict[key[len("cond_stage_model.transformer.") :]] = checkpoint[key]
|
| 631 |
+
|
| 632 |
+
text_model.load_state_dict(text_model_dict)
|
| 633 |
+
|
| 634 |
+
return text_model
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
if __name__ == "__main__":
|
| 638 |
+
parser = argparse.ArgumentParser()
|
| 639 |
+
|
| 640 |
+
parser.add_argument(
|
| 641 |
+
"--checkpoint_path", default=None, type=str, required=True, help="Path to the checkpoint to convert."
|
| 642 |
+
)
|
| 643 |
+
# !wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml
|
| 644 |
+
parser.add_argument(
|
| 645 |
+
"--original_config_file",
|
| 646 |
+
default=None,
|
| 647 |
+
type=str,
|
| 648 |
+
help="The YAML config file corresponding to the original architecture.",
|
| 649 |
+
)
|
| 650 |
+
parser.add_argument(
|
| 651 |
+
"--scheduler_type",
|
| 652 |
+
default="pndm",
|
| 653 |
+
type=str,
|
| 654 |
+
help="Type of scheduler to use. Should be one of ['pndm', 'lms', 'ddim', 'euler', 'euler-ancest', 'dpm']",
|
| 655 |
+
)
|
| 656 |
+
parser.add_argument(
|
| 657 |
+
"--extract_ema",
|
| 658 |
+
action="store_true",
|
| 659 |
+
help=(
|
| 660 |
+
"Only relevant for checkpoints that have both EMA and non-EMA weights. Whether to extract the EMA weights"
|
| 661 |
+
" or not. Defaults to `False`. Add `--extract_ema` to extract the EMA weights. EMA weights usually yield"
|
| 662 |
+
" higher quality images for inference. Non-EMA weights are usually better to continue fine-tuning."
|
| 663 |
+
),
|
| 664 |
+
)
|
| 665 |
+
parser.add_argument("--dump_path", default=None, type=str, required=True, help="Path to the output model.")
|
| 666 |
+
|
| 667 |
+
args = parser.parse_args()
|
| 668 |
+
|
| 669 |
+
if args.original_config_file is None:
|
| 670 |
+
os.system(
|
| 671 |
+
"wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
|
| 672 |
+
)
|
| 673 |
+
args.original_config_file = "./v1-inference.yaml"
|
| 674 |
+
|
| 675 |
+
original_config = OmegaConf.load(args.original_config_file)
|
| 676 |
+
|
| 677 |
+
checkpoint = torch.load(args.checkpoint_path)
|
| 678 |
+
checkpoint = checkpoint["state_dict"]
|
| 679 |
+
|
| 680 |
+
num_train_timesteps = original_config.model.params.timesteps
|
| 681 |
+
beta_start = original_config.model.params.linear_start
|
| 682 |
+
beta_end = original_config.model.params.linear_end
|
| 683 |
+
if args.scheduler_type == "pndm":
|
| 684 |
+
scheduler = PNDMScheduler(
|
| 685 |
+
beta_end=beta_end,
|
| 686 |
+
beta_schedule="scaled_linear",
|
| 687 |
+
beta_start=beta_start,
|
| 688 |
+
num_train_timesteps=num_train_timesteps,
|
| 689 |
+
skip_prk_steps=True,
|
| 690 |
+
)
|
| 691 |
+
elif args.scheduler_type == "lms":
|
| 692 |
+
scheduler = LMSDiscreteScheduler(beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear")
|
| 693 |
+
elif args.scheduler_type == "euler":
|
| 694 |
+
scheduler = EulerDiscreteScheduler(beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear")
|
| 695 |
+
elif args.scheduler_type == "euler-ancestral":
|
| 696 |
+
scheduler = EulerAncestralDiscreteScheduler(
|
| 697 |
+
beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear"
|
| 698 |
+
)
|
| 699 |
+
elif args.scheduler_type == "dpm":
|
| 700 |
+
scheduler = DPMSolverMultistepScheduler(
|
| 701 |
+
beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear"
|
| 702 |
+
)
|
| 703 |
+
elif args.scheduler_type == "ddim":
|
| 704 |
+
scheduler = DDIMScheduler(
|
| 705 |
+
beta_start=beta_start,
|
| 706 |
+
beta_end=beta_end,
|
| 707 |
+
beta_schedule="scaled_linear",
|
| 708 |
+
clip_sample=False,
|
| 709 |
+
set_alpha_to_one=False,
|
| 710 |
+
)
|
| 711 |
+
else:
|
| 712 |
+
raise ValueError(f"Scheduler of type {args.scheduler_type} doesn't exist!")
|
| 713 |
+
|
| 714 |
+
# Convert the UNet2DConditionModel model.
|
| 715 |
+
unet_config = create_unet_diffusers_config(original_config)
|
| 716 |
+
converted_unet_checkpoint = convert_ldm_unet_checkpoint(
|
| 717 |
+
checkpoint, unet_config, path=args.checkpoint_path, extract_ema=args.extract_ema
|
| 718 |
+
)
|
| 719 |
+
|
| 720 |
+
unet = UNet2DConditionModel(**unet_config)
|
| 721 |
+
unet.load_state_dict(converted_unet_checkpoint)
|
| 722 |
+
|
| 723 |
+
# Convert the VAE model.
|
| 724 |
+
vae_config = create_vae_diffusers_config(original_config)
|
| 725 |
+
converted_vae_checkpoint = convert_ldm_vae_checkpoint(checkpoint, vae_config)
|
| 726 |
+
|
| 727 |
+
vae = AutoencoderKL(**vae_config)
|
| 728 |
+
vae.load_state_dict(converted_vae_checkpoint)
|
| 729 |
+
|
| 730 |
+
# Convert the text model.
|
| 731 |
+
text_model_type = original_config.model.params.cond_stage_config.target.split(".")[-1]
|
| 732 |
+
if text_model_type == "FrozenCLIPEmbedder":
|
| 733 |
+
text_model = convert_ldm_clip_checkpoint(checkpoint)
|
| 734 |
+
tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14")
|
| 735 |
+
# safety_checker = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
|
| 736 |
+
# feature_extractor = AutoFeatureExtractor.from_pretrained("CompVis/stable-diffusion-safety-checker")
|
| 737 |
+
pipe = StableDiffusionPipeline(
|
| 738 |
+
vae=vae,
|
| 739 |
+
text_encoder=text_model,
|
| 740 |
+
tokenizer=tokenizer,
|
| 741 |
+
unet=unet,
|
| 742 |
+
scheduler=scheduler,
|
| 743 |
+
# safety_checker=safety_checker,
|
| 744 |
+
# feature_extractor=feature_extractor,
|
| 745 |
+
)
|
| 746 |
+
else:
|
| 747 |
+
text_config = create_ldm_bert_config(original_config)
|
| 748 |
+
text_model = convert_ldm_bert_checkpoint(checkpoint, text_config)
|
| 749 |
+
tokenizer = BertTokenizerFast.from_pretrained("bert-base-uncased")
|
| 750 |
+
pipe = LDMTextToImagePipeline(vqvae=vae, bert=text_model, tokenizer=tokenizer, unet=unet, scheduler=scheduler)
|
| 751 |
+
|
| 752 |
+
pipe.save_pretrained(args.dump_path)
|
convert_original_stable_diffusion_to_diffusers.py.2
ADDED
|
@@ -0,0 +1,752 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2022 The HuggingFace Inc. team.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
""" Conversion script for the LDM checkpoints. """
|
| 16 |
+
|
| 17 |
+
import argparse
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
import torch
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
from omegaconf import OmegaConf
|
| 25 |
+
except ImportError:
|
| 26 |
+
raise ImportError(
|
| 27 |
+
"OmegaConf is required to convert the LDM checkpoints. Please install it with `pip install OmegaConf`."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
from diffusers import (
|
| 31 |
+
AutoencoderKL,
|
| 32 |
+
DDIMScheduler,
|
| 33 |
+
DPMSolverMultistepScheduler,
|
| 34 |
+
EulerAncestralDiscreteScheduler,
|
| 35 |
+
EulerDiscreteScheduler,
|
| 36 |
+
LDMTextToImagePipeline,
|
| 37 |
+
LMSDiscreteScheduler,
|
| 38 |
+
PNDMScheduler,
|
| 39 |
+
StableDiffusionPipeline,
|
| 40 |
+
UNet2DConditionModel,
|
| 41 |
+
)
|
| 42 |
+
from diffusers.pipelines.latent_diffusion.pipeline_latent_diffusion import LDMBertConfig, LDMBertModel
|
| 43 |
+
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
|
| 44 |
+
from transformers import AutoFeatureExtractor, BertTokenizerFast, CLIPTextModel, CLIPTokenizer
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def shave_segments(path, n_shave_prefix_segments=1):
|
| 48 |
+
"""
|
| 49 |
+
Removes segments. Positive values shave the first segments, negative shave the last segments.
|
| 50 |
+
"""
|
| 51 |
+
if n_shave_prefix_segments >= 0:
|
| 52 |
+
return ".".join(path.split(".")[n_shave_prefix_segments:])
|
| 53 |
+
else:
|
| 54 |
+
return ".".join(path.split(".")[:n_shave_prefix_segments])
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def renew_resnet_paths(old_list, n_shave_prefix_segments=0):
|
| 58 |
+
"""
|
| 59 |
+
Updates paths inside resnets to the new naming scheme (local renaming)
|
| 60 |
+
"""
|
| 61 |
+
mapping = []
|
| 62 |
+
for old_item in old_list:
|
| 63 |
+
new_item = old_item.replace("in_layers.0", "norm1")
|
| 64 |
+
new_item = new_item.replace("in_layers.2", "conv1")
|
| 65 |
+
|
| 66 |
+
new_item = new_item.replace("out_layers.0", "norm2")
|
| 67 |
+
new_item = new_item.replace("out_layers.3", "conv2")
|
| 68 |
+
|
| 69 |
+
new_item = new_item.replace("emb_layers.1", "time_emb_proj")
|
| 70 |
+
new_item = new_item.replace("skip_connection", "conv_shortcut")
|
| 71 |
+
|
| 72 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 73 |
+
|
| 74 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 75 |
+
|
| 76 |
+
return mapping
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def renew_vae_resnet_paths(old_list, n_shave_prefix_segments=0):
|
| 80 |
+
"""
|
| 81 |
+
Updates paths inside resnets to the new naming scheme (local renaming)
|
| 82 |
+
"""
|
| 83 |
+
mapping = []
|
| 84 |
+
for old_item in old_list:
|
| 85 |
+
new_item = old_item
|
| 86 |
+
|
| 87 |
+
new_item = new_item.replace("nin_shortcut", "conv_shortcut")
|
| 88 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 89 |
+
|
| 90 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 91 |
+
|
| 92 |
+
return mapping
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def renew_attention_paths(old_list, n_shave_prefix_segments=0):
|
| 96 |
+
"""
|
| 97 |
+
Updates paths inside attentions to the new naming scheme (local renaming)
|
| 98 |
+
"""
|
| 99 |
+
mapping = []
|
| 100 |
+
for old_item in old_list:
|
| 101 |
+
new_item = old_item
|
| 102 |
+
|
| 103 |
+
# new_item = new_item.replace('norm.weight', 'group_norm.weight')
|
| 104 |
+
# new_item = new_item.replace('norm.bias', 'group_norm.bias')
|
| 105 |
+
|
| 106 |
+
# new_item = new_item.replace('proj_out.weight', 'proj_attn.weight')
|
| 107 |
+
# new_item = new_item.replace('proj_out.bias', 'proj_attn.bias')
|
| 108 |
+
|
| 109 |
+
# new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 110 |
+
|
| 111 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 112 |
+
|
| 113 |
+
return mapping
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def renew_vae_attention_paths(old_list, n_shave_prefix_segments=0):
|
| 117 |
+
"""
|
| 118 |
+
Updates paths inside attentions to the new naming scheme (local renaming)
|
| 119 |
+
"""
|
| 120 |
+
mapping = []
|
| 121 |
+
for old_item in old_list:
|
| 122 |
+
new_item = old_item
|
| 123 |
+
|
| 124 |
+
new_item = new_item.replace("norm.weight", "group_norm.weight")
|
| 125 |
+
new_item = new_item.replace("norm.bias", "group_norm.bias")
|
| 126 |
+
|
| 127 |
+
new_item = new_item.replace("q.weight", "query.weight")
|
| 128 |
+
new_item = new_item.replace("q.bias", "query.bias")
|
| 129 |
+
|
| 130 |
+
new_item = new_item.replace("k.weight", "key.weight")
|
| 131 |
+
new_item = new_item.replace("k.bias", "key.bias")
|
| 132 |
+
|
| 133 |
+
new_item = new_item.replace("v.weight", "value.weight")
|
| 134 |
+
new_item = new_item.replace("v.bias", "value.bias")
|
| 135 |
+
|
| 136 |
+
new_item = new_item.replace("proj_out.weight", "proj_attn.weight")
|
| 137 |
+
new_item = new_item.replace("proj_out.bias", "proj_attn.bias")
|
| 138 |
+
|
| 139 |
+
new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
|
| 140 |
+
|
| 141 |
+
mapping.append({"old": old_item, "new": new_item})
|
| 142 |
+
|
| 143 |
+
return mapping
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def assign_to_checkpoint(
|
| 147 |
+
paths, checkpoint, old_checkpoint, attention_paths_to_split=None, additional_replacements=None, config=None
|
| 148 |
+
):
|
| 149 |
+
"""
|
| 150 |
+
This does the final conversion step: take locally converted weights and apply a global renaming
|
| 151 |
+
to them. It splits attention layers, and takes into account additional replacements
|
| 152 |
+
that may arise.
|
| 153 |
+
|
| 154 |
+
Assigns the weights to the new checkpoint.
|
| 155 |
+
"""
|
| 156 |
+
assert isinstance(paths, list), "Paths should be a list of dicts containing 'old' and 'new' keys."
|
| 157 |
+
|
| 158 |
+
# Splits the attention layers into three variables.
|
| 159 |
+
if attention_paths_to_split is not None:
|
| 160 |
+
for path, path_map in attention_paths_to_split.items():
|
| 161 |
+
old_tensor = old_checkpoint[path]
|
| 162 |
+
channels = old_tensor.shape[0] // 3
|
| 163 |
+
|
| 164 |
+
target_shape = (-1, channels) if len(old_tensor.shape) == 3 else (-1)
|
| 165 |
+
|
| 166 |
+
num_heads = old_tensor.shape[0] // config["num_head_channels"] // 3
|
| 167 |
+
|
| 168 |
+
old_tensor = old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:])
|
| 169 |
+
query, key, value = old_tensor.split(channels // num_heads, dim=1)
|
| 170 |
+
|
| 171 |
+
checkpoint[path_map["query"]] = query.reshape(target_shape)
|
| 172 |
+
checkpoint[path_map["key"]] = key.reshape(target_shape)
|
| 173 |
+
checkpoint[path_map["value"]] = value.reshape(target_shape)
|
| 174 |
+
|
| 175 |
+
for path in paths:
|
| 176 |
+
new_path = path["new"]
|
| 177 |
+
|
| 178 |
+
# These have already been assigned
|
| 179 |
+
if attention_paths_to_split is not None and new_path in attention_paths_to_split:
|
| 180 |
+
continue
|
| 181 |
+
|
| 182 |
+
# Global renaming happens here
|
| 183 |
+
new_path = new_path.replace("middle_block.0", "mid_block.resnets.0")
|
| 184 |
+
new_path = new_path.replace("middle_block.1", "mid_block.attentions.0")
|
| 185 |
+
new_path = new_path.replace("middle_block.2", "mid_block.resnets.1")
|
| 186 |
+
|
| 187 |
+
if additional_replacements is not None:
|
| 188 |
+
for replacement in additional_replacements:
|
| 189 |
+
new_path = new_path.replace(replacement["old"], replacement["new"])
|
| 190 |
+
|
| 191 |
+
# proj_attn.weight has to be converted from conv 1D to linear
|
| 192 |
+
if "proj_attn.weight" in new_path:
|
| 193 |
+
checkpoint[new_path] = old_checkpoint[path["old"]][:, :, 0]
|
| 194 |
+
else:
|
| 195 |
+
checkpoint[new_path] = old_checkpoint[path["old"]]
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def conv_attn_to_linear(checkpoint):
|
| 199 |
+
keys = list(checkpoint.keys())
|
| 200 |
+
attn_keys = ["query.weight", "key.weight", "value.weight"]
|
| 201 |
+
for key in keys:
|
| 202 |
+
if ".".join(key.split(".")[-2:]) in attn_keys:
|
| 203 |
+
if checkpoint[key].ndim > 2:
|
| 204 |
+
checkpoint[key] = checkpoint[key][:, :, 0, 0]
|
| 205 |
+
elif "proj_attn.weight" in key:
|
| 206 |
+
if checkpoint[key].ndim > 2:
|
| 207 |
+
checkpoint[key] = checkpoint[key][:, :, 0]
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def create_unet_diffusers_config(original_config):
|
| 211 |
+
"""
|
| 212 |
+
Creates a config for the diffusers based on the config of the LDM model.
|
| 213 |
+
"""
|
| 214 |
+
model_params = original_config.model.params
|
| 215 |
+
unet_params = original_config.model.params.unet_config.params
|
| 216 |
+
|
| 217 |
+
block_out_channels = [unet_params.model_channels * mult for mult in unet_params.channel_mult]
|
| 218 |
+
|
| 219 |
+
down_block_types = []
|
| 220 |
+
resolution = 1
|
| 221 |
+
for i in range(len(block_out_channels)):
|
| 222 |
+
block_type = "CrossAttnDownBlock2D" if resolution in unet_params.attention_resolutions else "DownBlock2D"
|
| 223 |
+
down_block_types.append(block_type)
|
| 224 |
+
if i != len(block_out_channels) - 1:
|
| 225 |
+
resolution *= 2
|
| 226 |
+
|
| 227 |
+
up_block_types = []
|
| 228 |
+
for i in range(len(block_out_channels)):
|
| 229 |
+
block_type = "CrossAttnUpBlock2D" if resolution in unet_params.attention_resolutions else "UpBlock2D"
|
| 230 |
+
up_block_types.append(block_type)
|
| 231 |
+
resolution //= 2
|
| 232 |
+
|
| 233 |
+
config = dict(
|
| 234 |
+
sample_size=model_params.image_size,
|
| 235 |
+
in_channels=unet_params.in_channels,
|
| 236 |
+
out_channels=unet_params.out_channels,
|
| 237 |
+
down_block_types=tuple(down_block_types),
|
| 238 |
+
up_block_types=tuple(up_block_types),
|
| 239 |
+
block_out_channels=tuple(block_out_channels),
|
| 240 |
+
layers_per_block=unet_params.num_res_blocks,
|
| 241 |
+
cross_attention_dim=unet_params.context_dim,
|
| 242 |
+
attention_head_dim=unet_params.num_heads,
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
return config
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def create_vae_diffusers_config(original_config):
|
| 249 |
+
"""
|
| 250 |
+
Creates a config for the diffusers based on the config of the LDM model.
|
| 251 |
+
"""
|
| 252 |
+
vae_params = original_config.model.params.first_stage_config.params.ddconfig
|
| 253 |
+
_ = original_config.model.params.first_stage_config.params.embed_dim
|
| 254 |
+
|
| 255 |
+
block_out_channels = [vae_params.ch * mult for mult in vae_params.ch_mult]
|
| 256 |
+
down_block_types = ["DownEncoderBlock2D"] * len(block_out_channels)
|
| 257 |
+
up_block_types = ["UpDecoderBlock2D"] * len(block_out_channels)
|
| 258 |
+
|
| 259 |
+
config = dict(
|
| 260 |
+
sample_size=vae_params.resolution,
|
| 261 |
+
in_channels=vae_params.in_channels,
|
| 262 |
+
out_channels=vae_params.out_ch,
|
| 263 |
+
down_block_types=tuple(down_block_types),
|
| 264 |
+
up_block_types=tuple(up_block_types),
|
| 265 |
+
block_out_channels=tuple(block_out_channels),
|
| 266 |
+
latent_channels=vae_params.z_channels,
|
| 267 |
+
layers_per_block=vae_params.num_res_blocks,
|
| 268 |
+
)
|
| 269 |
+
return config
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
def create_diffusers_schedular(original_config):
|
| 273 |
+
schedular = DDIMScheduler(
|
| 274 |
+
num_train_timesteps=original_config.model.params.timesteps,
|
| 275 |
+
beta_start=original_config.model.params.linear_start,
|
| 276 |
+
beta_end=original_config.model.params.linear_end,
|
| 277 |
+
beta_schedule="scaled_linear",
|
| 278 |
+
)
|
| 279 |
+
return schedular
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def create_ldm_bert_config(original_config):
|
| 283 |
+
bert_params = original_config.model.parms.cond_stage_config.params
|
| 284 |
+
config = LDMBertConfig(
|
| 285 |
+
d_model=bert_params.n_embed,
|
| 286 |
+
encoder_layers=bert_params.n_layer,
|
| 287 |
+
encoder_ffn_dim=bert_params.n_embed * 4,
|
| 288 |
+
)
|
| 289 |
+
return config
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def convert_ldm_unet_checkpoint(checkpoint, config, path=None, extract_ema=False):
|
| 293 |
+
"""
|
| 294 |
+
Takes a state dict and a config, and returns a converted checkpoint.
|
| 295 |
+
"""
|
| 296 |
+
|
| 297 |
+
# extract state_dict for UNet
|
| 298 |
+
unet_state_dict = {}
|
| 299 |
+
keys = list(checkpoint.keys())
|
| 300 |
+
|
| 301 |
+
unet_key = "model.diffusion_model."
|
| 302 |
+
# at least a 100 parameters have to start with `model_ema` in order for the checkpoint to be EMA
|
| 303 |
+
if sum(k.startswith("model_ema") for k in keys) > 100:
|
| 304 |
+
print(f"Checkpoint {path} has both EMA and non-EMA weights.")
|
| 305 |
+
if extract_ema:
|
| 306 |
+
print(
|
| 307 |
+
"In this conversion only the EMA weights are extracted. If you want to instead extract the non-EMA"
|
| 308 |
+
" weights (useful to continue fine-tuning), please make sure to remove the `--extract_ema` flag."
|
| 309 |
+
)
|
| 310 |
+
for key in keys:
|
| 311 |
+
if key.startswith("model.diffusion_model"):
|
| 312 |
+
flat_ema_key = "model_ema." + "".join(key.split(".")[1:])
|
| 313 |
+
unet_state_dict[key.replace(unet_key, "")] = checkpoint.pop(flat_ema_key)
|
| 314 |
+
else:
|
| 315 |
+
print(
|
| 316 |
+
"In this conversion only the non-EMA weights are extracted. If you want to instead extract the EMA"
|
| 317 |
+
" weights (usually better for inference), please make sure to add the `--extract_ema` flag."
|
| 318 |
+
)
|
| 319 |
+
|
| 320 |
+
for key in keys:
|
| 321 |
+
if key.startswith(unet_key):
|
| 322 |
+
unet_state_dict[key.replace(unet_key, "")] = checkpoint.pop(key)
|
| 323 |
+
|
| 324 |
+
new_checkpoint = {}
|
| 325 |
+
|
| 326 |
+
new_checkpoint["time_embedding.linear_1.weight"] = unet_state_dict["time_embed.0.weight"]
|
| 327 |
+
new_checkpoint["time_embedding.linear_1.bias"] = unet_state_dict["time_embed.0.bias"]
|
| 328 |
+
new_checkpoint["time_embedding.linear_2.weight"] = unet_state_dict["time_embed.2.weight"]
|
| 329 |
+
new_checkpoint["time_embedding.linear_2.bias"] = unet_state_dict["time_embed.2.bias"]
|
| 330 |
+
|
| 331 |
+
new_checkpoint["conv_in.weight"] = unet_state_dict["input_blocks.0.0.weight"]
|
| 332 |
+
new_checkpoint["conv_in.bias"] = unet_state_dict["input_blocks.0.0.bias"]
|
| 333 |
+
|
| 334 |
+
new_checkpoint["conv_norm_out.weight"] = unet_state_dict["out.0.weight"]
|
| 335 |
+
new_checkpoint["conv_norm_out.bias"] = unet_state_dict["out.0.bias"]
|
| 336 |
+
new_checkpoint["conv_out.weight"] = unet_state_dict["out.2.weight"]
|
| 337 |
+
new_checkpoint["conv_out.bias"] = unet_state_dict["out.2.bias"]
|
| 338 |
+
|
| 339 |
+
# Retrieves the keys for the input blocks only
|
| 340 |
+
num_input_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "input_blocks" in layer})
|
| 341 |
+
input_blocks = {
|
| 342 |
+
layer_id: [key for key in unet_state_dict if f"input_blocks.{layer_id}" in key]
|
| 343 |
+
for layer_id in range(num_input_blocks)
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
# Retrieves the keys for the middle blocks only
|
| 347 |
+
num_middle_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "middle_block" in layer})
|
| 348 |
+
middle_blocks = {
|
| 349 |
+
layer_id: [key for key in unet_state_dict if f"middle_block.{layer_id}" in key]
|
| 350 |
+
for layer_id in range(num_middle_blocks)
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
# Retrieves the keys for the output blocks only
|
| 354 |
+
num_output_blocks = len({".".join(layer.split(".")[:2]) for layer in unet_state_dict if "output_blocks" in layer})
|
| 355 |
+
output_blocks = {
|
| 356 |
+
layer_id: [key for key in unet_state_dict if f"output_blocks.{layer_id}" in key]
|
| 357 |
+
for layer_id in range(num_output_blocks)
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
for i in range(1, num_input_blocks):
|
| 361 |
+
block_id = (i - 1) // (config["layers_per_block"] + 1)
|
| 362 |
+
layer_in_block_id = (i - 1) % (config["layers_per_block"] + 1)
|
| 363 |
+
|
| 364 |
+
resnets = [
|
| 365 |
+
key for key in input_blocks[i] if f"input_blocks.{i}.0" in key and f"input_blocks.{i}.0.op" not in key
|
| 366 |
+
]
|
| 367 |
+
attentions = [key for key in input_blocks[i] if f"input_blocks.{i}.1" in key]
|
| 368 |
+
|
| 369 |
+
if f"input_blocks.{i}.0.op.weight" in unet_state_dict:
|
| 370 |
+
new_checkpoint[f"down_blocks.{block_id}.downsamplers.0.conv.weight"] = unet_state_dict.pop(
|
| 371 |
+
f"input_blocks.{i}.0.op.weight"
|
| 372 |
+
)
|
| 373 |
+
new_checkpoint[f"down_blocks.{block_id}.downsamplers.0.conv.bias"] = unet_state_dict.pop(
|
| 374 |
+
f"input_blocks.{i}.0.op.bias"
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
paths = renew_resnet_paths(resnets)
|
| 378 |
+
meta_path = {"old": f"input_blocks.{i}.0", "new": f"down_blocks.{block_id}.resnets.{layer_in_block_id}"}
|
| 379 |
+
assign_to_checkpoint(
|
| 380 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
if len(attentions):
|
| 384 |
+
paths = renew_attention_paths(attentions)
|
| 385 |
+
meta_path = {"old": f"input_blocks.{i}.1", "new": f"down_blocks.{block_id}.attentions.{layer_in_block_id}"}
|
| 386 |
+
assign_to_checkpoint(
|
| 387 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
resnet_0 = middle_blocks[0]
|
| 391 |
+
attentions = middle_blocks[1]
|
| 392 |
+
resnet_1 = middle_blocks[2]
|
| 393 |
+
|
| 394 |
+
resnet_0_paths = renew_resnet_paths(resnet_0)
|
| 395 |
+
assign_to_checkpoint(resnet_0_paths, new_checkpoint, unet_state_dict, config=config)
|
| 396 |
+
|
| 397 |
+
resnet_1_paths = renew_resnet_paths(resnet_1)
|
| 398 |
+
assign_to_checkpoint(resnet_1_paths, new_checkpoint, unet_state_dict, config=config)
|
| 399 |
+
|
| 400 |
+
attentions_paths = renew_attention_paths(attentions)
|
| 401 |
+
meta_path = {"old": "middle_block.1", "new": "mid_block.attentions.0"}
|
| 402 |
+
assign_to_checkpoint(
|
| 403 |
+
attentions_paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
for i in range(num_output_blocks):
|
| 407 |
+
block_id = i // (config["layers_per_block"] + 1)
|
| 408 |
+
layer_in_block_id = i % (config["layers_per_block"] + 1)
|
| 409 |
+
output_block_layers = [shave_segments(name, 2) for name in output_blocks[i]]
|
| 410 |
+
output_block_list = {}
|
| 411 |
+
|
| 412 |
+
for layer in output_block_layers:
|
| 413 |
+
layer_id, layer_name = layer.split(".")[0], shave_segments(layer, 1)
|
| 414 |
+
if layer_id in output_block_list:
|
| 415 |
+
output_block_list[layer_id].append(layer_name)
|
| 416 |
+
else:
|
| 417 |
+
output_block_list[layer_id] = [layer_name]
|
| 418 |
+
|
| 419 |
+
if len(output_block_list) > 1:
|
| 420 |
+
resnets = [key for key in output_blocks[i] if f"output_blocks.{i}.0" in key]
|
| 421 |
+
attentions = [key for key in output_blocks[i] if f"output_blocks.{i}.1" in key]
|
| 422 |
+
|
| 423 |
+
resnet_0_paths = renew_resnet_paths(resnets)
|
| 424 |
+
paths = renew_resnet_paths(resnets)
|
| 425 |
+
|
| 426 |
+
meta_path = {"old": f"output_blocks.{i}.0", "new": f"up_blocks.{block_id}.resnets.{layer_in_block_id}"}
|
| 427 |
+
assign_to_checkpoint(
|
| 428 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 429 |
+
)
|
| 430 |
+
|
| 431 |
+
if ["conv.weight", "conv.bias"] in output_block_list.values():
|
| 432 |
+
index = list(output_block_list.values()).index(["conv.weight", "conv.bias"])
|
| 433 |
+
new_checkpoint[f"up_blocks.{block_id}.upsamplers.0.conv.weight"] = unet_state_dict[
|
| 434 |
+
f"output_blocks.{i}.{index}.conv.weight"
|
| 435 |
+
]
|
| 436 |
+
new_checkpoint[f"up_blocks.{block_id}.upsamplers.0.conv.bias"] = unet_state_dict[
|
| 437 |
+
f"output_blocks.{i}.{index}.conv.bias"
|
| 438 |
+
]
|
| 439 |
+
|
| 440 |
+
# Clear attentions as they have been attributed above.
|
| 441 |
+
if len(attentions) == 2:
|
| 442 |
+
attentions = []
|
| 443 |
+
|
| 444 |
+
if len(attentions):
|
| 445 |
+
paths = renew_attention_paths(attentions)
|
| 446 |
+
meta_path = {
|
| 447 |
+
"old": f"output_blocks.{i}.1",
|
| 448 |
+
"new": f"up_blocks.{block_id}.attentions.{layer_in_block_id}",
|
| 449 |
+
}
|
| 450 |
+
assign_to_checkpoint(
|
| 451 |
+
paths, new_checkpoint, unet_state_dict, additional_replacements=[meta_path], config=config
|
| 452 |
+
)
|
| 453 |
+
else:
|
| 454 |
+
resnet_0_paths = renew_resnet_paths(output_block_layers, n_shave_prefix_segments=1)
|
| 455 |
+
for path in resnet_0_paths:
|
| 456 |
+
old_path = ".".join(["output_blocks", str(i), path["old"]])
|
| 457 |
+
new_path = ".".join(["up_blocks", str(block_id), "resnets", str(layer_in_block_id), path["new"]])
|
| 458 |
+
|
| 459 |
+
new_checkpoint[new_path] = unet_state_dict[old_path]
|
| 460 |
+
|
| 461 |
+
return new_checkpoint
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
def convert_ldm_vae_checkpoint(checkpoint, config):
|
| 465 |
+
# extract state dict for VAE
|
| 466 |
+
vae_state_dict = {}
|
| 467 |
+
vae_key = "first_stage_model."
|
| 468 |
+
keys = list(checkpoint.keys())
|
| 469 |
+
for key in keys:
|
| 470 |
+
if key.startswith(vae_key):
|
| 471 |
+
vae_state_dict[key.replace(vae_key, "")] = checkpoint.get(key)
|
| 472 |
+
|
| 473 |
+
new_checkpoint = {}
|
| 474 |
+
|
| 475 |
+
new_checkpoint["encoder.conv_in.weight"] = vae_state_dict["encoder.conv_in.weight"]
|
| 476 |
+
new_checkpoint["encoder.conv_in.bias"] = vae_state_dict["encoder.conv_in.bias"]
|
| 477 |
+
new_checkpoint["encoder.conv_out.weight"] = vae_state_dict["encoder.conv_out.weight"]
|
| 478 |
+
new_checkpoint["encoder.conv_out.bias"] = vae_state_dict["encoder.conv_out.bias"]
|
| 479 |
+
new_checkpoint["encoder.conv_norm_out.weight"] = vae_state_dict["encoder.norm_out.weight"]
|
| 480 |
+
new_checkpoint["encoder.conv_norm_out.bias"] = vae_state_dict["encoder.norm_out.bias"]
|
| 481 |
+
|
| 482 |
+
new_checkpoint["decoder.conv_in.weight"] = vae_state_dict["decoder.conv_in.weight"]
|
| 483 |
+
new_checkpoint["decoder.conv_in.bias"] = vae_state_dict["decoder.conv_in.bias"]
|
| 484 |
+
new_checkpoint["decoder.conv_out.weight"] = vae_state_dict["decoder.conv_out.weight"]
|
| 485 |
+
new_checkpoint["decoder.conv_out.bias"] = vae_state_dict["decoder.conv_out.bias"]
|
| 486 |
+
new_checkpoint["decoder.conv_norm_out.weight"] = vae_state_dict["decoder.norm_out.weight"]
|
| 487 |
+
new_checkpoint["decoder.conv_norm_out.bias"] = vae_state_dict["decoder.norm_out.bias"]
|
| 488 |
+
|
| 489 |
+
new_checkpoint["quant_conv.weight"] = vae_state_dict["quant_conv.weight"]
|
| 490 |
+
new_checkpoint["quant_conv.bias"] = vae_state_dict["quant_conv.bias"]
|
| 491 |
+
new_checkpoint["post_quant_conv.weight"] = vae_state_dict["post_quant_conv.weight"]
|
| 492 |
+
new_checkpoint["post_quant_conv.bias"] = vae_state_dict["post_quant_conv.bias"]
|
| 493 |
+
|
| 494 |
+
# Retrieves the keys for the encoder down blocks only
|
| 495 |
+
num_down_blocks = len({".".join(layer.split(".")[:3]) for layer in vae_state_dict if "encoder.down" in layer})
|
| 496 |
+
down_blocks = {
|
| 497 |
+
layer_id: [key for key in vae_state_dict if f"down.{layer_id}" in key] for layer_id in range(num_down_blocks)
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
# Retrieves the keys for the decoder up blocks only
|
| 501 |
+
num_up_blocks = len({".".join(layer.split(".")[:3]) for layer in vae_state_dict if "decoder.up" in layer})
|
| 502 |
+
up_blocks = {
|
| 503 |
+
layer_id: [key for key in vae_state_dict if f"up.{layer_id}" in key] for layer_id in range(num_up_blocks)
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
for i in range(num_down_blocks):
|
| 507 |
+
resnets = [key for key in down_blocks[i] if f"down.{i}" in key and f"down.{i}.downsample" not in key]
|
| 508 |
+
|
| 509 |
+
if f"encoder.down.{i}.downsample.conv.weight" in vae_state_dict:
|
| 510 |
+
new_checkpoint[f"encoder.down_blocks.{i}.downsamplers.0.conv.weight"] = vae_state_dict.pop(
|
| 511 |
+
f"encoder.down.{i}.downsample.conv.weight"
|
| 512 |
+
)
|
| 513 |
+
new_checkpoint[f"encoder.down_blocks.{i}.downsamplers.0.conv.bias"] = vae_state_dict.pop(
|
| 514 |
+
f"encoder.down.{i}.downsample.conv.bias"
|
| 515 |
+
)
|
| 516 |
+
|
| 517 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 518 |
+
meta_path = {"old": f"down.{i}.block", "new": f"down_blocks.{i}.resnets"}
|
| 519 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 520 |
+
|
| 521 |
+
mid_resnets = [key for key in vae_state_dict if "encoder.mid.block" in key]
|
| 522 |
+
num_mid_res_blocks = 2
|
| 523 |
+
for i in range(1, num_mid_res_blocks + 1):
|
| 524 |
+
resnets = [key for key in mid_resnets if f"encoder.mid.block_{i}" in key]
|
| 525 |
+
|
| 526 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 527 |
+
meta_path = {"old": f"mid.block_{i}", "new": f"mid_block.resnets.{i - 1}"}
|
| 528 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 529 |
+
|
| 530 |
+
mid_attentions = [key for key in vae_state_dict if "encoder.mid.attn" in key]
|
| 531 |
+
paths = renew_vae_attention_paths(mid_attentions)
|
| 532 |
+
meta_path = {"old": "mid.attn_1", "new": "mid_block.attentions.0"}
|
| 533 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 534 |
+
conv_attn_to_linear(new_checkpoint)
|
| 535 |
+
|
| 536 |
+
for i in range(num_up_blocks):
|
| 537 |
+
block_id = num_up_blocks - 1 - i
|
| 538 |
+
resnets = [
|
| 539 |
+
key for key in up_blocks[block_id] if f"up.{block_id}" in key and f"up.{block_id}.upsample" not in key
|
| 540 |
+
]
|
| 541 |
+
|
| 542 |
+
if f"decoder.up.{block_id}.upsample.conv.weight" in vae_state_dict:
|
| 543 |
+
new_checkpoint[f"decoder.up_blocks.{i}.upsamplers.0.conv.weight"] = vae_state_dict[
|
| 544 |
+
f"decoder.up.{block_id}.upsample.conv.weight"
|
| 545 |
+
]
|
| 546 |
+
new_checkpoint[f"decoder.up_blocks.{i}.upsamplers.0.conv.bias"] = vae_state_dict[
|
| 547 |
+
f"decoder.up.{block_id}.upsample.conv.bias"
|
| 548 |
+
]
|
| 549 |
+
|
| 550 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 551 |
+
meta_path = {"old": f"up.{block_id}.block", "new": f"up_blocks.{i}.resnets"}
|
| 552 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 553 |
+
|
| 554 |
+
mid_resnets = [key for key in vae_state_dict if "decoder.mid.block" in key]
|
| 555 |
+
num_mid_res_blocks = 2
|
| 556 |
+
for i in range(1, num_mid_res_blocks + 1):
|
| 557 |
+
resnets = [key for key in mid_resnets if f"decoder.mid.block_{i}" in key]
|
| 558 |
+
|
| 559 |
+
paths = renew_vae_resnet_paths(resnets)
|
| 560 |
+
meta_path = {"old": f"mid.block_{i}", "new": f"mid_block.resnets.{i - 1}"}
|
| 561 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 562 |
+
|
| 563 |
+
mid_attentions = [key for key in vae_state_dict if "decoder.mid.attn" in key]
|
| 564 |
+
paths = renew_vae_attention_paths(mid_attentions)
|
| 565 |
+
meta_path = {"old": "mid.attn_1", "new": "mid_block.attentions.0"}
|
| 566 |
+
assign_to_checkpoint(paths, new_checkpoint, vae_state_dict, additional_replacements=[meta_path], config=config)
|
| 567 |
+
conv_attn_to_linear(new_checkpoint)
|
| 568 |
+
return new_checkpoint
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def convert_ldm_bert_checkpoint(checkpoint, config):
|
| 572 |
+
def _copy_attn_layer(hf_attn_layer, pt_attn_layer):
|
| 573 |
+
hf_attn_layer.q_proj.weight.data = pt_attn_layer.to_q.weight
|
| 574 |
+
hf_attn_layer.k_proj.weight.data = pt_attn_layer.to_k.weight
|
| 575 |
+
hf_attn_layer.v_proj.weight.data = pt_attn_layer.to_v.weight
|
| 576 |
+
|
| 577 |
+
hf_attn_layer.out_proj.weight = pt_attn_layer.to_out.weight
|
| 578 |
+
hf_attn_layer.out_proj.bias = pt_attn_layer.to_out.bias
|
| 579 |
+
|
| 580 |
+
def _copy_linear(hf_linear, pt_linear):
|
| 581 |
+
hf_linear.weight = pt_linear.weight
|
| 582 |
+
hf_linear.bias = pt_linear.bias
|
| 583 |
+
|
| 584 |
+
def _copy_layer(hf_layer, pt_layer):
|
| 585 |
+
# copy layer norms
|
| 586 |
+
_copy_linear(hf_layer.self_attn_layer_norm, pt_layer[0][0])
|
| 587 |
+
_copy_linear(hf_layer.final_layer_norm, pt_layer[1][0])
|
| 588 |
+
|
| 589 |
+
# copy attn
|
| 590 |
+
_copy_attn_layer(hf_layer.self_attn, pt_layer[0][1])
|
| 591 |
+
|
| 592 |
+
# copy MLP
|
| 593 |
+
pt_mlp = pt_layer[1][1]
|
| 594 |
+
_copy_linear(hf_layer.fc1, pt_mlp.net[0][0])
|
| 595 |
+
_copy_linear(hf_layer.fc2, pt_mlp.net[2])
|
| 596 |
+
|
| 597 |
+
def _copy_layers(hf_layers, pt_layers):
|
| 598 |
+
for i, hf_layer in enumerate(hf_layers):
|
| 599 |
+
if i != 0:
|
| 600 |
+
i += i
|
| 601 |
+
pt_layer = pt_layers[i : i + 2]
|
| 602 |
+
_copy_layer(hf_layer, pt_layer)
|
| 603 |
+
|
| 604 |
+
hf_model = LDMBertModel(config).eval()
|
| 605 |
+
|
| 606 |
+
# copy embeds
|
| 607 |
+
hf_model.model.embed_tokens.weight = checkpoint.transformer.token_emb.weight
|
| 608 |
+
hf_model.model.embed_positions.weight.data = checkpoint.transformer.pos_emb.emb.weight
|
| 609 |
+
|
| 610 |
+
# copy layer norm
|
| 611 |
+
_copy_linear(hf_model.model.layer_norm, checkpoint.transformer.norm)
|
| 612 |
+
|
| 613 |
+
# copy hidden layers
|
| 614 |
+
_copy_layers(hf_model.model.layers, checkpoint.transformer.attn_layers.layers)
|
| 615 |
+
|
| 616 |
+
_copy_linear(hf_model.to_logits, checkpoint.transformer.to_logits)
|
| 617 |
+
|
| 618 |
+
return hf_model
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def convert_ldm_clip_checkpoint(checkpoint):
|
| 622 |
+
text_model = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14")
|
| 623 |
+
|
| 624 |
+
keys = list(checkpoint.keys())
|
| 625 |
+
|
| 626 |
+
text_model_dict = {}
|
| 627 |
+
|
| 628 |
+
for key in keys:
|
| 629 |
+
if key.startswith("cond_stage_model.transformer"):
|
| 630 |
+
text_model_dict[key[len("cond_stage_model.transformer.") :]] = checkpoint[key]
|
| 631 |
+
|
| 632 |
+
text_model.load_state_dict(text_model_dict)
|
| 633 |
+
|
| 634 |
+
return text_model
|
| 635 |
+
|
| 636 |
+
|
| 637 |
+
if __name__ == "__main__":
|
| 638 |
+
parser = argparse.ArgumentParser()
|
| 639 |
+
|
| 640 |
+
parser.add_argument(
|
| 641 |
+
"--checkpoint_path", default=None, type=str, required=True, help="Path to the checkpoint to convert."
|
| 642 |
+
)
|
| 643 |
+
# !wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml
|
| 644 |
+
parser.add_argument(
|
| 645 |
+
"--original_config_file",
|
| 646 |
+
default=None,
|
| 647 |
+
type=str,
|
| 648 |
+
help="The YAML config file corresponding to the original architecture.",
|
| 649 |
+
)
|
| 650 |
+
parser.add_argument(
|
| 651 |
+
"--scheduler_type",
|
| 652 |
+
default="pndm",
|
| 653 |
+
type=str,
|
| 654 |
+
help="Type of scheduler to use. Should be one of ['pndm', 'lms', 'ddim', 'euler', 'euler-ancest', 'dpm']",
|
| 655 |
+
)
|
| 656 |
+
parser.add_argument(
|
| 657 |
+
"--extract_ema",
|
| 658 |
+
action="store_true",
|
| 659 |
+
help=(
|
| 660 |
+
"Only relevant for checkpoints that have both EMA and non-EMA weights. Whether to extract the EMA weights"
|
| 661 |
+
" or not. Defaults to `False`. Add `--extract_ema` to extract the EMA weights. EMA weights usually yield"
|
| 662 |
+
" higher quality images for inference. Non-EMA weights are usually better to continue fine-tuning."
|
| 663 |
+
),
|
| 664 |
+
)
|
| 665 |
+
parser.add_argument("--dump_path", default=None, type=str, required=True, help="Path to the output model.")
|
| 666 |
+
|
| 667 |
+
args = parser.parse_args()
|
| 668 |
+
|
| 669 |
+
if args.original_config_file is None:
|
| 670 |
+
os.system(
|
| 671 |
+
"wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
|
| 672 |
+
)
|
| 673 |
+
args.original_config_file = "./v1-inference.yaml"
|
| 674 |
+
|
| 675 |
+
original_config = OmegaConf.load(args.original_config_file)
|
| 676 |
+
|
| 677 |
+
checkpoint = torch.load(args.checkpoint_path)
|
| 678 |
+
checkpoint = checkpoint["state_dict"]
|
| 679 |
+
|
| 680 |
+
num_train_timesteps = original_config.model.params.timesteps
|
| 681 |
+
beta_start = original_config.model.params.linear_start
|
| 682 |
+
beta_end = original_config.model.params.linear_end
|
| 683 |
+
if args.scheduler_type == "pndm":
|
| 684 |
+
scheduler = PNDMScheduler(
|
| 685 |
+
beta_end=beta_end,
|
| 686 |
+
beta_schedule="scaled_linear",
|
| 687 |
+
beta_start=beta_start,
|
| 688 |
+
num_train_timesteps=num_train_timesteps,
|
| 689 |
+
skip_prk_steps=True,
|
| 690 |
+
)
|
| 691 |
+
elif args.scheduler_type == "lms":
|
| 692 |
+
scheduler = LMSDiscreteScheduler(beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear")
|
| 693 |
+
elif args.scheduler_type == "euler":
|
| 694 |
+
scheduler = EulerDiscreteScheduler(beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear")
|
| 695 |
+
elif args.scheduler_type == "euler-ancestral":
|
| 696 |
+
scheduler = EulerAncestralDiscreteScheduler(
|
| 697 |
+
beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear"
|
| 698 |
+
)
|
| 699 |
+
elif args.scheduler_type == "dpm":
|
| 700 |
+
scheduler = DPMSolverMultistepScheduler(
|
| 701 |
+
beta_start=beta_start, beta_end=beta_end, beta_schedule="scaled_linear"
|
| 702 |
+
)
|
| 703 |
+
elif args.scheduler_type == "ddim":
|
| 704 |
+
scheduler = DDIMScheduler(
|
| 705 |
+
beta_start=beta_start,
|
| 706 |
+
beta_end=beta_end,
|
| 707 |
+
beta_schedule="scaled_linear",
|
| 708 |
+
clip_sample=False,
|
| 709 |
+
set_alpha_to_one=False,
|
| 710 |
+
)
|
| 711 |
+
else:
|
| 712 |
+
raise ValueError(f"Scheduler of type {args.scheduler_type} doesn't exist!")
|
| 713 |
+
|
| 714 |
+
# Convert the UNet2DConditionModel model.
|
| 715 |
+
unet_config = create_unet_diffusers_config(original_config)
|
| 716 |
+
converted_unet_checkpoint = convert_ldm_unet_checkpoint(
|
| 717 |
+
checkpoint, unet_config, path=args.checkpoint_path, extract_ema=args.extract_ema
|
| 718 |
+
)
|
| 719 |
+
|
| 720 |
+
unet = UNet2DConditionModel(**unet_config)
|
| 721 |
+
unet.load_state_dict(converted_unet_checkpoint)
|
| 722 |
+
|
| 723 |
+
# Convert the VAE model.
|
| 724 |
+
vae_config = create_vae_diffusers_config(original_config)
|
| 725 |
+
converted_vae_checkpoint = convert_ldm_vae_checkpoint(checkpoint, vae_config)
|
| 726 |
+
|
| 727 |
+
vae = AutoencoderKL(**vae_config)
|
| 728 |
+
vae.load_state_dict(converted_vae_checkpoint)
|
| 729 |
+
|
| 730 |
+
# Convert the text model.
|
| 731 |
+
text_model_type = original_config.model.params.cond_stage_config.target.split(".")[-1]
|
| 732 |
+
if text_model_type == "FrozenCLIPEmbedder":
|
| 733 |
+
text_model = convert_ldm_clip_checkpoint(checkpoint)
|
| 734 |
+
tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14")
|
| 735 |
+
# safety_checker = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
|
| 736 |
+
# feature_extractor = AutoFeatureExtractor.from_pretrained("CompVis/stable-diffusion-safety-checker")
|
| 737 |
+
pipe = StableDiffusionPipeline(
|
| 738 |
+
vae=vae,
|
| 739 |
+
text_encoder=text_model,
|
| 740 |
+
tokenizer=tokenizer,
|
| 741 |
+
unet=unet,
|
| 742 |
+
scheduler=scheduler,
|
| 743 |
+
# safety_checker=safety_checker,
|
| 744 |
+
# feature_extractor=feature_extractor,
|
| 745 |
+
)
|
| 746 |
+
else:
|
| 747 |
+
text_config = create_ldm_bert_config(original_config)
|
| 748 |
+
text_model = convert_ldm_bert_checkpoint(checkpoint, text_config)
|
| 749 |
+
tokenizer = BertTokenizerFast.from_pretrained("bert-base-uncased")
|
| 750 |
+
pipe = LDMTextToImagePipeline(vqvae=vae, bert=text_model, tokenizer=tokenizer, unet=unet, scheduler=scheduler)
|
| 751 |
+
|
| 752 |
+
pipe.save_pretrained(args.dump_path)
|
feature_extractor/preprocessor_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"crop_size": 224,
|
| 3 |
+
"do_center_crop": true,
|
| 4 |
+
"do_convert_rgb": true,
|
| 5 |
+
"do_normalize": true,
|
| 6 |
+
"do_resize": true,
|
| 7 |
+
"feature_extractor_type": "CLIPFeatureExtractor",
|
| 8 |
+
"image_mean": [
|
| 9 |
+
0.48145466,
|
| 10 |
+
0.4578275,
|
| 11 |
+
0.40821073
|
| 12 |
+
],
|
| 13 |
+
"image_std": [
|
| 14 |
+
0.26862954,
|
| 15 |
+
0.26130258,
|
| 16 |
+
0.27577711
|
| 17 |
+
],
|
| 18 |
+
"resample": 3,
|
| 19 |
+
"size": 224
|
| 20 |
+
}
|
kanianime-finetune.ckpt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa2025fbf7e5c7b16b4380a8246b460347b23054fd1e289f37dc43a4afcc7849
|
| 3 |
+
size 4265336982
|
kanianime-finetune/model_index.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "StableDiffusionPipeline",
|
| 3 |
+
"_diffusers_version": "0.9.0",
|
| 4 |
+
"requires_safety_checker": false,
|
| 5 |
+
"scheduler": [
|
| 6 |
+
"diffusers",
|
| 7 |
+
"PNDMScheduler"
|
| 8 |
+
],
|
| 9 |
+
"text_encoder": [
|
| 10 |
+
"transformers",
|
| 11 |
+
"CLIPTextModel"
|
| 12 |
+
],
|
| 13 |
+
"tokenizer": [
|
| 14 |
+
"transformers",
|
| 15 |
+
"CLIPTokenizer"
|
| 16 |
+
],
|
| 17 |
+
"unet": [
|
| 18 |
+
"diffusers",
|
| 19 |
+
"UNet2DConditionModel"
|
| 20 |
+
],
|
| 21 |
+
"vae": [
|
| 22 |
+
"diffusers",
|
| 23 |
+
"AutoencoderKL"
|
| 24 |
+
]
|
| 25 |
+
}
|
kanianime-finetune/scheduler/scheduler_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "PNDMScheduler",
|
| 3 |
+
"_diffusers_version": "0.9.0",
|
| 4 |
+
"beta_end": 0.012,
|
| 5 |
+
"beta_schedule": "scaled_linear",
|
| 6 |
+
"beta_start": 0.00085,
|
| 7 |
+
"num_train_timesteps": 1000,
|
| 8 |
+
"set_alpha_to_one": false,
|
| 9 |
+
"skip_prk_steps": true,
|
| 10 |
+
"steps_offset": 1,
|
| 11 |
+
"trained_betas": null
|
| 12 |
+
}
|
kanianime-finetune/text_encoder/config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "openai/clip-vit-large-patch14",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"CLIPTextModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"dropout": 0.0,
|
| 9 |
+
"eos_token_id": 2,
|
| 10 |
+
"hidden_act": "quick_gelu",
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"initializer_factor": 1.0,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 3072,
|
| 15 |
+
"layer_norm_eps": 1e-05,
|
| 16 |
+
"max_position_embeddings": 77,
|
| 17 |
+
"model_type": "clip_text_model",
|
| 18 |
+
"num_attention_heads": 12,
|
| 19 |
+
"num_hidden_layers": 12,
|
| 20 |
+
"pad_token_id": 1,
|
| 21 |
+
"projection_dim": 768,
|
| 22 |
+
"torch_dtype": "float32",
|
| 23 |
+
"transformers_version": "4.25.1",
|
| 24 |
+
"vocab_size": 49408
|
| 25 |
+
}
|
kanianime-finetune/text_encoder/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:77243d827e922f188b9ae03a9f8aee06191458464dd5d65cd798ff3ba4c5c3e9
|
| 3 |
+
size 492307041
|
kanianime-finetune/tokenizer/merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
kanianime-finetune/tokenizer/special_tokens_map.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<|startoftext|>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": true,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|endoftext|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": true,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": "<|endoftext|>",
|
| 17 |
+
"unk_token": {
|
| 18 |
+
"content": "<|endoftext|>",
|
| 19 |
+
"lstrip": false,
|
| 20 |
+
"normalized": true,
|
| 21 |
+
"rstrip": false,
|
| 22 |
+
"single_word": false
|
| 23 |
+
}
|
| 24 |
+
}
|
kanianime-finetune/tokenizer/tokenizer_config.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"bos_token": {
|
| 4 |
+
"__type": "AddedToken",
|
| 5 |
+
"content": "<|startoftext|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false
|
| 10 |
+
},
|
| 11 |
+
"do_lower_case": true,
|
| 12 |
+
"eos_token": {
|
| 13 |
+
"__type": "AddedToken",
|
| 14 |
+
"content": "<|endoftext|>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": true,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false
|
| 19 |
+
},
|
| 20 |
+
"errors": "replace",
|
| 21 |
+
"model_max_length": 77,
|
| 22 |
+
"name_or_path": "openai/clip-vit-large-patch14",
|
| 23 |
+
"pad_token": "<|endoftext|>",
|
| 24 |
+
"special_tokens_map_file": "./special_tokens_map.json",
|
| 25 |
+
"tokenizer_class": "CLIPTokenizer",
|
| 26 |
+
"unk_token": {
|
| 27 |
+
"__type": "AddedToken",
|
| 28 |
+
"content": "<|endoftext|>",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": true,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false
|
| 33 |
+
}
|
| 34 |
+
}
|
kanianime-finetune/tokenizer/vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
kanianime-finetune/unet/config.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "UNet2DConditionModel",
|
| 3 |
+
"_diffusers_version": "0.9.0",
|
| 4 |
+
"act_fn": "silu",
|
| 5 |
+
"attention_head_dim": 8,
|
| 6 |
+
"block_out_channels": [
|
| 7 |
+
320,
|
| 8 |
+
640,
|
| 9 |
+
1280,
|
| 10 |
+
1280
|
| 11 |
+
],
|
| 12 |
+
"center_input_sample": false,
|
| 13 |
+
"cross_attention_dim": 768,
|
| 14 |
+
"down_block_types": [
|
| 15 |
+
"CrossAttnDownBlock2D",
|
| 16 |
+
"CrossAttnDownBlock2D",
|
| 17 |
+
"CrossAttnDownBlock2D",
|
| 18 |
+
"DownBlock2D"
|
| 19 |
+
],
|
| 20 |
+
"downsample_padding": 1,
|
| 21 |
+
"dual_cross_attention": false,
|
| 22 |
+
"flip_sin_to_cos": true,
|
| 23 |
+
"freq_shift": 0,
|
| 24 |
+
"in_channels": 4,
|
| 25 |
+
"layers_per_block": 2,
|
| 26 |
+
"mid_block_scale_factor": 1,
|
| 27 |
+
"norm_eps": 1e-05,
|
| 28 |
+
"norm_num_groups": 32,
|
| 29 |
+
"num_class_embeds": null,
|
| 30 |
+
"only_cross_attention": false,
|
| 31 |
+
"out_channels": 4,
|
| 32 |
+
"sample_size": 64,
|
| 33 |
+
"up_block_types": [
|
| 34 |
+
"UpBlock2D",
|
| 35 |
+
"CrossAttnUpBlock2D",
|
| 36 |
+
"CrossAttnUpBlock2D",
|
| 37 |
+
"CrossAttnUpBlock2D"
|
| 38 |
+
],
|
| 39 |
+
"use_linear_projection": false
|
| 40 |
+
}
|
kanianime-finetune/unet/diffusion_pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:86141972d0d10031f21e3507819362cf305984c56ebff414587e3447c6c78a92
|
| 3 |
+
size 3438366373
|
kanianime-finetune/vae/config.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "AutoencoderKL",
|
| 3 |
+
"_diffusers_version": "0.9.0",
|
| 4 |
+
"act_fn": "silu",
|
| 5 |
+
"block_out_channels": [
|
| 6 |
+
128,
|
| 7 |
+
256,
|
| 8 |
+
512,
|
| 9 |
+
512
|
| 10 |
+
],
|
| 11 |
+
"down_block_types": [
|
| 12 |
+
"DownEncoderBlock2D",
|
| 13 |
+
"DownEncoderBlock2D",
|
| 14 |
+
"DownEncoderBlock2D",
|
| 15 |
+
"DownEncoderBlock2D"
|
| 16 |
+
],
|
| 17 |
+
"in_channels": 3,
|
| 18 |
+
"latent_channels": 4,
|
| 19 |
+
"layers_per_block": 2,
|
| 20 |
+
"norm_num_groups": 32,
|
| 21 |
+
"out_channels": 3,
|
| 22 |
+
"sample_size": 256,
|
| 23 |
+
"up_block_types": [
|
| 24 |
+
"UpDecoderBlock2D",
|
| 25 |
+
"UpDecoderBlock2D",
|
| 26 |
+
"UpDecoderBlock2D",
|
| 27 |
+
"UpDecoderBlock2D"
|
| 28 |
+
]
|
| 29 |
+
}
|
kanianime-finetune/vae/diffusion_pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:56107d6f7d597295500834d2fb992d008df682ba328afe2ee7a8d64bce931411
|
| 3 |
+
size 334711857
|
model_index.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "StableDiffusionPipeline",
|
| 3 |
+
"_diffusers_version": "0.8.0.dev0",
|
| 4 |
+
"feature_extractor": [
|
| 5 |
+
"transformers",
|
| 6 |
+
"CLIPFeatureExtractor"
|
| 7 |
+
],
|
| 8 |
+
"safety_checker": [
|
| 9 |
+
"stable_diffusion",
|
| 10 |
+
"StableDiffusionSafetyChecker"
|
| 11 |
+
],
|
| 12 |
+
"scheduler": [
|
| 13 |
+
"diffusers",
|
| 14 |
+
"PNDMScheduler"
|
| 15 |
+
],
|
| 16 |
+
"text_encoder": [
|
| 17 |
+
"transformers",
|
| 18 |
+
"CLIPTextModel"
|
| 19 |
+
],
|
| 20 |
+
"tokenizer": [
|
| 21 |
+
"transformers",
|
| 22 |
+
"CLIPTokenizer"
|
| 23 |
+
],
|
| 24 |
+
"unet": [
|
| 25 |
+
"diffusers",
|
| 26 |
+
"UNet2DConditionModel"
|
| 27 |
+
],
|
| 28 |
+
"vae": [
|
| 29 |
+
"diffusers",
|
| 30 |
+
"AutoencoderKL"
|
| 31 |
+
]
|
| 32 |
+
}
|
safety_checker/config.json
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_commit_hash": "4bb648a606ef040e7685bde262611766a5fdd67b",
|
| 3 |
+
"_name_or_path": "CompVis/stable-diffusion-safety-checker",
|
| 4 |
+
"architectures": [
|
| 5 |
+
"StableDiffusionSafetyChecker"
|
| 6 |
+
],
|
| 7 |
+
"initializer_factor": 1.0,
|
| 8 |
+
"logit_scale_init_value": 2.6592,
|
| 9 |
+
"model_type": "clip",
|
| 10 |
+
"projection_dim": 768,
|
| 11 |
+
"text_config": {
|
| 12 |
+
"_name_or_path": "",
|
| 13 |
+
"add_cross_attention": false,
|
| 14 |
+
"architectures": null,
|
| 15 |
+
"attention_dropout": 0.0,
|
| 16 |
+
"bad_words_ids": null,
|
| 17 |
+
"begin_suppress_tokens": null,
|
| 18 |
+
"bos_token_id": 0,
|
| 19 |
+
"chunk_size_feed_forward": 0,
|
| 20 |
+
"cross_attention_hidden_size": null,
|
| 21 |
+
"decoder_start_token_id": null,
|
| 22 |
+
"diversity_penalty": 0.0,
|
| 23 |
+
"do_sample": false,
|
| 24 |
+
"dropout": 0.0,
|
| 25 |
+
"early_stopping": false,
|
| 26 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 27 |
+
"eos_token_id": 2,
|
| 28 |
+
"exponential_decay_length_penalty": null,
|
| 29 |
+
"finetuning_task": null,
|
| 30 |
+
"forced_bos_token_id": null,
|
| 31 |
+
"forced_eos_token_id": null,
|
| 32 |
+
"hidden_act": "quick_gelu",
|
| 33 |
+
"hidden_size": 768,
|
| 34 |
+
"id2label": {
|
| 35 |
+
"0": "LABEL_0",
|
| 36 |
+
"1": "LABEL_1"
|
| 37 |
+
},
|
| 38 |
+
"initializer_factor": 1.0,
|
| 39 |
+
"initializer_range": 0.02,
|
| 40 |
+
"intermediate_size": 3072,
|
| 41 |
+
"is_decoder": false,
|
| 42 |
+
"is_encoder_decoder": false,
|
| 43 |
+
"label2id": {
|
| 44 |
+
"LABEL_0": 0,
|
| 45 |
+
"LABEL_1": 1
|
| 46 |
+
},
|
| 47 |
+
"layer_norm_eps": 1e-05,
|
| 48 |
+
"length_penalty": 1.0,
|
| 49 |
+
"max_length": 20,
|
| 50 |
+
"max_position_embeddings": 77,
|
| 51 |
+
"min_length": 0,
|
| 52 |
+
"model_type": "clip_text_model",
|
| 53 |
+
"no_repeat_ngram_size": 0,
|
| 54 |
+
"num_attention_heads": 12,
|
| 55 |
+
"num_beam_groups": 1,
|
| 56 |
+
"num_beams": 1,
|
| 57 |
+
"num_hidden_layers": 12,
|
| 58 |
+
"num_return_sequences": 1,
|
| 59 |
+
"output_attentions": false,
|
| 60 |
+
"output_hidden_states": false,
|
| 61 |
+
"output_scores": false,
|
| 62 |
+
"pad_token_id": 1,
|
| 63 |
+
"prefix": null,
|
| 64 |
+
"problem_type": null,
|
| 65 |
+
"pruned_heads": {},
|
| 66 |
+
"remove_invalid_values": false,
|
| 67 |
+
"repetition_penalty": 1.0,
|
| 68 |
+
"return_dict": true,
|
| 69 |
+
"return_dict_in_generate": false,
|
| 70 |
+
"sep_token_id": null,
|
| 71 |
+
"suppress_tokens": null,
|
| 72 |
+
"task_specific_params": null,
|
| 73 |
+
"temperature": 1.0,
|
| 74 |
+
"tf_legacy_loss": false,
|
| 75 |
+
"tie_encoder_decoder": false,
|
| 76 |
+
"tie_word_embeddings": true,
|
| 77 |
+
"tokenizer_class": null,
|
| 78 |
+
"top_k": 50,
|
| 79 |
+
"top_p": 1.0,
|
| 80 |
+
"torch_dtype": null,
|
| 81 |
+
"torchscript": false,
|
| 82 |
+
"transformers_version": "4.24.0",
|
| 83 |
+
"typical_p": 1.0,
|
| 84 |
+
"use_bfloat16": false,
|
| 85 |
+
"vocab_size": 49408
|
| 86 |
+
},
|
| 87 |
+
"text_config_dict": {
|
| 88 |
+
"hidden_size": 768,
|
| 89 |
+
"intermediate_size": 3072,
|
| 90 |
+
"num_attention_heads": 12,
|
| 91 |
+
"num_hidden_layers": 12
|
| 92 |
+
},
|
| 93 |
+
"torch_dtype": "float32",
|
| 94 |
+
"transformers_version": null,
|
| 95 |
+
"vision_config": {
|
| 96 |
+
"_name_or_path": "",
|
| 97 |
+
"add_cross_attention": false,
|
| 98 |
+
"architectures": null,
|
| 99 |
+
"attention_dropout": 0.0,
|
| 100 |
+
"bad_words_ids": null,
|
| 101 |
+
"begin_suppress_tokens": null,
|
| 102 |
+
"bos_token_id": null,
|
| 103 |
+
"chunk_size_feed_forward": 0,
|
| 104 |
+
"cross_attention_hidden_size": null,
|
| 105 |
+
"decoder_start_token_id": null,
|
| 106 |
+
"diversity_penalty": 0.0,
|
| 107 |
+
"do_sample": false,
|
| 108 |
+
"dropout": 0.0,
|
| 109 |
+
"early_stopping": false,
|
| 110 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 111 |
+
"eos_token_id": null,
|
| 112 |
+
"exponential_decay_length_penalty": null,
|
| 113 |
+
"finetuning_task": null,
|
| 114 |
+
"forced_bos_token_id": null,
|
| 115 |
+
"forced_eos_token_id": null,
|
| 116 |
+
"hidden_act": "quick_gelu",
|
| 117 |
+
"hidden_size": 1024,
|
| 118 |
+
"id2label": {
|
| 119 |
+
"0": "LABEL_0",
|
| 120 |
+
"1": "LABEL_1"
|
| 121 |
+
},
|
| 122 |
+
"image_size": 224,
|
| 123 |
+
"initializer_factor": 1.0,
|
| 124 |
+
"initializer_range": 0.02,
|
| 125 |
+
"intermediate_size": 4096,
|
| 126 |
+
"is_decoder": false,
|
| 127 |
+
"is_encoder_decoder": false,
|
| 128 |
+
"label2id": {
|
| 129 |
+
"LABEL_0": 0,
|
| 130 |
+
"LABEL_1": 1
|
| 131 |
+
},
|
| 132 |
+
"layer_norm_eps": 1e-05,
|
| 133 |
+
"length_penalty": 1.0,
|
| 134 |
+
"max_length": 20,
|
| 135 |
+
"min_length": 0,
|
| 136 |
+
"model_type": "clip_vision_model",
|
| 137 |
+
"no_repeat_ngram_size": 0,
|
| 138 |
+
"num_attention_heads": 16,
|
| 139 |
+
"num_beam_groups": 1,
|
| 140 |
+
"num_beams": 1,
|
| 141 |
+
"num_channels": 3,
|
| 142 |
+
"num_hidden_layers": 24,
|
| 143 |
+
"num_return_sequences": 1,
|
| 144 |
+
"output_attentions": false,
|
| 145 |
+
"output_hidden_states": false,
|
| 146 |
+
"output_scores": false,
|
| 147 |
+
"pad_token_id": null,
|
| 148 |
+
"patch_size": 14,
|
| 149 |
+
"prefix": null,
|
| 150 |
+
"problem_type": null,
|
| 151 |
+
"pruned_heads": {},
|
| 152 |
+
"remove_invalid_values": false,
|
| 153 |
+
"repetition_penalty": 1.0,
|
| 154 |
+
"return_dict": true,
|
| 155 |
+
"return_dict_in_generate": false,
|
| 156 |
+
"sep_token_id": null,
|
| 157 |
+
"suppress_tokens": null,
|
| 158 |
+
"task_specific_params": null,
|
| 159 |
+
"temperature": 1.0,
|
| 160 |
+
"tf_legacy_loss": false,
|
| 161 |
+
"tie_encoder_decoder": false,
|
| 162 |
+
"tie_word_embeddings": true,
|
| 163 |
+
"tokenizer_class": null,
|
| 164 |
+
"top_k": 50,
|
| 165 |
+
"top_p": 1.0,
|
| 166 |
+
"torch_dtype": null,
|
| 167 |
+
"torchscript": false,
|
| 168 |
+
"transformers_version": "4.24.0",
|
| 169 |
+
"typical_p": 1.0,
|
| 170 |
+
"use_bfloat16": false
|
| 171 |
+
},
|
| 172 |
+
"vision_config_dict": {
|
| 173 |
+
"hidden_size": 1024,
|
| 174 |
+
"intermediate_size": 4096,
|
| 175 |
+
"num_attention_heads": 16,
|
| 176 |
+
"num_hidden_layers": 24,
|
| 177 |
+
"patch_size": 14
|
| 178 |
+
}
|
| 179 |
+
}
|
safety_checker/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:16d28f2b37109f222cdc33620fdd262102ac32112be0352a7f77e9614b35a394
|
| 3 |
+
size 1216064769
|
sample_data/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This directory includes a few sample datasets to get you started.
|
| 2 |
+
|
| 3 |
+
* `california_housing_data*.csv` is California housing data from the 1990 US
|
| 4 |
+
Census; more information is available at:
|
| 5 |
+
https://developers.google.com/machine-learning/crash-course/california-housing-data-description
|
| 6 |
+
|
| 7 |
+
* `mnist_*.csv` is a small sample of the
|
| 8 |
+
[MNIST database](https://en.wikipedia.org/wiki/MNIST_database), which is
|
| 9 |
+
described at: http://yann.lecun.com/exdb/mnist/
|
| 10 |
+
|
| 11 |
+
* `anscombe.json` contains a copy of
|
| 12 |
+
[Anscombe's quartet](https://en.wikipedia.org/wiki/Anscombe%27s_quartet); it
|
| 13 |
+
was originally described in
|
| 14 |
+
|
| 15 |
+
Anscombe, F. J. (1973). 'Graphs in Statistical Analysis'. American
|
| 16 |
+
Statistician. 27 (1): 17-21. JSTOR 2682899.
|
| 17 |
+
|
| 18 |
+
and our copy was prepared by the
|
| 19 |
+
[vega_datasets library](https://github.com/altair-viz/vega_datasets/blob/4f67bdaad10f45e3549984e17e1b3088c731503d/vega_datasets/_data/anscombe.json).
|
sample_data/anscombe.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{"Series":"I", "X":10.0, "Y":8.04},
|
| 3 |
+
{"Series":"I", "X":8.0, "Y":6.95},
|
| 4 |
+
{"Series":"I", "X":13.0, "Y":7.58},
|
| 5 |
+
{"Series":"I", "X":9.0, "Y":8.81},
|
| 6 |
+
{"Series":"I", "X":11.0, "Y":8.33},
|
| 7 |
+
{"Series":"I", "X":14.0, "Y":9.96},
|
| 8 |
+
{"Series":"I", "X":6.0, "Y":7.24},
|
| 9 |
+
{"Series":"I", "X":4.0, "Y":4.26},
|
| 10 |
+
{"Series":"I", "X":12.0, "Y":10.84},
|
| 11 |
+
{"Series":"I", "X":7.0, "Y":4.81},
|
| 12 |
+
{"Series":"I", "X":5.0, "Y":5.68},
|
| 13 |
+
|
| 14 |
+
{"Series":"II", "X":10.0, "Y":9.14},
|
| 15 |
+
{"Series":"II", "X":8.0, "Y":8.14},
|
| 16 |
+
{"Series":"II", "X":13.0, "Y":8.74},
|
| 17 |
+
{"Series":"II", "X":9.0, "Y":8.77},
|
| 18 |
+
{"Series":"II", "X":11.0, "Y":9.26},
|
| 19 |
+
{"Series":"II", "X":14.0, "Y":8.10},
|
| 20 |
+
{"Series":"II", "X":6.0, "Y":6.13},
|
| 21 |
+
{"Series":"II", "X":4.0, "Y":3.10},
|
| 22 |
+
{"Series":"II", "X":12.0, "Y":9.13},
|
| 23 |
+
{"Series":"II", "X":7.0, "Y":7.26},
|
| 24 |
+
{"Series":"II", "X":5.0, "Y":4.74},
|
| 25 |
+
|
| 26 |
+
{"Series":"III", "X":10.0, "Y":7.46},
|
| 27 |
+
{"Series":"III", "X":8.0, "Y":6.77},
|
| 28 |
+
{"Series":"III", "X":13.0, "Y":12.74},
|
| 29 |
+
{"Series":"III", "X":9.0, "Y":7.11},
|
| 30 |
+
{"Series":"III", "X":11.0, "Y":7.81},
|
| 31 |
+
{"Series":"III", "X":14.0, "Y":8.84},
|
| 32 |
+
{"Series":"III", "X":6.0, "Y":6.08},
|
| 33 |
+
{"Series":"III", "X":4.0, "Y":5.39},
|
| 34 |
+
{"Series":"III", "X":12.0, "Y":8.15},
|
| 35 |
+
{"Series":"III", "X":7.0, "Y":6.42},
|
| 36 |
+
{"Series":"III", "X":5.0, "Y":5.73},
|
| 37 |
+
|
| 38 |
+
{"Series":"IV", "X":8.0, "Y":6.58},
|
| 39 |
+
{"Series":"IV", "X":8.0, "Y":5.76},
|
| 40 |
+
{"Series":"IV", "X":8.0, "Y":7.71},
|
| 41 |
+
{"Series":"IV", "X":8.0, "Y":8.84},
|
| 42 |
+
{"Series":"IV", "X":8.0, "Y":8.47},
|
| 43 |
+
{"Series":"IV", "X":8.0, "Y":7.04},
|
| 44 |
+
{"Series":"IV", "X":8.0, "Y":5.25},
|
| 45 |
+
{"Series":"IV", "X":19.0, "Y":12.50},
|
| 46 |
+
{"Series":"IV", "X":8.0, "Y":5.56},
|
| 47 |
+
{"Series":"IV", "X":8.0, "Y":7.91},
|
| 48 |
+
{"Series":"IV", "X":8.0, "Y":6.89}
|
| 49 |
+
]
|
sample_data/california_housing_test.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sample_data/california_housing_train.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sample_data/mnist_test.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:51c292478d94ec3a01461bdfa82eb0885d262eb09e615679b2d69dedb6ad09e7
|
| 3 |
+
size 18289443
|
sample_data/mnist_train_small.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ef64781aa03180f4f5ce504314f058f5d0227277df86060473d973cf43b033e
|
| 3 |
+
size 36523880
|
train_dreambooth.py
ADDED
|
@@ -0,0 +1,695 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import itertools
|
| 3 |
+
import math
|
| 4 |
+
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from typing import Optional
|
| 7 |
+
from contextlib import nullcontext
|
| 8 |
+
from diffusers.pipelines.stable_diffusion import safety_checker
|
| 9 |
+
|
| 10 |
+
import torch
|
| 11 |
+
import torch.nn.functional as F
|
| 12 |
+
import torch.utils.checkpoint
|
| 13 |
+
from torch.utils.data import Dataset
|
| 14 |
+
|
| 15 |
+
from accelerate import Accelerator
|
| 16 |
+
from accelerate.logging import get_logger
|
| 17 |
+
from accelerate.utils import set_seed
|
| 18 |
+
from diffusers import AutoencoderKL, DDPMScheduler, StableDiffusionPipeline, UNet2DConditionModel
|
| 19 |
+
from diffusers.optimization import get_scheduler
|
| 20 |
+
from huggingface_hub import HfFolder, Repository, whoami
|
| 21 |
+
from PIL import Image
|
| 22 |
+
from torchvision import transforms
|
| 23 |
+
from tqdm.auto import tqdm
|
| 24 |
+
from transformers import CLIPTextModel, CLIPTokenizer
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
logger = get_logger(__name__)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def parse_args():
|
| 31 |
+
parser = argparse.ArgumentParser(description="Simple example of a training script.")
|
| 32 |
+
parser.add_argument(
|
| 33 |
+
"--pretrained_model_name_or_path",
|
| 34 |
+
type=str,
|
| 35 |
+
default=None,
|
| 36 |
+
required=True,
|
| 37 |
+
help="Path to pretrained model or model identifier from huggingface.co/models.",
|
| 38 |
+
)
|
| 39 |
+
parser.add_argument(
|
| 40 |
+
"--tokenizer_name",
|
| 41 |
+
type=str,
|
| 42 |
+
default=None,
|
| 43 |
+
help="Pretrained tokenizer name or path if not the same as model_name",
|
| 44 |
+
)
|
| 45 |
+
parser.add_argument(
|
| 46 |
+
"--instance_data_dir",
|
| 47 |
+
type=str,
|
| 48 |
+
default=None,
|
| 49 |
+
required=True,
|
| 50 |
+
help="A folder containing the training data of instance images.",
|
| 51 |
+
)
|
| 52 |
+
parser.add_argument(
|
| 53 |
+
"--class_data_dir",
|
| 54 |
+
type=str,
|
| 55 |
+
default=None,
|
| 56 |
+
required=False,
|
| 57 |
+
help="A folder containing the training data of class images.",
|
| 58 |
+
)
|
| 59 |
+
parser.add_argument(
|
| 60 |
+
"--instance_prompt",
|
| 61 |
+
type=str,
|
| 62 |
+
default=None,
|
| 63 |
+
help="The prompt with identifier specifying the instance",
|
| 64 |
+
)
|
| 65 |
+
parser.add_argument(
|
| 66 |
+
"--class_prompt",
|
| 67 |
+
type=str,
|
| 68 |
+
default=None,
|
| 69 |
+
help="The prompt to specify images in the same class as provided instance images.",
|
| 70 |
+
)
|
| 71 |
+
parser.add_argument(
|
| 72 |
+
"--with_prior_preservation",
|
| 73 |
+
default=False,
|
| 74 |
+
action="store_true",
|
| 75 |
+
help="Flag to add prior preservation loss.",
|
| 76 |
+
)
|
| 77 |
+
parser.add_argument("--prior_loss_weight", type=float, default=1.0, help="The weight of prior preservation loss.")
|
| 78 |
+
parser.add_argument(
|
| 79 |
+
"--num_class_images",
|
| 80 |
+
type=int,
|
| 81 |
+
default=100,
|
| 82 |
+
help=(
|
| 83 |
+
"Minimal class images for prior preservation loss. If not have enough images, additional images will be"
|
| 84 |
+
" sampled with class_prompt."
|
| 85 |
+
),
|
| 86 |
+
)
|
| 87 |
+
parser.add_argument(
|
| 88 |
+
"--output_dir",
|
| 89 |
+
type=str,
|
| 90 |
+
default="text-inversion-model",
|
| 91 |
+
help="The output directory where the model predictions and checkpoints will be written.",
|
| 92 |
+
)
|
| 93 |
+
parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.")
|
| 94 |
+
parser.add_argument(
|
| 95 |
+
"--resolution",
|
| 96 |
+
type=int,
|
| 97 |
+
default=512,
|
| 98 |
+
help=(
|
| 99 |
+
"The resolution for input images, all the images in the train/validation dataset will be resized to this"
|
| 100 |
+
" resolution"
|
| 101 |
+
),
|
| 102 |
+
)
|
| 103 |
+
parser.add_argument(
|
| 104 |
+
"--center_crop", action="store_true", help="Whether to center crop images before resizing to resolution"
|
| 105 |
+
)
|
| 106 |
+
parser.add_argument("--train_text_encoder", action="store_true", help="Whether to train the text encoder")
|
| 107 |
+
parser.add_argument(
|
| 108 |
+
"--train_batch_size", type=int, default=4, help="Batch size (per device) for the training dataloader."
|
| 109 |
+
)
|
| 110 |
+
parser.add_argument(
|
| 111 |
+
"--sample_batch_size", type=int, default=4, help="Batch size (per device) for sampling images."
|
| 112 |
+
)
|
| 113 |
+
parser.add_argument("--num_train_epochs", type=int, default=1)
|
| 114 |
+
parser.add_argument(
|
| 115 |
+
"--max_train_steps",
|
| 116 |
+
type=int,
|
| 117 |
+
default=None,
|
| 118 |
+
help="Total number of training steps to perform. If provided, overrides num_train_epochs.",
|
| 119 |
+
)
|
| 120 |
+
parser.add_argument(
|
| 121 |
+
"--gradient_accumulation_steps",
|
| 122 |
+
type=int,
|
| 123 |
+
default=1,
|
| 124 |
+
help="Number of updates steps to accumulate before performing a backward/update pass.",
|
| 125 |
+
)
|
| 126 |
+
parser.add_argument(
|
| 127 |
+
"--gradient_checkpointing",
|
| 128 |
+
action="store_true",
|
| 129 |
+
help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.",
|
| 130 |
+
)
|
| 131 |
+
parser.add_argument(
|
| 132 |
+
"--learning_rate",
|
| 133 |
+
type=float,
|
| 134 |
+
default=5e-6,
|
| 135 |
+
help="Initial learning rate (after the potential warmup period) to use.",
|
| 136 |
+
)
|
| 137 |
+
parser.add_argument(
|
| 138 |
+
"--scale_lr",
|
| 139 |
+
action="store_true",
|
| 140 |
+
default=False,
|
| 141 |
+
help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.",
|
| 142 |
+
)
|
| 143 |
+
parser.add_argument(
|
| 144 |
+
"--lr_scheduler",
|
| 145 |
+
type=str,
|
| 146 |
+
default="constant",
|
| 147 |
+
help=(
|
| 148 |
+
'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",'
|
| 149 |
+
' "constant", "constant_with_warmup"]'
|
| 150 |
+
),
|
| 151 |
+
)
|
| 152 |
+
parser.add_argument(
|
| 153 |
+
"--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler."
|
| 154 |
+
)
|
| 155 |
+
parser.add_argument(
|
| 156 |
+
"--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes."
|
| 157 |
+
)
|
| 158 |
+
parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.")
|
| 159 |
+
parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.")
|
| 160 |
+
parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.")
|
| 161 |
+
parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer")
|
| 162 |
+
parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.")
|
| 163 |
+
parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.")
|
| 164 |
+
parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.")
|
| 165 |
+
parser.add_argument(
|
| 166 |
+
"--hub_model_id",
|
| 167 |
+
type=str,
|
| 168 |
+
default=None,
|
| 169 |
+
help="The name of the repository to keep in sync with the local `output_dir`.",
|
| 170 |
+
)
|
| 171 |
+
parser.add_argument(
|
| 172 |
+
"--logging_dir",
|
| 173 |
+
type=str,
|
| 174 |
+
default="logs",
|
| 175 |
+
help=(
|
| 176 |
+
"[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to"
|
| 177 |
+
" *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***."
|
| 178 |
+
),
|
| 179 |
+
)
|
| 180 |
+
parser.add_argument("--log_interval", type=int, default=10, help="Log every N steps.")
|
| 181 |
+
parser.add_argument(
|
| 182 |
+
"--mixed_precision",
|
| 183 |
+
type=str,
|
| 184 |
+
default="no",
|
| 185 |
+
choices=["no", "fp16", "bf16"],
|
| 186 |
+
help=(
|
| 187 |
+
"Whether to use mixed precision. Choose"
|
| 188 |
+
"between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >= 1.10."
|
| 189 |
+
"and an Nvidia Ampere GPU."
|
| 190 |
+
),
|
| 191 |
+
)
|
| 192 |
+
parser.add_argument("--not_cache_latents", action="store_true", help="Do not precompute and cache latents from VAE.")
|
| 193 |
+
parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank")
|
| 194 |
+
|
| 195 |
+
args = parser.parse_args()
|
| 196 |
+
env_local_rank = int(os.environ.get("LOCAL_RANK", -1))
|
| 197 |
+
if env_local_rank != -1 and env_local_rank != args.local_rank:
|
| 198 |
+
args.local_rank = env_local_rank
|
| 199 |
+
|
| 200 |
+
if args.instance_data_dir is None:
|
| 201 |
+
raise ValueError("You must specify a train data directory.")
|
| 202 |
+
|
| 203 |
+
if args.with_prior_preservation:
|
| 204 |
+
if args.class_data_dir is None:
|
| 205 |
+
raise ValueError("You must specify a data directory for class images.")
|
| 206 |
+
if args.class_prompt is None:
|
| 207 |
+
raise ValueError("You must specify prompt for class images.")
|
| 208 |
+
|
| 209 |
+
return args
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class DreamBoothDataset(Dataset):
|
| 213 |
+
"""
|
| 214 |
+
A dataset to prepare the instance and class images with the prompts for fine-tuning the model.
|
| 215 |
+
It pre-processes the images and the tokenizes prompts.
|
| 216 |
+
"""
|
| 217 |
+
|
| 218 |
+
def __init__(
|
| 219 |
+
self,
|
| 220 |
+
instance_data_root,
|
| 221 |
+
instance_prompt,
|
| 222 |
+
tokenizer,
|
| 223 |
+
class_data_root=None,
|
| 224 |
+
class_prompt=None,
|
| 225 |
+
size=512,
|
| 226 |
+
center_crop=False,
|
| 227 |
+
):
|
| 228 |
+
self.size = size
|
| 229 |
+
self.center_crop = center_crop
|
| 230 |
+
self.tokenizer = tokenizer
|
| 231 |
+
|
| 232 |
+
self.instance_data_root = Path(instance_data_root)
|
| 233 |
+
if not self.instance_data_root.exists():
|
| 234 |
+
raise ValueError("Instance images root doesn't exists.")
|
| 235 |
+
|
| 236 |
+
self.instance_images_path = [x for x in Path(instance_data_root).iterdir() if x.is_file()]
|
| 237 |
+
self.num_instance_images = len(self.instance_images_path)
|
| 238 |
+
self.instance_prompt = instance_prompt
|
| 239 |
+
self._length = self.num_instance_images
|
| 240 |
+
|
| 241 |
+
if class_data_root is not None:
|
| 242 |
+
self.class_data_root = Path(class_data_root)
|
| 243 |
+
self.class_data_root.mkdir(parents=True, exist_ok=True)
|
| 244 |
+
self.class_images_path = [x for x in self.class_data_root.iterdir() if x.is_file()]
|
| 245 |
+
self.num_class_images = len(self.class_images_path)
|
| 246 |
+
self._length = max(self.num_class_images, self.num_instance_images)
|
| 247 |
+
self.class_prompt = class_prompt
|
| 248 |
+
else:
|
| 249 |
+
self.class_data_root = None
|
| 250 |
+
|
| 251 |
+
self.image_transforms = transforms.Compose(
|
| 252 |
+
[
|
| 253 |
+
transforms.Resize(size, interpolation=transforms.InterpolationMode.BILINEAR),
|
| 254 |
+
transforms.CenterCrop(size) if center_crop else transforms.RandomCrop(size),
|
| 255 |
+
transforms.ToTensor(),
|
| 256 |
+
transforms.Normalize([0.5], [0.5]),
|
| 257 |
+
]
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
def __len__(self):
|
| 261 |
+
return self._length
|
| 262 |
+
|
| 263 |
+
def __getitem__(self, index):
|
| 264 |
+
example = {}
|
| 265 |
+
instance_image = Image.open(self.instance_images_path[index % self.num_instance_images])
|
| 266 |
+
if not instance_image.mode == "RGB":
|
| 267 |
+
instance_image = instance_image.convert("RGB")
|
| 268 |
+
example["instance_images"] = self.image_transforms(instance_image)
|
| 269 |
+
example["instance_prompt_ids"] = self.tokenizer(
|
| 270 |
+
self.instance_prompt,
|
| 271 |
+
padding="do_not_pad",
|
| 272 |
+
truncation=True,
|
| 273 |
+
max_length=self.tokenizer.model_max_length,
|
| 274 |
+
).input_ids
|
| 275 |
+
|
| 276 |
+
if self.class_data_root:
|
| 277 |
+
class_image = Image.open(self.class_images_path[index % self.num_class_images])
|
| 278 |
+
if not class_image.mode == "RGB":
|
| 279 |
+
class_image = class_image.convert("RGB")
|
| 280 |
+
example["class_images"] = self.image_transforms(class_image)
|
| 281 |
+
example["class_prompt_ids"] = self.tokenizer(
|
| 282 |
+
self.class_prompt,
|
| 283 |
+
padding="do_not_pad",
|
| 284 |
+
truncation=True,
|
| 285 |
+
max_length=self.tokenizer.model_max_length,
|
| 286 |
+
).input_ids
|
| 287 |
+
|
| 288 |
+
return example
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
class PromptDataset(Dataset):
|
| 292 |
+
"A simple dataset to prepare the prompts to generate class images on multiple GPUs."
|
| 293 |
+
|
| 294 |
+
def __init__(self, prompt, num_samples):
|
| 295 |
+
self.prompt = prompt
|
| 296 |
+
self.num_samples = num_samples
|
| 297 |
+
|
| 298 |
+
def __len__(self):
|
| 299 |
+
return self.num_samples
|
| 300 |
+
|
| 301 |
+
def __getitem__(self, index):
|
| 302 |
+
example = {}
|
| 303 |
+
example["prompt"] = self.prompt
|
| 304 |
+
example["index"] = index
|
| 305 |
+
return example
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
class LatentsDataset(Dataset):
|
| 309 |
+
def __init__(self, latents_cache, text_encoder_cache):
|
| 310 |
+
self.latents_cache = latents_cache
|
| 311 |
+
self.text_encoder_cache = text_encoder_cache
|
| 312 |
+
|
| 313 |
+
def __len__(self):
|
| 314 |
+
return len(self.latents_cache)
|
| 315 |
+
|
| 316 |
+
def __getitem__(self, index):
|
| 317 |
+
return self.latents_cache[index], self.text_encoder_cache[index]
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
class AverageMeter:
|
| 321 |
+
def __init__(self, name=None):
|
| 322 |
+
self.name = name
|
| 323 |
+
self.reset()
|
| 324 |
+
|
| 325 |
+
def reset(self):
|
| 326 |
+
self.sum = self.count = self.avg = 0
|
| 327 |
+
|
| 328 |
+
def update(self, val, n=1):
|
| 329 |
+
self.sum += val * n
|
| 330 |
+
self.count += n
|
| 331 |
+
self.avg = self.sum / self.count
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
def get_full_repo_name(model_id: str, organization: Optional[str] = None, token: Optional[str] = None):
|
| 335 |
+
if token is None:
|
| 336 |
+
token = HfFolder.get_token()
|
| 337 |
+
if organization is None:
|
| 338 |
+
username = whoami(token)["name"]
|
| 339 |
+
return f"{username}/{model_id}"
|
| 340 |
+
else:
|
| 341 |
+
return f"{organization}/{model_id}"
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def main():
|
| 345 |
+
args = parse_args()
|
| 346 |
+
logging_dir = Path(args.output_dir, args.logging_dir)
|
| 347 |
+
|
| 348 |
+
accelerator = Accelerator(
|
| 349 |
+
gradient_accumulation_steps=args.gradient_accumulation_steps,
|
| 350 |
+
mixed_precision=args.mixed_precision,
|
| 351 |
+
log_with="tensorboard",
|
| 352 |
+
logging_dir=logging_dir,
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
# Currently, it's not possible to do gradient accumulation when training two models with accelerate.accumulate
|
| 356 |
+
# This will be enabled soon in accelerate. For now, we don't allow gradient accumulation when training two models.
|
| 357 |
+
# TODO (patil-suraj): Remove this check when gradient accumulation with two models is enabled in accelerate.
|
| 358 |
+
if args.train_text_encoder and args.gradient_accumulation_steps > 1 and accelerator.num_processes > 1:
|
| 359 |
+
raise ValueError(
|
| 360 |
+
"Gradient accumulation is not supported when training the text encoder in distributed training. "
|
| 361 |
+
"Please set gradient_accumulation_steps to 1. This feature will be supported in the future."
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
if args.seed is not None:
|
| 365 |
+
set_seed(args.seed)
|
| 366 |
+
|
| 367 |
+
if args.with_prior_preservation:
|
| 368 |
+
class_images_dir = Path(args.class_data_dir)
|
| 369 |
+
if not class_images_dir.exists():
|
| 370 |
+
class_images_dir.mkdir(parents=True)
|
| 371 |
+
cur_class_images = len(list(class_images_dir.iterdir()))
|
| 372 |
+
|
| 373 |
+
if cur_class_images < args.num_class_images:
|
| 374 |
+
torch_dtype = torch.float16 if accelerator.device.type == "cuda" else torch.float32
|
| 375 |
+
pipeline = StableDiffusionPipeline.from_pretrained(
|
| 376 |
+
args.pretrained_model_name_or_path, torch_dtype=torch_dtype, use_auth_token=False
|
| 377 |
+
)
|
| 378 |
+
pipeline.set_progress_bar_config(disable=True)
|
| 379 |
+
|
| 380 |
+
num_new_images = args.num_class_images - cur_class_images
|
| 381 |
+
logger.info(f"Number of class images to sample: {num_new_images}.")
|
| 382 |
+
|
| 383 |
+
sample_dataset = PromptDataset(args.class_prompt, num_new_images)
|
| 384 |
+
sample_dataloader = torch.utils.data.DataLoader(sample_dataset, batch_size=args.sample_batch_size)
|
| 385 |
+
|
| 386 |
+
sample_dataloader = accelerator.prepare(sample_dataloader)
|
| 387 |
+
pipeline.to(accelerator.device)
|
| 388 |
+
|
| 389 |
+
with torch.autocast("cuda"), torch.inference_mode():
|
| 390 |
+
for example in tqdm(
|
| 391 |
+
sample_dataloader, desc="Generating class images", disable=not accelerator.is_local_main_process
|
| 392 |
+
):
|
| 393 |
+
images = pipeline(example["prompt"]).images
|
| 394 |
+
|
| 395 |
+
for i, image in enumerate(images):
|
| 396 |
+
image.save(class_images_dir / f"{example['index'][i] + cur_class_images}.jpg")
|
| 397 |
+
|
| 398 |
+
del pipeline
|
| 399 |
+
if torch.cuda.is_available():
|
| 400 |
+
torch.cuda.empty_cache()
|
| 401 |
+
|
| 402 |
+
# Handle the repository creation
|
| 403 |
+
if accelerator.is_main_process:
|
| 404 |
+
if args.push_to_hub:
|
| 405 |
+
if args.hub_model_id is None:
|
| 406 |
+
repo_name = get_full_repo_name(Path(args.output_dir).name, token=args.hub_token)
|
| 407 |
+
else:
|
| 408 |
+
repo_name = args.hub_model_id
|
| 409 |
+
repo = Repository(args.output_dir, clone_from=repo_name)
|
| 410 |
+
|
| 411 |
+
with open(os.path.join(args.output_dir, ".gitignore"), "w+") as gitignore:
|
| 412 |
+
if "step_*" not in gitignore:
|
| 413 |
+
gitignore.write("step_*\n")
|
| 414 |
+
if "epoch_*" not in gitignore:
|
| 415 |
+
gitignore.write("epoch_*\n")
|
| 416 |
+
elif args.output_dir is not None:
|
| 417 |
+
os.makedirs(args.output_dir, exist_ok=True)
|
| 418 |
+
|
| 419 |
+
# Load the tokenizer
|
| 420 |
+
if args.tokenizer_name:
|
| 421 |
+
tokenizer = CLIPTokenizer.from_pretrained(args.tokenizer_name)
|
| 422 |
+
elif args.pretrained_model_name_or_path:
|
| 423 |
+
tokenizer = CLIPTokenizer.from_pretrained(args.pretrained_model_name_or_path, subfolder="tokenizer", use_auth_token=False)
|
| 424 |
+
|
| 425 |
+
# Load models and create wrapper for stable diffusion
|
| 426 |
+
text_encoder = CLIPTextModel.from_pretrained(args.pretrained_model_name_or_path, subfolder="text_encoder", use_auth_token=False)
|
| 427 |
+
vae = AutoencoderKL.from_pretrained(args.pretrained_model_name_or_path, subfolder="vae", use_auth_token=False)
|
| 428 |
+
unet = UNet2DConditionModel.from_pretrained(args.pretrained_model_name_or_path, subfolder="unet", use_auth_token=False)
|
| 429 |
+
|
| 430 |
+
vae.requires_grad_(False)
|
| 431 |
+
if not args.train_text_encoder:
|
| 432 |
+
text_encoder.requires_grad_(False)
|
| 433 |
+
|
| 434 |
+
if args.gradient_checkpointing:
|
| 435 |
+
unet.enable_gradient_checkpointing()
|
| 436 |
+
if args.train_text_encoder:
|
| 437 |
+
text_encoder.gradient_checkpointing_enable()
|
| 438 |
+
|
| 439 |
+
if args.scale_lr:
|
| 440 |
+
args.learning_rate = (
|
| 441 |
+
args.learning_rate * args.gradient_accumulation_steps * args.train_batch_size * accelerator.num_processes
|
| 442 |
+
)
|
| 443 |
+
|
| 444 |
+
# Use 8-bit Adam for lower memory usage or to fine-tune the model in 16GB GPUs
|
| 445 |
+
if args.use_8bit_adam:
|
| 446 |
+
try:
|
| 447 |
+
import bitsandbytes as bnb
|
| 448 |
+
except ImportError:
|
| 449 |
+
raise ImportError(
|
| 450 |
+
"To use 8-bit Adam, please install the bitsandbytes library: `pip install bitsandbytes`."
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
optimizer_class = bnb.optim.AdamW8bit
|
| 454 |
+
else:
|
| 455 |
+
optimizer_class = torch.optim.AdamW
|
| 456 |
+
|
| 457 |
+
params_to_optimize = (
|
| 458 |
+
itertools.chain(unet.parameters(), text_encoder.parameters()) if args.train_text_encoder else unet.parameters()
|
| 459 |
+
)
|
| 460 |
+
optimizer = optimizer_class(
|
| 461 |
+
params_to_optimize,
|
| 462 |
+
lr=args.learning_rate,
|
| 463 |
+
betas=(args.adam_beta1, args.adam_beta2),
|
| 464 |
+
weight_decay=args.adam_weight_decay,
|
| 465 |
+
eps=args.adam_epsilon,
|
| 466 |
+
)
|
| 467 |
+
|
| 468 |
+
noise_scheduler = DDPMScheduler(
|
| 469 |
+
beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000
|
| 470 |
+
)
|
| 471 |
+
|
| 472 |
+
train_dataset = DreamBoothDataset(
|
| 473 |
+
instance_data_root=args.instance_data_dir,
|
| 474 |
+
instance_prompt=args.instance_prompt,
|
| 475 |
+
class_data_root=args.class_data_dir if args.with_prior_preservation else None,
|
| 476 |
+
class_prompt=args.class_prompt,
|
| 477 |
+
tokenizer=tokenizer,
|
| 478 |
+
size=args.resolution,
|
| 479 |
+
center_crop=args.center_crop,
|
| 480 |
+
)
|
| 481 |
+
|
| 482 |
+
def collate_fn(examples):
|
| 483 |
+
input_ids = [example["instance_prompt_ids"] for example in examples]
|
| 484 |
+
pixel_values = [example["instance_images"] for example in examples]
|
| 485 |
+
|
| 486 |
+
# Concat class and instance examples for prior preservation.
|
| 487 |
+
# We do this to avoid doing two forward passes.
|
| 488 |
+
if args.with_prior_preservation:
|
| 489 |
+
input_ids += [example["class_prompt_ids"] for example in examples]
|
| 490 |
+
pixel_values += [example["class_images"] for example in examples]
|
| 491 |
+
|
| 492 |
+
pixel_values = torch.stack(pixel_values)
|
| 493 |
+
pixel_values = pixel_values.to(memory_format=torch.contiguous_format).float()
|
| 494 |
+
|
| 495 |
+
input_ids = tokenizer.pad({"input_ids": input_ids}, padding=True, return_tensors="pt").input_ids
|
| 496 |
+
|
| 497 |
+
batch = {
|
| 498 |
+
"input_ids": input_ids,
|
| 499 |
+
"pixel_values": pixel_values,
|
| 500 |
+
}
|
| 501 |
+
return batch
|
| 502 |
+
|
| 503 |
+
train_dataloader = torch.utils.data.DataLoader(
|
| 504 |
+
train_dataset, batch_size=args.train_batch_size, shuffle=True, collate_fn=collate_fn, pin_memory=True
|
| 505 |
+
)
|
| 506 |
+
|
| 507 |
+
weight_dtype = torch.float32
|
| 508 |
+
if args.mixed_precision == "fp16":
|
| 509 |
+
weight_dtype = torch.float16
|
| 510 |
+
elif args.mixed_precision == "bf16":
|
| 511 |
+
weight_dtype = torch.bfloat16
|
| 512 |
+
|
| 513 |
+
# Move text_encode and vae to gpu.
|
| 514 |
+
# For mixed precision training we cast the text_encoder and vae weights to half-precision
|
| 515 |
+
# as these models are only used for inference, keeping weights in full precision is not required.
|
| 516 |
+
vae.to(accelerator.device, dtype=weight_dtype)
|
| 517 |
+
if not args.train_text_encoder:
|
| 518 |
+
text_encoder.to(accelerator.device, dtype=weight_dtype)
|
| 519 |
+
|
| 520 |
+
if not args.not_cache_latents:
|
| 521 |
+
latents_cache = []
|
| 522 |
+
text_encoder_cache = []
|
| 523 |
+
for batch in tqdm(train_dataloader, desc="Caching latents"):
|
| 524 |
+
with torch.no_grad():
|
| 525 |
+
batch["pixel_values"] = batch["pixel_values"].to(accelerator.device, non_blocking=True, dtype=weight_dtype)
|
| 526 |
+
batch["input_ids"] = batch["input_ids"].to(accelerator.device, non_blocking=True)
|
| 527 |
+
latents_cache.append(vae.encode(batch["pixel_values"]).latent_dist)
|
| 528 |
+
if args.train_text_encoder:
|
| 529 |
+
text_encoder_cache.append(batch["input_ids"])
|
| 530 |
+
else:
|
| 531 |
+
text_encoder_cache.append(text_encoder(batch["input_ids"])[0])
|
| 532 |
+
train_dataset = LatentsDataset(latents_cache, text_encoder_cache)
|
| 533 |
+
train_dataloader = torch.utils.data.DataLoader(train_dataset, batch_size=1, collate_fn=lambda x: x, shuffle=True)
|
| 534 |
+
|
| 535 |
+
del vae
|
| 536 |
+
if not args.train_text_encoder:
|
| 537 |
+
del text_encoder
|
| 538 |
+
if torch.cuda.is_available():
|
| 539 |
+
torch.cuda.empty_cache()
|
| 540 |
+
|
| 541 |
+
# Scheduler and math around the number of training steps.
|
| 542 |
+
overrode_max_train_steps = False
|
| 543 |
+
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
|
| 544 |
+
if args.max_train_steps is None:
|
| 545 |
+
args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch
|
| 546 |
+
overrode_max_train_steps = True
|
| 547 |
+
|
| 548 |
+
lr_scheduler = get_scheduler(
|
| 549 |
+
args.lr_scheduler,
|
| 550 |
+
optimizer=optimizer,
|
| 551 |
+
num_warmup_steps=args.lr_warmup_steps * args.gradient_accumulation_steps,
|
| 552 |
+
num_training_steps=args.max_train_steps * args.gradient_accumulation_steps,
|
| 553 |
+
)
|
| 554 |
+
|
| 555 |
+
if args.train_text_encoder:
|
| 556 |
+
unet, text_encoder, optimizer, train_dataloader, lr_scheduler = accelerator.prepare(
|
| 557 |
+
unet, text_encoder, optimizer, train_dataloader, lr_scheduler
|
| 558 |
+
)
|
| 559 |
+
else:
|
| 560 |
+
unet, optimizer, train_dataloader, lr_scheduler = accelerator.prepare(
|
| 561 |
+
unet, optimizer, train_dataloader, lr_scheduler
|
| 562 |
+
)
|
| 563 |
+
|
| 564 |
+
# We need to recalculate our total training steps as the size of the training dataloader may have changed.
|
| 565 |
+
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
|
| 566 |
+
if overrode_max_train_steps:
|
| 567 |
+
args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch
|
| 568 |
+
# Afterwards we recalculate our number of training epochs
|
| 569 |
+
args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch)
|
| 570 |
+
|
| 571 |
+
# We need to initialize the trackers we use, and also store our configuration.
|
| 572 |
+
# The trackers initializes automatically on the main process.
|
| 573 |
+
if accelerator.is_main_process:
|
| 574 |
+
accelerator.init_trackers("dreambooth", config=vars(args))
|
| 575 |
+
|
| 576 |
+
# Train!
|
| 577 |
+
total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps
|
| 578 |
+
|
| 579 |
+
logger.info("***** Running training *****")
|
| 580 |
+
logger.info(f" Num examples = {len(train_dataset)}")
|
| 581 |
+
logger.info(f" Num batches each epoch = {len(train_dataloader)}")
|
| 582 |
+
logger.info(f" Num Epochs = {args.num_train_epochs}")
|
| 583 |
+
logger.info(f" Instantaneous batch size per device = {args.train_batch_size}")
|
| 584 |
+
logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}")
|
| 585 |
+
logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}")
|
| 586 |
+
logger.info(f" Total optimization steps = {args.max_train_steps}")
|
| 587 |
+
# Only show the progress bar once on each machine.
|
| 588 |
+
progress_bar = tqdm(range(args.max_train_steps), disable=not accelerator.is_local_main_process)
|
| 589 |
+
progress_bar.set_description("Steps")
|
| 590 |
+
global_step = 0
|
| 591 |
+
loss_avg = AverageMeter()
|
| 592 |
+
text_enc_context = nullcontext() if args.train_text_encoder else torch.no_grad()
|
| 593 |
+
for epoch in range(args.num_train_epochs):
|
| 594 |
+
unet.train()
|
| 595 |
+
for step, batch in enumerate(train_dataloader):
|
| 596 |
+
with accelerator.accumulate(unet):
|
| 597 |
+
# Convert images to latent space
|
| 598 |
+
with torch.no_grad():
|
| 599 |
+
if not args.not_cache_latents:
|
| 600 |
+
latent_dist = batch[0][0]
|
| 601 |
+
else:
|
| 602 |
+
latent_dist = vae.encode(batch["pixel_values"].to(dtype=weight_dtype)).latent_dist
|
| 603 |
+
latents = latent_dist.sample() * 0.18215
|
| 604 |
+
|
| 605 |
+
# Sample noise that we'll add to the latents
|
| 606 |
+
noise = torch.randn_like(latents)
|
| 607 |
+
bsz = latents.shape[0]
|
| 608 |
+
# Sample a random timestep for each image
|
| 609 |
+
timesteps = torch.randint(0, noise_scheduler.config.num_train_timesteps, (bsz,), device=latents.device)
|
| 610 |
+
timesteps = timesteps.long()
|
| 611 |
+
|
| 612 |
+
# Add noise to the latents according to the noise magnitude at each timestep
|
| 613 |
+
# (this is the forward diffusion process)
|
| 614 |
+
noisy_latents = noise_scheduler.add_noise(latents, noise, timesteps)
|
| 615 |
+
|
| 616 |
+
# Get the text embedding for conditioning
|
| 617 |
+
with text_enc_context:
|
| 618 |
+
if not args.not_cache_latents:
|
| 619 |
+
if args.train_text_encoder:
|
| 620 |
+
encoder_hidden_states = text_encoder(batch[0][1])[0]
|
| 621 |
+
else:
|
| 622 |
+
encoder_hidden_states = batch[0][1]
|
| 623 |
+
else:
|
| 624 |
+
encoder_hidden_states = text_encoder(batch["input_ids"])[0]
|
| 625 |
+
|
| 626 |
+
# Predict the noise residual
|
| 627 |
+
noise_pred = unet(noisy_latents, timesteps, encoder_hidden_states).sample
|
| 628 |
+
|
| 629 |
+
if args.with_prior_preservation:
|
| 630 |
+
# Chunk the noise and noise_pred into two parts and compute the loss on each part separately.
|
| 631 |
+
noise_pred, noise_pred_prior = torch.chunk(noise_pred, 2, dim=0)
|
| 632 |
+
noise, noise_prior = torch.chunk(noise, 2, dim=0)
|
| 633 |
+
|
| 634 |
+
# Compute instance loss
|
| 635 |
+
loss = F.mse_loss(noise_pred.float(), noise.float(), reduction="none").mean([1, 2, 3]).mean()
|
| 636 |
+
|
| 637 |
+
# Compute prior loss
|
| 638 |
+
prior_loss = F.mse_loss(noise_pred_prior.float(), noise_prior.float(), reduction="mean")
|
| 639 |
+
|
| 640 |
+
# Add the prior loss to the instance loss.
|
| 641 |
+
loss = loss + args.prior_loss_weight * prior_loss
|
| 642 |
+
else:
|
| 643 |
+
loss = F.mse_loss(noise_pred.float(), noise.float(), reduction="mean")
|
| 644 |
+
|
| 645 |
+
accelerator.backward(loss)
|
| 646 |
+
# if accelerator.sync_gradients:
|
| 647 |
+
# params_to_clip = (
|
| 648 |
+
# itertools.chain(unet.parameters(), text_encoder.parameters())
|
| 649 |
+
# if args.train_text_encoder
|
| 650 |
+
# else unet.parameters()
|
| 651 |
+
# )
|
| 652 |
+
# accelerator.clip_grad_norm_(params_to_clip, args.max_grad_norm)
|
| 653 |
+
optimizer.step()
|
| 654 |
+
lr_scheduler.step()
|
| 655 |
+
optimizer.zero_grad(set_to_none=True)
|
| 656 |
+
loss_avg.update(loss.detach_(), bsz)
|
| 657 |
+
|
| 658 |
+
if not global_step % args.log_interval:
|
| 659 |
+
logs = {"loss": loss_avg.avg.item(), "lr": lr_scheduler.get_last_lr()[0]}
|
| 660 |
+
progress_bar.set_postfix(**logs)
|
| 661 |
+
accelerator.log(logs, step=global_step)
|
| 662 |
+
|
| 663 |
+
progress_bar.update(1)
|
| 664 |
+
global_step += 1
|
| 665 |
+
|
| 666 |
+
if global_step >= args.max_train_steps:
|
| 667 |
+
break
|
| 668 |
+
|
| 669 |
+
accelerator.wait_for_everyone()
|
| 670 |
+
|
| 671 |
+
# Create the pipeline using using the trained modules and save it.
|
| 672 |
+
if accelerator.is_main_process:
|
| 673 |
+
if args.train_text_encoder:
|
| 674 |
+
pipeline = StableDiffusionPipeline.from_pretrained(
|
| 675 |
+
args.pretrained_model_name_or_path,
|
| 676 |
+
unet=accelerator.unwrap_model(unet),
|
| 677 |
+
text_encoder=accelerator.unwrap_model(text_encoder),
|
| 678 |
+
use_auth_token=False
|
| 679 |
+
)
|
| 680 |
+
else:
|
| 681 |
+
pipeline = StableDiffusionPipeline.from_pretrained(
|
| 682 |
+
args.pretrained_model_name_or_path,
|
| 683 |
+
unet=accelerator.unwrap_model(unet),
|
| 684 |
+
use_auth_token=False
|
| 685 |
+
)
|
| 686 |
+
pipeline.save_pretrained(args.output_dir)
|
| 687 |
+
|
| 688 |
+
if args.push_to_hub:
|
| 689 |
+
repo.push_to_hub(commit_message="End of training", blocking=False, auto_lfs_prune=True)
|
| 690 |
+
|
| 691 |
+
accelerator.end_training()
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
if __name__ == "__main__":
|
| 695 |
+
main()
|
v1-inference.yaml
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model:
|
| 2 |
+
base_learning_rate: 1.0e-04
|
| 3 |
+
target: ldm.models.diffusion.ddpm.LatentDiffusion
|
| 4 |
+
params:
|
| 5 |
+
linear_start: 0.00085
|
| 6 |
+
linear_end: 0.0120
|
| 7 |
+
num_timesteps_cond: 1
|
| 8 |
+
log_every_t: 200
|
| 9 |
+
timesteps: 1000
|
| 10 |
+
first_stage_key: "jpg"
|
| 11 |
+
cond_stage_key: "txt"
|
| 12 |
+
image_size: 64
|
| 13 |
+
channels: 4
|
| 14 |
+
cond_stage_trainable: false # Note: different from the one we trained before
|
| 15 |
+
conditioning_key: crossattn
|
| 16 |
+
monitor: val/loss_simple_ema
|
| 17 |
+
scale_factor: 0.18215
|
| 18 |
+
use_ema: False
|
| 19 |
+
|
| 20 |
+
scheduler_config: # 10000 warmup steps
|
| 21 |
+
target: ldm.lr_scheduler.LambdaLinearScheduler
|
| 22 |
+
params:
|
| 23 |
+
warm_up_steps: [ 10000 ]
|
| 24 |
+
cycle_lengths: [ 10000000000000 ] # incredibly large number to prevent corner cases
|
| 25 |
+
f_start: [ 1.e-6 ]
|
| 26 |
+
f_max: [ 1. ]
|
| 27 |
+
f_min: [ 1. ]
|
| 28 |
+
|
| 29 |
+
unet_config:
|
| 30 |
+
target: ldm.modules.diffusionmodules.openaimodel.UNetModel
|
| 31 |
+
params:
|
| 32 |
+
image_size: 32 # unused
|
| 33 |
+
in_channels: 4
|
| 34 |
+
out_channels: 4
|
| 35 |
+
model_channels: 320
|
| 36 |
+
attention_resolutions: [ 4, 2, 1 ]
|
| 37 |
+
num_res_blocks: 2
|
| 38 |
+
channel_mult: [ 1, 2, 4, 4 ]
|
| 39 |
+
num_heads: 8
|
| 40 |
+
use_spatial_transformer: True
|
| 41 |
+
transformer_depth: 1
|
| 42 |
+
context_dim: 768
|
| 43 |
+
use_checkpoint: True
|
| 44 |
+
legacy: False
|
| 45 |
+
|
| 46 |
+
first_stage_config:
|
| 47 |
+
target: ldm.models.autoencoder.AutoencoderKL
|
| 48 |
+
params:
|
| 49 |
+
embed_dim: 4
|
| 50 |
+
monitor: val/rec_loss
|
| 51 |
+
ddconfig:
|
| 52 |
+
double_z: true
|
| 53 |
+
z_channels: 4
|
| 54 |
+
resolution: 256
|
| 55 |
+
in_channels: 3
|
| 56 |
+
out_ch: 3
|
| 57 |
+
ch: 128
|
| 58 |
+
ch_mult:
|
| 59 |
+
- 1
|
| 60 |
+
- 2
|
| 61 |
+
- 4
|
| 62 |
+
- 4
|
| 63 |
+
num_res_blocks: 2
|
| 64 |
+
attn_resolutions: []
|
| 65 |
+
dropout: 0.0
|
| 66 |
+
lossconfig:
|
| 67 |
+
target: torch.nn.Identity
|
| 68 |
+
|
| 69 |
+
cond_stage_config:
|
| 70 |
+
target: ldm.modules.encoders.modules.FrozenCLIPEmbedder
|
v1-inference.yaml.1
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model:
|
| 2 |
+
base_learning_rate: 1.0e-04
|
| 3 |
+
target: ldm.models.diffusion.ddpm.LatentDiffusion
|
| 4 |
+
params:
|
| 5 |
+
linear_start: 0.00085
|
| 6 |
+
linear_end: 0.0120
|
| 7 |
+
num_timesteps_cond: 1
|
| 8 |
+
log_every_t: 200
|
| 9 |
+
timesteps: 1000
|
| 10 |
+
first_stage_key: "jpg"
|
| 11 |
+
cond_stage_key: "txt"
|
| 12 |
+
image_size: 64
|
| 13 |
+
channels: 4
|
| 14 |
+
cond_stage_trainable: false # Note: different from the one we trained before
|
| 15 |
+
conditioning_key: crossattn
|
| 16 |
+
monitor: val/loss_simple_ema
|
| 17 |
+
scale_factor: 0.18215
|
| 18 |
+
use_ema: False
|
| 19 |
+
|
| 20 |
+
scheduler_config: # 10000 warmup steps
|
| 21 |
+
target: ldm.lr_scheduler.LambdaLinearScheduler
|
| 22 |
+
params:
|
| 23 |
+
warm_up_steps: [ 10000 ]
|
| 24 |
+
cycle_lengths: [ 10000000000000 ] # incredibly large number to prevent corner cases
|
| 25 |
+
f_start: [ 1.e-6 ]
|
| 26 |
+
f_max: [ 1. ]
|
| 27 |
+
f_min: [ 1. ]
|
| 28 |
+
|
| 29 |
+
unet_config:
|
| 30 |
+
target: ldm.modules.diffusionmodules.openaimodel.UNetModel
|
| 31 |
+
params:
|
| 32 |
+
image_size: 32 # unused
|
| 33 |
+
in_channels: 4
|
| 34 |
+
out_channels: 4
|
| 35 |
+
model_channels: 320
|
| 36 |
+
attention_resolutions: [ 4, 2, 1 ]
|
| 37 |
+
num_res_blocks: 2
|
| 38 |
+
channel_mult: [ 1, 2, 4, 4 ]
|
| 39 |
+
num_heads: 8
|
| 40 |
+
use_spatial_transformer: True
|
| 41 |
+
transformer_depth: 1
|
| 42 |
+
context_dim: 768
|
| 43 |
+
use_checkpoint: True
|
| 44 |
+
legacy: False
|
| 45 |
+
|
| 46 |
+
first_stage_config:
|
| 47 |
+
target: ldm.models.autoencoder.AutoencoderKL
|
| 48 |
+
params:
|
| 49 |
+
embed_dim: 4
|
| 50 |
+
monitor: val/rec_loss
|
| 51 |
+
ddconfig:
|
| 52 |
+
double_z: true
|
| 53 |
+
z_channels: 4
|
| 54 |
+
resolution: 256
|
| 55 |
+
in_channels: 3
|
| 56 |
+
out_ch: 3
|
| 57 |
+
ch: 128
|
| 58 |
+
ch_mult:
|
| 59 |
+
- 1
|
| 60 |
+
- 2
|
| 61 |
+
- 4
|
| 62 |
+
- 4
|
| 63 |
+
num_res_blocks: 2
|
| 64 |
+
attn_resolutions: []
|
| 65 |
+
dropout: 0.0
|
| 66 |
+
lossconfig:
|
| 67 |
+
target: torch.nn.Identity
|
| 68 |
+
|
| 69 |
+
cond_stage_config:
|
| 70 |
+
target: ldm.modules.encoders.modules.FrozenCLIPEmbedder
|