| 150 | |
| 151 | |
| 152 | class SDMotionModelStateDictConverter: |
| 153 | def __init__(self): |
| 154 | pass |
| 155 | |
| 156 | def from_diffusers(self, state_dict): |
| 157 | rename_dict = { |
| 158 | "norm": "norm", |
| 159 | "proj_in": "proj_in", |
| 160 | "transformer_blocks.0.attention_blocks.0.to_q": "transformer_blocks.0.attn1.to_q", |
| 161 | "transformer_blocks.0.attention_blocks.0.to_k": "transformer_blocks.0.attn1.to_k", |
| 162 | "transformer_blocks.0.attention_blocks.0.to_v": "transformer_blocks.0.attn1.to_v", |
| 163 | "transformer_blocks.0.attention_blocks.0.to_out.0": "transformer_blocks.0.attn1.to_out", |
| 164 | "transformer_blocks.0.attention_blocks.0.pos_encoder": "transformer_blocks.0.pe1", |
| 165 | "transformer_blocks.0.attention_blocks.1.to_q": "transformer_blocks.0.attn2.to_q", |
| 166 | "transformer_blocks.0.attention_blocks.1.to_k": "transformer_blocks.0.attn2.to_k", |
| 167 | "transformer_blocks.0.attention_blocks.1.to_v": "transformer_blocks.0.attn2.to_v", |
| 168 | "transformer_blocks.0.attention_blocks.1.to_out.0": "transformer_blocks.0.attn2.to_out", |
| 169 | "transformer_blocks.0.attention_blocks.1.pos_encoder": "transformer_blocks.0.pe2", |
| 170 | "transformer_blocks.0.norms.0": "transformer_blocks.0.norm1", |
| 171 | "transformer_blocks.0.norms.1": "transformer_blocks.0.norm2", |
| 172 | "transformer_blocks.0.ff.net.0.proj": "transformer_blocks.0.act_fn.proj", |
| 173 | "transformer_blocks.0.ff.net.2": "transformer_blocks.0.ff", |
| 174 | "transformer_blocks.0.ff_norm": "transformer_blocks.0.norm3", |
| 175 | "proj_out": "proj_out", |
| 176 | } |
| 177 | name_list = sorted([i for i in state_dict if i.startswith("down_blocks.")]) |
| 178 | name_list += sorted([i for i in state_dict if i.startswith("mid_block.")]) |
| 179 | name_list += sorted([i for i in state_dict if i.startswith("up_blocks.")]) |
| 180 | state_dict_ = {} |
| 181 | last_prefix, module_id = "", -1 |
| 182 | for name in name_list: |
| 183 | names = name.split(".") |
| 184 | prefix_index = names.index("temporal_transformer") + 1 |
| 185 | prefix = ".".join(names[:prefix_index]) |
| 186 | if prefix != last_prefix: |
| 187 | last_prefix = prefix |
| 188 | module_id += 1 |
| 189 | middle_name = ".".join(names[prefix_index:-1]) |
| 190 | suffix = names[-1] |
| 191 | if "pos_encoder" in names: |
| 192 | rename = ".".join(["motion_modules", str(module_id), rename_dict[middle_name]]) |
| 193 | else: |
| 194 | rename = ".".join(["motion_modules", str(module_id), rename_dict[middle_name], suffix]) |
| 195 | state_dict_[rename] = state_dict[name] |
| 196 | return state_dict_ |
| 197 | |
| 198 | def from_civitai(self, state_dict): |
| 199 | return self.from_diffusers(state_dict) |
no outgoing calls
no test coverage detected