You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This codebook is differentiable, so we can finetune it: to evaluate this, we fine-tune using QuIP#’s methodology, tuning both the codebook entries and the as-yet-unquantized weights in a blockwise fashion.
However, I observed that gradients do not flow into the tlut parameters in the QuantizedLinear layer layer. This indicates that the current implementation does not actually update the codebook parameters during fine-tuning.
In the forward pass of QuantizedLinear layer, the code passes BitShiftLinearKernelAG for "decompress and matmul" during fine-tuning, whose backward function does not return grad of tlut. Please refer to the following minimal code for reproduce reported behavior in backward.
Reproducing the Behavior:
fromlib.utils.unsafe_importimportmodel_from_hf_pathimporttorchdefget_quantized_layer(path2qmodel="YOURPATH"):
# load a quantized modelquant_model=model_from_hf_path(path2qmodel)[0].float()
# select an arbitrary layer.quantized_layer=quant_model.model.layers[0].self_attn.q_proj# replicate the routine in finetune_e2e_llama.py #L95:107 with --ft_train_lut flag quantized_layer.SU=torch.nn.Parameter(quantized_layer.SU.float(), requires_grad=True)
quantized_layer.SV=torch.nn.Parameter(quantized_layer.SV.float(), requires_grad=True)
quantized_layer.mode="train-recons"quantized_layer.tlut.requires_grad=Truereturnquantized_layerdeftest_backward():
# load quantized layerquantized_layer=get_quantized_layer()
# initialize random input to the layerft_bs, ctx_size, in_features=4, 4096, 4096input=torch.randn(ft_bs, ctx_size, in_features).to('cuda').to(torch.float16)
input.requires_grad=Trueprint("=== Before backward ===")
print("input", input.grad)
print("SU", quantized_layer.SU.grad)
print("SV", quantized_layer.SV.grad)
print("tlut", quantized_layer.tlut.grad)
# forward passoutput=quantized_layer(input)
# backward passloss=output.sum()
loss.backward()
print("=== After backward ===")
print("input", input.grad)
print("SU", quantized_layer.SU.grad)
print("SV", quantized_layer.SV.grad)
print("tlut", quantized_layer.tlut.grad)
if__name__=="__main__":
test_backward()
In Page 8 of the QTIP paper, the authors state:
Important
This codebook is differentiable, so we can finetune it: to evaluate this, we fine-tune using QuIP#’s methodology, tuning both the codebook entries and the as-yet-unquantized weights in a blockwise fashion.
And, according to the instructions in this repo,
--ft_train_lutflag in both finetune_e2e_llama.py and quantize_finetune_llama.py is intended to enable fine-tuning of codebook entries.Issue:
However, I observed that gradients do not flow into the
tlutparameters in the QuantizedLinear layer layer. This indicates that the current implementation does not actually update the codebook parameters during fine-tuning.In the forward pass of QuantizedLinear layer, the code passes BitShiftLinearKernelAG for "decompress and matmul" during fine-tuning, whose backward function does not return grad of
tlut. Please refer to the following minimal code for reproduce reported behavior in backward.Reproducing the Behavior: