Skip to content
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

Enable FP8 Per-Tensor Scales and Integrate Marlin/MoE Kernels Repo for ROCm #2825

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mht-sharma
Copy link
Collaborator

What does this PR do?

Fixes following issues:

  1. Use FP8 per tensor scales for ROCM (wherever possible) to leverage scaled_mm efficiently.
  2. Fixes random NAN issues with custom PA in rocm
  3. Uses marlin_kernels and moe_kernels repositories for ROCM

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

RUN git clone https://github.com/danieldk/marlin-kernels.git && \
cd marlin-kernels && \
git checkout ${MARLIN_KERNELS_BRANCH} && \
python setup.py install
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how hard it'll be, but it would be nice to have precompiled wheels in the future to cut down the build times.

def per_tensor_dequantize(
tensor: torch.Tensor, inv_scale: Union[float, torch.Tensor]
) -> torch.Tensor:
fake_qweight = tensor.to(torch.float16)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be the model dtype? (The quantized numbers could represent values that are only in bfloat16's range.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes made the changes

input_scale = (
weights.get_tensor(f"{prefix}.input_scale", to_dtype=False)
.reshape(-1)
.max()
Copy link
Member

Choose a reason for hiding this comment

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

Is this safe? If input_scale is a vector, doesn't it need to be dequantized with the original scales first and then requantized with the new max?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this should be fine since it is the input_scale. Dequantization doesn’t make sense in this context because the input will be unquantized and will simply be quantized using this representative scale.

@mht-sharma mht-sharma requested a review from danieldk December 18, 2024 11:11
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.

2 participants