Skip to content

Conversation

tirthasheshpatel
Copy link
Contributor

Adds support for a positions array in our RotaryEmbedding layer. This is useful when non-arange positions arrays are required like the one used in this paper.

Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! couple tiny comments

tensor = ops.cast(positions, dtype="float32")
else:
seq_len = ops.shape(inputs)[sequence_axis]
tensor = ops.arange(seq_len, dtype="float32") + start_index
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this branch into it's own sub function?

That might make it easier to try overriding.

if positions is None:
    positions = self._compute_positions(inputs, start_index=0)
else:
    positions = ops.cast(positions, dtype="float32")

Copy link
Contributor Author

@tirthasheshpatel tirthasheshpatel Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are renaming the tensor var to positions, we can simply remove the else statement. Did that in the latest commit, let me know if it looks good!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually keep the self._compute_positions over-ridable method for a somewhat hacky reason. Since we don't have great "layer wrappinig" or generation mutation functionality right now, this allows for a patch on the layer itself that would control this computation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@mattdangerw mattdangerw merged commit ab8d951 into keras-team:master Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants