is_reduced_floating_point_v Class — pytorch Architecture
Architecture documentation for the is_reduced_floating_point_v class in layer_norm_kernel.cpp from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/cpu/layer_norm_kernel.cpp lines 57–95
template <typename T,
typename std::enable_if_t<!is_reduced_floating_point_v<T>, int> = 0>
void LayerNormKernelImplInternal(
const Tensor& X,
const Tensor& gamma,
const Tensor& beta,
int64_t M,
int64_t N,
T eps,
Tensor* Y,
Tensor* mean,
Tensor* rstd) {
const T* X_data = X.const_data_ptr<T>();
const T* gamma_data = gamma.defined() ? gamma.const_data_ptr<T>() : nullptr;
const T* beta_data = beta.defined() ? beta.const_data_ptr<T>() : nullptr;
T* Y_data = Y->data_ptr<T>();
T* mean_data = mean ? mean->data_ptr<T>() : nullptr;
T* rstd_data = rstd ? rstd->data_ptr<T>() : nullptr;
const bool mean_null = mean_data == nullptr;
const bool rstd_null = rstd_data == nullptr;
at::parallel_for(0, M, 1, [&](int64_t start, int64_t end) {
for (const auto i : c10::irange(start, end)) {
const T* X_ptr = X_data + i * N;
T* Y_ptr = Y_data + i * N;
auto [mean_val, rstd_val] = RowwiseMoments(X_ptr, N);
rstd_val = T(1) / std::sqrt(rstd_val + eps);
const T scale = rstd_val;
const T bias = - mean_val;
LayerNormSecondPass<T>(X_ptr, gamma_data, beta_data, Y_ptr, N, scale, bias);
if (!mean_null) {
mean_data[i] = mean_val;
}
if (!rstd_null) {
rstd_data[i] = rstd_val;
}
}
});
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free