Skip to content

Commit 097efab

Browse files
ppwwyyxxfacebook-github-bot
authored andcommitted
don't use a separate stream to gather losses
Summary: Task in the new stream can start even before the loss is computed. To do this correctly, it requires creating a cuda event before backward, and wait for the event in the new stream. The perf difference is tiny, so it's probably not worthwhile so just remove the stream entirely. Some refs: pytorch/pytorch#23729 Reviewed By: theschnitz Differential Revision: D26238335 fbshipit-source-id: 614a5b173861b0c0a2bd1240855f12c19d58b76e
1 parent a2a998a commit 097efab

File tree

10 files changed

+29
-22
lines changed

10 files changed

+29
-22
lines changed

.github/ISSUE_TEMPLATE/documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: "\U0001F4DA Documentation Issues"
3-
about: Issues or enhancements about docs and comments
3+
about: Docs and comments are missing, incorrect, or not clear enough
44
labels: documentation
55

66
---

.github/workflows/check-template.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
core.debug("Issue " + issue.data.title + " was skipped.");
3030
return;
3131
}
32-
const body = issue.data.body;
33-
const hasInstructions = body.toLowerCase().indexOf("reproduce") != -1;
34-
const hasEnvironment = body.indexOf("sys.platform") != -1;
32+
const body = issue.data.body.toLowerCase();
33+
const hasInstructions = body.indexOf("reproduce") != -1;
34+
const hasEnvironment = (body.indexOf("sys.platform") != -1) || (body.indexOf("colab") != -1);
3535
if (hasInstructions && hasEnvironment) {
3636
core.debug("Issue " + issue.data.title + " follows template.");
3737
return;

detectron2/engine/train_loop.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,13 @@ def _write_metrics(
255255
loss_dict (dict): dict of scalar losses
256256
data_time (float): time taken by the dataloader iteration
257257
"""
258-
device = next(iter(loss_dict.values())).device
258+
metrics_dict = {k: v.detach().cpu().item() for k, v in loss_dict.items()}
259+
metrics_dict["data_time"] = data_time
259260

260-
# Use a new stream so these ops don't wait for DDP or backward
261-
with torch.cuda.stream(torch.cuda.Stream() if device.type == "cuda" else None):
262-
metrics_dict = {k: v.detach().cpu().item() for k, v in loss_dict.items()}
263-
metrics_dict["data_time"] = data_time
264-
265-
# Gather metrics among all workers for logging
266-
# This assumes we do DDP-style training, which is currently the only
267-
# supported method in detectron2.
268-
all_metrics_dict = comm.gather(metrics_dict)
261+
# Gather metrics among all workers for logging
262+
# This assumes we do DDP-style training, which is currently the only
263+
# supported method in detectron2.
264+
all_metrics_dict = comm.gather(metrics_dict)
269265

270266
if comm.is_main_process():
271267
storage = get_event_storage()

detectron2/modeling/roi_heads/roi_heads.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ class Res5ROIHeads(ROIHeads):
345345
The ROIHeads in a typical "C4" R-CNN model, where
346346
the box and mask head share the cropping and
347347
the per-region feature computation by a Res5 block.
348+
See :paper:`ResNet` Appendix A.
348349
"""
349350

350351
@configurable

detectron2/utils/collect_env.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,8 @@ def collect_env_info():
187187
try:
188188
x = torch.tensor([1, 2.0], dtype=torch.float32)
189189
x = x.to(device)
190-
except Exception:
191-
print(f"Unable to copy tensor to device={device}")
190+
except Exception as e:
191+
print(
192+
f"Unable to copy tensor to device={device}: {e}. "
193+
"Your CUDA environment is broken."
194+
)

detectron2/utils/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def locate(name: str) -> Any:
3333
# Should use _locate directly if it's public.
3434
if obj is None:
3535
try:
36-
from hydra._internal.utils import _locate
36+
from hydra.utils import get_method
3737
except ImportError as e:
3838
raise ImportError(f"Cannot dynamically locate object {name}!") from e
3939
else:
40-
obj = _locate(name) # it raises if fails
40+
obj = get_method(name) # it raises if fails
4141

4242
return obj

docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cd docker && USER_ID=$UID docker-compose run detectron2
2525
After building the base detectron2 container as above, do:
2626
```
2727
# Build:
28-
docker build -t detectron2-deploy:v0 -f deploy.Dockerfile
28+
docker build -t detectron2-deploy:v0 -f deploy.Dockerfile .
2929
# Launch:
3030
docker run --gpus all -it detectron2-deploy:v0
3131
```

docs/modules/fvcore.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Detectron2 depends on utilities in
55
`fvcore <https://github.com/facebookresearch/fvcore/>`_.
66
We include part of fvcore documentation here for easier reference.
77

8-
fvcore.nn
8+
fvcore.nn
99
-----------------
1010

1111
.. automodule:: fvcore.nn
1212
:members:
1313
:undoc-members:
1414
:show-inheritance:
1515

16-
fvcore.common
16+
fvcore.common
1717
---------------------
1818

1919
.. automodule:: fvcore.common.checkpoint
@@ -31,6 +31,11 @@ fvcore.common
3131
:undoc-members:
3232
:show-inheritance:
3333

34+
.. automodule:: fvcore.common.param_scheduler
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
3439
.. automodule:: fvcore.common.registry
3540
:members:
3641
:undoc-members:

tools/benchmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from detectron2.modeling import build_model
2626
from detectron2.solver import build_optimizer
2727
from detectron2.utils import comm
28+
from detectron2.utils.collect_env import collect_env_info
2829
from detectron2.utils.events import CommonMetricPrinter
2930
from detectron2.utils.logger import setup_logger
3031

@@ -154,6 +155,7 @@ def f():
154155
args = parser.parse_args()
155156
assert not args.eval_only
156157

158+
logger.info("Environment info:\n" + collect_env_info())
157159
if args.task == "data":
158160
f = benchmark_data
159161
print("Initial " + RAM_msg())

tools/deploy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This directory contains the following examples:
1212
All C++ examples depend on libtorch and OpenCV. Some require more dependencies:
1313

1414
* Running caffe2-format models requires:
15-
* PyTorch with caffe2 inside
15+
* libtorch built with caffe2 inside
1616
* gflags, glog
1717
* protobuf library that matches the version used by PyTorch (version defined in `include/caffe2/proto/caffe2.pb.h` of your PyTorch installation)
1818
* MKL headers if caffe2 is built with MKL

0 commit comments

Comments
 (0)