Initializes a linear layer and provides additional parameters required for inference and quantization. Args: fd_config (FDConfig): Inference-related parameters. prefix (str): Unique name of the layer, used to name internal attributes. Can be
(
self,
fd_config: FDConfig,
prefix: str = "",
input_size: int = None,
output_size: int = None,
with_bias: bool = False,
skip_quant: bool = False,
weight_dtype: str = "",
weight_key: str = "",
)
| 94 | """ |
| 95 | |
| 96 | def __init__( |
| 97 | self, |
| 98 | fd_config: FDConfig, |
| 99 | prefix: str = "", |
| 100 | input_size: int = None, |
| 101 | output_size: int = None, |
| 102 | with_bias: bool = False, |
| 103 | skip_quant: bool = False, |
| 104 | weight_dtype: str = "", |
| 105 | weight_key: str = "", |
| 106 | ): |
| 107 | """ |
| 108 | Initializes a linear layer and provides additional parameters required for inference and quantization. |
| 109 | |
| 110 | Args: |
| 111 | fd_config (FDConfig): Inference-related parameters. |
| 112 | prefix (str): Unique name of the layer, used to name internal attributes. |
| 113 | Can be arbitrarily named. |
| 114 | input_size (int): Number of input features. Defaults to None. |
| 115 | output_size (int): Number of output features. Defaults to None. |
| 116 | with_bias (bool): Whether to include bias or not. Defaults to False. |
| 117 | skip_quant (bool): Whether to skip quantization. Defaults to False. |
| 118 | |
| 119 | Raises: |
| 120 | NotImplementedError: Raised if the current platform is not a CUDA platform. |
| 121 | """ |
| 122 | super().__init__() |
| 123 | if ( |
| 124 | current_platform.is_cuda() |
| 125 | or current_platform.is_xpu() |
| 126 | or current_platform.is_iluvatar() |
| 127 | or current_platform.is_gcu() |
| 128 | or current_platform.is_dcu() |
| 129 | or current_platform.is_maca() |
| 130 | or current_platform.is_intel_hpu() |
| 131 | ): |
| 132 | self.forward = self.forward_cuda |
| 133 | else: |
| 134 | raise NotImplementedError |
| 135 | |
| 136 | self.fd_config = fd_config |
| 137 | self.skip_quant = skip_quant |
| 138 | self.input_size = input_size |
| 139 | self.output_size = output_size |
| 140 | self.with_bias = with_bias |
| 141 | self.prefix = prefix |
| 142 | self.is_quantized = fd_config.model_config.is_quantized and not ( |
| 143 | fd_config.quant_config.name() == "mix_quant" and fd_config.quant_config.dense_quant_type is None |
| 144 | ) |
| 145 | # key |
| 146 | if weight_key: |
| 147 | self.weight_key = f"{prefix}.{weight_key}" |
| 148 | elif self.is_quantized and not skip_quant: |
| 149 | self.weight_key = f"{prefix}.quant_weight" |
| 150 | self.weight_scale_key = f"{prefix}.weight_scale" |
| 151 | self.act_scale_key = f"{prefix}.activation_scale" |
| 152 | else: |
| 153 | self.weight_key = f"{prefix}.weight" |
no test coverage detected