Skip to content

rocm: fall back to unfused bias-grad when hipBLASLt lacks BGRADB algo#1619

Open
sreerohi wants to merge 1 commit into
radixark:mainfrom
sreerohi:rocm/te-bgradb-fallback
Open

rocm: fall back to unfused bias-grad when hipBLASLt lacks BGRADB algo#1619
sreerohi wants to merge 1 commit into
radixark:mainfrom
sreerohi:rocm/te-bgradb-fallback

Conversation

@sreerohi

Copy link
Copy Markdown

TE's LayerNormColumnParallelLinear backward issues a bias-fused wgrad GEMM (HIPBLASLT_EPILOGUE_BGRADB on ROCm) via tex.generic_gemm. On gfx950 (MI350-355), hipBLASLt has no algorithm for some shapes (notably Qwen2.5-0.5B's QKV: BF16, M ~ max_tokens_per_gpu, N=1152, K=896), raising "Unable to find any suitable algorithms" in TE's backward.

Wrap tex.generic_gemm at module import on ROCm so that, when this specific RuntimeError fires AND the call is the bias-fused wgrad path (bias != None and grad == True), we retry the GEMM with bias=None and compute bias_grad ourselves via grad_output.sum(dim=0). Mathematically identical to BGRADB; just not fused into the same kernel.

The wrapper is a no-op on CUDA and on shapes hipBLASLt can serve.

Supersedes #1138

TE's LayerNormColumnParallelLinear backward issues a bias-fused wgrad
GEMM (HIPBLASLT_EPILOGUE_BGRADB) via tex.generic_gemm. On gfx950
(MI350-355), hipBLASLt has no algorithm for some shapes (notably
Qwen2.5-0.5B's QKV: BF16, M ~ max_tokens_per_gpu, N=1152, K=896),
raising "Unable to find any suitable algorithms" in TE's backward.

Wrap tex.generic_gemm at module import on ROCm so that, when this
specific RuntimeError fires AND the call is the bias-fused wgrad path
(bias != None and grad == True), we retry the GEMM with bias=None and
compute bias_grad ourselves via grad_output.sum(dim=0). Mathematically
identical to BGRADB; just not fused into the same kernel.

The wrapper is a no-op on CUDA and on shapes hipBLASLt can serve.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

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.

1 participant