vllm.model_executor.layers.quantization.rtn
NUM_BITS module-attribute
¶
NUM_BITS = getenv('RTN_NUM_BITS', '8')
By default, use group size of 128 parameters, but it can be overridden by setting the RTN_GROUP_SIZE envvar
logger module-attribute
¶
logger = init_logger(__name__)
By default, use 8 bit as target precision, but it can be overridden by setting the RTN_NUM_BITS envvar
RTNConfig ¶
Bases: QuantizationConfig
Config class for RTN.
Source code in vllm/model_executor/layers/quantization/rtn.py
__init__ ¶
Source code in vllm/model_executor/layers/quantization/rtn.py
from_config classmethod
¶
get_config_filenames classmethod
¶
get_name classmethod
¶
get_name() -> QuantizationMethods
get_quant_method ¶
get_quant_method(
layer: Module, prefix: str
) -> Optional[QuantizeMethodBase]
Source code in vllm/model_executor/layers/quantization/rtn.py
RTNLinearMethod ¶
Bases: LinearMethodBase
Linear method for RTN.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quant_config | RTNConfig | The RTN quantization config. | required |
Source code in vllm/model_executor/layers/quantization/rtn.py
apply ¶
Source code in vllm/model_executor/layers/quantization/rtn.py
create_weights ¶
create_weights(
layer: Module,
input_size_per_partition: int,
output_partition_sizes: list[int],
input_size: int,
output_size: int,
params_dtype: dtype,
**extra_weight_attrs,
)
Source code in vllm/model_executor/layers/quantization/rtn.py
RTNMoEMethod ¶
Bases: FusedMoEMethodBase
Source code in vllm/model_executor/layers/quantization/rtn.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
__init__ ¶
__init__(quant_config: RTNConfig, moe: FusedMoEConfig)
apply ¶
apply(
layer: Module,
x: Tensor,
router_logits: Tensor,
top_k: int,
renormalize: bool,
use_grouped_topk: bool = False,
topk_group: Optional[int] = None,
num_expert_group: Optional[int] = None,
global_num_experts: int = -1,
expert_map: Optional[Tensor] = None,
custom_routing_function: Optional[Callable] = None,
scoring_func: str = "softmax",
e_score_correction_bias: Optional[Tensor] = None,
apply_router_weight_on_input: bool = False,
activation: str = "silu",
enable_eplb: bool = False,
expert_load_view: Optional[Tensor] = None,
logical_to_physical_map: Optional[Tensor] = None,
logical_replica_count: Optional[Tensor] = None,
) -> Tensor
Source code in vllm/model_executor/layers/quantization/rtn.py
create_weights ¶
create_weights(
layer: Module,
num_experts: int,
hidden_size: int,
intermediate_size_per_partition: int,
params_dtype: dtype,
**extra_weight_attrs,
)
Source code in vllm/model_executor/layers/quantization/rtn.py
RTNParameter ¶
Bases: Parameter
A wrapper over Parameter that returns RTNTensor (a wrapper over Tensor) when its data is accessed. We need this wrapper for the data loading phase only, so we can intercept a weight copying function (torch.Tensor.copy_) and apply quantization on-the-fly.
Source code in vllm/model_executor/layers/quantization/rtn.py
__init__ ¶
RTNTensor ¶
A wrapper over Tensor that enables quantization on-the-fly by overloading the copy_ method.
Source code in vllm/model_executor/layers/quantization/rtn.py
fix_weights ¶
torch.compile does not know how to deal with a Parameter subclass (aka RTNParameter). As we don't really need RTNParameters for the forward pass, we replace them with equivalent instances of Parameters.
Source code in vllm/model_executor/layers/quantization/rtn.py
rtn_dequantize ¶
Dequantize a tensor using per-group static scaling factors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor | Tensor | The input tensor. | required |
scale | Tensor | The tensor with per-group scale factors. | required |
Source code in vllm/model_executor/layers/quantization/rtn.py
rtn_quantize ¶
Quantize a tensor using per-group static scaling factor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor | Tensor | The input tensor. | required |
num_bits | int | Target precision for the result (supported values are 8 or 4). | required |
group_size | int | Quantization granularity. If equal to -1, each row in the input tensor is treated as one group. | required |