mstar.model.components.distributed.linear#
Classes
|
Linear layer with column parallelism. |
|
Packed linear layers with column parallelism. |
|
Linear layers for the attention's QKV transformation. |
|
Linear layer with row parallelism. |
- class mstar.model.components.distributed.linear.ColumnParallelLinear(comm_group, input_size, output_size, bias=False, gather_output=False, skip_bias_add=False, dtype=None)[source]#
Bases:
ModuleLinear layer with column parallelism.
The linear layer is defined as Y = XA + b. A is parallelized along its second dimension as A = [A_1, …, A_p].
- Parameters:
- forward(input_)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mstar.model.components.distributed.linear.MergedColumnParallelLinear(comm_group, input_size, output_sizes, bias=True, gather_output=False, skip_bias_add=False, dtype=None)[source]#
Bases:
ColumnParallelLinearPacked linear layers with column parallelism.
Similar to ColumnParallelLinear, but the weight matrix is concatenated along the output dimension. When the weight matrix is loaded, the different partitions are sharded separately.
- Parameters:
- class mstar.model.components.distributed.linear.QKVParallelLinear(comm_group, hidden_size, head_size, total_num_heads, total_num_kv_heads=None, bias=True, skip_bias_add=False, dtype=None, v_head_size=None)[source]#
Bases:
ColumnParallelLinearLinear layers for the attention’s QKV transformation.
Linear layers for the linear transformation of the query, key, and value vectors in the attention layer. The weight matrix is concatenated along the output dimension. The layer is parallelized along the head dimension. When the number of key/value heads is smaller than the number of query heads (e.g., multi-query/grouped-query attention), the key/value head may be replicated while the query heads are partitioned.
- Parameters:
- weight_loader(param, loaded_weight, loaded_shard_id=None)[source]#
Copy this rank’s q / k / v slice into
paramat the right offset within the merged qkv parameter.loaded_shard_idmust be one of"q","k", or"v". For GQA wheretp_size > total_num_kv_headsthe K / V heads are replicated across ranks (each rank in the same KV-replica group loads the same KV head).
- class mstar.model.components.distributed.linear.RowParallelLinear(comm_group, input_size, output_size, bias=True, input_is_parallel=True, skip_bias_add=False, dtype=None, reduce_results=True)[source]#
Bases:
ModuleLinear layer with row parallelism.
The linear layer is defined as Y = XA + b. A is parallelized along its first dimension and X along its second dimension as:
A_1 |. |- A = | . | X = [X_1, …, X_p]
- . |A_p | - -
- Parameters:
- forward(input_)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.