MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / __init__

Method __init__

codegeex/megatron/model/transformer.py:110–162  ·  view source on GitHub ↗
(self, init_method,
                 output_layer_init_method, layer_number)

Source from the content-addressed store, hash-verified

108 """
109
110 def __init__(self, init_method,
111 output_layer_init_method, layer_number):
112 super(ParallelSelfAttention, self).__init__()
113 args = get_args()
114 self.fp16 = args.fp16
115 self.attention_softmax_in_fp32 = args.attention_softmax_in_fp32
116 self.layer_number = max(1, layer_number)
117
118 # Per attention head and per partition values.
119 world_size = mpu.get_model_parallel_world_size()
120 self.hidden_size_per_partition = mpu.divide(
121 args.hidden_size // 2 if args.compress else args.hidden_size,
122 world_size)
123 self.hidden_size_per_attention_head = mpu.divide(
124 args.hidden_size // 2 if args.compress else args.hidden_size, args.num_attention_heads)
125 self.num_attention_heads_per_partition = mpu.divide(
126 args.num_attention_heads, world_size)
127 if hasattr(args, 'attention_upweight'):
128 self.attention_upweight = args.attention_upweight
129 else:
130 self.attention_upweight = None
131 # Strided linear layer.
132 self.query = mpu.ColumnParallelLinear(
133 args.hidden_size,
134 args.hidden_size // 2 if args.compress else args.hidden_size,
135 gather_output=False,
136 init_method=init_method)
137 self.key = mpu.ColumnParallelLinear(
138 args.hidden_size,
139 args.hidden_size // 2 if args.compress else args.hidden_size,
140 gather_output=False,
141 init_method=init_method)
142 self.value = mpu.ColumnParallelLinear(
143 args.hidden_size,
144 args.hidden_size // 2 if args.compress else args.hidden_size,
145 gather_output=False,
146 init_method=init_method)
147
148 self.norm_factor = math.sqrt(self.hidden_size_per_attention_head)
149 self.softmax = torch.nn.Softmax(dim=-1)
150
151 # Dropout. Note that for a single iteration, this layer will generate
152 # different outputs on different number of parallel partitions but
153 # on average it should not be partition dependent.
154 self.attention_dropout = torch.nn.Dropout(args.attention_dropout)
155
156 # Output.
157 self.dense = mpu.RowParallelLinear(
158 args.hidden_size // 2 if args.compress else args.hidden_size,
159 args.hidden_size,
160 input_is_parallel=True if args.tensor_model_parallel_size > 1 else False,
161 init_method=output_layer_init_method,
162 skip_bias_add=True)
163
164 def forward(
165 self,

Callers

nothing calls this directly

Calls 2

get_argsFunction · 0.90
__init__Method · 0.45

Tested by

no test coverage detected