File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 44
44
context .set_context (ascend_config = {"precision_mode" : "allow_mix_precision" })
45
45
46
46
from mindspore import jit as ms_jit
47
+ from mindnlp import patch
47
48
from mindnlp import transformers
48
49
from mindnlp import dataset
49
50
from mindnlp import evaluate
Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+ import mindspore
3
+ from mindspore import Tensor
4
+
5
+ def infer_value_for_BroadcastTo (x , shape ):
6
+ """Infer value for BroadcastTo op."""
7
+ def none_in_tuple_or_list (x ):
8
+ return isinstance (x , (tuple , list )) and None in x
9
+ if shape is None or none_in_tuple_or_list (shape ) or x is None :
10
+ return None
11
+
12
+ shape = list (shape )
13
+ for idx , s in enumerate (shape ):
14
+ if s == - 1 :
15
+ shape [idx ] = x .shape [idx ]
16
+
17
+ np_data = np .broadcast_to (x .asnumpy (), shape )
18
+ return Tensor (np_data )
19
+
20
+ mindspore .ops .operations .manually_defined .ops_def .infer_value_for_BroadcastTo = infer_value_for_BroadcastTo
You can’t perform that action at this time.
0 commit comments