Fix FA kernel launch needs correct cuda device ctx in multi-gpu env#44967
Open
Qubitium wants to merge 5 commits intohuggingface:mainfrom
Open
Fix FA kernel launch needs correct cuda device ctx in multi-gpu env#44967Qubitium wants to merge 5 commits intohuggingface:mainfrom
Qubitium wants to merge 5 commits intohuggingface:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fix: FA kernel launches currently are not thread-safe (nogil) in multi-gpu env. This simple patch fixes the issue.
Bind to correct cuda device ctx before launching the FA kernel.
This is much harder to replicate but the patch is simple and I tihink, obivously enough to point to the src of potential bug.
This PR patches the ctx at the source of the FA kernel launch, but another method is make sure the entire inference call (upstream) has a single ctx biind so any down stream calls can be protected. So either move this up. the call stack or just leave it here. I leave the decision up to pkg maintainer.
Without this fix, my loop test (real code doing CB + Page Attn + FA2) on 2 gpu, 2 threads, 2 models, will sometimes, not always, emit FA stack-traces in the form of:
Code Agent Policy
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ArthurZucker @remi-or This is part of the same CB call stack as I run with CB + Paged Attn + FA2 with two models on two threads each with different gpu on
nogil.Note: This FA crash is much harder to reproduce. I still trying to generate a script to consistently reproduce this error.
Stack
The above looked exactly like the stacktrace I got but the problem is the above was generated by feeding FA kernel fp32 tensors or
nonetensor, which is not possible in my working code which can no longer replicate this crash for whatever reason. Sigh.Still working to reproduce this. I still believe this is related to cross-cuda ctx issue and memory cleared on the wrong cuda ctx thread by python or cuda memory allocator.