yangluo commited on
Commit
72b4aee
·
verified ·
1 Parent(s): e1c12b7

Upload train_sft_hf_cloud.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_sft_hf_cloud.py +21 -4
train_sft_hf_cloud.py CHANGED
@@ -70,9 +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 - 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"
@@ -164,11 +164,28 @@ def main():
164
  )
165
  elif USE_8BIT:
166
  print(" Using 8-bit quantization...")
167
- bnb_config = BitsAndBytesConfig(load_in_8bit=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  model = AutoModelForCausalLM.from_pretrained(
169
  MODEL_NAME,
170
  quantization_config=bnb_config,
171
  device_map="auto",
 
172
  trust_remote_code=True,
173
  )
174
  else:
 
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 multi-GPU (A100x4)
74
+ USE_4BIT = False
75
+ USE_8BIT = True
76
 
77
  # Trackio monitoring
78
  TRACKIO_PROJECT = "univer-api-training"
 
164
  )
165
  elif USE_8BIT:
166
  print(" Using 8-bit quantization...")
167
+ bnb_config = BitsAndBytesConfig(
168
+ load_in_8bit=True,
169
+ llm_int8_enable_fp32_cpu_offload=False, # Keep everything on GPU
170
+ )
171
+
172
+ # For multi-GPU, set max_memory per device
173
+ n_gpus = torch.cuda.device_count()
174
+ print(f" Detected {n_gpus} GPUs")
175
+
176
+ if n_gpus > 1:
177
+ # Distribute model across GPUs with balanced memory
178
+ max_memory = {i: "70GiB" for i in range(n_gpus)}
179
+ max_memory["cpu"] = "0GiB" # Don't offload to CPU
180
+ print(f" Max memory per GPU: 70GiB")
181
+ else:
182
+ max_memory = None
183
+
184
  model = AutoModelForCausalLM.from_pretrained(
185
  MODEL_NAME,
186
  quantization_config=bnb_config,
187
  device_map="auto",
188
+ max_memory=max_memory,
189
  trust_remote_code=True,
190
  )
191
  else: