(builder, node, graph, err)
convert to CoreML BatchedMatMul Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L3473
convert to CoreML BatchedMatMul Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L3473
convert to CoreML BatchedMatMul Layer : https : // github . com / apple / coremltools / blob / 655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492 / mlmodel / format / NeuralNetwork . proto#L3473
def _convert_matmul(builder, node, graph, err):
    '''
    convert to CoreML BatchedMatMul Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L3473
    '''
    weight_name = node.inputs[1]
    W = None
    weight_as_layer_parameter = False
    if weight_name in node.input_tensors:
        W = node.input_tensors[weight_name]

    if W is not None:
        if len(W.shape) != 2:
            # since weight as parameter in batchedMatMul layer must be rank 2
            builder.add_load_constant_nd(node.name + '_const_weight_input', weight_name, constant_value=W,shape=W.shape)
        else:
            weight_as_layer_parameter = True

    if weight_as_layer_parameter:
        builder.add_batched_mat_mul(name=node.name,
                                    input_names=[node.inputs[0]],
                                    output_name=node.outputs[0],
                                    weight_matrix_rows=W.shape[0],
                                    weight_matrix_columns=W.shape[1],
                                    W=W)
    else:
        builder.add_batched_mat_mul(name=node.name,
                                    input_names=[node.inputs[0], weight_name],
                                    output_name=node.outputs[0])
def _convert_matmul ( builder , node , graph , err ) : weight_name = node . inputs [ 1 ] W = None weight_as_layer_parameter = False if weight_name in node . input_tensors : W = node . input_tensors [ weight_name ] if W is not None : if len ( W . shape ) != 2 : # since weight as parameter in batchedMatMul layer must be rank 2 builder . add_load_constant_nd ( node . name + '_const_weight_input' , weight_name , constant_value = W , shape = W . shape ) else : weight_as_layer_parameter = True if weight_as_layer_parameter : builder . add_batched_mat_mul ( name = node . name , input_names = [ node . inputs [ 0 ] ] , output_name = node . outputs [ 0 ] , weight_matrix_rows = W . shape [ 0 ] , weight_matrix_columns = W . shape [ 1 ] , W = W ) else : builder . add_batched_mat_mul ( name = node . name , input_names = [ node . inputs [ 0 ] , weight_name ] , output_name = node . outputs [ 0 ] )