Jaswanth1210 commited on
Commit
33bf00a
·
1 Parent(s): b42adcc

fix: dtype kwarg + cast lm_head/embeds to bfloat16 to fix GRPO generate

Browse files
Files changed (1) hide show
  1. train/grpo_train.py +7 -1
train/grpo_train.py CHANGED
@@ -115,10 +115,16 @@ def _load_model_and_tokenizer(model_id: str, seed: int):
115
  model = AutoModelForCausalLM.from_pretrained(
116
  model_id,
117
  quantization_config=bnb,
118
- torch_dtype=torch.bfloat16,
119
  device_map="auto",
120
  trust_remote_code=True,
121
  )
 
 
 
 
 
 
122
  lora_cfg = LoraConfig(
123
  r=16,
124
  lora_alpha=16,
 
115
  model = AutoModelForCausalLM.from_pretrained(
116
  model_id,
117
  quantization_config=bnb,
118
+ dtype=torch.bfloat16,
119
  device_map="auto",
120
  trust_remote_code=True,
121
  )
122
+ # Cast non-quantized params (lm_head, embeddings, norms) to bfloat16 so they
123
+ # match the compute dtype during generation.
124
+ for name, module in model.named_modules():
125
+ if hasattr(module, "weight") and module.weight is not None and module.weight.dtype == torch.float32:
126
+ module.to(torch.bfloat16)
127
+
128
  lora_cfg = LoraConfig(
129
  r=16,
130
  lora_alpha=16,