Skip to content
Merged
Changes from 4 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
16 changes: 8 additions & 8 deletions keras_hub/src/models/parseq/parseq_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,14 @@ def call(
null_context = self.hidden_dim**0.5 * self.token_embedding(
token_ids[:, :1]
)
if tokens_length > 1:
content = self.pos_query_embeddings[:, : tokens_length - 1, :]
content = content + self.hidden_dim**0.5 * self.token_embedding(
token_ids[:, 1:]
)
content = ops.concatenate([null_context, content], axis=1)
else:
content = null_context

# Build content in a branchless way so both graph and JAX backends
# see a consistent tensor shape. Slicing with length 0 yields empty
# tensors, so concatenation still produces the correct
# (bs, tokens_length, hidden_dim) shape even when tokens_length == 1.
c = self.pos_query_embeddings[:, : tokens_length - 1, :]
c = c + self.hidden_dim**0.5 * self.token_embedding(token_ids[:, 1:])
content = ops.concatenate([null_context, c], axis=1)

content = self.dropout(content)

Expand Down
Loading