MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / updown_options

Method updown_options

diffusers/tests/lora/utils.py:1246–1266  ·  view source on GitHub ↗

Generate every possible combination for how a lora weight dict for the up/down part can be. E.g. 2, {"block_1": 2}, {"block_1": [2,2,2]}, {"block_1": 2, "block_2": [2,2,2]}, ...

(blocks_with_tf, layers_per_block, value)

Source from the content-addressed store, hash-verified

1244 """Tests that any valid combination of lora block scales can be used in pipe.set_adapter"""
1245
1246 def updown_options(blocks_with_tf, layers_per_block, value):
1247 """
1248 Generate every possible combination for how a lora weight dict for the up/down part can be.
1249 E.g. 2, {"block_1": 2}, {"block_1": [2,2,2]}, {"block_1": 2, "block_2": [2,2,2]}, ...
1250 """
1251 num_val = value
1252 list_val = [value] * layers_per_block
1253
1254 node_opts = [None, num_val, list_val]
1255 node_opts_foreach_block = [node_opts] * len(blocks_with_tf)
1256
1257 updown_opts = [num_val]
1258 for nodes in product(*node_opts_foreach_block):
1259 if all(n is None for n in nodes):
1260 continue
1261 opt = {}
1262 for b, n in zip(blocks_with_tf, nodes):
1263 if n is not None:
1264 opt["block_" + str(b)] = n
1265 updown_opts.append(opt)
1266 return updown_opts
1267
1268 def all_possible_dict_opts(unet, value):
1269 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected