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 a bug in make_divisible. #333

Merged
merged 1 commit into from
Oct 24, 2022
Merged
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
14 changes: 14 additions & 0 deletions mmrazor/models/utils/make_divisible.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) OpenMMLab. All rights reserved.
from typing import Optional

warn_once = False


def make_divisible(value: int,
divisor: int,
Expand All @@ -24,6 +26,18 @@ def make_divisible(value: int,

if min_value is None:
min_value = divisor
if min_value < divisor:
global warn_once
if warn_once is False:
from mmengine import MMLogger
MMLogger.get_current_instance().warning(
(f'min_value=={min_value} should greater or equal to '
f'divisor=={divisor}, '
'so we make min_value equal divisor.'))
warn_once = True

min_value = divisor

new_value = max(min_value, int(value + divisor / 2) // divisor * divisor)
# Make sure that round down does not go down by more than (1-min_ratio).
if new_value < min_ratio * value:
Expand Down