-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathdistconv_layer_norm.hpp
More file actions
78 lines (65 loc) · 2.82 KB
/
Copy pathdistconv_layer_norm.hpp
File metadata and controls
78 lines (65 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2014-2022, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory.
// Written by the LBANN Research Team (B. Van Essen, et al.) listed in
// the CONTRIBUTORS file. <lbann-dev@llnl.gov>
//
// LLNL-CODE-697807.
// All rights reserved.
//
// This file is part of LBANN: Livermore Big Artificial Neural Network
// Toolkit. For details, see http://software.llnl.gov/LBANN or
// https://github.com/LLNL/LBANN.
//
// Licensed under the Apache License, Version 2.0 (the "Licensee"); you
// may not use this file except in compliance with the License. You may
// obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the license.
////////////////////////////////////////////////////////////////////////////////
#ifndef LBANN_LAYERSE_REGULARIZERS_DISTCONV_LAYER_NORM
#define LBANN_LAYERSE_REGULARIZERS_DISTCONV_LAYER_NORM
#ifdef LBANN_HAS_DISTCONV
namespace distconv {
template <typename Backend, typename DataType>
class LayerNormalization
{
using LocaleMPI = tensor::LocaleMPI;
template <typename Allocator>
using DCTensor = tensor::Tensor<DataType, LocaleMPI, Allocator>;
public:
LayerNormalization(Backend& backend, DataType epsilon)
: m_backend(backend), m_epsilon(epsilon)
{}
template <typename Allocator>
void calculate_forward_stats(const DCTensor<Allocator>& input,
DCTensor<Allocator>& statistics);
template <typename Allocator>
void apply_normalization(const DCTensor<Allocator>& input,
DCTensor<Allocator>& statistics,
DCTensor<Allocator>& output);
template <typename Allocator>
void calculate_backward_stats(const DCTensor<Allocator>& input,
const DCTensor<Allocator>& output_grad,
const DCTensor<Allocator>& statistics,
DCTensor<Allocator>& statistics_grad);
template <typename Allocator>
void apply_grad(const DCTensor<Allocator>& input,
const DCTensor<Allocator>& output_grad,
const DCTensor<Allocator>& statistics,
const DCTensor<Allocator>& statistics_grad,
DCTensor<Allocator>& input_grad);
protected:
Backend& m_backend;
private:
DataType m_epsilon;
}; // class definition LayerNorm
} // namespace distconv
#endif // LBANN_HAS_DISTCONV
#endif // LBANN_LAYERS_REGULARIZERS_DISTCONV_LAYER_NORM