Skip to content

decode_n_tokens clean up #1532

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

Merged
merged 1 commit into from
Apr 22, 2025
Merged

decode_n_tokens clean up #1532

merged 1 commit into from
Apr 22, 2025

Conversation

manuelcandales
Copy link
Contributor

Deletes unused python arrays

Copy link

pytorch-bot bot commented Apr 21, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchchat/1532

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 3816bca with merge base 701d826 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 21, 2025
@@ -535,7 +535,6 @@ def decode_n_tokens(
attention_backend: SDPBackend = torch.nn.attention.SDPBackend.MATH,
**sampling_kwargs,
):
new_tokens, new_probs = [], []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really used. This function yields individual tokens and probabilities, not the arrays.

@@ -553,12 +552,10 @@ def decode_n_tokens(
**sampling_kwargs,
)
input_pos += 1
new_tokens.append(next_token.clone())
callback(new_tokens[-1], done_generating=_i == num_new_tokens - 2)
if need_probs or next_prob is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was backwards. It should be: if not need probs or next_prob is None:. Otherwise you are saying, if you need the probabilities you are getting None, and if you don't need them you are getting them.

@@ -788,7 +784,6 @@ def generate(
input_pos = input_pos + num_added
next_token = next_tokens[-1]
else:
generated_tokens = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not used. Generated tokens are appended after the call to decode_n_tokens, but then nothing happens.

callback(new_tokens[-1], done_generating=_i == num_new_tokens - 2)
if need_probs or next_prob is None:
callback(next_token.clone(), done_generating=_i == num_new_tokens - 2)
if not need_probs or next_prob is None:
Copy link
Contributor

@Jack-Khuu Jack-Khuu Apr 21, 2025

Choose a reason for hiding this comment

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

Everything else is just cleaning up unused code

not need_probs is the only real change and in the non-speculative path is always false so the old check is effectively just if next_prob is None

need_probs=False,

I think we should drop the check instead of negating here, so it becomes easier to rip spec decoding out completely. The returned prob doesn't get used either way

for generated_token, _ in self.decode_n_tokens(

Suggested change
if not need_probs or next_prob is None:
if next_prob is None:

Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly this is a nit we can just merge

@manuelcandales manuelcandales merged commit 8a0897d into main Apr 22, 2025
72 checks passed
@manuelcandales manuelcandales deleted the manuel/decode branch April 23, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants