MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
GeluLayer.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
6using MyCaffe.common;
7using MyCaffe.param;
8
9namespace MyCaffe.layers.gpt
10{
23 public class GeluLayer<T> : NeuronLayer<T>
24 {
25 bool m_bEnableBertVersion;
26
34 : base(cuda, log, p)
35 {
37 m_bEnableBertVersion = p.gelu_param.enable_bert_version;
38 }
39
53 protected override void forward(BlobCollection<T> colBottom, BlobCollection<T> colTop)
54 {
55 long hBottomData = colBottom[0].gpu_data;
56 long hTopData = colTop[0].mutable_gpu_data;
57 int nCount = colBottom[0].count();
58
59 m_cuda.gelu_fwd(nCount, hBottomData, hTopData, m_bEnableBertVersion);
60 }
61
79 protected override void backward(BlobCollection<T> colTop, List<bool> rgbPropagateDown, BlobCollection<T> colBottom)
80 {
81 long hTopData = colTop[0].gpu_data;
82 long hTopDiff = colTop[0].gpu_diff;
83 long hBottomDiff = colBottom[0].mutable_gpu_diff;
84 long hBottomData = colBottom[0].gpu_data;
85 int nCount = colBottom[0].count();
86
87 m_cuda.gelu_bwd(nCount, hTopDiff, hTopData, hBottomDiff, hBottomData, m_bEnableBertVersion);
88 }
89 }
90}
The Log class provides general output in text form.
Definition: Log.cs:13
The BlobCollection contains a list of Blobs.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
Definition: CudaDnn.cs:969
CudaDnn< T > m_cuda
Specifies the CudaDnn connection to Cuda.
Definition: Layer.cs:39
LayerParameter.LayerType m_type
Specifies the Layer type.
Definition: Layer.cs:35
The NeuronLayer is an interface for layers that take one blob as input (x) and produce only equally-s...
Definition: NeuronLayer.cs:22
The GeluLayer implements the New GELU activation function currently in Google BERT repo (same as Open...
Definition: GeluLayer.cs:24
override void backward(BlobCollection< T > colTop, List< bool > rgbPropagateDown, BlobCollection< T > colBottom)
Computes the error gradient w.r.t. the GELU value inputs.
Definition: GeluLayer.cs:79
override void forward(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Forward computation
Definition: GeluLayer.cs:53
GeluLayer(CudaDnn< T > cuda, Log log, LayerParameter p)
The GeluLayer constructor.
Definition: GeluLayer.cs:33
Specifies the base parameter for all layers.
LayerType
Specifies the layer type.
GeluParameter gelu_param
Returns the parameter set when initialized with LayerType.GELU
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
The MyCaffe.layers.gpt namespace contains all GPT related layers.
Definition: LayerFactory.cs:15
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12