Skip to content
Snippets Groups Projects
Commit 17be52c5 authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Added Python binding

parent 8afa4e13
No related branches found
No related tags found
1 merge request!13Draft: Add QAT
/********************************************************************************
* 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
/********************************************************************************
* 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
/********************************************************************************
* 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
/********************************************************************************
* 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
/********************************************************************************
* 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
......@@ -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
/********************************************************************************
* 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
/********************************************************************************
* 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
/********************************************************************************
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment