@@ -30,10 +30,10 @@ class MultiAdapter(ModelMixin):
30
30
MultiAdapter is a wrapper model that contains multiple adapter models and merges their outputs according to
31
31
user-assigned weighting.
32
32
33
- This model inherits from [`ModelMixin`]. Check the superclass documentation for the generic methods the library
34
- implements for all the model (such as downloading or saving, etc.)
33
+ This model inherits from [`ModelMixin`]. Check the superclass documentation for common methods such as downloading
34
+ or saving.
35
35
36
- Parameters :
36
+ Args :
37
37
adapters (`List[T2IAdapter]`, *optional*, defaults to None):
38
38
A list of `T2IAdapter` model instances.
39
39
"""
@@ -77,11 +77,13 @@ def forward(self, xs: torch.Tensor, adapter_weights: Optional[List[float]] = Non
77
77
r"""
78
78
Args:
79
79
xs (`torch.Tensor`):
80
- (batch, channel, height, width) input images for multiple adapter models concated along dimension 1,
81
- `channel` should equal to `num_adapter` * "number of channel of image".
80
+ A tensor of shape (batch, channel, height, width) representing input images for multiple adapter
81
+ models, concatenated along dimension 1(channel dimension). The `channel` dimension should be equal to
82
+ `num_adapter` * number of channel per image.
83
+
82
84
adapter_weights (`List[float]`, *optional*, defaults to None):
83
- List of floats representing the weight which will be multiply to each adapter's output before adding
84
- them together.
85
+ A list of floats representing the weights which will be multiplied by each adapter's output before
86
+ summing them together. If `None`, equal weights will be used for all adapters .
85
87
"""
86
88
if adapter_weights is None :
87
89
adapter_weights = torch .tensor ([1 / self .num_adapter ] * self .num_adapter )
@@ -109,24 +111,24 @@ def save_pretrained(
109
111
variant : Optional [str ] = None ,
110
112
):
111
113
"""
112
- Save a model and its configuration file to a directory, so that it can be re-loaded using the
114
+ Save a model and its configuration file to a specified directory, allowing it to be re-loaded with the
113
115
`[`~models.adapter.MultiAdapter.from_pretrained`]` class method.
114
116
115
- Arguments :
117
+ Args :
116
118
save_directory (`str` or `os.PathLike`):
117
- Directory to which to save. Will be created if it doesn't exist.
118
- is_main_process (`bool`, * optional* , defaults to ` True` ):
119
- Whether the process calling this is the main process or not. Useful when in distributed training like
120
- TPUs and need to call this function on all processes. In this case, set `is_main_process=True` only on
121
- the main process to avoid race conditions.
119
+ The directory where the model will be saved. If the directory does not exist, it will be created .
120
+ is_main_process (`bool`, optional, defaults= True):
121
+ Indicates whether current process is the main process or not. Useful for distributed training (e.g.,
122
+ TPUs) and need to call this function on all processes. In this case, set `is_main_process=True` only
123
+ for the main process to avoid race conditions.
122
124
save_function (`Callable`):
123
- The function to use to save the state dictionary. Useful on distributed training like TPUs when one
124
- need to replace `torch.save` by another method. Can be configured with the environment variable
125
- `DIFFUSERS_SAVE_MODE` .
126
- safe_serialization (`bool`, * optional* , defaults to ` True` ):
127
- Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`) .
125
+ Function used to save the state dictionary. Useful for distributed training (e.g., TPUs) to replace
126
+ `torch.save` with another method. Can also be configured using`DIFFUSERS_SAVE_MODE` environment
127
+ variable .
128
+ safe_serialization (`bool`, optional, defaults= True):
129
+ If `True`, save the model using `safetensors`. If `False`, save the model with `pickle`.
128
130
variant (`str`, *optional*):
129
- If specified, weights are saved in the format pytorch_model.<variant>.bin.
131
+ If specified, weights are saved in the format ` pytorch_model.<variant>.bin` .
130
132
"""
131
133
idx = 0
132
134
model_path_to_save = save_directory
@@ -145,19 +147,17 @@ def save_pretrained(
145
147
@classmethod
146
148
def from_pretrained (cls , pretrained_model_path : Optional [Union [str , os .PathLike ]], ** kwargs ):
147
149
r"""
148
- Instantiate a pretrained MultiAdapter model from multiple pre-trained adapter models.
150
+ Instantiate a pretrained ` MultiAdapter` model from multiple pre-trained adapter models.
149
151
150
152
The model is set in evaluation mode by default using `model.eval()` (Dropout modules are deactivated). To train
151
- the model, you should first set it back in training mode with `model.train()`.
153
+ the model, set it back to training mode using `model.train()`.
152
154
153
- The warning *Weights from XXX not initialized from pretrained model* means that the weights of XXX do not come
154
- pretrained with the rest of the model. It is up to you to train those weights with a downstream fine-tuning
155
- task.
155
+ Warnings:
156
+ *Weights from XXX not initialized from pretrained model* means that the weights of XXX are not pretrained
157
+ with the rest of the model. It is up to you to train those weights with a downstream fine-tuning. *Weights
158
+ from XXX not used in YYY* means that the layer XXX is not used by YYY, so those weights are discarded.
156
159
157
- The warning *Weights from XXX not used in YYY* means that the layer XXX is not used by YYY, therefore those
158
- weights are discarded.
159
-
160
- Parameters:
160
+ Args:
161
161
pretrained_model_path (`os.PathLike`):
162
162
A path to a *directory* containing model weights saved using
163
163
[`~diffusers.models.adapter.MultiAdapter.save_pretrained`], e.g., `./my_model_directory/adapter`.
@@ -175,20 +175,20 @@ def from_pretrained(cls, pretrained_model_path: Optional[Union[str, os.PathLike]
175
175
more information about each option see [designing a device
176
176
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
177
177
max_memory (`Dict`, *optional*):
178
- A dictionary device identifier to maximum memory. Will default to the maximum memory available for each
179
- GPU and the available CPU RAM if unset.
178
+ A dictionary mapping device identifiers to their maximum memory. Default to the maximum memory
179
+ available for each GPU and the available CPU RAM if unset.
180
180
low_cpu_mem_usage (`bool`, *optional*, defaults to `True` if torch version >= 1.9.0 else `False`):
181
181
Speed up model loading by not initializing the weights and only loading the pre-trained weights. This
182
182
also tries to not use more than 1x model size in CPU memory (including peak memory) while loading the
183
183
model. This is only supported when torch version >= 1.9.0. If you are using an older version of torch,
184
184
setting this argument to `True` will raise an error.
185
185
variant (`str`, *optional*):
186
- If specified load weights from `variant` filename, *e.g.* pytorch_model.<variant>.bin. `variant` is
187
- ignored when using `from_flax`.
186
+ If specified, load weights from a `variant` file ( *e.g.* pytorch_model.<variant>.bin) . `variant` will
187
+ be ignored when using `from_flax`.
188
188
use_safetensors (`bool`, *optional*, defaults to `None`):
189
- If set to `None`, the `safetensors` weights will be downloaded if they're available **and** if the
190
- `safetensors` library is installed. If set to `True`, the model will be forcibly loaded from
191
- `safetensors` weights. If set to `False`, loading will * not* use `safetensors` .
189
+ If `None`, the `safetensors` weights will be downloaded if available **and** if`safetensors` library is
190
+ installed. If `True`, the model will be forcibly loaded from`safetensors` weights. If `False`,
191
+ `safetensors` is not used .
192
192
"""
193
193
idx = 0
194
194
adapters = []
@@ -223,22 +223,22 @@ class T2IAdapter(ModelMixin, ConfigMixin):
223
223
and
224
224
[AdapterLight](https://github.com/TencentARC/T2I-Adapter/blob/686de4681515662c0ac2ffa07bf5dda83af1038a/ldm/modules/encoders/adapter.py#L235).
225
225
226
- This model inherits from [`ModelMixin`]. Check the superclass documentation for the generic methods the library
227
- implements for all the model (such as downloading or saving, etc.)
226
+ This model inherits from [`ModelMixin`]. Check the superclass documentation for the common methods, such as
227
+ downloading or saving.
228
228
229
- Parameters :
230
- in_channels (`int`, *optional*, defaults to 3 ):
231
- Number of channels of Aapter 's input(*control image*). Set this parameter to 1 if you're using gray scale
232
- image as *control image* .
229
+ Args :
230
+ in_channels (`int`, *optional*, defaults to `3` ):
231
+ The number of channels in the adapter 's input (*control image*). Set it to 1 if you're using a gray scale
232
+ image.
233
233
channels (`List[int]`, *optional*, defaults to `(320, 640, 1280, 1280)`):
234
- The number of channel of each downsample block's output hidden state. The `len(block_out_channels)` will
235
- also determine the number of downsample blocks in the Adapter .
236
- num_res_blocks (`int`, *optional*, defaults to 2 ):
234
+ The number of channels in each downsample block's output hidden state. The `len(block_out_channels)`
235
+ determines the number of downsample blocks in the adapter .
236
+ num_res_blocks (`int`, *optional*, defaults to `2` ):
237
237
Number of ResNet blocks in each downsample block.
238
- downscale_factor (`int`, *optional*, defaults to 8 ):
238
+ downscale_factor (`int`, *optional*, defaults to `8` ):
239
239
A factor that determines the total downscale factor of the Adapter.
240
240
adapter_type (`str`, *optional*, defaults to `full_adapter`):
241
- The type of Adapter to use. Choose either `full_adapter` or `full_adapter_xl` or `light_adapter`.
241
+ Adapter type ( `full_adapter` or `full_adapter_xl` or `light_adapter`) to use .
242
242
"""
243
243
244
244
@register_to_config
@@ -393,15 +393,15 @@ class AdapterBlock(nn.Module):
393
393
An AdapterBlock is a helper model that contains multiple ResNet-like blocks. It is used in the `FullAdapter` and
394
394
`FullAdapterXL` models.
395
395
396
- Parameters :
396
+ Args :
397
397
in_channels (`int`):
398
398
Number of channels of AdapterBlock's input.
399
399
out_channels (`int`):
400
400
Number of channels of AdapterBlock's output.
401
401
num_res_blocks (`int`):
402
402
Number of ResNet blocks in the AdapterBlock.
403
403
down (`bool`, *optional*, defaults to `False`):
404
- Whether to perform downsampling on AdapterBlock's input.
404
+ If `True`, perform downsampling on AdapterBlock's input.
405
405
"""
406
406
407
407
def __init__ (self , in_channels : int , out_channels : int , num_res_blocks : int , down : bool = False ):
@@ -440,7 +440,7 @@ class AdapterResnetBlock(nn.Module):
440
440
r"""
441
441
An `AdapterResnetBlock` is a helper model that implements a ResNet-like block.
442
442
443
- Parameters :
443
+ Args :
444
444
channels (`int`):
445
445
Number of channels of AdapterResnetBlock's input and output.
446
446
"""
@@ -518,15 +518,15 @@ class LightAdapterBlock(nn.Module):
518
518
A `LightAdapterBlock` is a helper model that contains multiple `LightAdapterResnetBlocks`. It is used in the
519
519
`LightAdapter` model.
520
520
521
- Parameters :
521
+ Args :
522
522
in_channels (`int`):
523
523
Number of channels of LightAdapterBlock's input.
524
524
out_channels (`int`):
525
525
Number of channels of LightAdapterBlock's output.
526
526
num_res_blocks (`int`):
527
527
Number of LightAdapterResnetBlocks in the LightAdapterBlock.
528
528
down (`bool`, *optional*, defaults to `False`):
529
- Whether to perform downsampling on LightAdapterBlock's input.
529
+ If `True`, perform downsampling on LightAdapterBlock's input.
530
530
"""
531
531
532
532
def __init__ (self , in_channels : int , out_channels : int , num_res_blocks : int , down : bool = False ):
@@ -561,7 +561,7 @@ class LightAdapterResnetBlock(nn.Module):
561
561
A `LightAdapterResnetBlock` is a helper model that implements a ResNet-like block with a slightly different
562
562
architecture than `AdapterResnetBlock`.
563
563
564
- Parameters :
564
+ Args :
565
565
channels (`int`):
566
566
Number of channels of LightAdapterResnetBlock's input and output.
567
567
"""
0 commit comments