diff --git a/python_binding/operator/pybind_CG-PACT.cpp b/python_binding/operator/pybind_CG-PACT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d0dd21a2557628d99e932b2051eb5ba7135ba216 --- /dev/null +++ b/python_binding/operator/pybind_CG-PACT.cpp @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> + +#include "aidge/data/Tensor.hpp" +#include "aidge/operator/CG-PACT.hpp" +#include "aidge/operator/OperatorTensor.hpp" + +namespace py = pybind11; +namespace Aidge { + +void init_CGPACT(py::module& m) { + py::class_<CGPACT_Op, std::shared_ptr<CGPACT_Op>, OperatorTensor>(m, "CGPACTOp", py::multiple_inheritance()) + .def(py::init<size_t>(), py::arg("range") = 255) + .def_static("get_inputs_name", &CGPACT_Op::getInputsName) + .def_static("get_outputs_name", &CGPACT_Op::getOutputsName); + declare_registrable<CGPACT_Op>(m, "CGPACTOp"); + m.def("CGPACT", &CGPACT, py::arg("range") = 255, py::arg("name") = ""); +} +} // namespace Aidge diff --git a/python_binding/operator/pybind_DoReFa.cpp b/python_binding/operator/pybind_DoReFa.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c274149cea2cfbda2395b34bf78737640bb88eac --- /dev/null +++ b/python_binding/operator/pybind_DoReFa.cpp @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> + +#include "aidge/data/Tensor.hpp" +#include "aidge/operator/DoReFa.hpp" +#include "aidge/operator/OperatorTensor.hpp" + +namespace py = pybind11; +namespace Aidge { + +void init_DoReFa(py::module& m) { + py::enum_<DoReFaMode>(m, "DoReFaMode") + .value("Default", DoReFaMode::Default) + .value("Symmetric", DoReFaMode::Symmetric) + .export_values(); + + py::class_<DoReFa_Op, std::shared_ptr<DoReFa_Op>, OperatorTensor>(m, "DoReFaOp", py::multiple_inheritance()) + .def(py::init<size_t, DoReFaMode>(), py::arg("range") = 255, py::arg("mode") = DoReFaMode::Default) + .def_static("get_inputs_name", &DoReFa_Op::getInputsName) + .def_static("get_outputs_name", &DoReFa_Op::getOutputsName); + declare_registrable<DoReFa_Op>(m, "DoReFaOp"); + m.def("DoReFa", &DoReFa, py::arg("range") = 255, py::arg("mode") = DoReFaMode::Default, py::arg("name") = ""); +} +} // namespace Aidge diff --git a/python_binding/operator/pybind_LSQ.cpp b/python_binding/operator/pybind_LSQ.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f5fe467c484067caed951aad873196c7fc8eef4 --- /dev/null +++ b/python_binding/operator/pybind_LSQ.cpp @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> + +#include "aidge/data/Tensor.hpp" +#include "aidge/operator/LSQ.hpp" +#include "aidge/operator/OperatorTensor.hpp" + +namespace py = pybind11; +namespace Aidge { + +void init_LSQ(py::module& m) { + py::class_<LSQ_Op, std::shared_ptr<LSQ_Op>, OperatorTensor>(m, "LSQOp", py::multiple_inheritance()) + .def(py::init<const std::pair<int, int>&>(), py::arg("range") = std::pair<int, int>{0, 255}) + .def_static("get_inputs_name", &LSQ_Op::getInputsName) + .def_static("get_outputs_name", &LSQ_Op::getOutputsName); + declare_registrable<LSQ_Op>(m, "LSQOp"); + m.def("LSQ", &LSQ, py::arg("range") = std::pair<int, int>{0, 255}, py::arg("name") = ""); +} +} // namespace Aidge diff --git a/python_binding/operator/pybind_ScaleAdjust.cpp b/python_binding/operator/pybind_ScaleAdjust.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b334f4a60452869274d3f6f70a367a736a83e69 --- /dev/null +++ b/python_binding/operator/pybind_ScaleAdjust.cpp @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> + +#include "aidge/data/Tensor.hpp" +#include "aidge/operator/ScaleAdjust.hpp" +#include "aidge/operator/OperatorTensor.hpp" + +namespace py = pybind11; +namespace Aidge { + +void init_ScaleAdjust(py::module& m) { + py::class_<ScaleAdjust_Op, std::shared_ptr<ScaleAdjust_Op>, OperatorTensor>(m, "ScaleAdjustOp", py::multiple_inheritance()) + .def(py::init<>()) + .def_static("get_inputs_name", &ScaleAdjust_Op::getInputsName) + .def_static("get_outputs_name", &ScaleAdjust_Op::getOutputsName); + declare_registrable<ScaleAdjust_Op>(m, "ScaleAdjustOp"); + m.def("ScaleAdjust", &ScaleAdjust, py::arg("name") = ""); +} +} // namespace Aidge diff --git a/python_binding/operator/pybind_TanhClamp.cpp b/python_binding/operator/pybind_TanhClamp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45ecb615cb206a2882e0822b740e61547306e2c9 --- /dev/null +++ b/python_binding/operator/pybind_TanhClamp.cpp @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> + +#include "aidge/data/Tensor.hpp" +#include "aidge/operator/TanhClamp.hpp" +#include "aidge/operator/OperatorTensor.hpp" + +namespace py = pybind11; +namespace Aidge { + +void init_TanhClamp(py::module& m) { + py::class_<TanhClamp_Op, std::shared_ptr<TanhClamp_Op>, OperatorTensor>(m, "TanhClampOp", py::multiple_inheritance()) + .def(py::init<>()) + .def_static("get_inputs_name", &TanhClamp_Op::getInputsName) + .def_static("get_outputs_name", &TanhClamp_Op::getOutputsName); + declare_registrable<TanhClamp_Op>(m, "TanhClampOp"); + m.def("TanhClamp", &TanhClamp, py::arg("name") = ""); +} +} // namespace Aidge diff --git a/python_binding/pybind_PTQ.cpp b/python_binding/pybind_PTQ.cpp index 1d9359c20b74943943104223a283edda8d0d74b5..9ee788b6c8065027ca20a7b51b2095c4196e351a 100644 --- a/python_binding/pybind_PTQ.cpp +++ b/python_binding/pybind_PTQ.cpp @@ -14,9 +14,9 @@ #include <string> -#include "aidge/PTQ/Clip.hpp" -#include "aidge/PTQ/CLE.hpp" -#include "aidge/PTQ/PTQ.hpp" +#include "aidge/quantization/PTQ/Clip.hpp" +#include "aidge/quantization/PTQ/CLE.hpp" +#include "aidge/quantization/PTQ/PTQ.hpp" #include "aidge/hook/Hook.hpp" #include "aidge/graph/GraphView.hpp" @@ -222,8 +222,4 @@ void init_QuantPTQ(py::module &m) { )mydelimiter"); } -PYBIND11_MODULE(aidge_quantization, m) { - init_QuantPTQ(m); -} - } // namespace Aidge diff --git a/python_binding/pybind_QuantQAT_LSQ.cpp b/python_binding/pybind_QuantQAT_LSQ.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bee8e562beac376dbd45da71c0d672b21dde7cb --- /dev/null +++ b/python_binding/pybind_QuantQAT_LSQ.cpp @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +#include <string> + +#include "aidge/QuantQAT_LSQ.hpp" + +#include "aidge/hook/Hook.hpp" +#include "aidge/graph/GraphView.hpp" + +namespace py = pybind11; + +namespace Aidge { +void init_QuantQAT_LSQ(py::module &m) { + auto mQuantLSQ = m.def_submodule("quant_lsq"); + mQuantLSQ.def("insert_act_quantizers", &QuantLSQ::insertActQuantizers, py::arg("graphView"), py::arg("nbBits")); + mQuantLSQ.def("insert_param_quantizers", &QuantLSQ::insertParamQuantizers, py::arg("graphView"), py::arg("nbBits")); + mQuantLSQ.def("update_first_and_last_param_quantizers", &QuantLSQ::updateFirstAndLastParamQuantizers, py::arg("graphView"), py::arg("nbBits")); + mQuantLSQ.def("insert_quantizers", &QuantLSQ::insertQuantizers, py::arg("graphView"), py::arg("nbBits")); + +} + +} // namespace Aidge diff --git a/python_binding/pybind_QuantQAT_SAT.cpp b/python_binding/pybind_QuantQAT_SAT.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5efe0ead052aa124d611f74a35a6bde376a45b67 --- /dev/null +++ b/python_binding/pybind_QuantQAT_SAT.cpp @@ -0,0 +1,39 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +#include <string> + +#include "aidge/QuantQAT_SAT.hpp" + +#include "aidge/hook/Hook.hpp" +#include "aidge/graph/GraphView.hpp" + +namespace py = pybind11; + +namespace Aidge { +void init_QuantQAT_SAT(py::module &m) { + auto mQuantSAT = m.def_submodule("quant_sat"); + mQuantSAT.def("insert_param_clamping", &QuantSAT::insertParamClamping, py::arg("graphView")); + mQuantSAT.def("insert_param_scaling_adjust", &QuantSAT::insertParamScalingAdjust, py::arg("graphView")); + mQuantSAT.def("insert_clamping", &QuantSAT::insertClamping, py::arg("graphView")); + mQuantSAT.def("insert_act_quantizers", &QuantSAT::insertActQuantizers, py::arg("graphView"), py::arg("nbBits"), py::arg("alpha") = 1.0); + mQuantSAT.def("insert_param_quantizers", &QuantSAT::insertParamQuantizers, py::arg("graphView"), py::arg("nbBits"), py::arg("mode") = DoReFaMode::Default); + mQuantSAT.def("update_first_and_last_param_quantizers", &QuantSAT::updateFirstAndLastParamQuantizers, py::arg("graphView"), py::arg("nbBits")); + mQuantSAT.def("insert_quantizers", &QuantSAT::insertQuantizers, py::arg("graphView"), py::arg("nbBits"));* + + mQuantSAT.def("fuse_quantizers", &QuantSAT::fuseQuantizers, py::arg("graphView"), py::arg("rInt") = false); + +} + +} // namespace Aidge diff --git a/python_binding/pybind_quantization.cpp b/python_binding/pybind_quantization.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e3deac51728c8f187899fdecbedb481ed2dd9b77 --- /dev/null +++ b/python_binding/pybind_quantization.cpp @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2023 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +#include <string> + +#include "aidge/hook/Hook.hpp" +#include "aidge/graph/GraphView.hpp" + +namespace py = pybind11; + +namespace Aidge { +void init_CGPACT(py::module&); +void init_DoReFa(py::module&); +void init_LSQ(py::module&); +void init_ScaleAdjust(py::module&); +void init_TanhClamp(py::module&); +void init_QuantPTQ(py::module&); +void init_QuantQAT_LSQ(py::module&); +void init_QuantQAT_SAT(py::module&); + +PYBIND11_MODULE(aidge_quantization, m) { + init_CGPACT(m); + init_DoReFa(m); + init_LSQ(m); + init_ScaleAdjust(m); + init_TanhClamp(m); + init_QuantPTQ(m); + init_QuantQAT_LSQ(m); + init_QuantQAT_SAT(m); +} + +} // namespace Aidge