Skip to content

Commit 2a62aad

Browse files
authored
Add docstrings in forward methods of adapter model (huggingface#5253)
* added docstrings in forward methods of T2IAdapter model and FullAdapter model * added docstrings in forward methods of FullAdapterXL and AdapterBlock models * Added docstrings in forward methods of adapter models
1 parent 4f74a5e commit 2a62aad

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/diffusers/models/adapter.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ def __init__(
258258
)
259259

260260
def forward(self, x: torch.Tensor) -> List[torch.Tensor]:
261+
r"""
262+
This function processes the input tensor `x` through the adapter model and returns a list of feature tensors,
263+
each representing information extracted at a different scale from the input.
264+
The length of the list is determined by the number of downsample blocks in the Adapter, as specified
265+
by the `channels` and `num_res_blocks` parameters during initialization.
266+
"""
261267
return self.adapter(x)
262268

263269
@property
@@ -296,6 +302,12 @@ def __init__(
296302
self.total_downscale_factor = downscale_factor * 2 ** (len(channels) - 1)
297303

298304
def forward(self, x: torch.Tensor) -> List[torch.Tensor]:
305+
r"""
306+
This method processes the input tensor `x` through the FullAdapter model and performs operations including
307+
pixel unshuffling, convolution, and a stack of AdapterBlocks. It returns a list of feature tensors, each capturing information
308+
at a different stage of processing within the FullAdapter model. The number of feature tensors in the list is determined
309+
by the number of downsample blocks specified during initialization.
310+
"""
299311
x = self.unshuffle(x)
300312
x = self.conv_in(x)
301313

@@ -338,6 +350,10 @@ def __init__(
338350
self.total_downscale_factor = downscale_factor * 2
339351

340352
def forward(self, x: torch.Tensor) -> List[torch.Tensor]:
353+
r"""
354+
This method takes the tensor x as input and processes it through FullAdapterXL model. It consists of operations
355+
including unshuffling pixels, applying convolution layer and appending each block into list of feature tensors.
356+
"""
341357
x = self.unshuffle(x)
342358
x = self.conv_in(x)
343359

@@ -367,6 +383,11 @@ def __init__(self, in_channels, out_channels, num_res_blocks, down=False):
367383
)
368384

369385
def forward(self, x):
386+
r"""
387+
This method takes tensor x as input and performs operations downsampling and convolutional layers if the
388+
self.downsample and self.in_conv properties of AdapterBlock model are specified. Then it applies a series
389+
of residual blocks to the input tensor.
390+
"""
370391
if self.downsample is not None:
371392
x = self.downsample(x)
372393

@@ -386,6 +407,10 @@ def __init__(self, channels):
386407
self.block2 = nn.Conv2d(channels, channels, kernel_size=1)
387408

388409
def forward(self, x):
410+
r"""
411+
This method takes input tensor x and applies a convolutional layer, ReLU activation,
412+
and another convolutional layer on the input tensor. It returns addition with the input tensor.
413+
"""
389414
h = x
390415
h = self.block1(h)
391416
h = self.act(h)
@@ -425,6 +450,10 @@ def __init__(
425450
self.total_downscale_factor = downscale_factor * (2 ** len(channels))
426451

427452
def forward(self, x):
453+
r"""
454+
This method takes the input tensor x and performs downscaling and appends it in list of feature tensors.
455+
Each feature tensor corresponds to a different level of processing within the LightAdapter.
456+
"""
428457
x = self.unshuffle(x)
429458

430459
features = []
@@ -450,6 +479,10 @@ def __init__(self, in_channels, out_channels, num_res_blocks, down=False):
450479
self.out_conv = nn.Conv2d(mid_channels, out_channels, kernel_size=1)
451480

452481
def forward(self, x):
482+
r"""
483+
This method takes tensor x as input and performs downsampling if required.
484+
Then it applies in convolution layer, a sequence of residual blocks, and out convolutional layer.
485+
"""
453486
if self.downsample is not None:
454487
x = self.downsample(x)
455488

@@ -468,6 +501,10 @@ def __init__(self, channels):
468501
self.block2 = nn.Conv2d(channels, channels, kernel_size=3, padding=1)
469502

470503
def forward(self, x):
504+
r"""
505+
This function takes input tensor x and processes it through one convolutional layer, ReLU activation,
506+
and another convolutional layer and adds it to input tensor.
507+
"""
471508
h = x
472509
h = self.block1(h)
473510
h = self.act(h)

0 commit comments

Comments
 (0)