Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
food-round2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joel Joseph
food-round2
Commits
4472c661
Commit
4472c661
authored
5 years ago
by
Rinat Shigapov
Committed by
Kai Chen
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix debug completed logging (#1897)
parent
8df11f96
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mmdet/utils/contextmanagers.py
+21
-17
21 additions, 17 deletions
mmdet/utils/contextmanagers.py
with
21 additions
and
17 deletions
mmdet/utils/contextmanagers.py
+
21
−
17
View file @
4472c661
...
...
@@ -14,8 +14,8 @@ DEBUG_COMPLETED_TIME = bool(os.environ.get('DEBUG_COMPLETED_TIME', False))
@contextlib.asynccontextmanager
async
def
completed
(
trace_name
=
""
,
name
=
""
,
async
def
completed
(
trace_name
=
''
,
name
=
''
,
sleep_interval
=
0.05
,
streams
:
List
[
torch
.
cuda
.
Stream
]
=
None
):
"""
...
...
@@ -42,7 +42,7 @@ async def completed(trace_name="",
stream_before_context_switch
.
record_event
(
start
)
cpu_start
=
time
.
monotonic
()
logger
.
debug
(
"
%s %s starting, streams: %s
"
,
trace_name
,
name
,
streams
)
logger
.
debug
(
'
%s %s starting, streams: %s
'
,
trace_name
,
name
,
streams
)
grad_enabled_before
=
torch
.
is_grad_enabled
()
try
:
yield
...
...
@@ -60,37 +60,41 @@ async def completed(trace_name="",
# observed change of torch.is_grad_enabled() during concurrent run of
# async_test_bboxes code
assert
grad_enabled_before
==
grad_enabled_after
,
\
"
Unexpected is_grad_enabled() value change
"
assert
(
grad_enabled_before
==
grad_enabled_after
),
'
Unexpected is_grad_enabled() value change
'
are_done
=
[
e
.
query
()
for
e
in
end_events
]
logger
.
debug
(
"
%s %s completed: %s streams: %s
"
,
trace_name
,
name
,
logger
.
debug
(
'
%s %s completed: %s streams: %s
'
,
trace_name
,
name
,
are_done
,
streams
)
with
torch
.
cuda
.
stream
(
stream_before_context_switch
):
while
not
all
(
are_done
):
await
asyncio
.
sleep
(
sleep_interval
)
are_done
=
[
e
.
query
()
for
e
in
end_events
]
logger
.
debug
(
"
%s %s completed: %s streams: %s
"
,
trace_name
,
name
,
are_done
,
streams
)
logger
.
debug
(
'
%s %s completed: %s streams: %s
'
,
trace_name
,
name
,
are_done
,
streams
,
)
current_stream
=
torch
.
cuda
.
current_stream
()
assert
current_stream
==
stream_before_context_switch
if
DEBUG_COMPLETED_TIME
:
cpu_time
=
(
cpu_end
-
cpu_start
)
*
1000
stream_times_ms
=
""
stream_times_ms
=
''
for
i
,
stream
in
enumerate
(
streams
):
elapsed_time
=
start
.
elapsed_time
(
end_events
[
i
])
stream_times_ms
+=
"
{stream} {elapsed_time:.2f} ms
"
.
format
(
stream
,
elapsed_time
)
logger
.
info
(
"
{trace_name} {name} cpu_time {cpu_time:.2f} ms
"
,
trace_name
,
name
,
cpu_time
,
stream_times_ms
)
stream_times_ms
+=
'
{} {:.2f} ms
'
.
format
(
stream
,
elapsed_time
)
logger
.
info
(
'
%s %s %.2f ms %s
'
,
trace_name
,
name
,
cpu_time
,
stream_times_ms
)
@contextlib.asynccontextmanager
async
def
concurrent
(
streamqueue
:
asyncio
.
Queue
,
trace_name
=
"
concurrent
"
,
name
=
"
stream
"
):
trace_name
=
'
concurrent
'
,
name
=
'
stream
'
):
"""
Run code concurrently in different streams.
:param streamqueue: asyncio.Queue instance.
...
...
@@ -110,12 +114,12 @@ async def concurrent(streamqueue: asyncio.Queue,
try
:
with
torch
.
cuda
.
stream
(
stream
):
logger
.
debug
(
"
%s %s is starting, stream: %s
"
,
trace_name
,
name
,
logger
.
debug
(
'
%s %s is starting, stream: %s
'
,
trace_name
,
name
,
stream
)
yield
current
=
torch
.
cuda
.
current_stream
()
assert
current
==
stream
logger
.
debug
(
"
%s %s has finished, stream: %s
"
,
trace_name
,
logger
.
debug
(
'
%s %s has finished, stream: %s
'
,
trace_name
,
name
,
stream
)
finally
:
streamqueue
.
task_done
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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