-
Notifications
You must be signed in to change notification settings - Fork 19
[Example] Add fused_linear_cross_entropy example and unit test #342
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
base: main
Are you sure you want to change the base?
Conversation
stack-info: PR: #342, branch: yf225/stack/37
"""Fused linear + cross entropy.""" | ||
loss, grad_input, grad_weight, grad_bias = fused_linear_cross_entropy_forward( | ||
input_tensor, weight, labels, bias | ||
) |
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.
Other implementation of fused_linear_cross_entropy
in tritonbench also include both the Python-level chunking code and the Triton kernel (per-chunk processing) in the benchmark timing measurement. So we do the same here for a fair comparison.
|
||
# Masked load of block | ||
mask = block_offsets < vocab_size | ||
logits_block = torch.where( |
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 masking should be added automatically in helion.
# Process in blocks like Liger | ||
for vocab_tile in hl.tile(vocab_size): | ||
# Create block offsets (like tl.arange in Triton) | ||
block_offsets = vocab_tile.index |
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.
Is the alias needed after you remove the extra masking?
n_total_samples: int, # Total number of samples for mean reduction | ||
) -> torch.Tensor: | ||
# Grid over samples - each program handles one sample | ||
for program_id in hl.grid(chunk_size): |
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.
Could this be a hl.tile
loop to allow tiling this dimension with block_size>1?
mask = block_offsets < vocab_size | ||
|
||
# Load block | ||
logits_block = torch.where( |
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.
Masking should be automatic. Are you sure this needed?
Stacked PRs:
[Example] Add fused_linear_cross_entropy example and unit test