使用shard接口遇到空指针的报错RuntineError: The pointer [comm_lib_instance_] is null.
收藏回复举报
使用shard接口遇到空指针的报错RuntineError: The pointer [comm_lib_instance_] is null.
发表于2023-09-14 17:38:17
0 查看

1 系统环境

硬件环境(Ascend/GPU/CPU): GPU

MindSpore版本: mindspore=2.0.0rc1

执行模式(PyNative/ Graph):不限

Python版本: Python=3.7.5

操作系统平台: 不限

2 报错信息

2.1 问题描述

在__init__按照如下方法使用shard方法:

self.w_q = nn.Dense(dim,

n_heads * self.head_dim,

has_bias=False)

self.w_q.shard(in_strategy=((parallel_config.data_parallel, 1, 1),),

out_strategy=(None,),

parameter_plan={"self.w_q.weight": (parallel_config.model_parallel, 1)},

device="GPU")

在construct中调用self.w_q时报错:RuntimeError: The pointer[comm_lib_instance_] is null.

2.2 报错信息

在construct中调用self.w_q时报错:RuntimeError: The pointer[comm_lib_instance_] is null.

2.3 脚本代码(代码格式,可上传附件)

import mindspore

from mindspore import nn, ops

from mindspore import numpy as mnp



from model import Test



class ParallelConfig:

def __init_(self, data_parallel=1, model_parallel=1):

self.data_parallel = data_parallel

self.model_parallel = model_parallel

if __name__ ==  “__main__”:

mindspore.set_context(mode=mindspore . PYNATIVE_MODE)

mindspore.set_auto_parallel_context(device_num=2)

mindspore.set_auto_parallel_context(parallel_mode=”auto_parallel”)

mindspore.set_auto_parallel_context(search_mode=”sharding_propagation”)

batch_size = 2

dim = 8

n_heads = 4

input = mnp.ones((batch_size, 16, dim))

Config=ParallelConfig(data_parallel=1, model_parallel=1)

attn = Test(dim=dim, n_heads=n_heads, parallel_config=config)

output = attn(input)

print(output)





import mindspore

from mindspore import nn, ops

from mindspore import numpy as mnp



class Test(nn.Cell):

def _init_(self,

dim=512,

n_layers=8,

n_head=8,

vocab_size=-1, # defined Later by tokenizer

multiple_of=256, # make SWIGLU hidden Layer size muLtipLe of Large power of 2

norm_eps=1e-5,

max_batch_size=32,

max_seq_len=2048,

parallel_config=None,):

super()._init_()

self.n_local_heads = n_heads // 2

self.head_dim = dim // n_heads

self.w_q = nn.Dense( dim, n_heads * self.head_dim, has_bias = False)

self.w_q.shard(in_strategy((parallel_config.data_parallel, 1, 1),),

out_strategy(None,),

parameter_plan{”self.w_q.weight”:(parallel_config.model_parallel,1)},

device=”GPU”)



def construct(self, _x):

bsz, seqien, _ = _x.shape

x_q = self.w_q(_x)

return x_q

3 根因分析

cke_8195.png

4 解决方案

******此处由用户补充******

包含文字方案和最终脚本代码

请将正确的脚本打包并上传附件

我要发帖子