Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test shapes directly #1064

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions keras_nlp/layers/position_embedding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_static_layer_output_shape(self):

# When using static position embedding shapes, the output is expected
# to be the same as the input shape in all dimensions save batch.
expected_output_shape = [None, sequence_length, feature_size]
self.assertEqual(expected_output_shape, output_tensor.shape.as_list())
expected_output_shape = (None, sequence_length, feature_size)
self.assertEqual(expected_output_shape, output_tensor.shape)
# The output dtype for this layer should match the compute dtype.
self.assertEqual(test_layer.compute_dtype, output_tensor.dtype)

Expand All @@ -61,13 +61,13 @@ def test_more_than_3_dimensions_static(self):

# When using static position embedding shapes, the output is expected
# to be the same as the input shape in all dimensions save batch.
expected_output_shape = [
expected_output_shape = (
None,
feature_size,
sequence_length,
feature_size,
]
self.assertEqual(expected_output_shape, output_tensor.shape.as_list())
)
self.assertEqual(expected_output_shape, output_tensor.shape)
# The output dtype for this layer should match the compute dtype.
self.assertEqual(test_layer.compute_dtype, output_tensor.dtype)

Expand All @@ -83,8 +83,8 @@ def test_float16_dtype(self):

# When using static position embedding shapes, the output is expected
# to be the same as the input shape in all dimensions save batch.
expected_output_shape = [None, sequence_length, feature_size]
self.assertEqual(expected_output_shape, output_tensor.shape.as_list())
expected_output_shape = (None, sequence_length, feature_size)
self.assertEqual(expected_output_shape, output_tensor.shape)
# The default output dtype for this layer should be "float32".
self.assertEqual(tf.float16, output_tensor.dtype)

Expand All @@ -101,8 +101,8 @@ def test_dynamic_layer_output_shape(self):
# When using dynamic position embedding shapes, the output is expected
# to be the same as the input shape in all dimensions - but may be None
# if the input shape is None there.
expected_output_shape = [None, None, feature_size]
self.assertEqual(expected_output_shape, output_tensor.shape.as_list())
expected_output_shape = (None, None, feature_size)
self.assertEqual(expected_output_shape, output_tensor.shape)

def test_more_than_3_dimensions_dynamic(self):
max_sequence_length = 60
Expand All @@ -117,8 +117,8 @@ def test_more_than_3_dimensions_dynamic(self):
# When using dynamic position embedding shapes, the output is expected
# to be the same as the input shape in all dimensions - but may be None
# if the input shape is None there.
expected_output_shape = [None, None, None, feature_size]
self.assertEqual(expected_output_shape, output_tensor.shape.as_list())
expected_output_shape = (None, None, None, feature_size)
self.assertEqual(expected_output_shape, output_tensor.shape)

def test_dynamic_layer_slicing(self):
max_sequence_length = 40
Expand Down
12 changes: 6 additions & 6 deletions keras_nlp/layers/sine_position_encoding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def test_static_layer_output_shape(self):

# When using static positional encoding shapes, the output is expected
# to be the same as the input shape in all dimensions.
expected_output_shape = [None, seq_length, hidden_size]
self.assertEqual(expected_output_shape, outputs.shape.as_list())
expected_output_shape = (None, seq_length, hidden_size)
self.assertEqual(expected_output_shape, outputs.shape)

def test_dynamic_layer_output_shape(self):
pos_encoding = sine_position_encoding.SinePositionEncoding()
Expand All @@ -51,8 +51,8 @@ def test_dynamic_layer_output_shape(self):

# When using dynamic positional encoding shapes, the output is expected
# to be the same as the input shape in all dimensions but may be None.
expected_output_shape = [None, None, hidden_size]
self.assertEqual(expected_output_shape, outputs.shape.as_list())
expected_output_shape = (None, None, hidden_size)
self.assertEqual(expected_output_shape, outputs.shape)

# do multi dimension before sequence length
def test_multi_dimension_layer_output_shape(self):
Expand All @@ -64,8 +64,8 @@ def test_multi_dimension_layer_output_shape(self):

# When using muliple dimensions before sequence length, the output is
# expected to be the same as the input shape in all dimensions.
expected_output_shape = [None, None, seq_length, hidden_size]
self.assertEqual(expected_output_shape, outputs.shape.as_list())
expected_output_shape = (None, None, seq_length, hidden_size)
self.assertEqual(expected_output_shape, outputs.shape)

def test_output_correct_values(self):
pos_encoding = sine_position_encoding.SinePositionEncoding()
Expand Down