From e350f311a5915aa15caebc9cf1f142674c448ba9 Mon Sep 17 00:00:00 2001 From: Nandika-A Date: Sun, 1 Oct 2023 12:16:19 +0530 Subject: [PATCH 1/3] added docstrings in forward methods of T2IAdapter model and FullAdapter model --- src/diffusers/models/adapter.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/diffusers/models/adapter.py b/src/diffusers/models/adapter.py index a5e7d0af92d1..ebe69931bd2c 100644 --- a/src/diffusers/models/adapter.py +++ b/src/diffusers/models/adapter.py @@ -258,6 +258,12 @@ def __init__( ) def forward(self, x: torch.Tensor) -> List[torch.Tensor]: + r""" + This function processes the input tensor `x` through the adapter model and returns a list of feature tensors, + each representing information extracted at a different scale from the input. + The length of the list is determined by the number of downsample blocks in the Adapter, as specified + by the `channels` and `num_res_blocks` parameters during initialization. + """ return self.adapter(x) @property @@ -296,6 +302,12 @@ def __init__( self.total_downscale_factor = downscale_factor * 2 ** (len(channels) - 1) def forward(self, x: torch.Tensor) -> List[torch.Tensor]: + r""" + This function processes the input tensor `x` through the FullAdapter model and performs operations including + pixel unshuffling, convolution, and a stack of AdapterBlocks. It returns a list of feature tensors, each capturing information at a different stage of processing within + the FullAdapter model. The number of feature tensors in the list is determined by the number of downsample blocks + specified during initialization. + """ x = self.unshuffle(x) x = self.conv_in(x) From 1b861cc069dccb789f8bfbe9759b5b0610df1d6c Mon Sep 17 00:00:00 2001 From: Nandika-A Date: Sun, 1 Oct 2023 12:37:30 +0530 Subject: [PATCH 2/3] added docstrings in forward methods of FullAdapterXL and AdapterBlock models --- src/diffusers/models/adapter.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/diffusers/models/adapter.py b/src/diffusers/models/adapter.py index ebe69931bd2c..200af364dc4b 100644 --- a/src/diffusers/models/adapter.py +++ b/src/diffusers/models/adapter.py @@ -303,7 +303,7 @@ def __init__( def forward(self, x: torch.Tensor) -> List[torch.Tensor]: r""" - This function processes the input tensor `x` through the FullAdapter model and performs operations including + This method processes the input tensor `x` through the FullAdapter model and performs operations including pixel unshuffling, convolution, and a stack of AdapterBlocks. It returns a list of feature tensors, each capturing information at a different stage of processing within the FullAdapter model. The number of feature tensors in the list is determined by the number of downsample blocks specified during initialization. @@ -350,6 +350,11 @@ def __init__( self.total_downscale_factor = downscale_factor * 2 def forward(self, x: torch.Tensor) -> List[torch.Tensor]: + r""" + This method takes the tensor x as input and processes it through FullAdapterXL model. FullAdapterXL + extracts extra-large (XL) features from the input image. It consists of multiple blocks, each responsible for + processing and downsampling the input. The feature tensors in the list correspond to the output of each processing block. + """ x = self.unshuffle(x) x = self.conv_in(x) @@ -379,6 +384,11 @@ def __init__(self, in_channels, out_channels, num_res_blocks, down=False): ) def forward(self, x): + r""" + This method takes tensor x as input and performs operations downsampling and convolutional layers if the + self.downsample and self.in_conv properties of AdapterBlock model are specified. Then it applies a series + of residual blocks to the input tensor. + """ if self.downsample is not None: x = self.downsample(x) From a62e3c0a12dec30012bac41b1d602e624af4caab Mon Sep 17 00:00:00 2001 From: Nandika-A Date: Sun, 1 Oct 2023 13:02:28 +0530 Subject: [PATCH 3/3] Added docstrings in forward methods of adapter models --- src/diffusers/models/adapter.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/diffusers/models/adapter.py b/src/diffusers/models/adapter.py index 200af364dc4b..d3a992f3b2bc 100644 --- a/src/diffusers/models/adapter.py +++ b/src/diffusers/models/adapter.py @@ -304,9 +304,9 @@ def __init__( def forward(self, x: torch.Tensor) -> List[torch.Tensor]: r""" This method processes the input tensor `x` through the FullAdapter model and performs operations including - pixel unshuffling, convolution, and a stack of AdapterBlocks. It returns a list of feature tensors, each capturing information at a different stage of processing within - the FullAdapter model. The number of feature tensors in the list is determined by the number of downsample blocks - specified during initialization. + pixel unshuffling, convolution, and a stack of AdapterBlocks. It returns a list of feature tensors, each capturing information + at a different stage of processing within the FullAdapter model. The number of feature tensors in the list is determined + by the number of downsample blocks specified during initialization. """ x = self.unshuffle(x) x = self.conv_in(x) @@ -351,9 +351,8 @@ def __init__( def forward(self, x: torch.Tensor) -> List[torch.Tensor]: r""" - This method takes the tensor x as input and processes it through FullAdapterXL model. FullAdapterXL - extracts extra-large (XL) features from the input image. It consists of multiple blocks, each responsible for - processing and downsampling the input. The feature tensors in the list correspond to the output of each processing block. + This method takes the tensor x as input and processes it through FullAdapterXL model. It consists of operations + including unshuffling pixels, applying convolution layer and appending each block into list of feature tensors. """ x = self.unshuffle(x) x = self.conv_in(x) @@ -408,6 +407,10 @@ def __init__(self, channels): self.block2 = nn.Conv2d(channels, channels, kernel_size=1) def forward(self, x): + r""" + This method takes input tensor x and applies a convolutional layer, ReLU activation, + and another convolutional layer on the input tensor. It returns addition with the input tensor. + """ h = x h = self.block1(h) h = self.act(h) @@ -447,6 +450,10 @@ def __init__( self.total_downscale_factor = downscale_factor * (2 ** len(channels)) def forward(self, x): + r""" + This method takes the input tensor x and performs downscaling and appends it in list of feature tensors. + Each feature tensor corresponds to a different level of processing within the LightAdapter. + """ x = self.unshuffle(x) features = [] @@ -472,6 +479,10 @@ def __init__(self, in_channels, out_channels, num_res_blocks, down=False): self.out_conv = nn.Conv2d(mid_channels, out_channels, kernel_size=1) def forward(self, x): + r""" + This method takes tensor x as input and performs downsampling if required. + Then it applies in convolution layer, a sequence of residual blocks, and out convolutional layer. + """ if self.downsample is not None: x = self.downsample(x) @@ -490,6 +501,10 @@ def __init__(self, channels): self.block2 = nn.Conv2d(channels, channels, kernel_size=3, padding=1) def forward(self, x): + r""" + This function takes input tensor x and processes it through one convolutional layer, ReLU activation, + and another convolutional layer and adds it to input tensor. + """ h = x h = self.block1(h) h = self.act(h)