Unverified Commit 0fb27dc9 authored by Yih-Dar's avatar Yih-Dar Committed by GitHub
Browse files

Update `TFTapasEmbeddings` (#21107)



Update TFTapasEmbeddings
Co-authored-by: default avatarydshieh <ydshieh@users.noreply.github.com>
parent 4bbbabcb
......@@ -234,6 +234,16 @@ class TFTapasEmbeddings(tf.keras.layers.Layer):
position_ids = tf.math.minimum(self.max_position_embeddings - 1, position - first_position)
if input_ids is not None:
# Note: tf.gather, on which the embedding layer is based, won't check positive out of bound
# indices on GPU, returning zeros instead. This is a dangerous silent behavior.
tf.debugging.assert_less(
input_ids,
tf.cast(self.vocab_size, dtype=input_ids.dtype),
message=(
"input_ids must be smaller than the embedding layer's input dimension (got"
f" {tf.math.reduce_max(input_ids)} >= {self.vocab_size})"
),
)
inputs_embeds = tf.gather(params=self.weight, indices=input_ids)
position_embeddings = tf.gather(self.position_embeddings, indices=position_ids)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment