Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeStyle][Typos][C-59] Fix typos (Conver) #70259

Merged
merged 15 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ caculate = 'caculate'
calcualtion = 'calcualtion'
checkings = 'checkings'
childs = 'childs'
Conver = 'Conver'
convience = 'convience'
coodinate = 'coodinate'
copyed = 'copyed'
Expand Down
90 changes: 45 additions & 45 deletions paddle/fluid/primitive/decomp_rule/decomp_rule/composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Tensor any_decomp(const Tensor& x, const IntArray& axis, bool keepdim) {

template <typename T>
Tensor mean_decomp(const Tensor& x, const IntArray& axis, bool keepdim) {
auto x_tmp = ConverToMT<T>(x);
auto x_tmp = ConvertToMT<T>(x);

std::vector<int64_t> x_dim = x_tmp.shape();
int64_t axis_size = axis.size();
Expand Down Expand Up @@ -82,7 +82,7 @@ Tensor mean_decomp(const Tensor& x, const IntArray& axis, bool keepdim) {

Tensor res = sum_x / value;

return ConverToOrig<T>(res, x.dtype());
return ConvertToOrig<T>(res, x.dtype());
}

static void check_valid_type(const DataType& dtype) {
Expand Down Expand Up @@ -112,7 +112,7 @@ Tensor p_norm_decomp(const Tensor& x,
const float epsilon = 1.0e-12f,
const bool& keepdim = false,
const bool& asvector = false) {
auto x_tmp = ConverToMT<T>(x);
auto x_tmp = ConvertToMT<T>(x);

Tensor res;
if (porder == 0.0) {
Expand Down Expand Up @@ -146,17 +146,17 @@ Tensor p_norm_decomp(const Tensor& x,
res = elementwise_pow<T>(res, inv_porder_tensor);
}

return ConverToOrig<T>(res, x.dtype());
return ConvertToOrig<T>(res, x.dtype());
}

template <typename T>
Tensor pow_decomp(const Tensor& x, const paddle::Scalar& y) {
auto x_cast = ConverToMT<T>(x);
auto x_cast = ConvertToMT<T>(x);

check_valid_type(y.dtype());
Tensor y_full = full_scalar<T>(y, x_cast.dtype(), x_cast.place());
auto ans = elementwise_pow<T>(x_cast, y_full);
return ConverToOrig<T>(ans, x.dtype());
return ConvertToOrig<T>(ans, x.dtype());
}

template <typename T>
Expand Down Expand Up @@ -263,7 +263,7 @@ std::tuple<Tensor, Tensor, Tensor, Tensor, Tensor, Tensor> batch_norm_decomp(
bool use_global_stats,
bool trainable_statistics) {
auto org_dtype = x.dtype();
Tensor x_cast = ConverToMT<T>(x);
Tensor x_cast = ConvertToMT<T>(x);

BatchNormDecompHelper<T> decomp_help(x, scale, bias, data_layout);

Expand Down Expand Up @@ -319,7 +319,7 @@ std::tuple<Tensor, Tensor, Tensor, Tensor, Tensor, Tensor> batch_norm_decomp(
: bias.get());
}

y = ConverToOrig<T>(y, org_dtype);
y = ConvertToOrig<T>(y, org_dtype);

if (!use_run_stat) {
batch_mean_ = squeeze<T>(batch_mean, reduce_axes);
Expand All @@ -336,25 +336,25 @@ std::tuple<Tensor, Tensor, Tensor, Tensor, Tensor, Tensor> batch_norm_decomp(

template <typename T>
Tensor softmax_decomp(const Tensor& x, const int& axis) {
auto x_tmp = ConverToMT<T>(x);
auto x_tmp = ConvertToMT<T>(x);

auto max_tmp = max<T>(x_tmp, {axis}, true);
auto molecular = exp<T>(x_tmp - max_tmp);
auto res = molecular / sum<T>(molecular, {axis}, molecular.dtype(), true);

return ConverToOrig<T>(res, x.dtype());
return ConvertToOrig<T>(res, x.dtype());
}

template <typename T>
Tensor log_softmax_decomp(const Tensor& x, const int& axis) {
auto x_tmp = ConverToMT<T>(x);
auto x_tmp = ConvertToMT<T>(x);

auto max_tmp = max<T>(x_tmp, {axis}, true);
auto sub = x_tmp - max_tmp;
auto molecular = exp<T>(sub);
auto res = sub - log<T>(sum<T>(molecular, {axis}, molecular.dtype(), true));

return ConverToOrig<T>(res, x.dtype());
return ConvertToOrig<T>(res, x.dtype());
}

template <typename T>
Expand Down Expand Up @@ -411,9 +411,9 @@ Tensor stack_decomp(const std::vector<Tensor>& x, const int& axis) {

template <typename T>
Tensor silu_decomp(const Tensor& x) {
auto x_tmp = ConverToMT<T>(x);
auto x_tmp = ConvertToMT<T>(x);
auto res = x_tmp * sigmoid<T>(x_tmp);
return ConverToOrig<T>(res, x.dtype());
return ConvertToOrig<T>(res, x.dtype());
}

template <typename T>
Expand Down Expand Up @@ -541,7 +541,7 @@ std::tuple<Tensor, Tensor, Tensor> layer_norm_decomp(
int begin_norm_axis) {
std::vector<int64_t> reduce_axis;
auto org_dtype = x.dtype();
Tensor x_cast = ConverToMT<T>(x);
Tensor x_cast = ConvertToMT<T>(x);

auto x_dims = x.dims();

Expand All @@ -562,13 +562,13 @@ std::tuple<Tensor, Tensor, Tensor> layer_norm_decomp(
Tensor scale_cast;
if (scale) {
scale_cast = decomp_helper.Process<T>(scale.get(), x_cast);
scale_cast = ConverToMT<T>(scale_cast);
scale_cast = ConvertToMT<T>(scale_cast);
out = out * scale_cast;
}
Tensor bias_cast;
if (bias) {
bias_cast = decomp_helper.Process<T>(bias.get(), x_cast);
bias_cast = ConverToMT<T>(bias_cast);
bias_cast = ConvertToMT<T>(bias_cast);
out = out + bias_cast;
}
mean_ = squeeze<T>(mean_, reduce_axis);
Expand All @@ -577,7 +577,7 @@ std::tuple<Tensor, Tensor, Tensor> layer_norm_decomp(
// same as LayerNormInferMeta
// x: float32 --> out: float32, mean: float32, variance: float32
// x: float16 --> out: float16, mean: float32, variance: float32
out = ConverToOrig<T>(out, org_dtype);
out = ConvertToOrig<T>(out, org_dtype);
return std::make_tuple(out, mean_, variance);
}

Expand Down Expand Up @@ -751,7 +751,7 @@ std::tuple<Tensor, Tensor, Tensor> instance_norm_decomp(
const paddle::optional<Tensor>& bias,
float epsilon) {
auto org_dtype = x.dtype();
Tensor x_cast = ConverToMT<T>(x);
Tensor x_cast = ConvertToMT<T>(x);
const std::vector<int64_t> x_dims = x.shape();

if (has_dynamic_shape(x_dims)) {
Expand Down Expand Up @@ -790,20 +790,20 @@ std::tuple<Tensor, Tensor, Tensor> instance_norm_decomp(

if (scale) {
auto scale_cast = backend::reshape<T>(scale.get(), slice_shape_tensor);
scale_cast = ConverToMT<T>(scale_cast);
scale_cast = ConvertToMT<T>(scale_cast);
out = out * scale_cast;
}

if (bias) {
auto bias_cast = backend::reshape<T>(bias.get(), slice_shape_tensor);
bias_cast = ConverToMT<T>(bias_cast);
bias_cast = ConvertToMT<T>(bias_cast);
out = out + bias_cast;
}

std::vector<int64_t> res_shape(1, -1);
auto mean_out = reshape<T>(mean_, res_shape);
auto variance_out = reshape<T>(rsqrt_var, res_shape);
auto res = ConverToOrig<T>(out, org_dtype);
auto res = ConvertToOrig<T>(out, org_dtype);

return std::make_tuple(res, mean_out, variance_out);
}
Expand All @@ -830,20 +830,20 @@ std::tuple<Tensor, Tensor, Tensor> instance_norm_decomp(
out = reshape<T>(out, x_dims);
if (scale) {
auto scale_cast = reshape<T>(scale.get(), slice_shape);
scale_cast = ConverToMT<T>(scale_cast);
scale_cast = ConvertToMT<T>(scale_cast);
out = out * scale_cast;
}

if (bias) {
auto bias_cast = reshape<T>(bias.get(), slice_shape);
bias_cast = ConverToMT<T>(bias_cast);
bias_cast = ConvertToMT<T>(bias_cast);
out = out + bias_cast;
}

std::vector<int64_t> res_shape(1, -1);
auto mean_out = reshape<T>(mean_, res_shape);
auto variance_out = reshape<T>(rsqrt_var, res_shape);
auto res = ConverToOrig<T>(out, org_dtype);
auto res = ConvertToOrig<T>(out, org_dtype);

return std::make_tuple(res, mean_out, variance_out);
}
Expand Down Expand Up @@ -985,7 +985,7 @@ std::tuple<Tensor, Tensor, Tensor> group_norm_decomp(
}

auto org_dtype = x.dtype();
Tensor x_cast = ConverToMT<T>(x);
Tensor x_cast = ConvertToMT<T>(x);

Tensor x_dim_t;
Tensor out, mean_, var_;
Expand Down Expand Up @@ -1047,7 +1047,7 @@ std::tuple<Tensor, Tensor, Tensor> group_norm_decomp(
} else {
scale_cast = scale.get();
}
scale_cast = ConverToMT<T>(scale_cast);
scale_cast = ConvertToMT<T>(scale_cast);
out = out * scale_cast;
}
Tensor bias_cast;
Expand All @@ -1057,7 +1057,7 @@ std::tuple<Tensor, Tensor, Tensor> group_norm_decomp(
} else {
bias_cast = bias.get();
}
bias_cast = ConverToMT<T>(bias_cast);
bias_cast = ConvertToMT<T>(bias_cast);
out = out + bias_cast;
}
Tensor mean_out, var_out;
Expand All @@ -1072,20 +1072,20 @@ std::tuple<Tensor, Tensor, Tensor> group_norm_decomp(
mean_out = reshape<T>(mean_, res_shape);
var_out = reshape<T>(var_, res_shape);
}
out = ConverToOrig<T>(out, org_dtype);
out = ConvertToOrig<T>(out, org_dtype);

return std::make_tuple(out, mean_out, var_out);
}

template <typename T>
Tensor square_decomp(const Tensor& x) {
auto x_cast = ConverToMT<T>(x);
auto x_cast = ConvertToMT<T>(x);

Tensor two;
two = full_scalar<T>(2, x_cast.dtype(), x_cast.place());

auto ans = elementwise_pow<T>(x_cast, two);
return ConverToOrig<T>(ans, x.dtype());
return ConvertToOrig<T>(ans, x.dtype());
}

template <typename T>
Expand Down Expand Up @@ -1131,7 +1131,7 @@ Tensor sigmoid_cross_entropy_with_logits_decomp(

template <typename T>
Tensor mean_all_decomp(const Tensor& x) {
auto x_cast = ConverToMT<T>(x);
auto x_cast = ConvertToMT<T>(x);
auto x_shape = x.shape();

Tensor ans;
Expand All @@ -1147,7 +1147,7 @@ Tensor mean_all_decomp(const Tensor& x) {
ans = sum<T>(x_cast) / x_cast.numel();
}

return ConverToOrig<T>(ans, x.dtype());
return ConvertToOrig<T>(ans, x.dtype());
}

template <typename T>
Expand Down Expand Up @@ -1243,7 +1243,7 @@ Tensor index_sample_decomp(const Tensor& x, const Tensor& index) {

template <typename T>
Tensor elu_decomp(const Tensor& x, const float alpha) {
auto x_cast = ConverToMT<T>(x);
auto x_cast = ConvertToMT<T>(x);

Tensor zero;
Tensor tmp_res;
Expand All @@ -1258,16 +1258,16 @@ Tensor elu_decomp(const Tensor& x, const float alpha) {
tmp_res = alpha * (exp<T>(x_cast) - 1);
}
auto ans = where<T>(x_cast > zero, x_cast, tmp_res);
return ConverToOrig<T>(ans, x.dtype());
return ConvertToOrig<T>(ans, x.dtype());
}

template <typename T>
Tensor lerp_decomp(const Tensor& x, const Tensor& y, const Tensor& weight) {
Tensor x_cast = ConverToMT<T>(x);
Tensor y_cast = ConverToMT<T>(y);
Tensor weight_cast = ConverToMT<T>(weight);
Tensor x_cast = ConvertToMT<T>(x);
Tensor y_cast = ConvertToMT<T>(y);
Tensor weight_cast = ConvertToMT<T>(weight);
Tensor res = x_cast + weight_cast * (y_cast - x_cast);
return ConverToOrig<T>(res, x.dtype());
return ConvertToOrig<T>(res, x.dtype());
}

template <typename T>
Expand Down Expand Up @@ -1420,27 +1420,27 @@ Tensor eye_decomp(const paddle::Scalar& num_rows,
int32_t min_num = std::min(num_rows.to<int>(), num_columns.to<int>());
Tensor zero_tensor =
full<T>({num_rows.to<int>(), num_columns.to<int>()}, 0, dtype, place);
auto zero_tensor_cast = ConverToMT<T>(zero_tensor);
auto zero_tensor_cast = ConvertToMT<T>(zero_tensor);
Tensor diag_one = unsqueeze<T>(full<T>({min_num}, 1, dtype, place), {1});
auto diag_one_cast = ConverToMT<T>(diag_one);
auto diag_one_cast = ConvertToMT<T>(diag_one);

auto start = full<T>({1}, 0, dtype, place);
auto stop = full<T>({1}, min_num, dtype, place);
auto step = full<T>({1}, 1, dtype, place);
Tensor index = unsqueeze<T>(
backend::arange<T>(start, stop, step, DataType::INT32, place), {1});

auto index_cast = ConverToMT<T>(index);
auto index_cast = ConvertToMT<T>(index);
Tensor res = put_along_axis<T>(zero_tensor_cast, index, diag_one_cast, 1);

return ConverToOrig<T>(res, dtype);
return ConvertToOrig<T>(res, dtype);
}

template <typename T>
Tensor diag_decomp(const Tensor& x,
const int& offset = 0,
const float& padding_value = 0.0) {
Tensor cast_x = ConverToMT<T>(x);
Tensor cast_x = ConvertToMT<T>(x);
int64_t rank = cast_x.dims().size();
Tensor res;
if (rank == 1) {
Expand Down Expand Up @@ -1482,7 +1482,7 @@ Tensor diag_decomp(const Tensor& x,
backend::arange<T>(start, end, stride, DataType::INT64, cast_x.place());
res = take_along_axis<T>(x_flat, indices, 0);
}
return ConverToOrig<T>(res, x.dtype());
return ConvertToOrig<T>(res, x.dtype());
}

} // namespace details
Expand Down
Loading