Skip to content

fix: support NPU/XPU compute stream in ContinuousBatchingState - #48937

Open
li-lizhe wants to merge 1 commit into
huggingface:mainfrom
li-lizhe:fix/cont-batch-npu-stream
Open

li-lizhe wants to merge 1 commit into
huggingface:mainfrom
li-lizhe:fix/cont-batch-npu-stream

Conversation

@li-lizhe

@li-lizhe li-lizhe commented Sep 18, 2026

Copy link
Copy Markdown

CPU CI GPU run-slow

What & why

ContinuousBatchingState.__init__ only creates torch.cuda.Stream(device=self.device) when device.type == "cuda". On Ascend NPU or Intel XPU, compute_stream is set to None, losing the benefit of async tensor transfers during continuous batching.

Fix

Add additional branches for Ascend NPU (torch.npu.Stream) and XPU (torch.Stream) when the corresponding device type is detected.

ContinuousBatchingState.__init__ only creates a torch.cuda.Stream when device.type == "cuda". On Ascend NPU or Intel XPU, compute_stream is set to None, losing async computation benefits. Add elif branches for torch.npu.Stream and torch.Stream (used by XPU).
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 35378396381
Result: failure | Grafana metrics are not available yet.

Code quality check failed: test jobs were skipped. Fix the code quality issues and push again to run tests.

@Rocketknight1

Copy link
Copy Markdown
Member

cc @IlyasMoutawwakil for Ascend!

Comment on lines +120 to +124
self.compute_stream = (torch.cuda.Stream(device=self.device) if device.type == "cuda" else None)
if hasattr(torch, "npu") and device.type == "npu":
self.compute_stream = torch.npu.Stream(device=self.device)
elif hasattr(torch, "xpu") and device.type == "xpu":
self.compute_stream = torch.Stream(device=self.device)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use torch.Stream always when not cpu ?

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.

3 participants