@@ -140,13 +140,17 @@ def examine_pickle(fb0, return_special=False):
140140 ## 3: this massive line also assigns values to keys, but does so differently
141141 ## _var2262.update({ 'cond_stage_model.transformer.text_model.encoder.layers.3.layer_norm2.bias': _var2001, [ .... and on and on ]})
142142 ##
143+ ## 4: in some pruned models, the last line is instead a combination of 2/3 into the final variable:
144+ ## result = {'model.diffusion_model.input_blocks.0.0.weight': _var1, 'model.diffusion_model.input_blocks.0.0.bias': _var3, }
145+ ##
143146 ## that's it
144147
145148 # make some REs to match the above.
146149 re_rebuild = re .compile ('^_var\d+ = _rebuild_tensor_v2\(UNPICKLER\.persistent_load\(\(.*\)$' )
147150 re_assign = re .compile ('^_var\d+ = \{.*\}$' )
148151 re_update = re .compile ('^_var\d+\.update\(\{.*\}\)$' )
149152 re_ordered_dict = re .compile ('^_var\d+ = OrderedDict\(\)$' )
153+ re_result = re .compile ('^result = \{.*\}$' )
150154
151155 load_instructions = {}
152156 assign_instructions = AssignInstructions ()
@@ -157,7 +161,7 @@ def examine_pickle(fb0, return_special=False):
157161 if re_rebuild .match (line ):
158162 variable_name , load_instruction = line .split (' = ' , 1 )
159163 load_instructions [variable_name ] = LoadInstruction (line , variable_name )
160- elif re_assign .match (line ):
164+ elif re_assign .match (line ) or re_result . match ( line ) :
161165 assign_instructions .parse_assign_line (line )
162166 elif re_update .match (line ):
163167 assign_instructions .parse_update_line (line )
@@ -184,11 +188,34 @@ def __init__(self, collect_special=False):
184188 self .integrated_instructions = {}
185189 self .collect_special = collect_special ;
186190
191+ def parse_result_line (self , line ):
192+ garbage , huge_mess = line .split (' = {' , 1 )
193+ assignments = huge_mess .split (', ' )
194+ del huge_mess
195+ assignments [- 1 ] = assignments [- 1 ].strip ('}' )
196+
197+ #compile RE here to avoid doing it every loop iteration:
198+ re_var = re .compile ('^_var\d+$' )
199+
200+ assignment_count = 0
201+ for a in assignments :
202+ if self ._add_assignment (a , re_var ):
203+ assignment_count = assignment_count + 1
204+ if NO_PICKLE_DEBUG :
205+ print (f"Added/merged { assignment_count } assignments. Total of { len (self .instructions )} assignment instructions" )
206+
187207 def parse_assign_line (self , line ):
188208 # input looks like this:
189209 # _var2262 = {'model.diffusion_model.input_blocks.0.0.weight': _var1, 'model.diffusion_model.input_blocks.0.0.bias': _var3,\
190210 # ...\
191211 # 'cond_stage_model.transformer.text_model.encoder.layers.3.layer_norm2.weight': _var1999}
212+
213+ # input looks like the above, but with 'result' in place of _var2262:
214+ # result = {'model.diffusion_model.input_blocks.0.0.weight': _var1, ... }
215+ #
216+ # or also look like:
217+ # result = {'state_dict': _var2314}
218+ # ... which will be ignored later
192219 garbage , huge_mess = line .split (' = {' , 1 )
193220 assignments = huge_mess .split (', ' )
194221 del huge_mess
@@ -211,7 +238,7 @@ def _add_assignment(self, assignment, re_var):
211238 # 'embedding_manager.embedder.transformer.text_model.encoder.layers.6.mlp.fc1': {'version': 1}
212239 sd_key , fickling_var = assignment .split (': ' , 1 )
213240 sd_key = sd_key .strip ("'" )
214- if re_var .match (fickling_var ):
241+ if sd_key != 'state_dict' and re_var .match (fickling_var ):
215242 self .instructions [sd_key ] = fickling_var
216243 return True
217244 elif self .collect_special :
@@ -225,7 +252,8 @@ def _add_assignment(self, assignment, re_var):
225252 v = v .strip ("'" )
226253 special_dict [k ] = v
227254 self .special_instructions [sd_key ] = special_dict
228- return False
255+
256+ return False
229257
230258 def integrate (self , load_instructions ):
231259 unfound_keys = {}
0 commit comments