File size: 2,028 Bytes
130525d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
import os
import torch
from transformers import AutoModelForVision2Seq, AutoProcessor
from dotenv import load_dotenv

# --- μ„€μ • λΆ€λΆ„ ---
MODEL_NAME = "kakaocorp/kanana-1.5-v-3b-instruct"
SAVE_DIRECTORY = "./lily_llm_core/models/kanana_1_5_v_3b_instruct"
# --- μ„€μ • 끝 ---

load_dotenv()
HF_TOKEN = os.getenv("HF_TOKEN")

print("="*60)
print(f"'{MODEL_NAME}' λͺ¨λΈ 및 ν”„λ‘œμ„Έμ„œ 곡식 λ‹€μš΄λ‘œλ“œλ₯Ό μ‹œμž‘ν•©λ‹ˆλ‹€.")
print(f"μ €μž₯ 경둜: {SAVE_DIRECTORY}")
print("="*60)

try:
    # 1. 곡식 AutoProcessor λ‘œλ“œ 및 λ‹€μš΄λ‘œλ“œ
    print("\n[1/2] ν”„λ‘œμ„Έμ„œ(Tokenizer+Image Processor) λ‹€μš΄λ‘œλ“œ 쀑...")
    processor = AutoProcessor.from_pretrained(
        MODEL_NAME,
        token=HF_TOKEN,
        trust_remote_code=True
    )
    print("βœ… ν”„λ‘œμ„Έμ„œ λ‹€μš΄λ‘œλ“œ 성곡!")

    # 2. 곡식 AutoModelForVision2Seq λ‘œλ“œ 및 λ‹€μš΄λ‘œλ“œ
    print("\n[2/2] λͺ¨λΈ λ‹€μš΄λ‘œλ“œ 쀑... (μ‹œκ°„μ΄ 걸릴 수 μžˆμŠ΅λ‹ˆλ‹€)")
    model = AutoModelForVision2Seq.from_pretrained(
        MODEL_NAME,
        token=HF_TOKEN,
        torch_dtype=torch.bfloat16, # 곡식 μ˜ˆμ œμ™€ λ™μΌν•˜κ²Œ bfloat16 μ‚¬μš©
        trust_remote_code=True
    )
    print("βœ… λͺ¨λΈ λ‹€μš΄λ‘œλ“œ 성곡!")

    # 3. 둜컬 κ²½λ‘œμ— λͺ¨λΈκ³Ό ν”„λ‘œμ„Έμ„œ λͺ¨λ‘ μ €μž₯
    print(f"\n[+] '{SAVE_DIRECTORY}' κ²½λ‘œμ— λͺ¨λ“  파일 μ €μž₯ 쀑...")
    if not os.path.exists(SAVE_DIRECTORY):
        os.makedirs(SAVE_DIRECTORY)
    
    processor.save_pretrained(SAVE_DIRECTORY)
    model.save_pretrained(SAVE_DIRECTORY)
    print("βœ… λͺ¨λΈκ³Ό ν”„λ‘œμ„Έμ„œ μ €μž₯ μ™„λ£Œ!")

    print("\n" + "="*60)
    print("πŸŽ‰ λͺ¨λ“  μž‘μ—…μ΄ μ„±κ³΅μ μœΌλ‘œ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
    print("이제 `kanana_1_5_v_3b_instruct.py` νŒŒμΌμ„ μˆ˜μ •ν•˜κ³  μ„œλ²„λ₯Ό μ‹€ν–‰ν•˜μ„Έμš”.")
    print("="*60)

except Exception as e:
    import traceback
    print(f"\n❌ 였λ₯˜ λ°œμƒ: {e}")
    traceback.print_exc()
    print("\nν—ˆκΉ…νŽ˜μ΄μŠ€ 토큰이 μ˜¬λ°”λ₯Έμ§€, `huggingface-cli login`을 μ‹€ν–‰ν–ˆλŠ”μ§€ ν™•μΈν•˜μ„Έμš”.")