xlangai/spider
Viewer • Updated • 8.03k • 10k • 176
This repository contains LoRA adapter weights fine-tuned on the Spider text-to-SQL dataset.
The base model was quantized to 4-bit NormalFloat (NF4) using a custom, from-scratch PyTorch implementation of block-wise quantization and 8-bit double quantization of scale factors, then injected with trainable LoRA adapters on attention projection layers.
Qwen/Qwen2.5-7B-Instructq_proj, v_projrichardr1126/spider-schema.0.2434 at step 350 / 1000Since these weights were trained using a custom from-scratch PyTorch quantization class, loading the model requires replacing the linear layers with QuantizedLinear before copying the adapter weights:
import torch
from transformers import AutoModelForCausalLM
# 1. Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-7B-Instruct",
torch_dtype=torch.float16,
device_map="auto"
)
# 2. Re-create the NF4 codebook
cb = make_nf4_codebook()
# 3. Swap linear layers to custom QuantizedLinear in-place
for layer in base_model.model.layers:
layer.self_attn.q_proj = QuantizedLinear.from_linear(layer.self_attn.q_proj, cb)
layer.self_attn.v_proj = QuantizedLinear.from_linear(layer.self_attn.v_proj, cb)
# 4. Inject LoRA adapters
inject_lora(base_model, r=8, alpha=16)
# 5. Load adapter weights from checkpoint
checkpoint = torch.load("best_qlora_checkpoint.pt")
lora_state = checkpoint["lora_state_dict"]
for name, param in base_model.named_parameters():
if name in lora_state:
param.data.copy_(lora_state[name].to(param.device))
print("Model successfully loaded with custom quantized weights!")