fbgemm_fp8:Keep the current device aligned with the input tensor#46403
Open
kaixuanliu wants to merge 3 commits into
Open
fbgemm_fp8:Keep the current device aligned with the input tensor#46403kaixuanliu wants to merge 3 commits into
kaixuanliu wants to merge 3 commits into
Conversation
Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>
Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>
Contributor
Author
|
@SunMarc ,pls help review, thx! |
SunMarc
reviewed
Jun 4, 2026
Comment on lines
+45
to
+62
| @contextmanager | ||
| def on_device(tensor): | ||
| """Force the global current device to match ``tensor``'s device. | ||
|
|
||
| This keeps quantization kernel launches aligned with the input tensor device when the | ||
| process current device differs from the module placement. | ||
| """ | ||
| device = getattr(tensor, "device", None) | ||
| device_type = getattr(device, "type", None) | ||
| if device_type == "cuda": | ||
| with torch.cuda.device(device): | ||
| yield | ||
| elif _is_torch_xpu_available and device_type == "xpu": | ||
| with torch.xpu.device(device): | ||
| yield | ||
| else: | ||
| yield | ||
|
|
Member
There was a problem hiding this comment.
can we put that in another file so that we can reuse them across quants integration ?
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.
As the comment in the code:
x_quantized and x_scale are not necessarily on the same device as xin L119, on xpu, although we usekernels-community/fp8-fbgemm, we still meet this problem. Even move the output can still produce incorrect output(nanoutput in middle layer). In this PR we use a context manager to fix the bug and optimize the code like what we did in mxfp4 .Cases to re-produce: