tf.keras.layers.MultiHeadAttention(
num_heads,
key_dim,
value_dim=None,
dropout=0.0,
use_bias=True,
output_shape=None,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.python.pywrap_mlir import import_graphdef | |
from tensorflow import keras | |
from tensorflow.keras import layers | |
from tensorflow.python.compiler.mlir import mlir | |
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2 | |
model = layers.MultiHeadAttention(num_heads=2, key_dim=2) | |
target = tf.keras.Input(shape=[8, 16], batch_size=64, dtype=tf.float32) | |
source = tf.keras.Input(shape=[4, 16], batch_size=64, dtype=tf.float32) |
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map = affine_map<(d0, d1) -> (0, d1)> | |
#map1 = affine_map<(d0, d1) -> (d0, d1)> | |
#map2 = affine_map<(d0, d1, d2, d3) -> (d0, 0, 0, d3)> | |
#map3 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)> | |
#map4 = affine_map<(d0, d1, d2, d3) -> ()> | |
#map5 = affine_map<(d0, d1, d2) -> (d0, d1)> | |
#map6 = affine_map<(d0, d1, d2) -> (d0, d1, d2)> | |
#map7 = affine_map<(d0, d1, d2) -> (0, d1, d2)> | |
#map8 = affine_map<(d0, d1, d2) -> (d0, d1, 0)> | |
#map9 = affine_map<(d0, d1, d2) -> (d2)> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.python.pywrap_mlir import import_graphdef | |
from tensorflow import keras | |
from tensorflow.keras import layers | |
class DotProductAttention(keras.layers.Layer): | |
def __init__(self, use_scale=True, **kwargs): | |
super(DotProductAttention, self).__init__(**kwargs) | |
self.use_scale = use_scale |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map2 = affine_map<(d0, d1, d2) -> (d0, d1)> | |
#map3 = affine_map<(d0, d1, d2) -> (d0, d1, d2)> | |
func.func @main(%arg0 : tensor<1x384xi32>) -> tensor<1x384x384xf32> { | |
%c1 = arith.constant 1 : index | |
%c0 = arith.constant 0 : index | |
%cst_607 = arith.constant 0.000000e+00 : f32 | |
%cst_608 = arith.constant dense<0.00165016507> : tensor<1x30522x128xf32> | |
%10 = tensor.empty() : tensor<1x384x128xf32> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map = affine_map<(d0, d1) -> (d1)> | |
#map1 = affine_map<(d0, d1) -> (d0, d1)> | |
module { | |
func.func @main(%arg0: tensor<32x384xf32>, %arg1: tensor<384x32xf32>, %arg2: tensor<32x384xf32>, %arg3: tensor<32x384xf32>, %arg4: tensor<32x384xf32>, %arg5: tensor<1x384x32xf32>, %arg6: tensor<1x384x32xf32>, %arg7: tensor<1x384x32xf32>) -> tensor<1536x384xf32> { | |
%cst = arith.constant 0.000000e+00 : f32 | |
%cst_0 = arith.constant dense<0.00164203614> : tensor<384xf32> | |
%0 = tensor.empty() : tensor<384x384xf32> | |
%1 = linalg.fill ins(%cst : f32) outs(%0 : tensor<384x384xf32>) -> tensor<384x384xf32> | |
%2 = linalg.matmul ins(%arg1, %arg2 : tensor<384x32xf32>, tensor<32x384xf32>) outs(%1 : tensor<384x384xf32>) -> tensor<384x384xf32> | |
%3 = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel"]} ins(%cst_0 : tensor<384xf32>) outs(%2 : tensor<384x384xf32>) { |
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#map = affine_map<(d0, d1) -> (d0, d1)> | |
#map1 = affine_map<(d0, d1, d2) -> (d0, d2)> | |
#map2 = affine_map<(d0, d1, d2) -> (d0, d1)> | |
#map3 = affine_map<(d0, d1, d2) -> (d0, d1, d2)> | |
#map4 = affine_map<(d0, d1, d2, d3) -> (d0, d1)> | |
#map5 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)> | |
#map6 = affine_map<(d0, d1) -> (d1)> | |
#map7 = affine_map<(d0, d1, d2, d3) -> (d0, d2, d1, d3)> | |
#map8 = affine_map<(d0, d1, d2, d3) -> (d0, d3, d1, d2)> | |
#map9 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d3, d2)> |
NewerOlder