MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
LayerNormParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param.gpt
9{
18 [Serializable]
19 [TypeConverter(typeof(ExpandableObjectConverter))]
21 {
22 double m_dfEpsilon = 1e-10;
23 bool m_bEnableCudaImplementation = false;
24 bool m_bEnablePassThrough = false;
25
28 {
29 }
30
34 [Description("Specifies the epsilon value used to avoid invalid values (default = 1e-10).")]
35 public double epsilon
36 {
37 get { return m_dfEpsilon; }
38 set { m_dfEpsilon = value; }
39 }
40
44 [Description("Specifies to pass-through the data on the forward and backward pass (e.g. skip the layer norm, used only for debugging. default = false).")]
46 {
47 get { return m_bEnablePassThrough; }
48 set { m_bEnablePassThrough = value; }
49 }
50
57 [Description("Specifies to use the low-level full cuda implementation of LayerNorm (default = false).")]
58 public bool enable_cuda_impl
59 {
60 get { return m_bEnableCudaImplementation; }
61 set { m_bEnableCudaImplementation = value; }
62 }
63
70 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
71 {
72 RawProto proto = RawProto.Parse(br.ReadString());
74
75 if (!bNewInstance)
76 Copy(p);
77
78 return p;
79 }
80
85 public override void Copy(LayerParameterBase src)
86 {
88 m_dfEpsilon = p.epsilon;
89 m_bEnableCudaImplementation = p.enable_cuda_impl;
90 m_bEnablePassThrough = p.enable_passthrough;
91 }
92
97 public override LayerParameterBase Clone()
98 {
100 p.Copy(this);
101 return p;
102 }
103
109 public override RawProto ToProto(string strName)
110 {
111 RawProtoCollection rgChildren = new RawProtoCollection();
112
113 rgChildren.Add("epsilon", m_dfEpsilon.ToString());
114 rgChildren.Add("enable_cuda_impl", m_bEnableCudaImplementation.ToString());
115
116 if (m_bEnablePassThrough)
117 rgChildren.Add("enable_passthrough", m_bEnablePassThrough.ToString());
118
119 return new RawProto(strName, "", rgChildren);
120 }
121
128 {
129 string strVal;
131
132 if ((strVal = rp.FindValue("epsilon")) != null)
133 p.m_dfEpsilon = double.Parse(strVal);
134
135 if ((strVal = rp.FindValue("enable_cuda_impl")) != null)
136 p.m_bEnableCudaImplementation = bool.Parse(strVal);
137
138 if ((strVal = rp.FindValue("enable_passthrough")) != null)
139 p.m_bEnablePassThrough = bool.Parse(strVal);
140
141 return p;
142 }
143 }
144}
The RawProtoCollection class is a list of RawProto objects.
void Add(RawProto p)
Adds a RawProto to the collection.
The RawProto class is used to parse and output Google prototxt file data.
Definition: RawProto.cs:17
static RawProto Parse(string str)
Parses a prototxt and places it in a new RawProto.
Definition: RawProto.cs:306
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the LayerNormalizationLayer.
static LayerNormParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
LayerNormParameter()
Constructor for the parameter.
bool enable_passthrough
Specifies to pass-through the data on the forward and backward pass (e.g. skip the layer norm,...
bool enable_cuda_impl
Specifies to use the low-level full cuda implementation of LayerNorm (default = false).
double epsilon
Specifies the epsilon value used to avoid invalid values (default = 1e-10).
override void Copy(LayerParameterBase src)
Copy on parameter to another.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12