unslothai / unsloth

Finetune Llama 3.2, Mistral, Phi, Qwen 2.5 & Gemma LLMs 2-5x faster with 80% less memory
https://unsloth.ai
Apache License 2.0
18.23k stars 1.27k forks source link

OSError: [Errno 39] Directory not empty: '_unsloth_sentencepiece_temp/lora_model' #597

Closed zhaowei0315 closed 5 months ago

zhaowei0315 commented 5 months ago

Hello Expert, an error happened when export gguf with F16.

model.save_pretrained_gguf("model", tokenizer, quantization_method = "f16") Unsloth: Merging 4bit and LoRA weights to 16bit... Unsloth: Will use up to 407.79 out of 503.63 RAM for saving. 100%|████████████████████████████████████████| 32/32 [00:43<00:00, 1.36s/it] Unsloth: Saving tokenizer... Done. Unsloth: Saving model... This might take 5 minutes for Llama-7b... Done. Traceback (most recent call last): File "", line 1, in File "/home/xxx/.conda/envs/unsloth/lib/python3.10/site-packages/unsloth/save.py", line 1393, in unsloth_save_pretrained_gguf is_sentencepiece_model = check_if_sentencepiece_model(self) File "/home/xxx/.conda/envs/unsloth/lib/python3.10/site-packages/unsloth/save.py", line 105, in check_if_sentencepiece_model shutil.rmtree(file_location) File "/home/xxx/.conda/envs/unsloth/lib/python3.10/shutil.py", line 731, in rmtree onerror(os.rmdir, path, sys.exc_info()) File "/home/xxx/.conda/envs/unsloth/lib/python3.10/shutil.py", line 729, in rmtree os.rmdir(path) OSError: [Errno 39] Directory not empty: '_unsloth_sentencepiece_temp/lora_model'

below methods are ok: model.save_pretrained_gguf("model", tokenizer)# 8bit model.save_pretrained_gguf("model", tokenizer, quantization_method = "q4_k_m")# 4bit model.save_pretrained_gguf("model", tokenizer, quantization_method = "f32")# 32bit

zhaowei0315 commented 5 months ago

Suggest to add shutil.rmtree(file_location , ignore_errors=True) to /unsloth/save.py 105 line.

danielhanchen commented 5 months ago

Fantastic idea!! Would you be open to be a contributor and open a PR :) If not, I can also do that!!

zhaowei0315 commented 5 months ago

@danielhanchen commit my change accordingly. please check.