-
Notifications
You must be signed in to change notification settings - Fork 37
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
Shard input_mask for Llama #905
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,20 +129,25 @@ def prefill( | |
# [bs, batch_seq_len] | ||
tokens: Union[torch.Tensor, ReplicatedTensor], | ||
*, | ||
# [bs, batch_seq_len] | ||
input_mask: Union[torch.Tensor, ReplicatedTensor], | ||
# [1, 1, batch_seq_len, batch_seq_len] | ||
attention_mask: Optional[Union[torch.Tensor, ReplicatedTensor]], | ||
# [bs, batch_seq_len // block_seq_stride] | ||
seq_block_ids: Union[torch.Tensor, ReplicatedTensor], | ||
cache_state: list[Union[torch.Tensor, SplitPrimitiveTensor]], | ||
): | ||
self._assert_device(tokens) | ||
self._assert_device(input_mask) | ||
self._assert_device(attention_mask, dtype=self.activation_dtype) | ||
self._assert_device(seq_block_ids) | ||
self._assert_device(*cache_state, dtype=self.activation_dtype) | ||
|
||
h = self.token_embedding(tokens) | ||
self.trace_tensor("llama.token_embedding", h) | ||
|
||
h *= input_mask.unsqueeze(-1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that if we assume this should somehow substitute the attention mask the math checks out. |
||
|
||
# Iterate over attention blocks. | ||
for block_idx, block in enumerate(self.attn_blocks): | ||
if block_idx == 0: | ||
|
@@ -166,6 +171,8 @@ def decode( | |
# [bs, 1] | ||
tokens: Union[torch.Tensor, ReplicatedTensor], | ||
*, | ||
# [bs, 1] | ||
input_mask: Union[torch.Tensor, ReplicatedTensor], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This input needs a check such that it should be mutually exclusive with the |
||
# [bs, 1, 1, batch_seq_len] | ||
attention_mask: Union[torch.Tensor, ReplicatedTensor], | ||
# [bs] of starting positions | ||
|
@@ -188,6 +195,7 @@ def decode( | |
== seq_block_ids.shape[1] * self.config.block_seq_stride | ||
) | ||
self._assert_device(tokens) | ||
self._assert_device(input_mask) | ||
self._assert_device(attention_mask, dtype=self.activation_dtype) | ||
self._assert_device(start_positions) | ||
self._assert_device(*cache_state, dtype=self.activation_dtype) | ||
|
@@ -202,6 +210,8 @@ def decode( | |
h = self.token_embedding(tokens) | ||
self.trace_tensor("llama.token_embedding", h) | ||
|
||
h *= input_mask.unsqueeze(-1) | ||
|
||
# Iterate over attention blocks. | ||
for block_idx, block in enumerate(self.attn_blocks): | ||
if block_idx == 0: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This input needs a check such that it should be mutually exclusive with the
attention_mask
arg.