MCPcopy Index your code
hub / github.com/huggingface/diffusers / run

Method run

src/diffusers/commands/custom_blocks.py:61–91  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

59 self.block_class_name = block_class_name
60
61 def run(self):
62 # determine the block to be saved.
63 out = self._get_class_names(self.block_module_name)
64 classes_found = list({cls for cls, _ in out})
65
66 if self.block_class_name is not None:
67 child_class, parent_class = self._choose_block(out, self.block_class_name)
68 if child_class is None and parent_class is None:
69 raise ValueError(
70 "`block_class_name` could not be retrieved. Available classes from "
71 f"{self.block_module_name}:\n{classes_found}"
72 )
73 else:
74 self.logger.info(
75 f"Found classes: {classes_found} will be using {classes_found[0]}. "
76 "If this needs to be changed, re-run the command specifying `block_class_name`."
77 )
78 child_class, parent_class = out[0][0], out[0][1]
79
80 # dynamically get the custom block and initialize it to call `save_pretrained` in the current directory.
81 # the user is responsible for running it, so I guess that is safe?
82 module_name = f"__dynamic__{self.block_module_name.stem}"
83 spec = importlib.util.spec_from_file_location(module_name, str(self.block_module_name))
84 module = importlib.util.module_from_spec(spec)
85 spec.loader.exec_module(module)
86 getattr(module, child_class)().save_pretrained(os.getcwd())
87
88 # or, we could create it manually.
89 # automap = self._create_automap(parent_class=parent_class, child_class=child_class)
90 # with open(CONFIG, "w") as f:
91 # json.dump(automap, f)
92
93 def _choose_block(self, candidates, chosen=None):
94 for cls, base in candidates:

Callers

nothing calls this directly

Calls 4

_get_class_namesMethod · 0.95
_choose_blockMethod · 0.95
infoMethod · 0.80
save_pretrainedMethod · 0.45

Tested by

no test coverage detected