Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
210130133
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
210130133
Commits
400fe454
Commit
400fe454
authored
5 years ago
by
scxfjiang
Committed by
Li Xinqi
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix (#2120)
parent
5f7eac7a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
oneflow/python/ops/reduce_mean.py
+9
-0
9 additions, 0 deletions
oneflow/python/ops/reduce_mean.py
oneflow/python/ops/reduce_sum.py
+10
-0
10 additions, 0 deletions
oneflow/python/ops/reduce_sum.py
oneflow/python/test/reduce_demo.py
+66
-0
66 additions, 0 deletions
oneflow/python/test/reduce_demo.py
with
85 additions
and
0 deletions
oneflow/python/ops/reduce_mean.py
+
9
−
0
View file @
400fe454
from
__future__
import
absolute_import
import
oneflow.core.operator.op_conf_pb2
as
op_conf_util
import
oneflow.core.register.logical_blob_id_pb2
as
logical_blob_id_util
import
oneflow.python.framework.id_util
as
id_util
import
oneflow.python.framework.compile_context
as
compile_context
import
oneflow.python.framework.remote_blob
as
remote_blob_util
from
oneflow.python.oneflow_export
import
oneflow_export
@oneflow_export
(
"
math.reduce_mean
"
)
def
reduce_mean
(
input_tensor
,
axis
=
None
,
keepdims
=
False
,
name
=
None
):
op_conf
=
op_conf_util
.
OperatorConf
()
...
...
This diff is collapsed.
Click to expand it.
oneflow/python/ops/reduce_sum.py
+
10
−
0
View file @
400fe454
from
__future__
import
absolute_import
import
oneflow.core.operator.op_conf_pb2
as
op_conf_util
import
oneflow.core.register.logical_blob_id_pb2
as
logical_blob_id_util
import
oneflow.python.framework.id_util
as
id_util
import
oneflow.python.framework.compile_context
as
compile_context
import
oneflow.python.framework.remote_blob
as
remote_blob_util
from
oneflow.python.oneflow_export
import
oneflow_export
@oneflow_export
(
"
math.reduce_sum
"
)
def
reduce_sum
(
input_tensor
,
axis
=
None
,
keepdims
=
False
,
name
=
None
):
op_conf
=
op_conf_util
.
OperatorConf
()
...
...
This diff is collapsed.
Click to expand it.
oneflow/python/test/reduce_demo.py
0 → 100644
+
66
−
0
View file @
400fe454
import
tensorflow
as
tf
import
oneflow
as
flow
import
numpy
as
np
tf
.
enable_eager_execution
()
assert
tf
.
executing_eagerly
()
def
test_reduce_sum
(
input_shape
,
axis
=
None
,
keepdims
=
False
):
input
=
np
.
random
.
random_sample
(
input_shape
).
astype
(
np
.
float32
)
# OneFlow
config
=
flow
.
ConfigProtoBuilder
()
config
.
gpu_device_num
(
1
)
flow
.
init
(
config
)
def
ReduceSumTestJob
(
input
=
flow
.
input_blob_def
(
input_shape
)):
job_conf
=
flow
.
get_cur_job_conf_builder
()
job_conf
.
batch_size
(
1
).
data_part_num
(
1
).
default_data_type
(
flow
.
float
)
return
flow
.
math
.
reduce_sum
(
input_tensor
=
input
,
axis
=
axis
,
keepdims
=
keepdims
)
flow
.
add_job
(
ReduceSumTestJob
)
with
flow
.
Session
()
as
sess
:
of_out
=
sess
.
run
(
ReduceSumTestJob
,
input
).
get
()
# TensorFlow
tf_out
=
tf
.
math
.
reduce_sum
(
tf
.
Variable
(
input
),
axis
=
axis
,
keepdims
=
keepdims
).
numpy
()
print
(
"
dense max diff:
"
+
str
(
np
.
max
(
np
.
abs
(
of_out
-
tf_out
))))
assert
np
.
allclose
(
of_out
,
tf_out
,
atol
=
1e-7
)
def
test_reduce_mean
(
input_shape
,
axis
=
None
,
keepdims
=
False
):
input
=
np
.
random
.
random_sample
(
input_shape
).
astype
(
np
.
float32
)
# OneFlow
config
=
flow
.
ConfigProtoBuilder
()
config
.
gpu_device_num
(
1
)
flow
.
init
(
config
)
def
ReduceMeanTestJob
(
input
=
flow
.
input_blob_def
(
input_shape
)):
job_conf
=
flow
.
get_cur_job_conf_builder
()
job_conf
.
batch_size
(
1
).
data_part_num
(
1
).
default_data_type
(
flow
.
float
)
return
flow
.
math
.
reduce_mean
(
input_tensor
=
input
,
axis
=
axis
,
keepdims
=
keepdims
)
flow
.
add_job
(
ReduceMeanTestJob
)
with
flow
.
Session
()
as
sess
:
of_out
=
sess
.
run
(
ReduceMeanTestJob
,
input
).
get
()
# TensorFlow
tf_out
=
tf
.
math
.
reduce_mean
(
tf
.
Variable
(
input
),
axis
=
axis
,
keepdims
=
keepdims
).
numpy
()
print
(
"
dense max diff:
"
+
str
(
np
.
max
(
np
.
abs
(
of_out
-
tf_out
))))
assert
np
.
allclose
(
of_out
,
tf_out
,
atol
=
1e-7
)
# run one example each time
if
__name__
==
"
__main__
"
:
test_reduce_sum
(
input_shape
=
(
1024
,
1024
))
# test_reduce_sum(input_shape=(1024, 1024), axis=[1], keepdims=True)
# test_reduce_sum(input_shape=(100, 100, 100), axis=[1, 2], keepdims=False)
# test_reduce_mean(input_shape=(1024, 1024))
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment