make sure everything stays in the same dtype when using dpo + FSDP (#1559)

This commit is contained in:
Wing Lian
2024-04-22 16:00:05 -04:00
committed by GitHub
parent 60f5ce0569
commit 68601ec6ad
2 changed files with 14 additions and 0 deletions

View File

@@ -993,3 +993,13 @@ def load_lora(model, cfg, inference=False, config_only=False):
setup_quantized_peft_meta_for_training(model)
return model, lora_config
def ensure_dtype(model, dtype=torch.bfloat16):
for name, module in model.named_modules():
try:
if module.weight.dtype != dtype:
print(f"Converting module {name}: {module.weight.dtype} -> {dtype}")
module.to(dtype)
except AttributeError:
pass