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

FP8 for norm inputs and residuals? #1193

Open
cbcase opened this issue Sep 21, 2024 · 1 comment
Open

FP8 for norm inputs and residuals? #1193

cbcase opened this issue Sep 21, 2024 · 1 comment
Labels
question Further information is requested

Comments

@cbcase
Copy link

cbcase commented Sep 21, 2024

Question for you guys: as best I can tell, there is no support at present for keeping activations in fp8 between the "output" matmul (of either an attention block or MLP block) and the next norm (layernorm or rmsnorm). The missing features to make that work are:

  • FP8 residual input/output (along with the necessary scales) to fp8 gemm
  • FP8 input (with scale) to {rms,layer}norm

Is this something you have considered, or is there a more fundamental limitation (kernel-wise or accuracy-wise) that means you always want to keep the residual path in a 16-bit format. (Fwiw, my own interest here is for inference.)

Thanks,
Carl

@timmoon10
Copy link
Collaborator

timmoon10 commented Oct 2, 2024

Matmuls are ideal for FP8 compute since they can take advantage of Tensor Cores and they're less sensitive to quantization error. While other operations might benefit (especially from reduced memory usage), we haven't prioritized them and performed the necessary convergence testing to trust them.

One other constraint is that TE modules usually treat FP8 activations as internal state, so it's cumbersome to make them handle complicated networks. For more flexibility, you may want to look into the experimental operation-based API (see transformer_engine/pytorch/ops):

fc1 = te.ops.Sequential(te.ops.Linear(...), te.ops.Quantize())
fc2 = te.ops.Sequential(te.ops.LayerNorm(...), te.ops.Linear(...), te.ops.Quantize())

with te.fp8_autocast():
    y = fc1(x)  # y is a Float8Tensor
    z = fc2(y) + y

This could implement your desired behavior once we have LayerNorm kernels that can accept FP8 input. However, right now it would cast FP8 to higher precision before the LayerNorm and the addition.

@timmoon10 timmoon10 added the question Further information is requested label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants