Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
727c55d3
Unverified
Commit
727c55d3
authored
Jul 02, 2019
by
Scott Cyphers
Committed by
GitHub
Jul 02, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3118 from NervanaSystems/arogowiec/lstm_fix
Fix fused sigmoid overflow.
parents
123d7663
5db8cbb6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
221 additions
and
36 deletions
+221
-36
sigmoid_multiply.hpp
src/ngraph/runtime/cpu/kernel/sigmoid_multiply.hpp
+68
-36
lstm_fwd_large_batch_no_clip.prototxt
test/models/onnx/lstm_fwd_large_batch_no_clip.prototxt
+107
-0
onnx_import_rnn.in.cpp
test/onnx/onnx_import_rnn.in.cpp
+46
-0
No files found.
src/ngraph/runtime/cpu/kernel/sigmoid_multiply.hpp
View file @
727c55d3
...
...
@@ -57,28 +57,28 @@ namespace ngraph
{
case
0
/*Logistic|Logistic*/
:
{
auto
c
=
(
in0
.
exp
()
*
in1
.
exp
())
/
((
in0
.
exp
()
+
1.
f
)
*
(
in1
.
exp
()
+
1.
f
));
auto
c
=
1.
f
/
(((
-
in0
).
exp
()
+
1.
f
)
*
((
-
in1
)
.
exp
()
+
1.
f
));
out_tm
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
c
;
}
break
;
case
1
/*Logistic|Tanh*/
:
{
auto
c
=
(
in0
.
exp
()
*
in1
.
tanh
())
/
(
in0
.
exp
()
+
1.
f
);
auto
c
=
in1
.
tanh
()
/
((
-
in0
)
.
exp
()
+
1.
f
);
out_tm
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
c
;
}
break
;
case
2
/*Logistic|Identity*/
:
{
auto
c
=
(
in0
.
exp
()
*
in1
)
/
(
in0
.
exp
()
+
1.
f
);
auto
c
=
in1
/
((
-
in0
)
.
exp
()
+
1.
f
);
out_tm
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
c
;
}
break
;
case
3
/*Tanh|Logistic*/
:
{
auto
c
=
(
in0
.
tanh
()
*
in1
.
exp
())
/
(
in1
.
exp
()
+
1.
f
);
auto
c
=
in0
.
tanh
()
/
((
-
in1
)
.
exp
()
+
1.
f
);
out_tm
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
c
;
}
...
...
@@ -99,7 +99,7 @@ namespace ngraph
break
;
case
6
/*Identity|Logistic*/
:
{
auto
c
=
(
in0
*
in1
.
exp
())
/
(
in1
.
exp
()
+
1.
f
);
auto
c
=
in0
/
((
-
in1
)
.
exp
()
+
1.
f
);
out_tm
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
c
;
}
...
...
@@ -141,10 +141,15 @@ namespace ngraph
{
case
0
/*Logistic|Logistic*/
:
{
auto
i0
=
delta
*
(
in1
.
exp
()
*
in0
.
exp
())
/
((
in1
.
exp
()
+
1.
f
)
*
((
in0
.
exp
()
+
1.
f
)
*
(
in0
.
exp
()
+
1.
f
)));
auto
i1
=
delta
*
(
in0
.
exp
()
*
in1
.
exp
())
/
((
in0
.
exp
()
+
1.
f
)
*
((
in1
.
exp
()
+
1.
f
)
*
(
in1
.
exp
()
+
1.
f
)));
auto
in0_neg_exp
=
(
-
in0
).
exp
();
auto
in0_log_denominator
=
in0_neg_exp
+
1.
f
;
auto
in1_neg_exp
=
(
-
in1
).
exp
();
auto
in1_log_denominator
=
in1_neg_exp
+
1.
f
;
auto
i0
=
delta
*
in0_neg_exp
/
(
in1_log_denominator
*
in0_log_denominator
*
in0_log_denominator
);
auto
i1
=
delta
*
in1_neg_exp
/
(
in0_log_denominator
*
in1_log_denominator
*
in1_log_denominator
);
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
@@ -153,12 +158,17 @@ namespace ngraph
break
;
case
1
/*Logistic|Tanh*/
:
{
auto
in0_neg_exp
=
(
-
in0
).
exp
();
auto
in0_log_denominator
=
in0_neg_exp
+
1.
f
;
auto
in1_2exp
=
(
in1
*
2.
f
).
exp
();
auto
in1_tanh_denominator
=
in1_2exp
+
1.
f
;
auto
i0
=
delta
*
((
(
in1
*
2.
f
).
exp
()
-
1.
f
)
*
in0
.
exp
()
)
/
(
((
in1
*
2.
f
).
exp
()
+
1.
f
)
*
((
in0
.
exp
()
+
1.
f
)
*
(
in0
.
exp
()
+
1.
f
))
);
auto
i1
=
delta
*
(
in0
.
exp
()
*
(
4.
f
*
(
in1
*
2.
f
).
exp
()))
/
((
in0
.
exp
()
+
1.
f
)
*
(((
in1
*
2.
f
).
exp
()
+
1.
f
)
*
((
in1
*
2.
f
).
exp
()
+
1.
f
))
);
delta
*
((
in1_2exp
-
1.
f
)
*
in0_neg_exp
)
/
(
in1_tanh_denominator
*
in0_log_denominator
*
in0_log_denominator
);
auto
i1
=
delta
*
(
4.
f
*
in1_2exp
)
/
(
in0_log_denominator
*
in1_tanh_denominator
*
in1_tanh_denominator
);
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
@@ -167,9 +177,12 @@ namespace ngraph
break
;
case
2
/*Logistic|Identity*/
:
{
auto
i0
=
delta
*
(
in1
*
in0
.
exp
())
/
((
in0
.
exp
()
+
1.
f
)
*
(
in0
.
exp
()
+
1.
f
));
auto
i1
=
delta
*
in0
.
exp
()
/
((
in0
.
exp
()
+
1.
f
));
auto
in0_neg_exp
=
(
-
in0
).
exp
();
auto
in0_log_denominator
=
in0_neg_exp
+
1.
f
;
auto
i0
=
delta
*
(
in1
*
in0_neg_exp
)
/
(
in0_log_denominator
*
in0_log_denominator
);
auto
i1
=
delta
/
in0_log_denominator
;
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
@@ -178,12 +191,17 @@ namespace ngraph
break
;
case
3
/*Tanh|Logistic*/
:
{
auto
i0
=
delta
*
(
in1
.
exp
()
*
(
4.
f
*
(
in0
*
2.
f
).
exp
()))
/
((
in1
.
exp
()
+
1.
f
)
*
((
in0
*
2.
f
).
exp
()
+
1.
f
)
*
((
in0
*
2.
f
).
exp
()
+
1.
f
));
auto
in0_2exp
=
(
in0
*
2.
f
).
exp
();
auto
in0_tanh_denominator
=
in0_2exp
+
1.
f
;
auto
in1_neg_exp
=
(
-
in1
).
exp
();
auto
in1_log_denominator
=
in1_neg_exp
+
1.
f
;
auto
i0
=
delta
*
(
4.
f
*
in0_2exp
)
/
(
in1_log_denominator
*
in0_tanh_denominator
*
in0_tanh_denominator
);
auto
i1
=
delta
*
((
(
in0
*
2.
f
).
exp
()
-
1.
f
)
*
in1
.
exp
()
)
/
(
((
in0
*
2.
f
).
exp
()
+
1.
f
)
*
((
in1
.
exp
()
+
1.
f
)
*
(
in1
.
exp
()
+
1.
f
))
);
delta
*
((
in0_2exp
-
1.
f
)
*
in1_neg_exp
)
/
(
in0_tanh_denominator
*
in1_log_denominator
*
in1_log_denominator
);
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
@@ -192,12 +210,17 @@ namespace ngraph
break
;
case
4
/*Tanh|Tanh*/
:
{
auto
i0
=
delta
*
(((
in1
*
2.
f
).
exp
()
-
1.
f
)
*
(
4.
f
*
(
in0
*
2.
f
).
exp
()))
/
(((
in1
*
2.
f
).
exp
()
+
1.
f
)
*
(((
in0
*
2.
f
).
exp
()
+
1.
f
)
*
((
in0
*
2.
f
).
exp
()
+
1.
f
)));
auto
i1
=
delta
*
(((
in0
*
2.
f
).
exp
()
-
1.
f
)
*
(
4.
f
*
(
in1
*
2.
f
).
exp
()))
/
(((
in0
*
2.
f
).
exp
()
+
1.
f
)
*
(((
in1
*
2.
f
).
exp
()
+
1.
f
)
*
((
in1
*
2.
f
).
exp
()
+
1.
f
)));
auto
in0_2exp
=
(
in0
*
2.
f
).
exp
();
auto
in0_tanh_denominator
=
in0_2exp
+
1.
f
;
auto
in1_2exp
=
(
in1
*
2.
f
).
exp
();
auto
in1_tanh_denominator
=
in1_2exp
+
1.
f
;
auto
i0
=
delta
*
(
in1_2exp
-
1.
f
)
*
4.
f
*
in0_2exp
/
(
in1_tanh_denominator
*
in0_tanh_denominator
*
in0_tanh_denominator
);
auto
i1
=
delta
*
(
in0_2exp
-
1.
f
)
*
4.
f
*
in1_2exp
/
(
in0_tanh_denominator
*
in1_tanh_denominator
*
in1_tanh_denominator
);
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
@@ -206,9 +229,12 @@ namespace ngraph
break
;
case
5
/*Tanh|Identity*/
:
{
auto
i0
=
delta
*
(
in1
*
(
4.
f
*
(
in0
*
2.
f
).
exp
()))
/
(((
in0
*
2.
f
).
exp
()
+
1.
f
)
*
((
in0
*
2.
f
).
exp
()
+
1.
f
));
auto
i1
=
delta
*
((
in0
*
2.
f
).
exp
()
-
1.
f
)
/
((
in0
*
2.
f
).
exp
()
+
1.
f
);
auto
in0_2exp
=
(
in0
*
2.
f
).
exp
();
auto
in0_tanh_denominator
=
in0_2exp
+
1.
f
;
auto
i0
=
delta
*
in1
*
4.
f
*
in0_2exp
/
(
in0_tanh_denominator
*
in0_tanh_denominator
);
auto
i1
=
delta
*
(
in0_2exp
-
1.
f
)
/
in0_tanh_denominator
;
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
@@ -217,9 +243,12 @@ namespace ngraph
break
;
case
6
/*Identity|Logistic*/
:
{
auto
i0
=
delta
*
(
in1
.
exp
())
/
(
in1
.
exp
()
+
1.
f
);
auto
in1_neg_exp
=
(
-
in1
).
exp
();
auto
in1_log_denominator
=
in1_neg_exp
+
1.
f
;
auto
i0
=
delta
*
1.
f
/
in1_log_denominator
;
auto
i1
=
delta
*
(
in0
*
in1
.
exp
())
/
((
in1
.
exp
()
+
1.
f
)
*
(
in1
.
exp
()
+
1.
f
)
);
delta
*
in0
*
in1_neg_exp
/
(
in1_log_denominator
*
in1_log_denominator
);
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
@@ -228,9 +257,12 @@ namespace ngraph
break
;
case
7
/*Identity|Tanh*/
:
{
auto
i0
=
delta
*
((
in1
*
2.
f
).
exp
()
-
1.
f
)
/
((
in1
*
2.
f
).
exp
()
+
1.
f
);
auto
i1
=
delta
*
(
in0
*
(
4.
f
*
(
in1
*
2.
f
).
exp
()))
/
(((
in1
*
2.
f
).
exp
()
+
1.
f
)
*
((
in1
*
2.
f
).
exp
()
+
1.
f
));
auto
in1_2exp
=
(
in1
*
2.
f
).
exp
();
auto
in1_tanh_denominator
=
in1_2exp
+
1.
f
;
auto
i0
=
delta
*
(
in1_2exp
-
1.
f
)
/
in1_tanh_denominator
;
auto
i1
=
delta
*
(
in0
*
(
4.
f
*
in1_2exp
))
/
(
in1_tanh_denominator
*
in1_tanh_denominator
);
i0_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
arena
))
=
i0
;
i1_delta
.
device
(
ngraph
::
runtime
::
cpu
::
executor
::
GetCPUExecutor
().
get_device
(
...
...
test/models/onnx/lstm_fwd_large_batch_no_clip.prototxt
0 → 100644
View file @
727c55d3
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "X"
input: "W"
input: "R"
output: ""
output: "Y_h"
op_type: "LSTM"
attribute {
name: "clip"
f: 9999.0
type: FLOAT
}
attribute {
name: "direction"
s: "forward"
type: STRING
}
attribute {
name: "hidden_size"
i: 3
type: INT
}
}
name: "compute_graph"
input {
name: "X"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 2
}
dim {
dim_value: 32
}
dim {
dim_value: 1
}
}
}
}
}
input {
name: "W"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 12
}
dim {
dim_value: 1
}
}
}
}
}
input {
name: "R"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 12
}
dim {
dim_value: 3
}
}
}
}
}
output {
name: "Y_h"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 32
}
dim {
dim_value: 3
}
}
}
}
}
}
opset_import {
version: 7
}
test/onnx/onnx_import_rnn.in.cpp
View file @
727c55d3
...
...
@@ -20,6 +20,7 @@
#include <fstream>
#include <iterator>
#include <limits>
#include <numeric>
#include <sstream>
#include <stdexcept>
#include <vector>
...
...
@@ -203,3 +204,48 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, model_lstm_fwd_hardsigmoid_activation)
test_case
.
set_tolerance
(
6
);
test_case
.
run
();
}
NGRAPH_TEST
(
onnx_
$
{
BACKEND_NAME
},
model_lstm_fwd_large_batch_no_clip
)
{
auto
function
=
onnx_import
::
import_onnx_model
(
file_util
::
path_join
(
SERIALIZED_ZOO
,
"onnx/lstm_fwd_large_batch_no_clip.prototxt"
));
auto
test_case
=
ngraph
::
test
::
NgraphTestCase
(
function
,
"${BACKEND_NAME}"
);
std
::
size_t
seq_length
=
2
;
std
::
size_t
batch_size
=
32
;
std
::
size_t
input_size
=
1
;
std
::
size_t
hidden_size
=
3
;
std
::
vector
<
float
>
in_X
(
seq_length
*
batch_size
*
input_size
);
std
::
iota
(
std
::
begin
(
in_X
),
std
::
end
(
in_X
),
1.
f
);
std
::
vector
<
float
>
in_R
(
4
*
hidden_size
*
hidden_size
,
0.1
f
);
// X
test_case
.
add_input
<
float
>
(
in_X
);
// W
test_case
.
add_input
<
float
>
(
{
0.1
f
,
0.2
f
,
0.3
f
,
0.4
f
,
1.
f
,
2.
f
,
3.
f
,
4.
f
,
10.
f
,
11.
f
,
12.
f
,
13.
f
});
// R
test_case
.
add_input
<
float
>
(
in_R
);
// Y_h_data
test_case
.
add_expected_output
<
float
>
(
Shape
{
1
,
batch_size
,
hidden_size
},
{
0.90387899
f
,
0.9135572
f
,
0.91772245
f
,
0.90897038
f
,
0.92132433
f
,
0.92825467
f
,
0.91365823
f
,
0.92815113
f
,
0.93676105
f
,
0.91799162
f
,
0.93406357
f
,
0.94344562
f
,
0.92199681
f
,
0.93912057
f
,
0.94859476
f
,
0.92569357
f
,
0.94340185
f
,
0.95250664
f
,
0.92909964
f
,
0.94699686
f
,
0.95545127
f
,
0.93223207
f
,
0.94999634
f
,
0.95765468
f
,
0.93510761
f
,
0.9524867
f
,
0.95929726
f
,
0.93774272
f
,
0.9545467
f
,
0.96051891
f
,
0.9401536
f
,
0.95624603
f
,
0.96142619
f
,
0.94235605
f
,
0.95764499
f
,
0.96209939
f
,
0.94436539
f
,
0.95879495
f
,
0.96259862
f
,
0.94619635
f
,
0.95973921
f
,
0.96296872
f
,
0.94786299
f
,
0.96051397
f
,
0.96324302
f
,
0.94937864
f
,
0.96114929
f
,
0.96344629
f
,
0.95075587
f
,
0.96167006
f
,
0.96359692
f
,
0.95200645
f
,
0.96209679
f
,
0.96370852
f
,
0.95314133
f
,
0.9624464
f
,
0.9637912
f
,
0.95417069
f
,
0.96273278
f
,
0.96385246
f
,
0.95510395
f
,
0.96296733
f
,
0.96389785
f
,
0.95594975
f
,
0.96315942
f
,
0.96393147
f
,
0.95671607
f
,
0.96331673
f
,
0.96395638
f
,
0.9574102
f
,
0.96344554
f
,
0.96397483
f
,
0.9580388
f
,
0.96355102
f
,
0.9639885
f
,
0.95860795
f
,
0.96363739
f
,
0.96399863
f
,
0.95912322
f
,
0.96370811
f
,
0.96400613
f
,
0.95958963
f
,
0.96376601
f
,
0.96401169
f
,
0.96001179
f
,
0.96381342
f
,
0.96401581
f
,
0.96039386
f
,
0.96385224
f
,
0.96401886
f
,
0.96073964
f
,
0.96388402
f
,
0.96402112
f
,
0.96105254
f
,
0.96391004
f
,
0.96402279
f
});
test_case
.
run
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment