Skip to content

FP16 forward pass blows up with NaNs past 32k context length #38

Description

@kds1123001

Ran into an issue while testing long sequences using FP16. Everything works great up to around 32k tokens, but as soon as I push past seq_len = 32769, the forward pass starts dumping NaNs in the attention output.

to reproduce:

import torch
from flash_qla import flash_qla_forward

Anything > 32768 causes issues in FP16

q = torch.randn(1, 32769, 16, 128, dtype=torch.float16, device="cuda")
k = torch.randn(1, 32769, 16, 128, dtype=torch.float16, device="cuda")
v = torch.randn(1, 32769, 16, 128, dtype=torch.float16, device="cuda")

out = flash_qla_forward(q, k, v)
print(torch.isnan(out).any()) # True

Switching over to bfloat16 completely resolves it, so it looks like a numerical overflow in the Triton kernel accumulator when processing long sequence blocks.

Tested on an H100 with CUDA 12.4 / PyTorch 2.4.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions