算子名称 |
MatmulAllReduce |
---|---|
torch_npu api接口 |
torch_npu.npu_mm_all_reduce_base(x1, x2, group, reduce_op, bias, comm_turn) |
支持的torch_npu版本 |
1.11.0, 2.1.0 |
支持的芯片类型 |
Atlas A2 训练系列产品 |
支持的数据类型 |
float16, bfloat16 |
REG_OP(MatmulAllReduce) .INPUT(x1, TensorType({DT_FLOAT16, DT_BF16})) .INPUT(x2, TensorType({DT_FLOAT16, DT_BF16})) .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_BF16})) .OUTPUT(y, TensorType({DT_FLOAT16, DT_BF16})) .REQUIRED_ATTR(group, String) .ATTR(reduce_op, String, "sum") .ATTR(is_trans_a, Bool, false) .ATTR(is_trans_b, Bool, false) .ATTR(comm_turn, Int, 0) .OP_END_FACTORY_REG(MatmulAllReduce)
npu_mm_all_reduce_base(Tensor self, Tensor x2, string group, *, str reduce_op='sum', Tensor? bias=None, int comm_turn=0) -> Tensor
torch_npu接口中的问号表示这个输入参数是可选的。
import torch.distributed as dist world_size = 8 rank = 8 master_ip = '127.0.0.1' master_port = '50001' m = 64 k = 512 n = 128 input_shape = [m,k] weight_shape = [k,n] torch_npu.npu.set_device(rank) init_method = 'tcp://' init_method += master_ip + ':' + master_port dist.init_process_group(backend="hccl", rank=rank, world_size=world_size, init_method=init_method) if dist.is_available(): from torch.distributed.distributed_c10d import _get_default_group, ReduceOp default_pg = _get_default_group() world_size = torch.distributed.get_world_size(default_pg) if torch.__version__ > '2.0.1': hcomm_info = default_pg._get_backend(torch.device("npu")).get_hccl_comm_name(rank) else: hcomm_info = default_pg.get_hccl_comm_name(rank) weight = torch.randn(weight_shape, dtype=dtype).npu() input = torch.randn(input_shape, dtype=dtype).npu() output = torch.matmul(input, weight) dist.all_reduce(output,op=ReduceOp.SUM)
output = torch_npu.npu_mm_all_reduce_base(input, weight, hcomm_info, reduce_op="sum", comm_turn=0)
MatMul/hcom_allReduce
当前仅支持Atlas A2 训练系列产品TP切分场景
GPT3 65B
x1: S = 1 ~ 8192,{S,1024}, BF16/FP16
x2: {1024,8192}, BF16/FP16
bias: {8192}
x1: S = 1 ~ 8192,{S,2732}, BF16/FP16
x2: {2732,8192}, BF16/FP16
bias: {8192}
x1: B = 1 ~ 24,{B,1024}, BF16/FP16
x2: {1024,8192}, BF16/FP16
bias: {8192}
x1: B = 1 ~ 24,{B,2732}, BF16/FP16
x2: {2732,8192}, BF16/FP16
bias: {8192}