Skip to content

Commit

Permalink
Add flag for push-button transition between v1 and v2 (#3479)
Browse files Browse the repository at this point in the history
Signed-off-by: Kyunggeun Lee <quic_kyunggeu@quicinc.com>
  • Loading branch information
quic-kyunggeu authored Nov 13, 2024
1 parent 556e121 commit 9ad3254
Show file tree
Hide file tree
Showing 37 changed files with 807 additions and 697 deletions.
2 changes: 1 addition & 1 deletion Docs/api_docs/torch_batchnorm_re_estimation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Top-level APIs

**API for BatchNorm fold to scale**

.. autofunction:: aimet_torch.batch_norm_fold.fold_all_batch_norms_to_scale
.. autofunction:: aimet_torch.v1.batch_norm_fold.fold_all_batch_norms_to_scale

Code Example - BN-Reestimation
==============================
Expand Down
4 changes: 2 additions & 2 deletions Docs/api_docs/torch_primitive_apis_cle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Higher Level APIs for Cross Layer Equalization

**API for Batch Norm Folding**

.. autofunction:: aimet_torch.batch_norm_fold.fold_all_batch_norms
.. autofunction:: aimet_torch.v1.batch_norm_fold.fold_all_batch_norms

|
Expand Down Expand Up @@ -79,7 +79,7 @@ Lower Level APIs for Cross Layer Equalization

**API for Batch Norm Folding**

.. autofunction:: aimet_torch.batch_norm_fold.fold_given_batch_norms
.. autofunction:: aimet_torch.v1.batch_norm_fold.fold_given_batch_norms

|
Expand Down
2 changes: 1 addition & 1 deletion Docs/torch_code_examples/bn_reestimation_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def call_bn_reestimation_apis(quant_sim, use_cuda):

# Call fold_all_batch_norms_to_scale

from aimet_torch.batch_norm_fold import fold_all_batch_norms_to_scale
from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms_to_scale

fold_all_batch_norms_to_scale(quant_sim)

Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/AMP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
},
"outputs": [],
"source": [
"from aimet_torch.batch_norm_fold import fold_all_batch_norms\n",
"from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms\n",
"\n",
"_ = fold_all_batch_norms(model, input_shapes=(1, 3, 224, 224))"
]
Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/adaround.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
"metadata": {},
"outputs": [],
"source": [
"from aimet_torch.batch_norm_fold import fold_all_batch_norms\n",
"from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms\n",
"\n",
"_ = fold_all_batch_norms(model, input_shapes=(1, 3, 224, 224))"
]
Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/adaround.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import aimet_common
from aimet_common.defs import QuantScheme
from aimet_torch.v1.adaround.adaround_weight import Adaround, AdaroundParameters
from aimet_torch.batch_norm_fold import fold_all_batch_norms
from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms
from aimet_torch.v1.quantsim import QuantizationSimModel

# imports for data pipelines
Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/bn_reestimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
"metadata": {},
"outputs": [],
"source": [
"from aimet_torch.batch_norm_fold import fold_all_batch_norms_to_scale\n",
"from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms_to_scale\n",
"\n",
"fold_all_batch_norms_to_scale(sim)"
]
Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/cle_bc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
"metadata": {},
"outputs": [],
"source": [
"from aimet_torch.batch_norm_fold import fold_all_batch_norms\n",
"from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms\n",
"\n",
"_ = fold_all_batch_norms(model, input_shapes=(1, 3, 224, 224))"
]
Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/qat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"metadata": {},
"outputs": [],
"source": [
"from aimet_torch.batch_norm_fold import fold_all_batch_norms\n",
"from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms\n",
"\n",
"_ = fold_all_batch_norms(model, input_shapes=(1, 3, 224, 224))"
]
Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/qat_range_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
"metadata": {},
"outputs": [],
"source": [
"from aimet_torch.batch_norm_fold import fold_all_batch_norms\n",
"from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms\n",
"\n",
"_ = fold_all_batch_norms(model, input_shapes=(1, 3, 224, 224))"
]
Expand Down
2 changes: 1 addition & 1 deletion Examples/torch/quantization/range_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

# imports for AIMET
from aimet_common.defs import QuantScheme, EvalFunction
from aimet_torch.batch_norm_fold import fold_all_batch_norms
from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms
from aimet_torch.cross_layer_equalization import equalize_model
from aimet_torch.v1.quantsim import QuantizationSimModel

