#include <ATen/functorch/BatchRulesHelper.h>
#include <utility>
#include <ATen/Operators.h>
#include <ATen/functorch/PlumbingHelper.h>
#include <ATen/core/TensorBody.h>
#include <c10/core/ScalarType.h>
#include <c10/core/SymIntArrayRef.h>
#include <ATen/InferSize.h>
namespace at::functorch {
namespace{
std::tuple<Tensor, std::optional<int64_t>> clone_batch_rule_result(
const Tensor& result,
std::optional<int64_t> result_bdim) {
return std::make_tuple(
result.clone(at::MemoryFormat::Contiguous), result_bdim);
}
std::tuple<Tensor, std::optional<int64_t>> unsqueeze_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
int64_t dim) {
auto self_ = moveBatchDimToFront(self, self_bdim);
auto rank = rankWithoutBatchDim(self, self_bdim);
dim = maybe_wrap_dim(dim, rank + 1) + 1;
return std::make_tuple(self_.unsqueeze(dim), 0);
}
std::tuple<Tensor, std::optional<int64_t>> unsqueeze_copy_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
int64_t dim) {
auto [result, result_bdim] = unsqueeze_batch_rule(self, self_bdim, dim);
return clone_batch_rule_result(result, result_bdim);
}
std::tuple<Tensor, std::optional<int64_t>> repeat_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
c10::SymIntArrayRef sizes) {
SymDimVector sizes_with_bdim = { sizes.begin(), sizes.end() };
sizes_with_bdim.insert(sizes_with_bdim.begin(), 1);
auto self_ = moveBatchDimToFront(self, self_bdim);
while (self_.dim() < static_cast<int64_t>(sizes_with_bdim.size())) {
self_ = self_.unsqueeze(1);
}
return std::make_tuple(self_.repeat_symint(sizes_with_bdim), 0);
}
std::tuple<Tensor, std::optional<int64_t>> _unsafe_view_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
c10::SymIntArrayRef size) {
auto self_ = moveBatchDimToFront(self, self_bdim);
SymDimVector view_size(size);
view_size.insert(view_size.begin(), self_.sym_size(0));
const at::SymDimVector inferred_size = at::infer_size_dv(view_size, self_.sym_numel());
const auto stride = at::detail::computeStride(self_.sym_sizes(),
self_.sym_strides(),
inferred_size);
if (!stride.has_value()) {
self_ = self_.contiguous();
}
return std::make_tuple(at::_unsafe_view_symint(self_, view_size), 0);
}
std::tuple<Tensor, std::optional<int64_t>> flip_batch_rule(const Tensor& self, std::optional<int64_t> self_bdim, IntArrayRef dims) {
auto self_ = moveBatchDimToFront(self, self_bdim);
VmapDimVector new_dims;
new_dims.reserve(dims.size());
for (auto i: dims) {
new_dims.push_back(getPhysicalDim(self_, true, i));
}
return std::make_tuple(at::flip(self_, new_dims), 0);
}
const Tensor& resize__plumbing(
const Tensor& self,
IntArrayRef size,
std::optional<MemoryFormat> optional_memory_format) {
TORCH_CHECK(
!optional_memory_format.has_value() ||
optional_memory_format == c10::MemoryFormat::Contiguous,
"resize_: batching rule only supports None or Contiguous MemoryFormat");
auto maybe_layer = maybeCurrentDynamicLayer();
vmap_check_escaped(maybe_layer, "resize__plumbing");
int64_t cur_level = maybe_layer->layerId();
if (!isBatchedAtLevel(self, cur_level)) {
c10::impl::ExcludeDispatchKeyGuard guard2(DispatchKey::FuncTorchBatched);
return self.resize_(size, optional_memory_format);
}
auto [self_value, self_bdim] = unwrapTensorAtLevel(self, cur_level);
TORCH_INTERNAL_ASSERT(self_bdim.has_value());
TORCH_INTERNAL_ASSERT(self_bdim == 0, "NYI: resize_ batch rule for batch dim != 0");
c10::impl::ExcludeDispatchKeyGuard guard(DispatchKey::FuncTorchBatched);
self_value = moveBatchDimToFront(self_value, self_bdim);
VmapDimVector new_size(size);
new_size.insert(new_size.begin(), self_value.size(*self_bdim));
self_value.resize_(new_size);
auto* batched = maybeGetBatchedImpl(self);
TORCH_INTERNAL_ASSERT(batched);
batched->refreshTensorMetadata();
return self;
}
std::tuple<Tensor, std::optional<int64_t>> squeeze_batch_rule(const Tensor& self, std::optional<int64_t> bdim) {
TORCH_INTERNAL_ASSERT(bdim.has_value());
if (self.dim() == 1) {
return std::make_tuple(self.alias(), bdim);
}
auto shape = self.sym_sizes();
SymDimVector squeezed_sizes;
bool before_batch_idx = true;
int64_t new_batch_idx = 0;
int64_t original_idx = 0;
for (const auto& it : shape) {
if (it != 1 || original_idx == bdim) {
squeezed_sizes.push_back(it);
if (original_idx == bdim) {
before_batch_idx = false;
}
if (before_batch_idx) {
++new_batch_idx;
}
}
++original_idx;
}
auto result = self.view_symint(squeezed_sizes);
return std::make_tuple(std::move(result), std::optional<int64_t>(new_batch_idx));
}
std::tuple<Tensor, std::optional<int64_t>> squeeze_copy_batch_rule(
const Tensor& self,
std::optional<int64_t> bdim) {
auto [result, result_bdim] = squeeze_batch_rule(self, bdim);
return clone_batch_rule_result(result, result_bdim);
}
std::tuple<Tensor, std::optional<int64_t>> squeeze_dims_batch_rule(
const Tensor& self, std::optional<int64_t> bdim, IntArrayRef dims) {
TORCH_INTERNAL_ASSERT(bdim.has_value());
auto ndim = self.dim();
if (ndim == 1) {
TORCH_CHECK(
dims.empty() || (dims.size() == 1 && dims[0] == 0),
"Dimension is out of range (expected to be in range of [-1, 0], but got ", dims);
return std::make_tuple(self.alias(), bdim);
}
DimVector adjusted_dims(dims.begin(), dims.end());
int64_t updated_batch_idx = *bdim;
for (auto &d : adjusted_dims) {
auto actual_dim = c10::maybe_wrap_dim(d, ndim - 1);
if (actual_dim < *bdim) {
d = actual_dim;
if (self.sym_size(actual_dim) == 1) {
--updated_batch_idx;
}
} else {
d = actual_dim + 1;
}
}
return std::make_tuple(self.squeeze(adjusted_dims), std::optional<int64_t>(updated_batch_idx));
}
std::tuple<Tensor, std::optional<int64_t>> squeeze_copy_dims_batch_rule(
const Tensor& self, std::optional<int64_t> bdim, IntArrayRef dims) {
auto [result, result_bdim] = squeeze_dims_batch_rule(self, bdim, dims);
return clone_batch_rule_result(result, result_bdim);
}
std::tuple<Tensor, std::optional<int64_t>> squeeze_dim_batch_rule(
const Tensor& self, std::optional<int64_t> bdim, int64_t dim) {
return squeeze_dims_batch_rule(self, bdim, {dim});
}
std::tuple<Tensor, std::optional<int64_t>> squeeze_copy_dim_batch_rule(
const Tensor& self, std::optional<int64_t> bdim, int64_t dim) {
return squeeze_copy_dims_batch_rule(self, bdim, {dim});
}
std::tuple<Tensor, std::optional<int64_t>> select_batching_rule(const Tensor& self, std::optional<int64_t> bdim, int64_t dim, c10::SymInt index) {
if (!bdim) {
return std::make_tuple(self.select_symint(dim, std::move(index)), std::nullopt);
}
auto _self = moveBatchDimToFront(self, bdim);
auto dim_physical = getPhysicalDim(_self, true, dim);
auto result = _self.select_symint(dim_physical, std::move(index));
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> _reshape_alias_batch_rule(const Tensor& self, std::optional<int64_t> bdim, const c10::SymIntArrayRef shape, const c10::SymIntArrayRef strides) {
(void) strides;
TORCH_INTERNAL_ASSERT(bdim.has_value());
auto self_ = moveBatchDimToFront(self, bdim);
c10::SymDimVector new_shape(shape.size() + 1);
new_shape[0] = self_.sym_size(0);
std::copy(shape.begin(), shape.end(), new_shape.begin() + 1);
return std::make_tuple(at::reshape_symint(self_, new_shape), 0);
}
std::tuple<Tensor, std::optional<int64_t>> roll_batch_rule(const Tensor& self, std::optional<int64_t> bdim, SymIntArrayRef shifts, IntArrayRef dims) {
TORCH_INTERNAL_ASSERT(bdim.has_value());
auto self_ = moveBatchDimToFront(self, bdim);
VmapDimVector new_dims;
if (!dims.empty()) {
new_dims.reserve(dims.size());
for (auto i: dims) {
new_dims.push_back(getPhysicalDim(self, true, i));
}
return std::make_tuple(at::roll_symint(self_, shifts, new_dims), 0);
}
auto old_shape = self_.sym_sizes();
new_dims.push_back(1);
auto logical_rank = rankWithoutBatchDim(self, bdim);
if (logical_rank == 0) {
self_ = self_.unsqueeze(0);
}
auto output = at::roll_symint(self_.flatten(1), shifts, new_dims);
output = output.reshape_symint(old_shape);
return std::make_tuple(std::move(output), 0);
}
std::tuple<Tensor, std::optional<int64_t>> diagonal_batching_rule(
const Tensor &self, std::optional<int64_t> self_bdim,
int64_t offset, int64_t dim1, int64_t dim2)
{
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
auto self_ = moveBatchDimToFront(self, self_bdim);
auto dim1_ = maybe_wrap_dim(dim1, logical_rank) + 1;
auto dim2_ = maybe_wrap_dim(dim2, logical_rank) + 1;
auto result = at::diagonal(self_, offset, dim1_, dim2_);
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> diagonal_backward_batch_rule(
const Tensor& grad_input, std::optional<int64_t> grad_input_bdim,
c10::SymIntArrayRef input_sizes, int64_t offset, int64_t dim1, int64_t dim2) {
auto logical_rank = rankWithoutBatchDim(grad_input, grad_input_bdim);
auto grad_input_ = moveBatchDimToFront(grad_input, grad_input_bdim);
dim1 = maybe_wrap_dim(dim1, logical_rank + 1) + 1;
dim2 = maybe_wrap_dim(dim2, logical_rank + 1) + 1;
c10::SymDimVector input_sizes_(input_sizes.size() + 1);
input_sizes_[0] = grad_input_.size(0);
std::copy(input_sizes.begin(), input_sizes.end(), input_sizes_.begin() + 1);
auto result = at::diagonal_backward_symint(grad_input_, input_sizes_, offset, dim1, dim2);
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> slice_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
int64_t dim,
std::optional<c10::SymInt> start,
std::optional<c10::SymInt> end,
c10::SymInt step) {
auto self_ = moveBatchDimToFront(self, self_bdim);
dim = getPhysicalDim(self, self_bdim.has_value(), dim);
auto result = self_.slice_symint(dim, std::move(start), std::move(end), std::move(step));
return std::make_tuple(std::move(result), 0);
}
bool is_allowed_dim_on_scalar_tensor(int64_t dim) {
return dim == 0 || dim == -1;
}
std::tuple<Tensor, std::optional<int64_t>>
transpose_int_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
int64_t dim0,
int64_t dim1) {
if (self.dim() == 1 && is_allowed_dim_on_scalar_tensor(dim0) &&
is_allowed_dim_on_scalar_tensor(dim1)) {
return std::make_tuple(self, self_bdim);
}
auto self_ = moveBatchDimToFront(self, self_bdim);
dim0 = getPhysicalDim(self, self_bdim.has_value(), dim0);
dim1 = getPhysicalDim(self, self_bdim.has_value(), dim1);
auto result = self_.transpose(dim0, dim1);
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>>
transpose_copy_int_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
int64_t dim0,
int64_t dim1) {
auto [result, result_bdim] =
transpose_int_batch_rule(self, self_bdim, dim0, dim1);
return clone_batch_rule_result(result, result_bdim);
}
std::tuple<Tensor, std::optional<int64_t>> permute_batching_rule(
const Tensor &self, std::optional<int64_t> self_bdim, IntArrayRef dims)
{
if (!self_bdim.has_value()) {
return std::make_tuple(self.permute(dims), self_bdim);
}
auto self_ = moveBatchDimToFront(self, self_bdim);
VmapDimVector dims_;
dims_.reserve(dims.size() + 1);
dims_.emplace_back(0);
for (auto dim : dims) {
dims_.emplace_back(getPhysicalDim(self_, self_bdim.has_value(), dim));
}
return std::make_tuple(self_.permute(dims_), 0);
}
std::tuple<Tensor, std::optional<int64_t>> permute_copy_batching_rule(
const Tensor &self, std::optional<int64_t> self_bdim, IntArrayRef dims)
{
auto [result, result_bdim] = permute_batching_rule(self, self_bdim, dims);
return clone_batch_rule_result(result, result_bdim);
}
std::tuple<Tensor, std::optional<int64_t>> t_copy_batching_rule(
const Tensor& self,
std::optional<int64_t> self_bdim) {
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
TORCH_CHECK(
logical_rank <= 2,
"t() expects a tensor with <= 2 dimensions, but self is ",
logical_rank,
"D");
if (logical_rank < 2) {
auto self_ = moveBatchDimToFront(self, self_bdim);
std::optional<int64_t> result_bdim;
if (self_bdim.has_value()) {
result_bdim = 0;
}
return clone_batch_rule_result(self_, result_bdim);
}
return transpose_copy_int_batch_rule(self, self_bdim, 0, 1);
}
std::tuple<Tensor, std::optional<int64_t>> select_backward_batch_rule(
const Tensor& grad_input, std::optional<int64_t> grad_input_bdim,
c10::SymIntArrayRef input_sizes, int64_t dim, c10::SymInt index) {
auto logical_rank = rankWithoutBatchDim(grad_input, grad_input_bdim);
auto grad_input_ = moveBatchDimToFront(grad_input, grad_input_bdim);
dim = maybe_wrap_dim(dim, logical_rank + 1) + 1;
c10::SymDimVector input_sizes_(input_sizes.size() + 1);
input_sizes_[0] = grad_input_.sym_size(0);
std::copy(input_sizes.begin(), input_sizes.end(), input_sizes_.begin() + 1);
auto result = at::select_backward_symint(grad_input_, input_sizes_, dim, std::move(index));
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> slice_backward_batch_rule(
const Tensor& grad_input, std::optional<int64_t> grad_input_bdim,
SymIntArrayRef input_sizes, int64_t dim, c10::SymInt start, c10::SymInt end, c10::SymInt step) {
auto logical_rank = rankWithoutBatchDim(grad_input, grad_input_bdim);
auto grad_input_ = moveBatchDimToFront(grad_input, grad_input_bdim);
dim = maybe_wrap_dim(dim, logical_rank) + 1;
c10::SymDimVector input_sizes_(input_sizes.size() + 1);
input_sizes_[0] = grad_input_.size(0);
std::copy(input_sizes.begin(), input_sizes.end(), input_sizes_.begin() + 1);
auto result = at::slice_backward_symint(grad_input_, input_sizes_, dim, std::move(start), std::move(end), std::move(step));
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> view_batching_rule(
const Tensor &self, std::optional<int64_t> self_bdim, SymIntArrayRef sym_size)
{
TORCH_INTERNAL_ASSERT(self_bdim.has_value());
auto self_ = moveBatchDimToFront(self, self_bdim);
c10::SmallVector<c10::SymInt> size_(sym_size.size() + 1);
size_[0] = self_.sym_size(0);
std::copy(sym_size.cbegin(), sym_size.cend(), size_.begin() + 1);
return std::make_tuple(self_.view_symint(size_), 0);
}
std::tuple<Tensor, std::optional<int64_t>> view_dtype_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
ScalarType dtype) {
TORCH_INTERNAL_ASSERT(self_bdim.has_value());
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
TORCH_CHECK(
logical_rank != 0 || self.itemsize() == c10::elementSize(dtype),
"self.dim() cannot be 0 to view ", self.scalar_type(), " as ", dtype, " (different element sizes)");
auto self_ = moveBatchDimToFront(self, self_bdim);
return std::make_tuple(self_.view(dtype), 0);
}
std::tuple<Tensor, std::optional<int64_t>> view_copy_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
c10::SymIntArrayRef size) {
auto self_ = moveBatchDimToFront(self, self_bdim);
SymDimVector view_size(size.size() + 1);
view_size[0] = self_.size(0);
std::copy(size.cbegin(), size.cend(), view_size.begin() + 1);
return std::make_tuple(at::view_copy_symint(self_, view_size), 0);
}
template <typename F, F Func>
std::tuple<Tensor, std::optional<int64_t>> expand_batch_rule(
const Tensor &self, std::optional<int64_t> self_bdim, SymIntArrayRef size, bool implicit)
{
auto self_dim = self.dim();
TORCH_CHECK(static_cast<uint64_t>(self_dim - 1) <= size.size(),
"expand: the number of sizes provided (", size.size(), ") ",
"must be greater or equal to the number of dimensions in the tensor (", static_cast<uint64_t>(self_dim - 1), ")");
auto self_ = moveBatchDimToFront(self, self_bdim);
auto self_sizes = self_.sym_sizes();
const auto& batch_size = self_sizes[0];
c10::SmallVector<c10::SymInt> size_(size.size() + 1);
size_[0] = batch_size;
std::copy(size.cbegin(), size.cend(), size_.begin() + 1);
auto extra_dims = size.size() - (self_dim - 1);
c10::SmallVector<c10::SymInt> view_shape(size_.size(), 1);
view_shape[0] = batch_size;
std::copy(self_sizes.cbegin() + 1, self_sizes.cend(),
view_shape.begin() + 1 + extra_dims);
return std::make_tuple(Func(self_.view_symint(view_shape), size_, implicit), 0);
}
std::tuple<Tensor, std::optional<int64_t>> unfold_batch_rule(
const Tensor &self, std::optional<int64_t> self_bdim, int64_t dim, int64_t size, int64_t step)
{
TORCH_INTERNAL_ASSERT(self_bdim.has_value());
auto self_ = moveBatchDimToFront(self, self_bdim);
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
dim = maybe_wrap_dim(dim, logical_rank) + 1;
if (logical_rank==0) {
self_ = self_.unsqueeze(-1);
}
auto result = self_.unfold(dim, size, step);
if (logical_rank==0) {
result = result.squeeze(-1);
}
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> narrow_copy_batch_rule(
const Tensor &self, std::optional<int64_t> self_bdim, int64_t dim, c10::SymInt start, c10::SymInt length)
{
TORCH_INTERNAL_ASSERT(self_bdim.has_value());
auto self_ = moveBatchDimToFront(self, self_bdim);
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
dim = maybe_wrap_dim(dim, logical_rank) + 1;
auto result = self_.narrow_copy_symint(dim, std::move(start), std::move(length));
return std::make_tuple(std::move(result), 0);
}
std::tuple<std::vector<Tensor>, std::optional<int64_t>> unsafe_split_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
c10::SymInt split_size,
int64_t dim) {
TORCH_INTERNAL_ASSERT(self_bdim.has_value());
auto self_ = moveBatchDimToFront(self, self_bdim);
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
dim = maybe_wrap_dim(dim, logical_rank) + 1;
auto result = self_.unsafe_split_symint(std::move(split_size), dim);
return std::make_tuple(std::move(result), 0);
}
std::tuple<std::vector<Tensor>, std::optional<int64_t>> unbind_copy_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
int64_t dim) {
TORCH_INTERNAL_ASSERT(self_bdim.has_value());
auto self_ = moveBatchDimToFront(self, self_bdim);
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
dim = maybe_wrap_dim(dim, logical_rank) + 1;
auto result = at::unbind_copy(self_, dim);
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> diag_embed_batch_rule(const Tensor& self, std::optional<int64_t> self_bdim, int64_t offset, int64_t dim1, int64_t dim2) {
auto logical_rank = rankWithoutBatchDim(self, self_bdim);
auto self_ = moveBatchDimToFront(self, self_bdim);
dim1 = maybe_wrap_dim(dim1, logical_rank + 1) + 1;
dim2 = maybe_wrap_dim(dim2, logical_rank + 1) + 1;
return std::make_tuple(at::diag_embed(self_, offset, dim1, dim2), 0);
}
Tensor trace_decomp(const Tensor& tensor) {
TORCH_CHECK(tensor.dim() == 2, "trace: expected a matrix, but got tensor with dim ", tensor.dim());
return tensor.diagonal().sum();
}
std::tuple<Tensor, std::optional<int64_t>> tril_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
c10::SymInt diagonal = 0) {
TORCH_CHECK(self.dim() >= 2, "tril: The input tensor must have at least 2 dimensions.");
auto self_ = moveBatchDimToFront(self, self_bdim);
auto result = at::tril_symint(self_, std::move(diagonal));
return std::make_tuple(std::move(result), 0);
}
std::tuple<Tensor, std::optional<int64_t>> triu_batch_rule(
const Tensor& self,
std::optional<int64_t> self_bdim,
c10::SymInt diagonal = 0) {
TORCH_CHECK(self.dim() >= 2, "triu: The input tensor must have at least 2 dimensions.");
auto self_ = moveBatchDimToFront(self, self_bdim);
auto result = at::triu_symint(self_, std::move(diagonal));
return std::make_tuple(std::move(result), 0);
}
}
TORCH_LIBRARY_IMPL(aten, FuncTorchBatched, m) {
VMAP_SUPPORT(flip, flip_batch_rule);
m.impl("trace", trace_decomp);
VMAP_SUPPORT(tril, tril_batch_rule);
VMAP_SUPPORT(triu, triu_batch_rule);
VMAP_SUPPORT(repeat, repeat_batch_rule);
VMAP_SUPPORT(_unsafe_view, _unsafe_view_batch_rule);
VMAP_SUPPORT(unsqueeze, unsqueeze_batch_rule);
VMAP_SUPPORT(unsqueeze_copy, unsqueeze_copy_batch_rule);
m.impl("resize_", resize__plumbing);
VMAP_SUPPORT2(select, int, select_batching_rule);
VMAP_SUPPORT(squeeze, squeeze_batch_rule);
VMAP_SUPPORT(squeeze_copy, squeeze_copy_batch_rule);
VMAP_SUPPORT2(squeeze, dim, squeeze_dim_batch_rule);
VMAP_SUPPORT2(squeeze_copy, dim, squeeze_copy_dim_batch_rule);
VMAP_SUPPORT2(squeeze, dims, squeeze_dims_batch_rule);
VMAP_SUPPORT2(squeeze_copy, dims, squeeze_copy_dims_batch_rule);
VMAP_SUPPORT(_reshape_alias, _reshape_alias_batch_rule);
VMAP_SUPPORT(roll, roll_batch_rule);
VMAP_SUPPORT(permute, permute_batching_rule);
VMAP_SUPPORT(permute_copy, permute_copy_batching_rule);
VMAP_SUPPORT(diagonal, diagonal_batching_rule);
VMAP_SUPPORT(diagonal_backward, diagonal_backward_batch_rule);
VMAP_SUPPORT(select_backward, select_backward_batch_rule);
VMAP_SUPPORT(slice_backward, slice_backward_batch_rule);
VMAP_SUPPORT2(unbind_copy, int, unbind_copy_batch_rule);
VMAP_SUPPORT(view, view_batching_rule);
VMAP_SUPPORT2(view, dtype, view_dtype_batch_rule);
VMAP_SUPPORT(view_copy, view_copy_batch_rule);
VMAP_SUPPORT(expand, SINGLE_ARG(expand_batch_rule<decltype(&ATEN_FN(expand)), &ATEN_FN(expand)>));
VMAP_SUPPORT(expand_copy, SINGLE_ARG(expand_batch_rule<decltype(&ATEN_FN(expand_copy)), &ATEN_FN(expand_copy)>));
VMAP_SUPPORT(unfold, unfold_batch_rule);
VMAP_SUPPORT2(slice, Tensor, slice_batch_rule);
VMAP_SUPPORT2(transpose, int, transpose_int_batch_rule);
VMAP_SUPPORT2(transpose_copy, int, transpose_copy_int_batch_rule);
m.impl("t", native::t);
m.impl("t_", native::t_);
VMAP_SUPPORT(t_copy, t_copy_batching_rule);
VMAP_SUPPORT(diag_embed, diag_embed_batch_rule);
VMAP_SUPPORT(narrow_copy, narrow_copy_batch_rule);
VMAP_SUPPORT2(unsafe_split, Tensor, unsafe_split_batch_rule);
}
}