-
Noam Zerah authoredNoam Zerah authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
pybind_PTQMetaOps.cpp 3.84 KiB
/********************************************************************************
* 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 <pybind11/functional.h>
#include "aidge/operator/PTQMetaOps.hpp"
#include "aidge/graph/Node.hpp"
#include "aidge/utils/Types.h"
namespace py = pybind11;
namespace Aidge {
void init_PTQMetaOps(py::module &m) {
// Quantizer creation and manipulation
m.def("quantizer", &Quantizer,
py::arg("scaling_factor"),
py::arg("name") = "",
R"doc(
Create a quantizer node with specified scaling factor.
Args:
scaling_factor (float): The scaling factor to apply
name (str): Optional name for the quantizer node
Returns:
Node: The created quantizer node
)doc");
m.def("multiply_scaling_factor", &multiplyScalingFactor,
py::arg("quantizer"),
py::arg("coefficient"),
R"doc(
Multiply the scaling factor of a quantizer by a coefficient.
Args:
quantizer (Node): The quantizer node to modify
coefficient (float): The multiplication factor
)doc");
m.def("get_scaling_factor", &getScalingFactor,
py::arg("quantizer"),
R"doc(
Get the current scaling factor of a quantizer.
Args:
quantizer (Node): The quantizer node to query
Returns:
float: The current scaling factor
)doc");
// Quantizer modification functions
m.def("append_round_clip", &appendRoundClip,
py::arg("quantizer"),
py::arg("clip_min"),
py::arg("clip_max"),
R"doc(
Append round and clip operations to a quantizer.
Args:
quantizer (Node): The quantizer node to modify
clip_min (float): Minimum clipping value
clip_max (float): Maximum clipping value
)doc");
m.def("set_clip_range", &setClipRange,
py::arg("quantizer"),
py::arg("min"),
py::arg("max"),
R"doc(
Set the clipping range of a quantizer that already has clip operations.
Args:
quantizer (Node): The quantizer node to modify
min (float): New minimum clipping value
max (float): New maximum clipping value
)doc");
m.def("remove_round", &removeRound,
py::arg("quantizer"),
R"doc(
Remove the round operation from a quantizer.
Args:
quantizer (Node): The quantizer node to modify
)doc");
// Advanced quantization operations
m.def("replace_scaling_with_bitshift", &replaceScalingWithBitShift,
py::arg("quantizer"),
R"doc(
Replace multiplicative scaling with bit-shift operations.
Args:
quantizer (Node): The quantizer node to modify
)doc");
m.def("cast_quantizer_ios", &castQuantizerIOs,
py::arg("quantizer"),
py::arg("external_type"),
R"doc(
Cast the input/output of a quantizer to specified data type.
Args:
quantizer (Node): The quantizer node to modify
external_type (DataType): Target data type for I/O
)doc");
}
} // namespace Aidge