Update lora_quantization_layers.py #10876
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix parallel QLoRA in reference to paddlenlp/quantization/quantization_linear.py
The original lora_quantization_layers.py is in paddlenlp/peft/lora
In class QuantizationLoRABaseLinear:
In method init:
insert codes '
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)
else:
raise NotImplementedError(
f"Not supported weight_quantize_algo {self.weight_quantize_algo}"
)
'
between 'self.bias = layer.bias' and 'self.lora_config = lora_config'
In method forward:
insert 'act_state=(self.state, self.training, self.act_scale, self.group)' in the parameter list of 'output=quant_weight_linear'
insert codes '
if self.training:
self.state += 1
'
before 'return output'
However, after such change, in different cases, I found that loss would start to converge with different beginnings (I have deleted all checkpoints every time I start a new case):