Skip to content

Conversation

@Silv3S
Copy link
Contributor

@Silv3S Silv3S commented Nov 17, 2025

Fixes #2240

Copilot AI review requested due to automatic review settings November 17, 2025 19:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the buffer tensor shape allocation in the log_sigmoid_forward_xpu function to properly support vmap and JVP (Jacobian-vector product) operations. Previously, the buffer was initialized with shape {0}, which is incompatible with batched operations.

Key changes:

  • Modified buffer allocation to use at::empty_like(input) instead of at::empty({0}, input.options())

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@guangyey
Copy link
Contributor

May I know if there is the same issue existing on CUDA. I see CUDA use empty as well

std::tuple<Tensor, Tensor> log_sigmoid_forward_cuda(const Tensor& input) {
  auto result = at::empty_like(input);
  auto buffer = at::empty({0}, input.options());
  log_sigmoid_forward_out_cuda(input, result, buffer);
  return std::forward_as_tuple(result, buffer);
}

Copy link
Contributor

@EikanWang EikanWang left a comment

Choose a reason for hiding this comment

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

Could you please add a regression test?

@Silv3S
Copy link
Contributor Author

Silv3S commented Nov 18, 2025

It works on CUDA, as there are extra checks in log_sigmoid_backward_batch_rule() if input tensors are on CUDA device. We can either go with this patch or keep old version and add analogous check for XPU backend in upstream PyTorch.

@guangyey
Copy link
Contributor

Thanks, @Silv3S.
Regarding the logic in
https://github.com/pytorch/pytorch/blob/2f023bf7b962e69c0de01b89af197388d9df27cc/aten/src/ATen/functorch/BatchRulesBinaryOps.cpp#L320-L331,
I think it may be worth changing the logic here.
@EikanWang, what’s your opinion?

@Silv3S
Copy link
Contributor Author

Silv3S commented Nov 18, 2025

CUDA custom batching strategy was introduced in pytorch/pytorch#84892

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

Labels

None yet

Projects

None yet

4 participants