A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 4, 06:15 UTC
Remove unnecessary runtime asserts from linear layers (#41729)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Harry Mellor committed
May 5, 2026 at 15:42 UTC
84bd8a3c1eb7560a810ff4d99a476708a6f9f2f2
1 file changed
+5
-9
vllm/model_executor/layers/linear.py
+5
-9
@@ -268,10 +268,13 @@ class LinearBase(PluggableLayer):
268
self.quant_config = quant_config
269
self.prefix = prefix
270
self.allow_fp8_block_shape_mismatch = False
271
+ self.quant_method: QuantizeMethodBase
272
if quant_config is None:
272
- self.quant_method: QuantizeMethodBase | None = UnquantizedLinearMethod()
273
+ self.quant_method = UnquantizedLinearMethod()
274
+ elif quant_method := quant_config.get_quant_method(self, prefix=prefix):
275
+ self.quant_method = quant_method
276
else:
274
- self.quant_method = quant_config.get_quant_method(self, prefix=prefix)
277
+ raise ValueError("All linear layers should support quant method.")
278
self.return_bias = return_bias
279
self.disable_tp = disable_tp
280
self.tp_rank = get_tensor_model_parallel_rank() if not disable_tp else 0
@@ -335,8 +338,6 @@ class ReplicatedLinear(LinearBase):
338
disable_tp=disable_tp,
339
)
340
338
- # All the linear layer supports quant method.
339
- assert self.quant_method is not None
341
self.quant_method.create_weights(
342
self,
343
self.input_size,
@@ -389,7 +390,6 @@ class ReplicatedLinear(LinearBase):
390
x: torch.Tensor,
391
) -> torch.Tensor | tuple[torch.Tensor, Parameter | None]:
392
bias = self.bias if not self.skip_bias_add else None
392
- assert self.quant_method is not None
393
394
output = self.quant_method.apply(self, x, bias)
395
@@ -474,7 +474,6 @@ class ColumnParallelLinear(LinearBase):
474
self._maybe_allow_fp8_block_shape_mismatch()
475
self.gather_output = gather_output
476
477
- assert self.quant_method is not None
477
self.quant_method.create_weights(
478
layer=self,
479
input_size_per_partition=self.input_size_per_partition,
@@ -583,7 +582,6 @@ class ColumnParallelLinear(LinearBase):
582
bias = self.bias if not self.skip_bias_add else None
583
584
# Matrix multiply.
586
- assert self.quant_method is not None
585
output_parallel = self.quant_method.apply(self, input_, bias)
586
587
if self.gather_output and self.tp_size > 1:
@@ -1463,7 +1461,6 @@ class RowParallelLinear(LinearBase):
1461
self.input_is_parallel = input_is_parallel
1462
self.reduce_results = reduce_results
1463
1466
- assert self.quant_method is not None
1464
self.quant_method.create_weights(
1465
layer=self,
1466
input_size_per_partition=self.input_size_per_partition,
@@ -1553,7 +1550,6 @@ class RowParallelLinear(LinearBase):
1550
input_parallel = split_input[self.tp_rank].contiguous()
1551
1552
# Matrix multiply.
1556
- assert self.quant_method is not None
1553
# Only fuse bias add into GEMM for rank 0 (this ensures that
1554
# bias will not get added more than once in TP>1 case)
1555
bias_ = None if (self.tp_rank > 0 or self.skip_bias_add) else self.bias