bitorch.layers.qlinear.QLinearBase¶
- class bitorch.layers.qlinear.QLinearBase(*args: int, input_quantization: Optional[Union[Quantization, str]] = None, gradient_cancellation_threshold: Optional[float] = None, weight_quantization: Optional[Union[Quantization, str]] = None, **kwargs: bool)[source]¶
Methods
Applies the given quantization functions on weights and inputs before applying the linear operation.
Forwards x through the binary linear layer.
Gather all arguments that were used to create a QLinear layer with argument names.
Attributes
gradient_cancellation_threshold
input_quantization
- __init__(*args: int, input_quantization: Optional[Union[Quantization, str]] = None, gradient_cancellation_threshold: Optional[float] = None, weight_quantization: Optional[Union[Quantization, str]] = None, **kwargs: bool) None [source]¶
Applies the given quantization functions on weights and inputs before applying the linear operation.
- Parameters:
*args – positional arguments for linear layer
input_quantization (Union[str, Quantization], optional) – quantization module used for input quantization. Defaults to None.
gradient_cancellation_threshold (Union[float, None], optional) – threshold for input gradient cancellation. disabled if threshold is None. Defaults to None.
weight_quantization (Union[str, Quantization], optional) – quantization module or name of quantization function. Defaults to None.
**kwargs – keyword arguments for linear layer
- forward(x: Tensor) Tensor [source]¶
Forwards x through the binary linear layer.
- Parameters:
x (torch.Tensor) – tensor to forward
- Returns:
forwarded tensor
- Return type:
torch.Tensors
- static get_args_as_kwargs(recipe: LayerRecipe) Dict[str, Any] [source]¶
Gather all arguments that were used to create a QLinear layer with argument names. Can be used to recreate a layer with identical arguments.
- Returns:
A dictionary with all arguments (key is the argument name as a string even for positional arguments)