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
11ed222d
Commit
11ed222d
authored
Oct 18, 2017
by
Scott Cyphers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Numeric/sym comparison works.
parent
420c1abe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
12 deletions
+14
-12
utils.cpp
src/ngraph/runtime/utils.cpp
+8
-10
utils.hpp
src/ngraph/runtime/utils.hpp
+4
-0
autodiff.cpp
test/autodiff.cpp
+2
-2
No files found.
src/ngraph/runtime/utils.cpp
View file @
11ed222d
...
...
@@ -87,7 +87,6 @@ ngraph::runtime::FunctionSpec::operator std::shared_ptr<Function>() const
return
std
::
make_shared
<
ngraph
::
Function
>
(
m_result
,
m_result_type
,
m_parameters
);
}
// Returns (dy/(dXs))(C, Xs)
std
::
shared_ptr
<
ngraph
::
runtime
::
FunctionSpec
>
ngraph
::
runtime
::
derivative
(
const
std
::
shared_ptr
<
ngraph
::
runtime
::
FunctionSpec
>&
f
)
{
...
...
@@ -121,7 +120,7 @@ std::vector<std::shared_ptr<ngraph::runtime::ParameterizedTensorView<ET>>>
Shape
y_shape
=
std
::
dynamic_pointer_cast
<
const
ngraph
::
TensorViewType
>
(
y
->
get_value_type
())
->
get_shape
();
//
Check all the shapes
//
Results for each derivative, shape Y|X_i
std
::
vector
<
std
::
shared_ptr
<
ngraph
::
runtime
::
ParameterizedTensorView
<
ET
>>>
results
;
for
(
size_t
i
=
0
;
i
<
args
.
size
();
i
++
)
{
...
...
@@ -141,11 +140,11 @@ std::vector<std::shared_ptr<ngraph::runtime::ParameterizedTensorView<ET>>>
args_tv
.
insert
(
args_tv
.
begin
(),
args
.
begin
(),
args
.
end
());
cf
->
tensor_call
(
args_tv
,
TensorViewPtrs
{
ref_y
});
auto
ref_vec
=
ref_y
->
get_vector
();
auto
&
ref_vec
=
ref_y
->
get_vector
();
// inc_y will hold f(x+dx) values
auto
inc_y
=
backend
->
make_parameterized_tensor_view
<
ET
>
(
y_shape
);
auto
inc_vec
=
inc_y
->
get_vector
();
auto
&
inc_vec
=
inc_y
->
get_vector
();
// Assuming vars, y, and results are row-major
...
...
@@ -155,8 +154,8 @@ std::vector<std::shared_ptr<ngraph::runtime::ParameterizedTensorView<ET>>>
auto
arg
=
args
[
i
];
auto
df_darg
=
results
[
i
];
auto
df_darg_it
=
df_darg
->
get_vector
().
begin
();
std
::
vector
<
typename
ET
::
type
>
&
vec
=
arg
->
get_vector
();
for
(
size_t
j
=
0
;
j
<
vec
.
size
();
i
++
)
auto
&
vec
=
arg
->
get_vector
();
for
(
size_t
j
=
0
;
j
<
vec
.
size
();
j
++
)
{
auto
old_val
=
vec
[
j
];
vec
[
j
]
+=
delta
;
...
...
@@ -247,7 +246,7 @@ std::vector<std::shared_ptr<ngraph::runtime::ParameterizedTensorView<ET>>>
TensorViewPtrs
bprops_tv
;
bprops_tv
.
insert
(
bprops_tv
.
begin
(),
bprops
.
begin
(),
bprops
.
end
());
auto
c_vec
=
c_arg
->
get_vector
();
auto
&
c_vec
=
c_arg
->
get_vector
();
for
(
size_t
i
=
0
;
i
<
c_vec
.
size
();
i
++
)
{
c_vec
[
i
]
=
1
;
...
...
@@ -255,9 +254,8 @@ std::vector<std::shared_ptr<ngraph::runtime::ParameterizedTensorView<ET>>>
c_vec
[
i
]
=
0
;
for
(
size_t
j
=
0
;
j
<
results
.
size
();
j
++
)
{
auto
bprop_vec
=
bprops
[
j
]
->
get_vector
();
result_pos
[
j
]
=
results
[
j
]
->
get_vector
().
insert
(
result_pos
[
j
],
bprop_vec
.
begin
(),
bprop_vec
.
end
());
auto
&
bprop_vec
=
bprops
[
j
]
->
get_vector
();
result_pos
[
j
]
=
std
::
copy
(
bprop_vec
.
begin
(),
bprop_vec
.
end
(),
result_pos
[
j
]);
}
}
...
...
src/ngraph/runtime/utils.hpp
View file @
11ed222d
...
...
@@ -90,6 +90,7 @@ namespace ngraph
double
rtol
,
double
atol
);
/// @brief Contains the information in a Function, but can be used to construct derived functions such as derivatives.
class
FunctionSpec
{
public
:
...
...
@@ -125,6 +126,9 @@ namespace ngraph
std
::
vector
<
std
::
shared_ptr
<
op
::
Parameter
>>
m_parameters
;
};
/// @brief Returns a FunctionSpec for the backprop derivative of its argument.
/// @param f is f(X_i...)
/// @returns f'(c, X_i...) -> tuple of tensors in same order as in X_i
std
::
shared_ptr
<
ngraph
::
runtime
::
FunctionSpec
>
derivative
(
const
std
::
shared_ptr
<
ngraph
::
runtime
::
FunctionSpec
>&
f
);
...
...
test/autodiff.cpp
View file @
11ed222d
...
...
@@ -91,7 +91,7 @@ TEST(backwards, multiply)
auto
f_num
=
make_graph
();
auto
results_num
=
runtime
::
numeric_derivative
<
element
::
Float32
>
(
manager
,
backend
,
f_num
,
{
x0
,
x1
},
.01
f
);
runtime
::
numeric_derivative
<
element
::
Float32
>
(
manager
,
backend
,
f_num
,
{
x0
,
x1
},
.0
0
1
f
);
auto
f_sym
=
make_graph
();
auto
results_sym
=
runtime
::
backwards_derivative
<
element
::
Float32
>
(
manager
,
backend
,
f_sym
,
{
x0
,
x1
});
...
...
@@ -99,7 +99,7 @@ TEST(backwards, multiply)
{
auto
result_num
=
results_num
[
i
];
auto
result_sym
=
results_sym
[
i
];
bool
ac
=
all_close
(
result_num
,
result_sym
);
bool
ac
=
all_close
(
result_num
,
result_sym
,
.01
f
,
.01
f
);
EXPECT_TRUE
(
ac
);
}
}
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