Linear¶
- class tripy.Linear(in_features: int, out_features: int, bias: bool = True, dtype: dtype = float32, quant_dtype: dtype | None = None, weight_quant_dim: int | None = None)[source]¶
Bases:
Module
Applies a linear transformation to the input:
\(Linear(x) = xW^T + b\)
- Parameters:
in_features (int) – Size of input features.
out_features (int) – Size of output features.
bias (Parameter | None) – Whether to include the bias term.
dtype (dtype) – The data type to use for the weight and bias parameters.
quant_dtype (dtype | None) – The data type for quantization.
weight_quant_dim (int | None) – The dimension along which to apply the weight quantization scale.
Example
1linear = tp.Linear(3, 4) 2 3input = tp.iota((2, 3)) 4output = linear(input)
>>> linear.state_dict() { weight: tensor( [[0.0000, 1.0000, 2.0000], [3.0000, 4.0000, 5.0000], [6.0000, 7.0000, 8.0000], [9.0000, 10.0000, 11.0000]], dtype=float32, loc=gpu:0, shape=(4, 3)), bias: tensor([0.0000, 1.0000, 2.0000, 3.0000], dtype=float32, loc=gpu:0, shape=(4,)), } >>> input tensor( [[0.0000, 0.0000, 0.0000], [1.0000, 1.0000, 1.0000]], dtype=float32, loc=gpu:0, shape=(2, 3)) >>> output tensor( [[0.0000, 1.0000, 2.0000, 3.0000], [3.0000, 13.0000, 23.0000, 33.0000]], dtype=float32, loc=gpu:0, shape=(2, 4))
- weight_quant_dim: int | None¶
The dimension along which to apply the weight quantization scale.