Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
f5c9bc93
Unverified
Commit
f5c9bc93
authored
Apr 22, 2020
by
Andrew Reusch
Committed by
GitHub
Apr 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Customize SI prefix in logging (#5411)
* Customize SI prefix in logging * Include unit test
parent
8f9796bd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
8 deletions
+71
-8
python/tvm/autotvm/tuner/callback.py
+11
-4
python/tvm/autotvm/tuner/tuner.py
+10
-4
python/tvm/autotvm/util.py
+9
-0
tests/python/unittest/test_format_si_prefix.py
+41
-0
No files found.
python/tvm/autotvm/tuner/callback.py
View file @
f5c9bc93
...
...
@@ -23,6 +23,7 @@ import logging
import
numpy
as
np
from
..
import
record
from
..util
import
format_si_prefix
logger
=
logging
.
getLogger
(
'autotvm'
)
...
...
@@ -105,7 +106,7 @@ class Monitor(object):
return
np
.
array
(
self
.
timestamps
)
def
progress_bar
(
total
,
prefix
=
''
):
def
progress_bar
(
total
,
prefix
=
''
,
si_prefix
=
'G'
):
"""Display progress bar for tuning
Parameters
...
...
@@ -114,6 +115,8 @@ def progress_bar(total, prefix=''):
The total number of trials
prefix: str
The prefix of output message
si_prefix: str
SI prefix for flops
"""
class
_Context
(
object
):
"""Context to store local variables"""
...
...
@@ -130,6 +133,9 @@ def progress_bar(total, prefix=''):
ctx
=
_Context
()
tic
=
time
.
time
()
# Validate si_prefix argument
format_si_prefix
(
0
,
si_prefix
)
if
logger
.
level
<
logging
.
DEBUG
:
# only print progress bar in non-debug mode
sys
.
stdout
.
write
(
'
\r
%
s Current/Best:
%7.2
f/
%7.2
f GFLOPS | Progress: (
%
d/
%
d) '
'|
%.2
f s'
%
(
prefix
,
0
,
0
,
0
,
total
,
time
.
time
()
-
tic
))
...
...
@@ -147,10 +153,11 @@ def progress_bar(total, prefix=''):
ctx
.
cur_flops
=
flops
ctx
.
best_flops
=
tuner
.
best_flops
sys
.
stdout
.
write
(
'
\r
%
s Current/Best:
%7.2
f/
%7.2
f
G
FLOPS | Progress: (
%
d/
%
d) '
sys
.
stdout
.
write
(
'
\r
%
s Current/Best:
%7.2
f/
%7.2
f
%
s
FLOPS | Progress: (
%
d/
%
d) '
'|
%.2
f s'
%
(
prefix
,
ctx
.
cur_flops
/
1e9
,
ctx
.
best_flops
/
1e9
,
ctx
.
ct
,
ctx
.
total
,
time
.
time
()
-
tic
))
(
prefix
,
format_si_prefix
(
ctx
.
cur_flops
,
si_prefix
),
format_si_prefix
(
ctx
.
best_flops
,
si_prefix
),
si_prefix
,
ctx
.
ct
,
ctx
.
total
,
time
.
time
()
-
tic
))
sys
.
stdout
.
flush
()
return
_callback
python/tvm/autotvm/tuner/tuner.py
View file @
f5c9bc93
...
...
@@ -21,6 +21,7 @@ import logging
import
numpy
as
np
from
..measure
import
MeasureInput
,
create_measure_batch
from
..util
import
format_si_prefix
from
..env
import
GLOBAL_SCOPE
...
...
@@ -87,7 +88,7 @@ class Tuner(object):
"""
def
tune
(
self
,
n_trial
,
measure_option
,
early_stopping
=
None
,
callbacks
=
()):
def
tune
(
self
,
n_trial
,
measure_option
,
early_stopping
=
None
,
callbacks
=
()
,
si_prefix
=
'G'
):
"""Begin tuning
Parameters
...
...
@@ -104,6 +105,8 @@ class Tuner(object):
(Tuner, List of MeasureInput, List of MeasureResult)
with no return value. These callback functions will be called on
every measurement pair. See autotvm/tuner/callback.py for some examples.
si_prefix: str
One of tvm.autotvm.util.SI_PREFIXES. The SI prefix to use when reporting FLOPS.
"""
measure_batch
=
create_measure_batch
(
self
.
task
,
measure_option
)
n_parallel
=
getattr
(
measure_batch
,
'n_parallel'
,
1
)
...
...
@@ -111,6 +114,9 @@ class Tuner(object):
self
.
n_trial
=
n_trial
self
.
early_stopping
=
early_stopping
# Validate si_prefix arg
format_si_prefix
(
0
,
si_prefix
)
old_level
=
logger
.
level
GLOBAL_SCOPE
.
in_tuning
=
True
...
...
@@ -140,9 +146,9 @@ class Tuner(object):
self
.
best_measure_pair
=
(
inp
,
res
)
self
.
best_iter
=
i
+
k
logger
.
debug
(
"No:
%
d
\t
G
FLOPS:
%.2
f/
%.2
f
\t
result:
%
s
\t
%
s"
,
i
+
k
+
1
,
flops
/
1e9
,
self
.
best_flops
/
1e9
,
res
,
config
)
logger
.
debug
(
"No:
%
d
\t
%
s
FLOPS:
%.2
f/
%.2
f
\t
result:
%
s
\t
%
s"
,
i
+
k
+
1
,
si_prefix
,
format_si_prefix
(
flops
,
si_prefix
)
,
format_si_prefix
(
self
.
best_flops
,
si_prefix
),
res
,
config
)
i
+=
len
(
results
)
self
.
ttl
=
min
(
early_stopping
+
self
.
best_iter
,
n_trial
)
-
i
...
...
python/tvm/autotvm/util.py
View file @
f5c9bc93
...
...
@@ -188,3 +188,12 @@ def get_const_tuple(in_tuple):
else
:
ret
.
append
(
get_const_int
(
elem
))
return
tuple
(
ret
)
SI_PREFIXES
=
'yzafpn
\xb5
m kMGTPEZY'
YOCTO_EXP10
=
-
24
def
format_si_prefix
(
x
,
si_prefix
):
exp10
=
10
**
(
SI_PREFIXES
.
index
(
si_prefix
)
*
3
+
YOCTO_EXP10
)
return
float
(
x
)
/
exp10
tests/python/unittest/test_format_si_prefix.py
0 → 100644
View file @
f5c9bc93
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from
numpy
import
isclose
import
random
from
tvm.autotvm
import
util
SI_PREFIXES
=
'yzafpn
\xb5
m kMGTPEZY'
def
test_format_si_prefix
():
# test float conversion
assert
util
.
format_si_prefix
(
1024
,
'k'
)
==
1.024
for
i
,
prefix
in
enumerate
(
SI_PREFIXES
):
integer
,
decimal
=
random
.
randint
(
0
,
1000
),
random
.
randint
(
0
,
1000
)
exp
=
-
24
+
3
*
i
# 0th prefix (yocto) is 10^-24
number
=
integer
*
(
10
**
exp
)
+
decimal
*
(
10
**
(
exp
-
3
))
expected
=
(
integer
+
decimal
/
1000
)
assert
isclose
(
util
.
format_si_prefix
(
number
,
prefix
),
expected
)
assert
util
.
format_si_prefix
(
0
,
'y'
)
==
0
if
__name__
==
'__main__'
:
test_format_si_prefix
()
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