Skip to content

[WIP] float8 rowwise all gather #1157

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle two inputs in torchtitan
  • Loading branch information
danielvegamyhre committed Apr 30, 2025
commit 8bac877fc9dccdd5298b2ea582f8d1d17cbf1043
10 changes: 7 additions & 3 deletions torchtitan/models/llama3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ def forward(
torch.Tensor: Output tensor after attention.

"""

bs, seqlen, _ = x.shape
xq, xk, xv = self.wq(x), self.wk(x), self.wv(x)
if isinstance(x, tuple):
x_fp8_rowwise, x_fp8_colwise = x
bs, seqlen, _ = x_fp8_rowwise.shape
xq, xk, xv = self.wq(x_fp8_rowwise, x_fp8_colwise), self.wk(x_fp8_rowwise, x_fp8_colwise), self.wv(x_fp8_rowwise, x_fp8_colwise)
else:
bs, seqlen, _ = x.shape
xq, xk, xv = self.wq(x), self.wk(x), self.wv(x)

# Use -1 instead of `n_heads` (or `n_kv_heads`) to infer the actual
# local heads from sizes of xq, xk, and xv as TP may have sharded them
Expand Down
3 changes: 2 additions & 1 deletion torchtitan/models/llama3/parallelize_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ def apply_tp(
from torchao.float8.float8_tensor_parallel_rowwise_scales import (
Float8ColwiseParallel,
Float8RowwiseParallel,
PrepareFloat8ModuleInput,
)
rowwise_parallel, colwise_parallel, prepare_module_input = (
Float8RowwiseParallel,
Float8ColwiseParallel,
PrepareModuleInput,
PrepareFloat8ModuleInput,
)
logger.info("Using float8 rowwise all-gather")
else:
Expand Down
Loading