Skip to content

Commit 576a8d1

Browse files
Seperated rnn bricking and made minor modifications
1 parent dfec2e8 commit 576a8d1

27 files changed

+584
-339
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ c_reference/models/q_scut_head_b_face4_model/detection2.h filter=lfs diff=lfs me
6363
c_reference/tests/kws/keyword_spotting_io_1.h filter=lfs diff=lfs merge=lfs -text
6464
c_reference/tests/kws/keyword_spotting_io_2.h filter=lfs diff=lfs merge=lfs -text
6565
c_reference/tests/kws/keyword_spotting_io_3.h filter=lfs diff=lfs merge=lfs -text
66-
c_reference/tests/conv1d/avg_pool/avg_io.h filter=lfs diff=lfs merge=lfs -text
6766
c_reference/tests/conv1d/conv1d_regular/conv_param.h filter=lfs diff=lfs merge=lfs -text
6867
c_reference/tests/conv1d/conv1d_lr/conv_param_lr.h filter=lfs diff=lfs merge=lfs -text
6968
c_reference/tests/conv1d/conv1d_lr_depthwise/conv_param_lr_depth.h filter=lfs diff=lfs merge=lfs -text
@@ -73,3 +72,5 @@ c_reference/tests/kws/postcnn_params.h filter=lfs diff=lfs merge=lfs -text
7372
c_reference/tests/kws/rnn_params.h filter=lfs diff=lfs merge=lfs -text
7473
c_reference/tests/dscnn/dscnn_param_lr.h filter=lfs diff=lfs merge=lfs -text
7574
c_reference/tests/dscnn/dscnn_param_lr_depth_point.h filter=lfs diff=lfs merge=lfs -text
75+
c_reference/tests/rnn_bricked/rnn_params.h filter=lfs diff=lfs merge=lfs -text
76+
c_reference/tests/rnn_bricked/rnn_bricked_io.h filter=lfs diff=lfs merge=lfs -text

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Algorithms that shine in this setting in terms of both model size and compute, n
1717
- **EMI-RNN**: Training routine to recover the critical signature from time series data for faster and accurate RNN predictions.
1818
- **Shallow RNN**: A meta-architecture for training RNNs that can be applied to streaming data.
1919
- **FastRNN & FastGRNN - FastCells**: **F**ast, **A**ccurate, **S**table and **T**iny (**G**ated) RNN cells.
20-
- **Conv1D**: 1-D regular and low-rank convolution architectures for time-series data.
2120
- **DROCC**: **D**eep **R**obust **O**ne-**C**lass **C**lassfiication for training robust anomaly detectors.
2221
- **RNNPool**: An efficient non-linear pooling operator for RAM constrained inference.
2322

c_reference/include/conv1d.h

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
#ifndef __CONVLAYERS_H__
5-
#define __CONVLAYERS_H__
4+
#ifndef __CONV1D_H__
5+
#define __CONV1D_H__
66