Expand Down
2 changes: 1 addition & 1 deletion NightlyTests/torch/test_mixed_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from aimet_common.defs import QuantizationDataType, CallbackFunc
from aimet_torch.v1.quantsim import QuantizationSimModel
from aimet_torch.model_preparer import prepare_model
from aimet_torch.batch_norm_fold import fold_all_batch_norms
from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms
from aimet_torch.amp import utils as mixed_precision_utils
from aimet_torch.amp.mixed_precision_algo import EvalCallbackFactory
from aimet_torch.v1.qc_quantize_op import QcQuantizeWrapper
Expand Down
2 changes: 1 addition & 1 deletion NightlyTests/torch/test_quantize_resnet18.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from models.supervised_classification_pipeline import create_stand_alone_supervised_classification_evaluator,\
create_supervised_classification_trainer
from aimet_torch.bn_reestimation import reestimate_bn_stats
from aimet_torch.batch_norm_fold import fold_all_batch_norms_to_scale
from aimet_torch.v1.batch_norm_fold import fold_all_batch_norms_to_scale
from aimet_torch.model_preparer import prepare_model

two_class_image_dir = './data/tiny-imagenet-2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@
#
# @@-COPYRIGHT-END-@@
# =============================================================================
""" Alias to legacy adaround """
from ..v1.adaround import * # pylint: disable=wildcard-import, unused-wildcard-import
""" Alias to v1/v2 adaround """
from ..utils import _get_default_api

if _get_default_api() == "v1":
from ..v1.adaround import * # pylint: disable=wildcard-import, unused-wildcard-import
else:
from ..v2.adaround import * # pylint: disable=wildcard-import, unused-wildcard-import
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
#
# @@-COPYRIGHT-END-@@
# =============================================================================
""" Alias to legacy adaround.adaround_weight """
from ..v1.adaround.adaround_weight import * # pylint: disable=wildcard-import, unused-wildcard-import
""" Alias to v1/v2 adaround.adaround_weight """
from ..utils import _get_default_api

from ..utils import _warn_replaced_in_v2
from ..v1.adaround import adaround_weight as _v1_api
from ..v2 import adaround as _v2_api
if _get_default_api() == "v1":
from ..v1.adaround.adaround_weight import * # pylint: disable=wildcard-import, unused-wildcard-import

_warn_replaced_in_v2(__name__,
v2_new_api=_v2_api.__name__,
v1_legacy_api=_v1_api.__name__)
from ..utils import _warn_replaced_in_v2
from ..v1.adaround import adaround_weight as _v1_api
from ..v2 import adaround as _v2_api

_warn_replaced_in_v2(__name__,
v2_new_api=_v2_api.__name__,
v1_legacy_api=_v1_api.__name__)
else:
from ..v2.adaround import * # pylint: disable=wildcard-import, unused-wildcard-import
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from aimet_common.utils import AimetLogger

from aimet_torch.meta.connectedgraph import ConnectedGraph
from aimet_torch.batch_norm_fold import find_standalone_batchnorm_ops
from aimet_torch.v1.batch_norm_fold import find_standalone_batchnorm_ops

logger = AimetLogger.get_area_logger(AimetLogger.LogAreas.Utils)

Expand Down
21 changes: 13 additions & 8 deletions TrainingExtensions/torch/src/python/aimet_torch/auto_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@
#
# @@-COPYRIGHT-END-@@
# =============================================================================
""" Alias to legacy auto_quant """
from .v1.auto_quant import * # pylint: disable=wildcard-import, unused-wildcard-import
""" Alias to v1/v2 auto_quant """
from .utils import _get_default_api

from .utils import _warn_replaced_in_v2
from .v1 import auto_quant as _v1_api
from .v2 import auto_quant as _v2_api
if _get_default_api() == "v1":
from .v1.auto_quant import * # pylint: disable=wildcard-import, unused-wildcard-import

_warn_replaced_in_v2(__name__,
v2_new_api=_v2_api.__name__,
v1_legacy_api=_v1_api.__name__)
from .utils import _warn_replaced_in_v2
from .v1 import auto_quant as _v1_api
from .v2 import auto_quant as _v2_api

_warn_replaced_in_v2(__name__,
v2_new_api=_v2_api.__name__,
v1_legacy_api=_v1_api.__name__)
else:
from .v2.auto_quant import * # pylint: disable=wildcard-import, unused-wildcard-import
Loading

0 comments on commit 9ad3254

Please sign in to comment.