From d9abc5e2ad891d4c00b860539aa82b2c0b52cd2d Mon Sep 17 00:00:00 2001 From: "Yao, Matrix" Date: Wed, 6 Aug 2025 21:23:16 +0000 Subject: [PATCH] enable qalora on xpu, pass Signed-off-by: Yao, Matrix --- examples/qalora_finetuning/README.md | 4 ++-- examples/qalora_finetuning/qalora_gptq_finetuning.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/qalora_finetuning/README.md b/examples/qalora_finetuning/README.md index 288580d942..a1dfea11c0 100644 --- a/examples/qalora_finetuning/README.md +++ b/examples/qalora_finetuning/README.md @@ -78,7 +78,7 @@ python qalora_gptq_finetuning.py \ --qalora_group_size 32 \ --eval_step 10 \ --save_step 100 \ - --device "cuda:0" \ + --device "auto" \ --lora_r 16 \ --lora_alpha 32 \ --lora_dropout 0.05 \ @@ -154,4 +154,4 @@ For most use cases, we recommend keeping the base quantized model and the QALoRA journal={arXiv preprint arXiv:2309.14717}, year={2023} } -``` \ No newline at end of file +``` diff --git a/examples/qalora_finetuning/qalora_gptq_finetuning.py b/examples/qalora_finetuning/qalora_gptq_finetuning.py index 25e384629a..a396d3ef12 100644 --- a/examples/qalora_finetuning/qalora_gptq_finetuning.py +++ b/examples/qalora_finetuning/qalora_gptq_finetuning.py @@ -164,7 +164,7 @@ def train_model( quantize: Whether to use quantization eval_step: Steps between evaluations save_step: Steps between saving checkpoints - device: Device to use (cuda:0, etc.) + device: Device to use (cuda:0, xpu:0, etc.) lora_r: LoRA rank lora_alpha: LoRA alpha lora_dropout: LoRA dropout rate @@ -209,7 +209,7 @@ def train_model( model.print_trainable_parameters() # Move model to device if not already there - if device.type != "cuda" or not hasattr(model, "device") or model.device.type != "cuda": + if not hasattr(model, "device") or model.device.type != device.type: model = model.to(device) # Load and prepare dataset @@ -313,13 +313,17 @@ def train_model( # Training process options parser.add_argument("--eval_step", type=int, default=100, help="Evaluation step interval") parser.add_argument("--save_step", type=int, default=500, help="Save step interval") - parser.add_argument("--device", type=str, default="cuda", help="Device to use for training") + parser.add_argument("--device", type=str, default="auto", help="Device to use for training") # Hugging Face Hub options parser.add_argument("--push_to_hub", action="store_true", help="Whether to push the model to Hugging Face Hub") args = parser.parse_args() + device = args.device + if args.device == "auto": + device = torch.accelerator.current_accelerator().type if hasattr(torch, "accelerator") else "cuda" + # If use_qalora isn't explicitly set in args but passed to train_model if not args.use_qalora: args.use_qalora = True # Default to True as in the original code @@ -336,7 +340,7 @@ def train_model( use_qalora=args.use_qalora, eval_step=args.eval_step, save_step=args.save_step, - device=args.device, + device=device, lora_r=args.lora_r, lora_alpha=args.lora_alpha, lora_dropout=args.lora_dropout,