Skip to content

Define B/D/F upfront in the roofline matmul section - #127

Open
Future-Outlier wants to merge 3 commits into
jax-ml:mainfrom
Future-Outlier:roofline-clarify-B-is-token-count
Open

Define B/D/F upfront in the roofline matmul section#127
Future-Outlier wants to merge 3 commits into
jax-ml:mainfrom
Future-Outlier:roofline-clarify-B-is-token-count

Conversation

@Future-Outlier

@Future-Outlier Future-Outlier commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Define B, D, F once at the top of the Matrix multiplication
section — one short sentence each — so the reader knows each dimension
right away:

  • B is the batch size — the number of tokens (not sequences).
  • D is the model dimension d_model (the embedding size).
  • F is the MLP hidden dimension d_ff.

The key point is that the batch size B counts tokens, not sequences.
Since it's now defined once upfront, the rest of the section keeps the
familiar term "batch size B" and drops the repeated "(not sequences)"
asides — which reads more cleanly than renaming B to "number of tokens"
everywhere.

image image

…ne matmul section

In the "Matrix multiplication" section the activation X has shape [B, D],
so B is the number of tokens (the rows of X) -- i.e. batch_size x
sequence_length, the same quantity written B*T in the Transformer chapters.
Labeling this B as the "batch size" is easy to confuse with the usual batch
size (a count of *sequences*) and with the book's own use of B for the
sequence count elsewhere.

- Define B, D, F explicitly where the matmul is introduced.
- Refer to B as the "number of tokens" consistently instead of "batch size".
- Keep one contrasting note that this is not the usual per-sequence batch size.

No math or numbers change; wording/clarity only.
@google-cla

google-cla Bot commented Jul 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Signed-off-by: Future-Outlier <eric901201@gmail.com>
@Future-Outlier
Future-Outlier force-pushed the roofline-clarify-B-is-token-count branch from c387f74 to 6ae6a90 Compare July 11, 2026 05:17
@Future-Outlier

Copy link
Copy Markdown
Author

cc @jacobaustin123 to take a look, tks!

@Future-Outlier Future-Outlier changed the title Clarify that B is the number of tokens (not batch size) in the roofline matmul section Clarify that B is the number of tokens in the roofline matmul section Jul 12, 2026
Signed-off-by: Future-Outlier <eric901201@gmail.com>
@Future-Outlier Future-Outlier changed the title Clarify that B is the number of tokens in the roofline matmul section Define B/D/F upfront in the roofline matmul section (batch size = tokens, not sequences) Jul 12, 2026
@Future-Outlier Future-Outlier changed the title Define B/D/F upfront in the roofline matmul section (batch size = tokens, not sequences) Define B/D/F upfront in the roofline matmul section Jul 12, 2026

@JiangJiaWei1103 JiangJiaWei1103 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overall LGTM. Defining the notations at the top makes it easy to follow!

@Future-Outlier

Copy link
Copy Markdown
Author

Overall LGTM. Defining the notations at the top makes it easy to follow!

thanks for the review

@jacobaustin123

Copy link
Copy Markdown
Collaborator

Thanks for sending this. I'll try to find a way to tweak this section. I'm not a fan of emphasizing tokens since this section isn't even about Transformers, it's just about matrix multiplication as an abstract algorithm.

@Future-Outlier

Copy link
Copy Markdown
Author

Thanks for sending this. I'll try to find a way to tweak this section. I'm not a fan of emphasizing tokens since this section isn't even about Transformers, it's just about matrix multiplication as an abstract algorithm.

Thank you!

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.

3 participants