From edfffcd0bcf845b83b1bc774dafff4d1e39152dc Mon Sep 17 00:00:00 2001 From: Dave Welsch Date: Tue, 12 Nov 2024 11:11:07 -0800 Subject: [PATCH] Add copyright stirng and exclude code snippets from pylint check Signed-off-by: Kyunggeun Lee --- .pylintrc | 8 +++- Docs/beta/featureguide/adaround.rst | 4 ++ Docs/beta/snippets/torch/apply_adaround.py | 37 +++++++++++++++ .../torch/create_quantizationsimmodel.py | 39 +++++++++++++++- Docs/beta/snippets/torch/evaluate.py | 43 ++++++++++++++++-- Docs/beta/snippets/torch/export.py | 45 +++++++++++++++++-- .../snippets/torch/pass_calibration_data.py | 37 +++++++++++++++ Docs/beta/snippets/torch/prepare_model.py | 39 +++++++++++++++- 8 files changed, 242 insertions(+), 10 deletions(-) diff --git a/.pylintrc b/.pylintrc index 6996595c70b..95e6d18c174 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,7 +7,13 @@ extension-pkg-whitelist= # Add files or directories to the blacklist. They should be base names, not # paths. -ignore=CVS +ignore=CVS, + apply_adaround.py, + create_quantizationsimmodel.py, + evaluate.py, + export.py, + pass_calibration_data.py, + prepare_model.py # Add files or directories matching the regex patterns to the blacklist. The # regex matches against base names, not paths. diff --git a/Docs/beta/featureguide/adaround.rst b/Docs/beta/featureguide/adaround.rst index a7c4e10c9e3..9ba69283c4b 100644 --- a/Docs/beta/featureguide/adaround.rst +++ b/Docs/beta/featureguide/adaround.rst @@ -80,6 +80,7 @@ Prepare the model for quantization. .. literalinclude:: ../snippets/torch/prepare_model.py :language: python + :lines: 38- For details of the model preparer API see the :ref:`Model Preparer API `. @@ -104,6 +105,7 @@ Apply AdaRound to the model. .. literalinclude:: ../snippets/torch/apply_adaround.py :language: python + :lines: 38- .. tab:: TensorFlow @@ -126,6 +128,7 @@ Evaluate the model. .. literalinclude:: ../snippets/torch/evaluate.py :language: python + :lines: 38- .. tab:: TensorFlow @@ -155,6 +158,7 @@ If AdaRound resulted in satisfactory accuracy, export the model. .. literalinclude:: ../snippets/torch/export.py :language: python + :lines: 38- .. tab:: TensorFlow diff --git a/Docs/beta/snippets/torch/apply_adaround.py b/Docs/beta/snippets/torch/apply_adaround.py index c09013436c5..9b09d8ced1f 100644 --- a/Docs/beta/snippets/torch/apply_adaround.py +++ b/Docs/beta/snippets/torch/apply_adaround.py @@ -1,3 +1,40 @@ +# -*- mode: python -*- +# ============================================================================= +# @@-COPYRIGHT-START-@@ +# +# Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# @@-COPYRIGHT-END-@@ +# ============================================================================= +# pylint: disable=all # Apply AdaRound from aimet_common.defs import QuantScheme from aimet_torch.v1.quantsim import QuantizationSimModel diff --git a/Docs/beta/snippets/torch/create_quantizationsimmodel.py b/Docs/beta/snippets/torch/create_quantizationsimmodel.py index a400476649f..108b02af221 100644 --- a/Docs/beta/snippets/torch/create_quantizationsimmodel.py +++ b/Docs/beta/snippets/torch/create_quantizationsimmodel.py @@ -1,3 +1,40 @@ +# -*- mode: python -*- +# ============================================================================= +# @@-COPYRIGHT-START-@@ +# +# Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# @@-COPYRIGHT-END-@@ +# ============================================================================= +# pylint: disable=all from aimet_common.defs import QuantScheme from aimet_torch.v1.quantsim import QuantizationSimModel from aimet_torch.v1.adaround.adaround_weight import Adaround, AdaroundParameters @@ -10,4 +47,4 @@ # is a model to which AIMET AdaRound has been applied # is a selected AIMET quantization scheme # and are the bit widths of the quantized model -# is any data that conforms to the model input shape. It is not used. \ No newline at end of file +# is any data that conforms to the model input shape. It is not used. diff --git a/Docs/beta/snippets/torch/evaluate.py b/Docs/beta/snippets/torch/evaluate.py index 55d8923aa28..1d7412fb875 100644 --- a/Docs/beta/snippets/torch/evaluate.py +++ b/Docs/beta/snippets/torch/evaluate.py @@ -1,3 +1,40 @@ - # Determine simulated accuracy - accuracy = ImageNetDataPipeline.evaluate(sim.model, use_cuda) - print(accuracy) \ No newline at end of file +# -*- mode: python -*- +# ============================================================================= +# @@-COPYRIGHT-START-@@ +# +# Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# @@-COPYRIGHT-END-@@ +# ============================================================================= +# pylint: disable=all +# Determine simulated accuracy +accuracy = ImageNetDataPipeline.evaluate(sim.model, use_cuda) +print(accuracy) diff --git a/Docs/beta/snippets/torch/export.py b/Docs/beta/snippets/torch/export.py index e36a1a3a3cb..f901de34b52 100644 --- a/Docs/beta/snippets/torch/export.py +++ b/Docs/beta/snippets/torch/export.py @@ -1,4 +1,41 @@ - # Export the model - # Export the model which saves pytorch model without any simulation nodes and saves encodings file for both - # activations and parameters in JSON format - model.export(path='./', filename_prefix='', dummy_input=dummy_input.cpu()) +# -*- mode: python -*- +# ============================================================================= +# @@-COPYRIGHT-START-@@ +# +# Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# @@-COPYRIGHT-END-@@ +# ============================================================================= +# pylint: disable=all +# Export the model +# Export the model which saves pytorch model without any simulation nodes and saves encodings file for both +# activations and parameters in JSON format +model.export(path='./', filename_prefix='', dummy_input=dummy_input.cpu()) diff --git a/Docs/beta/snippets/torch/pass_calibration_data.py b/Docs/beta/snippets/torch/pass_calibration_data.py index cb998a2c7f6..3897b79df37 100644 --- a/Docs/beta/snippets/torch/pass_calibration_data.py +++ b/Docs/beta/snippets/torch/pass_calibration_data.py @@ -1,3 +1,40 @@ +# -*- mode: python -*- +# ============================================================================= +# @@-COPYRIGHT-START-@@ +# +# Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# @@-COPYRIGHT-END-@@ +# ============================================================================= +# pylint: disable=all # PyTorch imports import torch diff --git a/Docs/beta/snippets/torch/prepare_model.py b/Docs/beta/snippets/torch/prepare_model.py index 6c0d6621622..9f00f7b85b0 100644 --- a/Docs/beta/snippets/torch/prepare_model.py +++ b/Docs/beta/snippets/torch/prepare_model.py @@ -1,5 +1,42 @@ +# -*- mode: python -*- +# ============================================================================= +# @@-COPYRIGHT-START-@@ +# +# Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# @@-COPYRIGHT-END-@@ +# ============================================================================= +# pylint: disable=all # Prepare the model from aimet_torch.model_preparer import prepare_model prepared_model = prepare_model() -# where is a torch.nn.Module \ No newline at end of file +# where is a torch.nn.Module