Skip to content

Commit 090f38f

Browse files
committed
update linear interface
1 parent c605cd0 commit 090f38f

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

vllm/model_executor/layers/linear.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ def forward(
391391
) -> Union[torch.Tensor, tuple[torch.Tensor, Optional[Parameter]]]:
392392
bias = self.bias if not self.skip_bias_add else None
393393
assert self.quant_method is not None
394+
from vllm.model_executor.layers.quantization.fp8 import Fp8LinearMethod
395+
if isinstance(self.quant_method, Fp8LinearMethod):
396+
output = self.quant_method.apply(self, x, bias, x_quant_scales=x_quant_scales)
397+
else:
398+
assert x_quant_scales is None, f"x_quant_scales input is not supported for {self.quant_method.__class__}"
399+
output = self.quant_method.apply(self, x, bias)
394400
# output = self.quant_method.apply(self, x, bias)
395401
if isinstance(self.quant_method, UnquantizedLinearMethod):
396402
assert x_quant_scales is None, "UnquantizedLinearMethod should not have quantized input"
@@ -611,13 +617,18 @@ def weight_loader_v2(self, param: Parameter, loaded_weight: torch.Tensor):
611617
param.load_column_parallel_weight(loaded_weight=loaded_weight)
612618

613619
def forward(
614-
self, input_
620+
self, input_, x_quant_scales: torch.Tensor = None,
615621
) -> Union[torch.Tensor, tuple[torch.Tensor, Optional[Parameter]]]:
616622
bias = self.bias if not self.skip_bias_add else None
617623

618624
# Matrix multiply.
619625
assert self.quant_method is not None
620-
output_parallel = self.quant_method.apply(self, input_, bias)
626+
from vllm.model_executor.layers.quantization.fp8 import Fp8LinearMethod
627+
if isinstance(self.quant_method, Fp8LinearMethod):
628+
output_parallel = self.quant_method.apply(self, input_, bias, x_quant_scales=x_quant_scales)
629+
else:
630+
assert x_quant_scales is None, f"x_quant_scales input is not supported for {self.quant_method.__class__}"
631+
output_parallel = self.quant_method.apply(self, input_, bias)
621632
if self.gather_output:
622633
# All-gather across the partitions.
623634
output = tensor_model_parallel_all_gather(output_parallel)
@@ -1386,7 +1397,8 @@ def weight_loader_v2(self, param: BasevLLMParameter,
13861397
param.load_row_parallel_weight(loaded_weight=loaded_weight)
13871398

13881399
def forward(
1389-
self, input_
1400+
self, input_,
1401+
x_quant_scales = None
13901402
) -> Union[torch.Tensor, tuple[torch.Tensor, Optional[Parameter]]]:
13911403
if self.input_is_parallel:
13921404
input_parallel = input_
@@ -1401,9 +1413,12 @@ def forward(
14011413
# Only fuse bias add into GEMM for rank 0 (this ensures that
14021414
# bias will not get added more than once in TP>1 case)
14031415
bias_ = None if (self.tp_rank > 0 or self.skip_bias_add) else self.bias
1404-
output_parallel = self.quant_method.apply(self,
1405-
input_parallel,
1406-
bias=bias_)
1416+
from vllm.model_executor.layers.quantization.fp8 import Fp8LinearMethod
1417+
if isinstance(self.quant_method, Fp8LinearMethod):
1418+
output_parallel = self.quant_method.apply(self, input_parallel, bias_, x_quant_scales=x_quant_scales)
1419+
else:
1420+
assert x_quant_scales is None, f"x_quant_scales input is not supported for {self.quant_method.__class__}"
1421+
output_parallel = self.quant_method.apply(self, input_parallel, bias_)
14071422
if self.reduce_results and self.tp_size > 1:
14081423
output = tensor_model_parallel_all_reduce(output_parallel)
14091424
else:

0 commit comments

Comments
 (0)