yangluo commited on
Commit
e1c12b7
·
verified ·
1 Parent(s): 9386de3

Upload train_sft_hf_cloud.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_sft_hf_cloud.py +19 -3
train_sft_hf_cloud.py CHANGED
@@ -70,8 +70,9 @@ LORA_DROPOUT = 0.05
70
  # MLP layers (gate_proj, up_proj, down_proj) are in 512 experts - too many params
71
  LORA_TARGET_MODULES = ["q_proj", "k_proj", "v_proj", "o_proj"]
72
 
73
- # Quantization - 8-bit for 80B model on single A100
74
- USE_8BIT = True
 
75
 
76
  # Trackio monitoring
77
  TRACKIO_PROJECT = "univer-api-training"
@@ -125,6 +126,7 @@ def main():
125
  print(f"LR: {LEARNING_RATE}")
126
  print(f"LoRA: r={LORA_R}, alpha={LORA_ALPHA}")
127
  print(f"Targets: {LORA_TARGET_MODULES}")
 
128
  print(f"8-bit: {USE_8BIT}")
129
  print("=" * 60)
130
 
@@ -146,7 +148,21 @@ def main():
146
  tokenizer.pad_token = tokenizer.eos_token
147
 
148
  # Configure quantization
149
- if USE_8BIT:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  print(" Using 8-bit quantization...")
151
  bnb_config = BitsAndBytesConfig(load_in_8bit=True)
152
  model = AutoModelForCausalLM.from_pretrained(
 
70
  # MLP layers (gate_proj, up_proj, down_proj) are in 512 experts - too many params
71
  LORA_TARGET_MODULES = ["q_proj", "k_proj", "v_proj", "o_proj"]
72
 
73
+ # Quantization - 4-bit QLoRA for 80B model (more stable than 8-bit on multi-GPU)
74
+ USE_4BIT = True
75
+ USE_8BIT = False
76
 
77
  # Trackio monitoring
78
  TRACKIO_PROJECT = "univer-api-training"
 
126
  print(f"LR: {LEARNING_RATE}")
127
  print(f"LoRA: r={LORA_R}, alpha={LORA_ALPHA}")
128
  print(f"Targets: {LORA_TARGET_MODULES}")
129
+ print(f"4-bit: {USE_4BIT}")
130
  print(f"8-bit: {USE_8BIT}")
131
  print("=" * 60)
132
 
 
148
  tokenizer.pad_token = tokenizer.eos_token
149
 
150
  # Configure quantization
151
+ if USE_4BIT:
152
+ print(" Using 4-bit QLoRA quantization...")
153
+ bnb_config = BitsAndBytesConfig(
154
+ load_in_4bit=True,
155
+ bnb_4bit_quant_type="nf4",
156
+ bnb_4bit_compute_dtype=torch.bfloat16,
157
+ bnb_4bit_use_double_quant=True,
158
+ )
159
+ model = AutoModelForCausalLM.from_pretrained(
160
+ MODEL_NAME,
161
+ quantization_config=bnb_config,
162
+ device_map="auto",
163
+ trust_remote_code=True,
164
+ )
165
+ elif USE_8BIT:
166
  print(" Using 8-bit quantization...")
167
  bnb_config = BitsAndBytesConfig(load_in_8bit=True)
168
  model = AutoModelForCausalLM.from_pretrained(