Skip to content

Remove two if statements in fp8 padding #935

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
8 changes: 1 addition & 7 deletions torchao/float8/float8_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ def _get_min_alignment(size: int, alignment_value: int) -> int:
16
```
"""
if size % alignment_value == 0:
return size
return (1 + (size // alignment_value)) * alignment_value
return (1 + ((size - 1) // alignment_value)) * alignment_value


def pad_tensor_for_matmul(
Expand Down Expand Up @@ -234,10 +232,6 @@ def pad_tensor_for_matmul(
dim1_aligned = _get_min_alignment(dim1, 16) if 0 in dims else dim1
dim2_aligned = _get_min_alignment(dim2, 16) if 1 in dims else dim2

# Check if padding is needed for either dimension
if dim1 == dim1_aligned and dim2 == dim2_aligned:
return tensor

# Calculate padding values for both dimensions
pad_dim1 = dim1_aligned - dim1
pad_dim2 = dim2_aligned - dim2
Expand Down
Loading