Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix accuracy test errors #5348

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DATASETS:
TEST: ("coco_2017_val_100",)
TEST:
EXPECTED_RESULTS: [["bbox", "AP", 50.18, 0.02], ["segm", "AP", 43.87, 0.02]]
FLOAT32_PRECISION: "highest"
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DATASETS:
TEST: ("coco_2017_val_100",)
TEST:
EXPECTED_RESULTS: [["bbox", "AP", 45.70, 0.02]]
FLOAT32_PRECISION: "highest"
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DATASETS:
TEST: ("keypoints_coco_2017_val_100",)
TEST:
EXPECTED_RESULTS: [["bbox", "AP", 52.47, 0.02], ["keypoints", "AP", 67.36, 0.02]]
FLOAT32_PRECISION: "highest"
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DATASETS:
TEST: ("coco_2017_val_100",)
TEST:
EXPECTED_RESULTS: [["bbox", "AP", 47.37, 0.02], ["segm", "AP", 40.99, 0.02]]
FLOAT32_PRECISION: "highest"
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DATASETS:
TEST: ("coco_2017_val_100",)
TEST:
EXPECTED_RESULTS: [["bbox", "AP", 47.44, 0.02], ["segm", "AP", 42.94, 0.02]]
FLOAT32_PRECISION: "highest"
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ TEST:
AUG:
ENABLED: True
MIN_SIZES: (700, 800) # to save some time
FLOAT32_PRECISION: "highest"
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DATASETS:
TEST: ("coco_2017_val_100_panoptic_separated",)
TEST:
EXPECTED_RESULTS: [["bbox", "AP", 46.47, 0.02], ["segm", "AP", 43.39, 0.02], ["sem_seg", "mIoU", 42.55, 0.02], ["panoptic_seg", "PQ", 38.99, 0.02]]
FLOAT32_PRECISION: "highest"
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ DATASETS:
TEST: ("coco_2017_val_100",)
TEST:
EXPECTED_RESULTS: [["box_proposals", "AR@1000", 58.16, 0.02]]
FLOAT32_PRECISION: "highest"
4 changes: 4 additions & 0 deletions detectron2/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@
# for about 10k iterations. It usually hurts total time, but can benefit for certain models.
# If input images have the same or similar sizes, benchmark is often helpful.
_C.CUDNN_BENCHMARK = False
# Option to set PyTorch matmul and CuDNN's float32 precision. When set to non-empty string,
# the corresponding precision ("highest", "high" or "medium") will be used. The highest
# precision will effectively disable tf32.
_C.FLOAT32_PRECISION = ""
# The period (in terms of steps) for minibatch visualization at train time.
# Set to 0 to disable.
_C.VIS_PERIOD = 0
Expand Down
32 changes: 32 additions & 0 deletions detectron2/engine/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,30 @@ def _highlight(code, filename):
return code


# adapted from:
# https://github.com/pytorch/tnt/blob/ebda066f8f55af6a906807d35bc829686618074d/torchtnt/utils/device.py#L328-L346
def _set_float32_precision(precision: str = "high") -> None:
"""Sets the precision of float32 matrix multiplications and convolution operations.
For more information, see the PyTorch docs:
- https://pytorch.org/docs/stable/generated/torch.set_float32_matmul_precision.html
- https://pytorch.org/docs/stable/backends.html#torch.backends.cudnn.allow_tf32
Args:
precision: The setting to determine which datatypes to use for matrix
multiplication and convolution operations.
"""
if not (torch.cuda.is_available()): # Not relevant for non-CUDA devices
return
# set precision for matrix multiplications
torch.set_float32_matmul_precision(precision)
# set precision for convolution operations
if precision == "highest":
torch.backends.cudnn.allow_tf32 = False
else:
torch.backends.cudnn.allow_tf32 = True


def default_setup(cfg, args):
"""
Perform some basic common setups at the beginning of a job, including:
Expand Down Expand Up @@ -226,6 +250,14 @@ def default_setup(cfg, args):
cfg, "CUDNN_BENCHMARK", "train.cudnn_benchmark", default=False
)

fp32_precision = _try_get_key(cfg, "FLOAT32_PRECISION", "train.float32_precision", default="")
if fp32_precision != "":
logger.info(f"Set fp32 precision to {fp32_precision}")
_set_float32_precision(fp32_precision)
logger.info(f"{torch.get_float32_matmul_precision()=}")
logger.info(f"{torch.backends.cuda.matmul.allow_tf32=}")
logger.info(f"{torch.backends.cudnn.allow_tf32=}")


def default_writers(output_dir: str, max_iter: Optional[int] = None):
"""
Expand Down
Loading