patrickvonplaten
commited on
Commit
·
d938da0
1
Parent(s):
912b6df
upload new config changer
Browse files- adapt_config.py +28 -46
adapt_config.py
CHANGED
@@ -43,17 +43,22 @@ def is_index_stable_diffusion_like(config_dict):
|
|
43 |
|
44 |
|
45 |
def convert_single(model_id: str, folder: str) -> List["CommitOperationAdd"]:
|
46 |
-
config_file = "
|
47 |
-
os.makedirs(os.path.join(folder, "scheduler"), exist_ok=True)
|
48 |
model_index_file = hf_hub_download(repo_id=model_id, filename="model_index.json")
|
49 |
|
50 |
with open(model_index_file, "r") as f:
|
51 |
index_dict = json.load(f)
|
52 |
-
if
|
53 |
-
print(f"{model_id}
|
54 |
return False, False
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
new_config_file = os.path.join(folder, config_file)
|
59 |
success = convert_file(old_config_file, new_config_file)
|
@@ -72,45 +77,18 @@ def convert_file(
|
|
72 |
with open(old_config, "r") as f:
|
73 |
old_dict = json.load(f)
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
81 |
|
82 |
-
# is_stable_diffusion = "down_block_types" in old_dict and list(old_dict["down_block_types"]) == ["CrossAttnDownBlock2D", "CrossAttnDownBlock2D", "CrossAttnDownBlock2D", "DownBlock2D"]
|
83 |
-
#
|
84 |
-
# is_stable_diffusion_1 = is_stable_diffusion and ("use_linear_projection" not in old_dict or old_dict["use_linear_projection"] is False)
|
85 |
-
# is_stable_diffusion_2 = is_stable_diffusion and ("use_linear_projection" in old_dict and old_dict["use_linear_projection"] is True)
|
86 |
-
#
|
87 |
-
# if not is_stable_diffusion_1 and not is_stable_diffusion_2:
|
88 |
-
# print("No matching config")
|
89 |
-
# return False
|
90 |
-
#
|
91 |
-
# if is_stable_diffusion_1:
|
92 |
-
# if old_dict["sample_size"] == 64:
|
93 |
-
# print("Dict correct")
|
94 |
-
# return False
|
95 |
-
#
|
96 |
-
# print("Correct stable diffusion 1")
|
97 |
-
# old_dict["sample_size"] = 64
|
98 |
-
#
|
99 |
-
# if is_stable_diffusion_2:
|
100 |
-
# if old_dict["sample_size"] == 96:
|
101 |
-
# print("Dict correct")
|
102 |
-
# return False
|
103 |
-
#
|
104 |
-
# print("Correct stable diffusion 2")
|
105 |
-
# old_dict["sample_size"] = 96
|
106 |
-
#
|
107 |
with open(new_config, 'w') as f:
|
108 |
json_str = json.dumps(old_dict, indent=2, sort_keys=True) + "\n"
|
109 |
f.write(json_str)
|
110 |
|
111 |
-
#
|
112 |
-
# return "Stable Diffusion 1" if is_stable_diffusion_1 else "Stable Diffusion 2"
|
113 |
-
|
114 |
return "Stable Diffusion"
|
115 |
|
116 |
|
@@ -126,17 +104,17 @@ def previous_pr(api: "HfApi", model_id: str, pr_title: str) -> Optional["Discuss
|
|
126 |
|
127 |
def convert(api: "HfApi", model_id: str, force: bool = False) -> Optional["CommitInfo"]:
|
128 |
# pr_title = "Correct `sample_size` of {}'s unet to have correct width and height default"
|
129 |
-
pr_title = "
|
130 |
info = api.model_info(model_id)
|
131 |
filenames = set(s.rfilename for s in info.siblings)
|
132 |
|
133 |
-
if "
|
134 |
-
print(f"Model: {model_id} has no
|
135 |
return
|
136 |
|
137 |
-
if "vae/config.json" not in filenames:
|
138 |
-
|
139 |
-
|
140 |
|
141 |
with TemporaryDirectory() as d:
|
142 |
folder = os.path.join(d, repo_folder_name(repo_id=model_id, repo_type="models"))
|
@@ -166,7 +144,11 @@ def convert(api: "HfApi", model_id: str, force: bool = False) -> Optional["Commi
|
|
166 |
# )
|
167 |
contributor = model_id.split("/")[0]
|
168 |
pr_description = (
|
169 |
-
|
|
|
|
|
|
|
|
|
170 |
)
|
171 |
new_pr = api.create_commit(
|
172 |
repo_id=model_id,
|
|
|
43 |
|
44 |
|
45 |
def convert_single(model_id: str, folder: str) -> List["CommitOperationAdd"]:
|
46 |
+
config_file = "model_index.json"
|
47 |
+
# os.makedirs(os.path.join(folder, "scheduler"), exist_ok=True)
|
48 |
model_index_file = hf_hub_download(repo_id=model_id, filename="model_index.json")
|
49 |
|
50 |
with open(model_index_file, "r") as f:
|
51 |
index_dict = json.load(f)
|
52 |
+
if index_dict.get("feature_extractor", None) is None:
|
53 |
+
print(f"{model_id} has no feature extractor")
|
54 |
return False, False
|
55 |
|
56 |
+
if index_dict["feature_extractor"][-1] != "CLIPFeatureExtractor":
|
57 |
+
print(f"{model_id} is not out of date or is not CLIP")
|
58 |
+
return False, False
|
59 |
+
|
60 |
+
# old_config_file = hf_hub_download(repo_id=model_id, filename=config_file)
|
61 |
+
old_config_file = model_index_file
|
62 |
|
63 |
new_config_file = os.path.join(folder, config_file)
|
64 |
success = convert_file(old_config_file, new_config_file)
|
|
|
77 |
with open(old_config, "r") as f:
|
78 |
old_dict = json.load(f)
|
79 |
|
80 |
+
old_dict["feature_extractor"][-1] = "CLIPImageProcessor"
|
81 |
+
# if "clip_sample" not in old_dict:
|
82 |
+
# print("Make scheduler DDIM compatible")
|
83 |
+
# old_dict["clip_sample"] = False
|
84 |
+
# else:
|
85 |
+
# print("No matching config")
|
86 |
+
# return False
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
with open(new_config, 'w') as f:
|
89 |
json_str = json.dumps(old_dict, indent=2, sort_keys=True) + "\n"
|
90 |
f.write(json_str)
|
91 |
|
|
|
|
|
|
|
92 |
return "Stable Diffusion"
|
93 |
|
94 |
|
|
|
104 |
|
105 |
def convert(api: "HfApi", model_id: str, force: bool = False) -> Optional["CommitInfo"]:
|
106 |
# pr_title = "Correct `sample_size` of {}'s unet to have correct width and height default"
|
107 |
+
pr_title = "Fix deprecation warning by changing `CLIPFeatureExtractor` to `CLIPImageProcessor`."
|
108 |
info = api.model_info(model_id)
|
109 |
filenames = set(s.rfilename for s in info.siblings)
|
110 |
|
111 |
+
if "model_index.json" not in filenames:
|
112 |
+
print(f"Model: {model_id} has no model_index.json file to change")
|
113 |
return
|
114 |
|
115 |
+
# if "vae/config.json" not in filenames:
|
116 |
+
# print(f"Model: {model_id} has no 'vae/config.json' file to change")
|
117 |
+
# return
|
118 |
|
119 |
with TemporaryDirectory() as d:
|
120 |
folder = os.path.join(d, repo_folder_name(repo_id=model_id, repo_type="models"))
|
|
|
144 |
# )
|
145 |
contributor = model_id.split("/")[0]
|
146 |
pr_description = (
|
147 |
+
f"Hey {contributor} 👋, \n\n Your model repository seems to contain logic to load a feature extractor that is deprecated, which you should notice by seeing the warning: "
|
148 |
+
"\n\n ```\ntransformers/models/clip/feature_extraction_clip.py:28: FutureWarning: The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. "
|
149 |
+
f"Please use CLIPImageProcessor instead. warnings.warn(\n``` \n\n when running `pipe = DiffusionPipeline.from_pretrained({model_id})`."
|
150 |
+
"This PR makes sure that the warning does not show anymore by replacing `CLIPFeatureExtractor` with `CLIPImageProcessor`. This will certainly not change or break your checkpoint, but only"
|
151 |
+
"make sure that everything is up to date. \n\n Best, the 🧨 Diffusers team."
|
152 |
)
|
153 |
new_pr = api.create_commit(
|
154 |
repo_id=model_id,
|