mirror of https://github.com/llvm/torch-mlir
Replace c10::optional with std::optional (#3126)
They replaced all `c10::optional` usages with `std::optional` in
torchgen'd code in
fb90b4d4b2
causing the LTC build to break.
Replacing all usages of `c10::optional` with `std::optional` in
`projects/ltc` has fixed the issue
Issue: #3120
pull/3130/head
parent
184d8c13f4
commit
8951a8cc23
|
@ -123,12 +123,12 @@ class GenTorchMlirLTC:
|
||||||
self.generated_path.mkdir(parents=True, exist_ok=True)
|
self.generated_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Create symlink to match doc structure
|
# Create symlink to match doc structure
|
||||||
generated_path = self.backend_path.joinpath("generated").resolve()
|
generated_path = self.backend_path.joinpath("generated")
|
||||||
if not generated_path.exists():
|
generated_path.unlink(missing_ok=True)
|
||||||
generated_path.symlink_to(
|
generated_path.symlink_to(
|
||||||
os.path.relpath(self.generated_path, generated_path.parent),
|
os.path.relpath(self.generated_path, generated_path.parent),
|
||||||
target_is_directory=True,
|
target_is_directory=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.tensor_class = "torch::lazy::LazyTensor"
|
self.tensor_class = "torch::lazy::LazyTensor"
|
||||||
|
|
||||||
|
@ -350,7 +350,15 @@ class GenTorchMlirLTC:
|
||||||
def extract_signatures(text):
|
def extract_signatures(text):
|
||||||
signatures = set()
|
signatures = set()
|
||||||
for name, args in sig_re.findall(text):
|
for name, args in sig_re.findall(text):
|
||||||
|
# Remove all whitespace from signature
|
||||||
signature = re.sub(r"\s+", "", f"{name}({args})")
|
signature = re.sub(r"\s+", "", f"{name}({args})")
|
||||||
|
# Ignore optional's namespace
|
||||||
|
signature = re.sub(r":*\w*:*optional", "optional", signature)
|
||||||
|
# Remove const type qualifier
|
||||||
|
signature = re.sub(r"const", "", signature)
|
||||||
|
# Remove type reference
|
||||||
|
signature = re.sub(r"&", "", signature)
|
||||||
|
|
||||||
global_signatures[signature] = (name, args)
|
global_signatures[signature] = (name, args)
|
||||||
signatures.add(signature)
|
signatures.add(signature)
|
||||||
return signatures
|
return signatures
|
||||||
|
|
|
@ -50,6 +50,7 @@ cmake -S "$repo_root/externals/llvm-project/llvm" -B "$build_dir" \
|
||||||
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$repo_root" \
|
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$repo_root" \
|
||||||
-DLLVM_TARGETS_TO_BUILD=host \
|
-DLLVM_TARGETS_TO_BUILD=host \
|
||||||
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
|
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
|
||||||
|
-DTORCH_MLIR_ENABLE_LTC=ON
|
||||||
echo "::endgroup::"
|
echo "::endgroup::"
|
||||||
|
|
||||||
echo "::group::Build"
|
echo "::group::Build"
|
||||||
|
|
|
@ -434,8 +434,6 @@ function clean_build() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_torch_mlir() {
|
function build_torch_mlir() {
|
||||||
# Disable LTC build for releases to avoid linker issues
|
|
||||||
export TORCH_MLIR_ENABLE_LTC=0
|
|
||||||
local torch_version="$1"
|
local torch_version="$1"
|
||||||
case $torch_version in
|
case $torch_version in
|
||||||
nightly)
|
nightly)
|
||||||
|
|
|
@ -117,7 +117,7 @@ TorchMlirBackendImpl::GetComputationDataFromNode(const Node *node) const {
|
||||||
|
|
||||||
at::Tensor TorchMlirBackendImpl::MakeTensorFromComputationData(
|
at::Tensor TorchMlirBackendImpl::MakeTensorFromComputationData(
|
||||||
const BackendDataPtr data,
|
const BackendDataPtr data,
|
||||||
c10::optional<at::ScalarType> logical_scalar_type) const {
|
std::optional<at::ScalarType> logical_scalar_type) const {
|
||||||
PRINT_FUNCTION();
|
PRINT_FUNCTION();
|
||||||
|
|
||||||
TorchMlirBackendData *torch_mlir_data =
|
TorchMlirBackendData *torch_mlir_data =
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TORCH_API TorchMlirBackendData : public BackendData {
|
||||||
public:
|
public:
|
||||||
struct Info : public BackendData::Info {
|
struct Info : public BackendData::Info {
|
||||||
at::Tensor tensor;
|
at::Tensor tensor;
|
||||||
c10::optional<at::Scalar> scalar;
|
std::optional<at::Scalar> scalar;
|
||||||
bool requires_grad;
|
bool requires_grad;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public:
|
||||||
|
|
||||||
virtual at::Tensor MakeTensorFromComputationData(
|
virtual at::Tensor MakeTensorFromComputationData(
|
||||||
const BackendDataPtr data,
|
const BackendDataPtr data,
|
||||||
c10::optional<at::ScalarType> logical_scalar_type) const override;
|
std::optional<at::ScalarType> logical_scalar_type) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lowering, Compilation, Execution
|
* Lowering, Compilation, Execution
|
||||||
|
|
|
@ -34,7 +34,7 @@ struct TorchMlirIrBuilder : IrBuilder {
|
||||||
NodePtr MakeDeviceData(const std::shared_ptr<BackendData>& data) const override { return MakeNode<DeviceData>(data); }
|
NodePtr MakeDeviceData(const std::shared_ptr<BackendData>& data) const override { return MakeNode<DeviceData>(data); }
|
||||||
NodePtr MakeScalar(const at::Scalar& value, const at::ScalarType& type) const override { return MakeNode<Scalar>(value, type); }
|
NodePtr MakeScalar(const at::Scalar& value, const at::ScalarType& type) const override { return MakeNode<Scalar>(value, type); }
|
||||||
NodePtr MakeExpand(const Value& input0, const std::vector<int64_t>& size, const bool& is_scalar_expand) const override { return MakeNode<Expand>(input0, size, is_scalar_expand); }
|
NodePtr MakeExpand(const Value& input0, const std::vector<int64_t>& size, const bool& is_scalar_expand) const override { return MakeNode<Expand>(input0, size, is_scalar_expand); }
|
||||||
NodePtr MakeCast(const Value& input0, const at::ScalarType& dtype, const c10::optional<at::ScalarType>& stype = c10::nullopt) const override { return MakeNode<Cast>(input0, dtype, stype); }
|
NodePtr MakeCast(const Value& input0, const at::ScalarType& dtype, const std::optional<at::ScalarType>& stype = c10::nullopt) const override { return MakeNode<Cast>(input0, dtype, stype); }
|
||||||
NodePtr MakeTensorList(const OpList& inputs) const override { return MakeNode<TorchMlirTensorList>(inputs); }
|
NodePtr MakeTensorList(const OpList& inputs) const override { return MakeNode<TorchMlirTensorList>(inputs); }
|
||||||
NodePtr MakeGeneric(const OpKind& op, const OpList& operands, const Shape& shape, const size_t& num_outputs = 1, const hash_t& hash_seed = static_cast<uint32_t>(0x5a2d296e9)) const override { return MakeNode<Generic>(op, operands, shape, num_outputs, hash_seed); }
|
NodePtr MakeGeneric(const OpKind& op, const OpList& operands, const Shape& shape, const size_t& num_outputs = 1, const hash_t& hash_seed = static_cast<uint32_t>(0x5a2d296e9)) const override { return MakeNode<Generic>(op, operands, shape, num_outputs, hash_seed); }
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ at::Tensor to_meta(const at::Tensor &tensor) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
c10::optional<at::Tensor> to_meta(const c10::optional<at::Tensor> &tensor) {
|
std::optional<at::Tensor> to_meta(const std::optional<at::Tensor> &tensor) {
|
||||||
if (tensor.has_value()) {
|
if (tensor.has_value()) {
|
||||||
return to_meta(*tensor);
|
return to_meta(*tensor);
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,9 @@ c10::optional<at::Tensor> to_meta(const c10::optional<at::Tensor> &tensor) {
|
||||||
return outs;
|
return outs;
|
||||||
}
|
}
|
||||||
|
|
||||||
c10::List<c10::optional<at::Tensor>>
|
c10::List<std::optional<at::Tensor>>
|
||||||
to_meta(const c10::List<c10::optional<at::Tensor>> &t_list) {
|
to_meta(const c10::List<std::optional<at::Tensor>> &t_list) {
|
||||||
c10::List<c10::optional<at::Tensor>> outs;
|
c10::List<std::optional<at::Tensor>> outs;
|
||||||
outs.reserve(t_list.size());
|
outs.reserve(t_list.size());
|
||||||
for (const auto &tensor : t_list) {
|
for (const auto &tensor : t_list) {
|
||||||
outs.push_back(to_meta(tensor));
|
outs.push_back(to_meta(tensor));
|
||||||
|
@ -94,7 +94,7 @@ namespace {
|
||||||
|
|
||||||
[[maybe_unused]] at::Tensor
|
[[maybe_unused]] at::Tensor
|
||||||
CreateLtcTensor(const at::Tensor &tensor,
|
CreateLtcTensor(const at::Tensor &tensor,
|
||||||
const c10::optional<torch::lazy::BackendDevice> &device) {
|
const std::optional<torch::lazy::BackendDevice> &device) {
|
||||||
if (tensor.defined() && device) {
|
if (tensor.defined() && device) {
|
||||||
return torch::lazy::CreateAtenFromLtcTensor(
|
return torch::lazy::CreateAtenFromLtcTensor(
|
||||||
torch::lazy::LazyTensor::Create(tensor, *device));
|
torch::lazy::LazyTensor::Create(tensor, *device));
|
||||||
|
@ -102,8 +102,8 @@ CreateLtcTensor(const at::Tensor &tensor,
|
||||||
return tensor;
|
return tensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]] c10::optional<torch::lazy::BackendDevice>
|
[[maybe_unused]] std::optional<torch::lazy::BackendDevice>
|
||||||
GetLtcDevice(const c10::optional<c10::Device> &device) {
|
GetLtcDevice(const std::optional<c10::Device> &device) {
|
||||||
if (!device) {
|
if (!device) {
|
||||||
return c10::nullopt;
|
return c10::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ void copy_(torch::lazy::LazyTensorPtr &input, torch::lazy::LazyTensorPtr &src) {
|
||||||
// This should be safe to do, because every operator in the LT is functional.
|
// This should be safe to do, because every operator in the LT is functional.
|
||||||
at::Tensor
|
at::Tensor
|
||||||
LazyNativeFunctions::clone(const at::Tensor &self,
|
LazyNativeFunctions::clone(const at::Tensor &self,
|
||||||
c10::optional<at::MemoryFormat> memory_format) {
|
std::optional<at::MemoryFormat> memory_format) {
|
||||||
auto self_lt = torch::lazy::TryGetLtcTensor(self);
|
auto self_lt = torch::lazy::TryGetLtcTensor(self);
|
||||||
return torch::lazy::CreateAtenFromLtcTensor(
|
return torch::lazy::CreateAtenFromLtcTensor(
|
||||||
self_lt->Create(self_lt->GetIrValue(), self_lt->GetDevice()));
|
self_lt->Create(self_lt->GetIrValue(), self_lt->GetDevice()));
|
||||||
|
@ -234,10 +234,10 @@ at::Tensor LazyNativeFunctions::_copy_from_and_resize(const at::Tensor &self,
|
||||||
}
|
}
|
||||||
|
|
||||||
at::Tensor LazyNativeFunctions::_to_copy(
|
at::Tensor LazyNativeFunctions::_to_copy(
|
||||||
const at::Tensor &self, c10::optional<at::ScalarType> dtype,
|
const at::Tensor &self, std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout, c10::optional<at::Device> device,
|
std::optional<at::Layout> layout, std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory, bool non_blocking,
|
std::optional<bool> pin_memory, bool non_blocking,
|
||||||
c10::optional<at::MemoryFormat> memory_format) {
|
std::optional<at::MemoryFormat> memory_format) {
|
||||||
PRINT_FUNCTION();
|
PRINT_FUNCTION();
|
||||||
auto options = self.options();
|
auto options = self.options();
|
||||||
if (dtype) {
|
if (dtype) {
|
||||||
|
@ -482,7 +482,7 @@ LazyNativeFunctions::split_copy_symint(const at::Tensor &self,
|
||||||
|
|
||||||
at::Tensor LazyNativeFunctions::index(
|
at::Tensor LazyNativeFunctions::index(
|
||||||
const at::Tensor &self,
|
const at::Tensor &self,
|
||||||
const c10::List<c10::optional<at::Tensor>> &indices) {
|
const c10::List<std::optional<at::Tensor>> &indices) {
|
||||||
TORCH_LAZY_FN_COUNTER("lazy::");
|
TORCH_LAZY_FN_COUNTER("lazy::");
|
||||||
auto common_device = torch::lazy::GetBackendDevice(self);
|
auto common_device = torch::lazy::GetBackendDevice(self);
|
||||||
TORCH_INTERNAL_ASSERT(common_device);
|
TORCH_INTERNAL_ASSERT(common_device);
|
||||||
|
@ -491,7 +491,7 @@ at::Tensor LazyNativeFunctions::index(
|
||||||
|
|
||||||
std::vector<torch::lazy::Value> values;
|
std::vector<torch::lazy::Value> values;
|
||||||
for (const auto &it : indices) {
|
for (const auto &it : indices) {
|
||||||
c10::optional<at::Tensor> tensor = it;
|
std::optional<at::Tensor> tensor = it;
|
||||||
LazyTensorPtr lazy_tensor =
|
LazyTensorPtr lazy_tensor =
|
||||||
torch::lazy::TryGetLtcTensor(tensor.value_or(at::Tensor()));
|
torch::lazy::TryGetLtcTensor(tensor.value_or(at::Tensor()));
|
||||||
values.push_back(
|
values.push_back(
|
||||||
|
@ -532,7 +532,7 @@ at::Tensor LazyNativeFunctions::index(
|
||||||
}
|
}
|
||||||
|
|
||||||
at::Tensor LazyNativeFunctions::index_put(
|
at::Tensor LazyNativeFunctions::index_put(
|
||||||
const at::Tensor &self, const c10::List<c10::optional<at::Tensor>> &indices,
|
const at::Tensor &self, const c10::List<std::optional<at::Tensor>> &indices,
|
||||||
const at::Tensor &values, bool accumulate) {
|
const at::Tensor &values, bool accumulate) {
|
||||||
TORCH_LAZY_FN_COUNTER("lazy::");
|
TORCH_LAZY_FN_COUNTER("lazy::");
|
||||||
auto common_device = torch::lazy::GetBackendDevice(self);
|
auto common_device = torch::lazy::GetBackendDevice(self);
|
||||||
|
@ -544,7 +544,7 @@ at::Tensor LazyNativeFunctions::index_put(
|
||||||
|
|
||||||
std::vector<torch::lazy::Value> indices_vector;
|
std::vector<torch::lazy::Value> indices_vector;
|
||||||
for (const auto &it : indices) {
|
for (const auto &it : indices) {
|
||||||
c10::optional<at::Tensor> tensor = it;
|
std::optional<at::Tensor> tensor = it;
|
||||||
LazyTensorPtr lazy_tensor =
|
LazyTensorPtr lazy_tensor =
|
||||||
torch::lazy::TryGetLtcTensor(tensor.value_or(at::Tensor()));
|
torch::lazy::TryGetLtcTensor(tensor.value_or(at::Tensor()));
|
||||||
indices_vector.push_back(
|
indices_vector.push_back(
|
||||||
|
@ -616,9 +616,9 @@ at::Tensor LazyNativeFunctions::block_diag(at::TensorList tensors) {
|
||||||
}
|
}
|
||||||
at::Tensor LazyNativeFunctions::new_empty_strided_symint(
|
at::Tensor LazyNativeFunctions::new_empty_strided_symint(
|
||||||
const at::Tensor &self, c10::SymIntArrayRef size,
|
const at::Tensor &self, c10::SymIntArrayRef size,
|
||||||
c10::SymIntArrayRef stride, c10::optional<at::ScalarType> dtype,
|
c10::SymIntArrayRef stride, std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout, c10::optional<at::Device> device,
|
std::optional<at::Layout> layout, std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
std::optional<bool> pin_memory) {
|
||||||
if (!device || device->type() == c10::DeviceType::Lazy) {
|
if (!device || device->type() == c10::DeviceType::Lazy) {
|
||||||
return at::functionalization::functionalize_aten_op_symint<ATEN_OP(
|
return at::functionalization::functionalize_aten_op_symint<ATEN_OP(
|
||||||
new_empty_strided)>::call(self, size, stride, dtype, layout, device,
|
new_empty_strided)>::call(self, size, stride, dtype, layout, device,
|
||||||
|
@ -628,8 +628,8 @@ at::Tensor LazyNativeFunctions::new_empty_strided_symint(
|
||||||
// lazy_tensor.new_empty_strided(..., "cpu") we need to avoid explicit
|
// lazy_tensor.new_empty_strided(..., "cpu") we need to avoid explicit
|
||||||
// functionalization. To do that we create regular cpu tensors.
|
// functionalization. To do that we create regular cpu tensors.
|
||||||
at::Tensor t = at::empty_symint(
|
at::Tensor t = at::empty_symint(
|
||||||
size, (dtype ? dtype : c10::optional<at::ScalarType>(self.scalar_type())),
|
size, (dtype ? dtype : std::optional<at::ScalarType>(self.scalar_type())),
|
||||||
(layout ? layout : c10::optional<at::Layout>(self.layout())), device,
|
(layout ? layout : std::optional<at::Layout>(self.layout())), device,
|
||||||
pin_memory, c10::nullopt);
|
pin_memory, c10::nullopt);
|
||||||
return t.as_strided_symint(size, stride, /*storage_offset=*/0);
|
return t.as_strided_symint(size, stride, /*storage_offset=*/0);
|
||||||
}
|
}
|
||||||
|
@ -679,8 +679,8 @@ at::Tensor LazyNativeFunctions::_trilinear(
|
||||||
unroll_dim);
|
unroll_dim);
|
||||||
}
|
}
|
||||||
at::Tensor LazyNativeFunctions::linalg_pinv(
|
at::Tensor LazyNativeFunctions::linalg_pinv(
|
||||||
const at::Tensor &self, const c10::optional<at::Tensor> &atol,
|
const at::Tensor &self, const std::optional<at::Tensor> &atol,
|
||||||
const c10::optional<at::Tensor> &rtol, bool hermitian) {
|
const std::optional<at::Tensor> &rtol, bool hermitian) {
|
||||||
return at::functionalization::functionalize_aten_op<ATEN_OP2(
|
return at::functionalization::functionalize_aten_op<ATEN_OP2(
|
||||||
linalg_pinv, atol_rtol_tensor)>::call(self, atol, rtol, hermitian);
|
linalg_pinv, atol_rtol_tensor)>::call(self, atol, rtol, hermitian);
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ c10::TensorType &cast_tensor_type(c10::TypePtr value_type) {
|
||||||
return *tensor_type.get();
|
return *tensor_type.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
c10::optional<std::vector<int64_t>>
|
std::optional<std::vector<int64_t>>
|
||||||
get_tensor_type_shape(c10::TensorType &tensor_type) {
|
get_tensor_type_shape(c10::TensorType &tensor_type) {
|
||||||
auto &symbolic_shape = tensor_type.symbolic_sizes();
|
auto &symbolic_shape = tensor_type.symbolic_sizes();
|
||||||
if (!symbolic_shape.rank()) {
|
if (!symbolic_shape.rank()) {
|
||||||
|
|
|
@ -25,11 +25,11 @@ namespace lazy {
|
||||||
class ToCopy : public torch::lazy::TorchMlirNode {
|
class ToCopy : public torch::lazy::TorchMlirNode {
|
||||||
public:
|
public:
|
||||||
ToCopy(const torch::lazy::Value &self,
|
ToCopy(const torch::lazy::Value &self,
|
||||||
const c10::optional<at::ScalarType> &dtype,
|
const std::optional<at::ScalarType> &dtype,
|
||||||
const c10::optional<at::Layout> &layout,
|
const std::optional<at::Layout> &layout,
|
||||||
const c10::optional<at::Device> &device,
|
const std::optional<at::Device> &device,
|
||||||
const c10::optional<bool> &pin_memory, const bool &non_blocking,
|
const std::optional<bool> &pin_memory, const bool &non_blocking,
|
||||||
const c10::optional<at::MemoryFormat> &memory_format,
|
const std::optional<at::MemoryFormat> &memory_format,
|
||||||
std::vector<torch::lazy::Shape> &&shapes)
|
std::vector<torch::lazy::Shape> &&shapes)
|
||||||
: torch::lazy::TorchMlirNode(
|
: torch::lazy::TorchMlirNode(
|
||||||
torch::lazy::OpKind(at::aten::_to_copy), {self}, std::move(shapes),
|
torch::lazy::OpKind(at::aten::_to_copy), {self}, std::move(shapes),
|
||||||
|
@ -95,12 +95,12 @@ public:
|
||||||
return _to_copy_out;
|
return _to_copy_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
c10::optional<at::ScalarType> dtype;
|
std::optional<at::ScalarType> dtype;
|
||||||
c10::optional<at::Layout> layout;
|
std::optional<at::Layout> layout;
|
||||||
c10::optional<at::Device> device;
|
std::optional<at::Device> device;
|
||||||
c10::optional<bool> pin_memory;
|
std::optional<bool> pin_memory;
|
||||||
bool non_blocking;
|
bool non_blocking;
|
||||||
c10::optional<at::MemoryFormat> memory_format;
|
std::optional<at::MemoryFormat> memory_format;
|
||||||
};
|
};
|
||||||
} // namespace lazy
|
} // namespace lazy
|
||||||
} // namespace torch
|
} // namespace torch
|
||||||
|
|
|
@ -149,15 +149,22 @@ std::vector<torch::lazy::Shape> compute_shape_mul(const at::Tensor &self,
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_var(const at::Tensor &self, at::OptionalIntArrayRef dim,
|
compute_shape_var(const at::Tensor &self, at::OptionalIntArrayRef dim,
|
||||||
const c10::optional<at::Scalar> &correction, bool keepdim) {
|
const ::std::optional<at::Scalar> &correction, bool keepdim) {
|
||||||
// Result of variance is scalar tensor.
|
// Result of variance is scalar tensor.
|
||||||
return {Shape(self.scalar_type(), {})};
|
return {Shape(self.scalar_type(), {})};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_nan_to_num(const at::Tensor &self, c10::optional<double> nan,
|
compute_shape_var(const at::Tensor &self, at::OptionalIntArrayRef dim,
|
||||||
c10::optional<double> posinf,
|
::std::optional<at::Scalar> &correction, bool keepdim) {
|
||||||
c10::optional<double> neginf) {
|
// Result of variance is scalar tensor.
|
||||||
|
return {Shape(self.scalar_type(), {})};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<torch::lazy::Shape>
|
||||||
|
compute_shape_nan_to_num(const at::Tensor &self, ::std::optional<double> nan,
|
||||||
|
::std::optional<double> posinf,
|
||||||
|
::std::optional<double> neginf) {
|
||||||
return {Shape(self.scalar_type(), self.sizes().vec())};
|
return {Shape(self.scalar_type(), self.sizes().vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,8 +233,8 @@ std::vector<torch::lazy::Shape> compute_shape_fmod(const at::Tensor &self,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_native_group_norm(
|
std::vector<torch::lazy::Shape> compute_shape_native_group_norm(
|
||||||
const at::Tensor &input, const c10::optional<at::Tensor> &weight,
|
const at::Tensor &input, const ::std::optional<at::Tensor> &weight,
|
||||||
const c10::optional<at::Tensor> &bias, int64_t N, int64_t C, int64_t HxW,
|
const ::std::optional<at::Tensor> &bias, int64_t N, int64_t C, int64_t HxW,
|
||||||
int64_t group, double eps) {
|
int64_t group, double eps) {
|
||||||
|
|
||||||
TORCH_CHECK(input.sizes().size() >= 2,
|
TORCH_CHECK(input.sizes().size() >= 2,
|
||||||
|
@ -263,8 +270,9 @@ compute_shape_im2col(const at::Tensor &self, at::IntArrayRef kernel_size,
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_native_group_norm_backward(
|
std::vector<torch::lazy::Shape> compute_shape_native_group_norm_backward(
|
||||||
const at::Tensor &grad_out, const at::Tensor &input, const at::Tensor &mean,
|
const at::Tensor &grad_out, const at::Tensor &input, const at::Tensor &mean,
|
||||||
const at::Tensor &rstd, const c10::optional<at::Tensor> &weight, int64_t N,
|
const at::Tensor &rstd, const ::std::optional<at::Tensor> &weight,
|
||||||
int64_t C, int64_t HxW, int64_t group, ::std::array<bool, 3> output_mask) {
|
int64_t N, int64_t C, int64_t HxW, int64_t group,
|
||||||
|
::std::array<bool, 3> output_mask) {
|
||||||
|
|
||||||
TORCH_CHECK(input.sizes().size() >= 2,
|
TORCH_CHECK(input.sizes().size() >= 2,
|
||||||
"Input tensor must have at least batch and channel dimensions!");
|
"Input tensor must have at least batch and channel dimensions!");
|
||||||
|
@ -317,20 +325,20 @@ compute_shape_reflection_pad2d(const at::Tensor &self,
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_uniform(const at::Tensor &self, double from, double to,
|
compute_shape_uniform(const at::Tensor &self, double from, double to,
|
||||||
c10::optional<at::Generator> generator) {
|
::std::optional<at::Generator> generator) {
|
||||||
return {Shape(self.scalar_type(), self.sizes().vec())};
|
return {Shape(self.scalar_type(), self.sizes().vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_normal_functional(const at::Tensor &self, double mean, double std,
|
compute_shape_normal_functional(const at::Tensor &self, double mean, double std,
|
||||||
c10::optional<at::Generator> generator) {
|
::std::optional<at::Generator> generator) {
|
||||||
return {Shape(self.scalar_type(), self.sizes().vec())};
|
return {Shape(self.scalar_type(), self.sizes().vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_multinomial(const at::Tensor &self, int64_t num_samples,
|
compute_shape_multinomial(const at::Tensor &self, int64_t num_samples,
|
||||||
bool replacement,
|
bool replacement,
|
||||||
c10::optional<at::Generator> generator) {
|
::std::optional<at::Generator> generator) {
|
||||||
// Input tensor can be either 1D or 2D. The last dim of output
|
// Input tensor can be either 1D or 2D. The last dim of output
|
||||||
// should be 'num_samples'. So the output shape can be either
|
// should be 'num_samples'. So the output shape can be either
|
||||||
// [num_samples] or [m, num_samples].
|
// [num_samples] or [m, num_samples].
|
||||||
|
@ -341,30 +349,29 @@ compute_shape_multinomial(const at::Tensor &self, int64_t num_samples,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_eye(int64_t n, c10::optional<at::ScalarType> dtype,
|
compute_shape_eye(int64_t n, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout,
|
::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device,
|
::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
::std::optional<bool> pin_memory) {
|
||||||
auto out_meta =
|
auto out_meta =
|
||||||
at::eye(n, dtype, layout, c10::Device(c10::kMeta), pin_memory);
|
at::eye(n, dtype, layout, c10::Device(c10::kMeta), pin_memory);
|
||||||
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_eye(int64_t n, int64_t m, c10::optional<at::ScalarType> dtype,
|
compute_shape_eye(int64_t n, int64_t m, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout,
|
::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device,
|
::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
::std::optional<bool> pin_memory) {
|
||||||
auto out_meta =
|
auto out_meta =
|
||||||
at::eye(n, m, dtype, layout, c10::Device(c10::kMeta), pin_memory);
|
at::eye(n, m, dtype, layout, c10::Device(c10::kMeta), pin_memory);
|
||||||
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape> compute_shape_arange(
|
||||||
compute_shape_arange(const at::Scalar &end, c10::optional<at::ScalarType> dtype,
|
const at::Scalar &end, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout,
|
::std::optional<at::Layout> layout, ::std::optional<at::Device> device,
|
||||||
c10::optional<at::Device> device,
|
::std::optional<bool> pin_memory) {
|
||||||
c10::optional<bool> pin_memory) {
|
|
||||||
auto out_meta =
|
auto out_meta =
|
||||||
at::arange(end, dtype, layout, c10::Device(c10::kMeta), pin_memory);
|
at::arange(end, dtype, layout, c10::Device(c10::kMeta), pin_memory);
|
||||||
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
||||||
|
@ -372,8 +379,8 @@ compute_shape_arange(const at::Scalar &end, c10::optional<at::ScalarType> dtype,
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_arange(
|
std::vector<torch::lazy::Shape> compute_shape_arange(
|
||||||
const at::Scalar &start, const at::Scalar &end,
|
const at::Scalar &start, const at::Scalar &end,
|
||||||
c10::optional<at::ScalarType> dtype, c10::optional<at::Layout> layout,
|
::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device, c10::optional<bool> pin_memory) {
|
::std::optional<at::Device> device, ::std::optional<bool> pin_memory) {
|
||||||
auto out_meta = at::arange(start, end, dtype, layout, c10::Device(c10::kMeta),
|
auto out_meta = at::arange(start, end, dtype, layout, c10::Device(c10::kMeta),
|
||||||
pin_memory);
|
pin_memory);
|
||||||
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
||||||
|
@ -381,8 +388,8 @@ std::vector<torch::lazy::Shape> compute_shape_arange(
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_arange(
|
std::vector<torch::lazy::Shape> compute_shape_arange(
|
||||||
const at::Scalar &start, const at::Scalar &end, const at::Scalar &step,
|
const at::Scalar &start, const at::Scalar &end, const at::Scalar &step,
|
||||||
c10::optional<at::ScalarType> dtype, c10::optional<at::Layout> layout,
|
::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device, c10::optional<bool> pin_memory) {
|
::std::optional<at::Device> device, ::std::optional<bool> pin_memory) {
|
||||||
auto out_meta = at::arange(start, end, step, dtype, layout,
|
auto out_meta = at::arange(start, end, step, dtype, layout,
|
||||||
c10::Device(c10::kMeta), pin_memory);
|
c10::Device(c10::kMeta), pin_memory);
|
||||||
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
||||||
|
@ -390,44 +397,44 @@ std::vector<torch::lazy::Shape> compute_shape_arange(
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_full(
|
std::vector<torch::lazy::Shape> compute_shape_full(
|
||||||
at::IntArrayRef size, const at::Scalar &fill_value,
|
at::IntArrayRef size, const at::Scalar &fill_value,
|
||||||
c10::optional<at::ScalarType> dtype, c10::optional<at::Layout> layout,
|
::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device, c10::optional<bool> pin_memory) {
|
::std::optional<at::Device> device, ::std::optional<bool> pin_memory) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_ones(at::IntArrayRef size, c10::optional<at::ScalarType> dtype,
|
compute_shape_ones(at::IntArrayRef size, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout,
|
::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device,
|
::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
::std::optional<bool> pin_memory) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_zeros(at::IntArrayRef size, c10::optional<at::ScalarType> dtype,
|
compute_shape_zeros(at::IntArrayRef size, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout,
|
::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device,
|
::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
::std::optional<bool> pin_memory) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_empty(at::IntArrayRef size, c10::optional<at::ScalarType> dtype,
|
compute_shape_empty(at::IntArrayRef size, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout,
|
::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device,
|
::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory,
|
::std::optional<bool> pin_memory,
|
||||||
c10::optional<at::MemoryFormat> memory_format) {
|
::std::optional<at::MemoryFormat> memory_format) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_empty_strided(
|
std::vector<torch::lazy::Shape> compute_shape_empty_strided(
|
||||||
at::IntArrayRef size, at::IntArrayRef stride,
|
at::IntArrayRef size, at::IntArrayRef stride,
|
||||||
c10::optional<at::ScalarType> dtype, c10::optional<at::Layout> layout,
|
::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device, c10::optional<bool> pin_memory) {
|
::std::optional<at::Device> device, ::std::optional<bool> pin_memory) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
@ -443,46 +450,46 @@ std::vector<torch::lazy::Shape> compute_shape_fill(const at::Tensor &self,
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_randn(at::IntArrayRef size, c10::optional<at::ScalarType> dtype,
|
compute_shape_randn(at::IntArrayRef size, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout,
|
::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device,
|
::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
::std::optional<bool> pin_memory) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_randint(
|
std::vector<torch::lazy::Shape> compute_shape_randint(
|
||||||
int64_t high, at::IntArrayRef size, c10::optional<at::ScalarType> dtype,
|
int64_t high, at::IntArrayRef size, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout, c10::optional<at::Device> device,
|
::std::optional<at::Layout> layout, ::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
::std::optional<bool> pin_memory) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_randint(
|
std::vector<torch::lazy::Shape> compute_shape_randint(
|
||||||
int64_t low, int64_t high, at::IntArrayRef size,
|
int64_t low, int64_t high, at::IntArrayRef size,
|
||||||
c10::optional<at::ScalarType> dtype, c10::optional<at::Layout> layout,
|
::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device, c10::optional<bool> pin_memory) {
|
::std::optional<at::Device> device, ::std::optional<bool> pin_memory) {
|
||||||
return {
|
return {
|
||||||
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
Shape(dtype.value_or(at::get_default_dtype_as_scalartype()), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_resize(const at::Tensor &self, at::IntArrayRef size,
|
compute_shape_resize(const at::Tensor &self, at::IntArrayRef size,
|
||||||
c10::optional<at::MemoryFormat> memory_format) {
|
::std::optional<at::MemoryFormat> memory_format) {
|
||||||
return {Shape(self.scalar_type(), size.vec())};
|
return {Shape(self.scalar_type(), size.vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape>
|
std::vector<torch::lazy::Shape>
|
||||||
compute_shape_bernoulli(const at::Tensor &self, const at::Tensor &p,
|
compute_shape_bernoulli(const at::Tensor &self, const at::Tensor &p,
|
||||||
c10::optional<at::Generator> generator) {
|
::std::optional<at::Generator> generator) {
|
||||||
return {Shape(self.scalar_type(), self.sizes().vec())};
|
return {Shape(self.scalar_type(), self.sizes().vec())};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_scalar_tensor(
|
std::vector<torch::lazy::Shape> compute_shape_scalar_tensor(
|
||||||
const at::Scalar &s, c10::optional<at::ScalarType> dtype,
|
const at::Scalar &s, ::std::optional<at::ScalarType> dtype,
|
||||||
c10::optional<at::Layout> layout, c10::optional<at::Device> device,
|
::std::optional<at::Layout> layout, ::std::optional<at::Device> device,
|
||||||
c10::optional<bool> pin_memory) {
|
::std::optional<bool> pin_memory) {
|
||||||
return {Shape(dtype.value_or(s.type()), c10::ArrayRef<int64_t>{})};
|
return {Shape(dtype.value_or(s.type()), c10::ArrayRef<int64_t>{})};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,8 +501,8 @@ std::vector<torch::lazy::Shape> compute_shape_roll(const at::Tensor &self,
|
||||||
|
|
||||||
std::vector<torch::lazy::Shape> compute_shape_linspace(
|
std::vector<torch::lazy::Shape> compute_shape_linspace(
|
||||||
const at::Scalar &start, const at::Scalar &end, int64_t steps,
|
const at::Scalar &start, const at::Scalar &end, int64_t steps,
|
||||||
c10::optional<at::ScalarType> dtype, c10::optional<at::Layout> layout,
|
::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout,
|
||||||
c10::optional<at::Device> device, c10::optional<bool> pin_memory) {
|
::std::optional<at::Device> device, ::std::optional<bool> pin_memory) {
|
||||||
auto out_meta = at::linspace(start, end, steps, dtype, layout,
|
auto out_meta = at::linspace(start, end, steps, dtype, layout,
|
||||||
c10::Device(c10::kMeta), pin_memory);
|
c10::Device(c10::kMeta), pin_memory);
|
||||||
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
return {Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
|
||||||
|
|
|
@ -75,7 +75,7 @@ torch::lazy::DeviceData *device_data_cast(const torch::lazy::Value &value) {
|
||||||
|
|
||||||
torch::lazy::DeviceData *
|
torch::lazy::DeviceData *
|
||||||
device_data_cast(const at::Tensor &tensor,
|
device_data_cast(const at::Tensor &tensor,
|
||||||
c10::optional<torch::lazy::BackendDevice> device) {
|
std::optional<torch::lazy::BackendDevice> device) {
|
||||||
if (!device) {
|
if (!device) {
|
||||||
device = torch::lazy::GetBackendDevice(tensor);
|
device = torch::lazy::GetBackendDevice(tensor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ TORCH_API torch::lazy::DeviceData *
|
||||||
device_data_cast(const torch::lazy::Value &value);
|
device_data_cast(const torch::lazy::Value &value);
|
||||||
TORCH_API torch::lazy::DeviceData *device_data_cast(
|
TORCH_API torch::lazy::DeviceData *device_data_cast(
|
||||||
const at::Tensor &tensor,
|
const at::Tensor &tensor,
|
||||||
c10::optional<torch::lazy::BackendDevice> device = c10::nullopt);
|
std::optional<torch::lazy::BackendDevice> device = c10::nullopt);
|
||||||
|
|
||||||
} // namespace lazy
|
} // namespace lazy
|
||||||
} // namespace torch
|
} // namespace torch
|
||||||
|
|
Loading…
Reference in New Issue