File size: 1,691 Bytes
4739096 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from unsloth import FastLanguageModel
import torch
import os
import glob
# ==========================================
# [Smart Export Script] μ΅μ 체ν¬ν¬μΈνΈ μλ κ°μ§
# ==========================================
print(">>> [System] GGUF λ³ν μμ
μ μμν©λλ€...")
# 1. μ΅μ 체ν¬ν¬μΈνΈ ν΄λ μ°ΎκΈ° (ν΅μ¬!)
output_dir = "outputs_final"
if not os.path.exists(output_dir):
print(f">>> [Error] '{output_dir}' ν΄λκ° μμ΅λλ€!")
exit()
# checkpoint- μ«μ ν΄λλ€μ λ€ μ°Ύμμ μ«μκ° μ μΌ ν° λμ κ³ λ¦
subfolders = [f.path for f in os.scandir(output_dir) if f.is_dir() and "checkpoint" in f.name]
if not subfolders:
print(">>> [Error] 체ν¬ν¬μΈνΈ ν΄λλ₯Ό μ°Ύμ μ μμ΅λλ€!")
exit()
# μ«μλ‘ μ λ ¬ν΄μ κ°μ₯ λ§μ§λ§ κ² μ ν (μ: checkpoint-3171)
latest_checkpoint = max(subfolders, key=lambda x: int(x.split('-')[-1]))
print(f">>> [Found] κ°μ₯ νμ΅μ΄ μ λ λͺ¨λΈμ μ°Ύμμ΅λλ€: {latest_checkpoint}")
print(">>> [Model] λͺ¨λΈ λ‘λ μ€... (xFormers κ²½κ³ λ 무μνμΈμ)")
# 2. λͺ¨λΈ λ‘λ (μ νν κ²½λ‘ μ
λ ₯)
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = latest_checkpoint, # <--- μλμΌλ‘ μ°Ύμ κ²½λ‘
max_seq_length = 2048,
dtype = None,
load_in_4bit = True,
)
# 3. GGUF λ³ν
print(f">>> [Convert] '{latest_checkpoint}' -> GGUF λ³ν μμ (5~10λΆ μμ)")
# q4_k_m: μ©λ/μ±λ₯ λ°Έλ°μ€ν
model.save_pretrained_gguf("BiddinMate_Model", tokenizer, quantization_method = "q4_k_m")
print(">>> [Success] λ³ν μλ£!")
print(f">>> 'BiddinMate_Model' ν΄λ μμ .gguf νμΌμ΄ μμ±λμμ΅λλ€.")
|