(models, input_dir)
| 960 | weights.pop() |
| 961 | |
| 962 | def load_model_hook(models, input_dir): |
| 963 | while len(models) > 0: |
| 964 | # pop models so that they are not loaded again |
| 965 | model = models.pop() |
| 966 | |
| 967 | if isinstance(model, type(unwrap_model(text_encoder))): |
| 968 | # load transformers style into model |
| 969 | load_model = text_encoder_cls.from_pretrained(input_dir, subfolder="text_encoder") |
| 970 | model.config = load_model.config |
| 971 | else: |
| 972 | # load diffusers style into model |
| 973 | load_model = UNet2DConditionModel.from_pretrained(input_dir, subfolder="unet") |
| 974 | model.register_to_config(**load_model.config) |
| 975 | |
| 976 | model.load_state_dict(load_model.state_dict()) |
| 977 | del load_model |
| 978 | |
| 979 | accelerator.register_save_state_pre_hook(save_model_hook) |
| 980 | accelerator.register_load_state_pre_hook(load_model_hook) |
nothing calls this directly
no test coverage detected