Skip to content

Update lora_quantization_layers.py #10876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions paddlenlp/peft/lora/lora_quantization_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
mark_as_sequence_parallel_parameter,
)

from ...quantization.quantization_linear import quant_weight_linear
from ...quantization.quantization_linear import quant_weight_linear, get_act_scale_group
from ...utils.log import logger
from .utils import rng_ctx

Expand All @@ -44,7 +44,17 @@ def __init__(self, layer, lora_config):
else:
self.quant_scale = layer.quant_scale
self.bias = layer.bias

self.state = 0
if self.weight_quantize_algo in ["a8w8linear", "a8w4linear", "fp8linear"]:
self.act_scale = self.create_parameter(
shape=[1],
dtype=self._dtype,
is_bias=False,
default_initializer=nn.initializer.Constant(value=0.0),
)
self.act_scale.is_distributed = False
self.act_scale.stop_gradient = True
self.group = get_act_scale_group(is_row=True)
# LoRA related parameters
self.lora_config = lora_config
if not isinstance(self.lora_config.r, int) or self.lora_config.r <= 0:
Expand Down Expand Up @@ -77,7 +87,10 @@ def forward(self, x, add_bias=True):
if (self.weight_quantize_algo in ["fp4", "nf4"] and self.quantization_config.qlora_weight_double_quant)
else None,
bias=self.bias if add_bias else None,
act_state=(self.state, self.training, self.act_scale, self.group)
)
if self.training:
self.state += 1
return output

def merge(self):
Expand Down