Skip to content

Commit c0b5ce1

Browse files
authored
pytorch-finetuning: pin full fine-tuning model to one device (#687)
device_map=auto offloaded gemma-3-4b across GPU and CPU on halo; full fine-tuning cannot train across that split and crashed. Pin to the GPU. Fixes #672.
1 parent 7b5ef63 commit c0b5ce1

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

playbooks/supplemental/pytorch-finetuning/assets/train_full_finetuning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ def format_chat(ex):
9696
print("Note: Model is stored as MXFP4 on Hugging Face but will be loaded as BF16 for training")
9797
print("(This is expected - the warning about MXFP4 is informational)\n")
9898

99+
device = "cuda" if torch.cuda.is_available() else "cpu"
99100
model = AutoModelForCausalLM.from_pretrained(
100101
MODEL,
101102
dtype=torch.bfloat16, # Use BF16 for better stability and ROCm support (dtype not torch_dtype)
102-
device_map="auto", # Automatically distribute across available GPUs
103+
device_map=device,
103104
trust_remote_code=True,
104105
low_cpu_mem_usage=True # Reduce CPU memory during loading
105106
)

0 commit comments

Comments
 (0)