code: def testConv1dValidPadding(self):
      converter = test_utils.NumpyConverter()
      batch = 2
      d_model = 6
      d_out = 1
      length = 4
      filter_size = 3
  
      x = np.random.randn(batch, length, d_model)
      x_mtf = converter.convert_np_array_to_mtf_tensor(
          x, dtype=tf.float32, dim_names=["batch", "length", "d_model"]
      )
  
      conv_filter = np.random.randn(1, filter_size, d_model, d_out)
      initializer = lambda shape, dtype, **kwargs: conv_filter
      output_mtf = mtf.layers.conv1d(
          x_mtf,
          output_dim=mtf.Dimension("output_dim", d_out),
          filter_size=filter_size,
          padding="VALID",
          filter_initializer=initializer,
      )
      actual = converter.convert_mtf_tensor_to_np_array(output_mtf)
  
      # Expected length is 2.
      expected = np.empty(shape=(batch, 2, d_out), dtype=np.float32)
  
      # [filter_size, d_model]
      current_filter = conv_filter[0, :, :, 0]
      # b: batch, k: filter_size, d: d_model.
      expected[:, 0] = np.einsum(
          "bkd,kd->b", x[:, :filter_size, :], current_filter
      ).reshape(batch, 1)
      expected[:, 1] = np.einsum(
          "bkd,kd->b", x[:, 1:, :], current_filter
      ).reshape(batch, 1)
      self.assertAllClose(actual, expected)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import mesh_tensorflow
  from mesh_tensorflow import test_utils
  import mock
  import numpy
  import tensorflow.compat.v1
  import tensorflow_probability
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 13 for calling the LayersTest obj's underlying member method code with example usage: obj.testConv1dValidPadding() without return types