77
/**
8-
* @brief Model paramters for the 1D Convolution Layer
8+
* @brief Model parameters for the 1D Convolution Layer
99
* @var W pointer to convolutional weights W, size for regular = out_channels*in_channels*kernel_size, size for depth based = out_channels*kernel_size
1010
* @var B pointer to the bias vector for the convolution, shape = [out_channels]
1111
*/
@@ -16,13 +16,16 @@ typedef struct ConvLayers_Params {
1616

1717
/**
1818
* @brief Model definition for the 1D Convolution Layer
19-
* @param[out] output_signal pointer to the output signal, size = out_T * out_channels
20-
* @param[in] out_T number of time steps in the output
21-
* @param[in] out_channels number of output channels for the ouput of the conv layer
22-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
23-
* @param[in] in_T number of time steps in the input
19+
* @param[out] output_signal pointer to the output signal, size = out_time * out_channels
20+
* @param[in] out_time number of time steps in the output
21+
* @param[in] out_channels number of output channels for the output of the conv layer
22+
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
23+
* @param[in] in_time number of time steps in the input
2424
* @param[in] in_channels number of input channels
25-
* @param[in] padding padding applied to the input before the conv is performed. Note: padding is applied to both the start and end
25+
* @param[in] padding padding applied to the input before the conv is performed.
26+
* Note: padding is applied to both the starting and ending of the input, along the time axis
27+
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(teim step in_time).
28+
*
2629
* @param[in] kernel_size kernel size of the conv filter
2730
* @param[in] params weights, bias and other essential parameters used to describe the layer
2831
* @param[in] activations an integer to choose the type of activation function.
@@ -31,18 +34,21 @@ typedef struct ConvLayers_Params {
3134
* 2: tanh
3235
* 3: relu
3336
*/
34-
int conv1d(float *output_signal, unsigned out_T, unsigned out_channels, const float *input_signal,
35-
unsigned in_T, unsigned in_channels, int padding, unsigned kernel_size,
37+
int conv1d(float *output_signal, unsigned out_time, unsigned out_channels, const float *input_signal,
38+
unsigned in_time, unsigned in_channels, int padding, unsigned kernel_size,
3639
const void* params, int activations);
3740

3841
/**
3942
* @brief Model definition for the 1D Depthwise Convolution Layer
40-
* @param[out] output_signal pointer to the output signal, size = out_T * in_channels
41-
* @param[in] out_T number of time steps in the output
42-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
43-
* @param[in] in_T number of time steps in the input
43+
* @param[out] output_signal pointer to the output signal, size = out_time * in_channels
44+
* @param[in] out_time number of time steps in the output
45+
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
46+
* @param[in] in_time number of time steps in the input
4447
* @param[in] in_channels number of input channels. The output will have the same number of channels
45-
* @param[in] padding padding applied to the input before the conv is performed. Note: padding is applied to both the start and end
48+
* @param[in] padding padding applied to the input before the conv is performed.
49+
* Note: padding is applied to both the starting and ending of the input, along the time axis
50+
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(teim step in_time).
51+
*
4652
* @param[in] kernel_size kernel size of the conv filter
4753
* @param[in] params weights, bias and other essential parameters used to describe the layer
4854
* @param[in] activations an integer to choose the type of activation function.
@@ -51,14 +57,13 @@ int conv1d(float *output_signal, unsigned out_T, unsigned out_channels, const fl
5157
* 2: tanh
5258
* 3: relu
5359
*/
54-
int conv1d_depth(float *output_signal, unsigned out_T, const float *input_signal,
55-
unsigned in_T, unsigned in_channels, int padding, unsigned kernel_size,
60+
int conv1d_depth(float *output_signal, unsigned out_time, const float *input_signal,
61+
unsigned in_time, unsigned in_channels, int padding, unsigned kernel_size,
5662
const void* params, int activations);
5763

5864

59-
// Low Rank Convolution
6065
/**
61-
* @brief Model paramters for the 1D Convolution Layer
66+
* @brief Model parameters for the 1D Low Rank Convolution Layer
6267
* @var W1 pointer to the 1st low-rank component of the weights, size = out_channels * rank
6368
* @var W2 pointer to the 2nd low-rank component of the weights, size for regular = rank * in_channels * kernel_size, size for depthwise = rank * kernel_size
6469
* @var B pointer to the bias vector for the convolution, shape = [out_channels]
@@ -73,14 +78,17 @@ typedef struct ConvLayers_LR_Params {
7378

7479
/**
7580
* @brief Model definition for the 1D Low Rank Convolution Layer
76-
* @brief Identical to the non-low-rank form. One modification is the mulitplication of the weights handeled witin the layer
77-
* @param[out] output_signal pointer to the output signal, size = out_T * out_channels
78-
* @param[in] out_T number of time steps in the output
81+
* @brief Identical to the non-low-rank form. One modification is the mulitplication of the weights handeled within the layer
82+
* @param[out] output_signal pointer to the output signal, size = out_time * out_channels
83+
* @param[in] out_time number of time steps in the output
7984
* @param[in] out_channels number of output channels for the ouput of the conv layer
80-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
81-
* @param[in] in_T number of time steps in the input
85+
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
86+
* @param[in] in_time number of time steps in the input
8287
* @param[in] in_channels number of input channels
83-
* @param[in] padding padding applied to the input before the conv is performed. Note: padding is applied to both the start and end
88+
* @param[in] padding padding applied to the input before the conv is performed.
89+
* Note: padding is applied to both the starting and ending of the input, along the time axis
90+
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(teim step in_time).
91+
*
8492
* @param[in] kernel_size kernel size of the conv filter
8593
* @param[in] params weights, bias and other essential parameters used to describe the layer
8694
* @param[in] activations an integer to choose the type of activation function.
@@ -89,19 +97,22 @@ typedef struct ConvLayers_LR_Params {
8997
* 2: tanh
9098
* 3: relu
9199
*/
92-
int conv1d_lr(float *output_signal, unsigned out_T, unsigned out_channels, const float *input_signal,
93-
unsigned in_T, unsigned in_channels, int padding, unsigned kernel_size,
100+
int conv1d_lr(float *output_signal, unsigned out_time, unsigned out_channels, const float *input_signal,
101+
unsigned in_time, unsigned in_channels, int padding, unsigned kernel_size,
94102
const void* params, int activations);
95103

96104
/**
97105
* @brief Model definition for the 1D Depthwise Convolution Layer
98106
* @brief Identical to the non-low-rank form. One modification is the mulitplication of the weights handeled witin the layer
99-
* @param[out] output_signal pointer to the output signal, size = out_T * in_channels
100-
* @param[in] out_T number of time steps in the output
101-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
102-
* @param[in] in_T number of time steps in the input
107+
* @param[out] output_signal pointer to the output signal, size = out_time * in_channels
108+
* @param[in] out_time number of time steps in the output
109+
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
110+
* @param[in] in_time number of time steps in the input
103111
* @param[in] in_channels number of input channels. The output will have the same number of channels
104-
* @param[in] padding padding applied to the input before the conv is performed. Note: padding is applied to both the start and end
112+
* @param[in] padding padding applied to the input before the conv is performed.
113+
* Note: padding is applied to both the starting and ending of the input, along the time axis
114+
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(teim step in_time).
115+
*
105116
* @param[in] kernel_size kernel size of the conv filter
106117
* @param[in] params weights, bias and other essential parameters used to describe the layer
107118
* @param[in] activations an integer to choose the type of activation function.
@@ -110,44 +121,47 @@ int conv1d_lr(float *output_signal, unsigned out_T, unsigned out_channels, const
110121
* 2: tanh
111122
* 3: relu
112123
*/
113-
int conv1d_depth_lr(float *output_signal, unsigned out_T, const float *input_signal,
114-
unsigned in_T, unsigned in_channels, int padding, unsigned kernel_size,
124+
int conv1d_depth_lr(float *output_signal, unsigned out_time, const float *input_signal,
125+
unsigned in_time, unsigned in_channels, int padding, unsigned kernel_size,
115126
const void* params, int activations);
116127

117128
// Auxillary Layers
118129
/**
119130
* @brief Model definition for the 1D Average Pooling Layer
120-
* @param[out] output_signal pointer to the output signal, size = out_T * in_channels. Provide Null/0 incase of inplace computation
121-
* @param[in] out_T number of time steps in the output
122-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
123-
* @param[in] in_T number of time steps in the input
131+
* @param[out] output_signal pointer to the output signal, size = out_time * in_channels. Provide Null/0 incase of in-place computation
132+
* @param[in] out_time number of time steps in the output
133+
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
134+
* @param[in] in_time number of time steps in the input
124135
* @param[in] in_channels number of input channels. The output will have the same number of channels
125-
* @param[in] padding padding applied to the input before the pool is performed. Note: padding is applied to both the start and end
136+
* @param[in] padding padding applied to the input before the conv is performed.
137+
* Note: padding is applied to both the starting and ending of the input, along the time axis
138+
* E.g : padding = 3, the input is padded with zeros(for 3 time steps), both before the input_signal(time step 0) and after the input_signal(teim step in_time).
139+
*
126140
* @param[in] kernel_size kernel size of the pool filter
127141
* @param[in] activations an integer to choose the type of activation function.
128142
* 0: none
129143
* 1: sigmoid
130144
* 2: tanh
131145
* 3: relu
132146
*/
133-
int avgpool1d(float *output_signal, unsigned out_T, const float *input_signal, unsigned in_T, unsigned in_channels,
147+
int avgpool1d(float *output_signal, unsigned out_time, const float *input_signal, unsigned in_time, unsigned in_channels,
134148
int padding, unsigned kernel_size, int activations);
135149

136150
/**
137151
* @brief Model definition for the 1D batch Normalization Layer
138-
* @param[out] output_signal pointer to the output signal, size = out_T * in_channels. Provide Null/0 incase of inplace computation
139-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
140-
* @param[in] in_T number of time steps in the input
152+
* @param[out] output_signal pointer to the output signal, size = out_time * in_channels. Provide Null/0 incase of in-place computation
153+
* @param[in] input_signal pointer to the input signal. size = in_time * in_channels
154+
* @param[in] in_time number of time steps in the input
141155
* @param[in] in_channels number of input channels. The output will have the same number of channels
142156
* @param[in] mean pointer to the mean for the batch normalization, size = in_channels
143157
* @param[in] var pointer to the variance for the batch normalization, size = in_channels
144158
* @param[in] affine whether the affine operations are applied
145159
* @param[in] gamma pointer to the scaling factors for the post-norm affine operation, size = in_channels
146160
* @param[in] beta pointer to the scalar offsets for the post-norm affine operation, size = in_channels
147-
* @param[in] in_place in place computation of the batchnorm i.e. the output is stored in place of the input signal. Storage efficient
161+
* @param[in] in_place in-place computation of the batchnorm i.e. the output is stored in-place of the input signal. Storage efficient
148162
* @param[in] eps a very small +ve value to avoid division by 0. For the default value, assign = 0.00001
149163
*/
150-
int batchnorm1d(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels,
164+
int batchnorm1d(float* output_signal, float* input_signal, unsigned in_time, unsigned in_channels,
151165
float* mean, float* var, unsigned affine, float* gamma , float * beta, unsigned in_place, float eps);
152166

153167
#endif

c_reference/include/conv_utils.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,8 @@
44
#ifndef __CONVLAYER_UTILS__
55
#define __CONVLAYER_UTILS__
66

7-
/**
8-
* @brief Definition for the Utility Fucntion for Preparing the Low Rank Conv Weights
9-
* @param[out] out pointer to the output signal, size (regular) = out_T * in_channels * kernel_size, size (depthwise) = out_t * kernel_size
10-
* @param[in] W1 1st component of the low rank weight tensor. size = out_channels * rank
11-
* @param[in] W2 2nd component of the low rank weight tensor. size (regular) = rank * in_channels * kernel_size, size (depthwise) = rank * kernel_size
12-
* @param[in] rank rank of the weight tensor. Low Rank
13-
* @param[in] I dim 0 for W1, value = out_channels
14-
* @param[in] J dim 1 for W2, value = in_channels * kernel_size, (or for depthwise) = kernel_size
15-
*/
16-
int matmul(float* out, float* W1, float* W2, unsigned rank, unsigned I, unsigned J);
177

18-
/**
19-
* @brief Definition for the Custom non-linear layer : The TanhGate
20-
* @param[out] output_signal pointer to the output signal, size = out_T * in_channels
21-
* @param[in] input_signal pointer to the input signal. size = in_T * in_channels
22-
* @param[in] in_T number of time steps in the input
23-
* @param[in] in_channels number of input channels. The output will have the half the number of channels. Recommended in_channel % 2 == 0
24-
*/
25-
int TanhGate(float* output_signal, float* input_signal, unsigned in_T, unsigned in_channels);
8+
9+
2610

2711
#endif

0 commit comments

Comments
 (0)