(self, hidden_size, num_attention_heads,
attention_dropout_prob, output_dropout_prob,
init_method, output_layer_init_method=None, relative_encoding=False,
performer=False, attention_scale=1.0)
| 179 | """ |
| 180 | |
| 181 | def __init__(self, hidden_size, num_attention_heads, |
| 182 | attention_dropout_prob, output_dropout_prob, |
| 183 | init_method, output_layer_init_method=None, relative_encoding=False, |
| 184 | performer=False, attention_scale=1.0): |
| 185 | super(ParallelSelfAttention, self).__init__() |
| 186 | self.performer = performer |
| 187 | # Set output layer initialization if not provided. |
| 188 | if output_layer_init_method is None: |
| 189 | output_layer_init_method = init_method |
| 190 | # Per attention head and per partition values. |
| 191 | world_size = get_model_parallel_world_size() |
| 192 | self.hidden_size_per_partition = divide(hidden_size, world_size) |
| 193 | self.hidden_size_per_attention_head = divide(hidden_size, |
| 194 | num_attention_heads) |
| 195 | self.num_attention_heads_per_partition = divide(num_attention_heads, |
| 196 | world_size) |
| 197 | self.relative_encoding = relative_encoding |
| 198 | self.attention_scale = attention_scale |
| 199 | # Strided linear layer. |
| 200 | self.query_key_value = ColumnParallelLinear(hidden_size, 3 * hidden_size, |
| 201 | stride=3, |
| 202 | gather_output=False, |
| 203 | init_method=init_method) |
| 204 | if relative_encoding: |
| 205 | self.relative = ColumnParallelLinear(hidden_size, hidden_size, gather_output=False, |
| 206 | init_method=init_method) |
| 207 | # Dropout. Note that for a single iteration, this layer will generate |
| 208 | # different outputs on different number of parallel partitions but |
| 209 | # on average it should not be partition dependent. |
| 210 | self.attention_dropout = torch.nn.Dropout(attention_dropout_prob) |
| 211 | |
| 212 | # Output. |
| 213 | self.dense = RowParallelLinear(hidden_size, |
| 214 | hidden_size, |
| 215 | input_is_parallel=True, |
| 216 | init_method=output_layer_init_method) |
| 217 | self.output_dropout = torch.nn.Dropout(output_dropout_prob) |
| 218 | |
| 219 | if deepspeed.checkpointing.is_configured(): |
| 220 | global get_cuda_rng_tracker, checkpoint |
| 221 | get_cuda_rng_tracker = deepspeed.checkpointing.get_cuda_rng_tracker |
| 222 | checkpoint = deepspeed.checkpointing.checkpoint |
| 223 | |
| 224 | def _transpose_for_scores(self, tensor): |
| 225 | """Transpose a 3D tensor [b, s, np*hn] into a 4D tensor with |
nothing calls this directly
no test coverage detected