Skip to content

Commit

Permalink
Fix a bug in make_divisible. (#333)
Browse files Browse the repository at this point in the history
fix bug in make_divisible

Co-authored-by: liukai <liukai@pjlab.org.cn>
  • Loading branch information
LKJacky and liukai committed Oct 24, 2022
1 parent b3c8bb9 commit 6659a34
Showing 1 changed file with 14 additions and 0 deletions.
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

0 comments on commit 6659a34

Please sign in to comment.