r""" Args: xs (`torch.Tensor`): (batch, channel, height, width) input images for multiple adapter models concated along dimension 1, `channel` should equal to `num_adapter` * "number of channel of image". adapter_weights (`List[float]`,
(self, xs: torch.Tensor, adapter_weights: Optional[List[float]] = None)
| 74 | self.downscale_factor = first_adapter_downscale_factor |
| 75 | |
| 76 | def forward(self, xs: torch.Tensor, adapter_weights: Optional[List[float]] = None) -> List[torch.Tensor]: |
| 77 | r""" |
| 78 | Args: |
| 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". |
| 82 | 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 | """ |
| 86 | if adapter_weights is None: |
| 87 | adapter_weights = torch.tensor([1 / self.num_adapter] * self.num_adapter) |
| 88 | else: |
| 89 | adapter_weights = torch.tensor(adapter_weights) |
| 90 | |
| 91 | accume_state = None |
| 92 | for x, w, adapter in zip(xs, adapter_weights, self.adapters): |
| 93 | features = adapter(x) |
| 94 | if accume_state is None: |
| 95 | accume_state = features |
| 96 | for i in range(len(accume_state)): |
| 97 | accume_state[i] = w * accume_state[i] |
| 98 | else: |
| 99 | for i in range(len(features)): |
| 100 | accume_state[i] += w * features[i] |
| 101 | return accume_state |
| 102 | |
| 103 | def save_pretrained( |
| 104 | self, |
nothing calls this directly
no outgoing calls
no test coverage detected