File size: 2,947 Bytes
149ff1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
"""
Kanana ๋ชจ๋ธ์˜ ์ •ํ™•ํ•œ target modules ํŒจํ„ด ์ฐพ๊ธฐ
"""
import sys
import os
from pathlib import Path

# ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ๊ฒฝ๋กœ ์ถ”๊ฐ€
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

def find_exact_target_modules():
    """์ •ํ™•ํ•œ target modules ํŒจํ„ด ์ฐพ๊ธฐ"""
    print("๐Ÿ” Kanana ๋ชจ๋ธ์˜ ์ •ํ™•ํ•œ target modules ํŒจํ„ด ์ฐพ๊ธฐ...")
    
    try:
        import torch
        from transformers import AutoModelForVision2Seq
        
        model_path = "./lily_llm_core/models/kanana_1_5_v_3b_instruct"
        
        print(f"๐Ÿ“ฅ ๋ชจ๋ธ ๋กœ๋”ฉ ์ค‘: {model_path}")
        
        # ๋ชจ๋ธ ๋กœ๋“œ
        model = AutoModelForVision2Seq.from_pretrained(
            model_path,
            trust_remote_code=True,
            local_files_only=True,
            torch_dtype=torch.bfloat16
        )
        
        print(f"โœ… ๋ชจ๋ธ ๋กœ๋“œ ์„ฑ๊ณต!")
        
        # language_model ๋ถ€๋ถ„์˜ ์ •ํ™•ํ•œ ๋ชจ๋“ˆ ์ด๋ฆ„ ์ฐพ๊ธฐ
        print("\n๐ŸŽฏ Language Model ๋ชจ๋“ˆ ๊ฒ€์ƒ‰:")
        
        target_candidates = []
        
        for name, module in model.named_modules():
            # language_model ๋ถ€๋ถ„๋งŒ ํ•„ํ„ฐ๋ง
            if name.startswith("language_model.model.layers."):
                if hasattr(module, 'weight') and module.weight is not None:
                    module_type = type(module).__name__
                    
                    # LoRA์— ์ ํ•ฉํ•œ ๋ชจ๋“ˆ๋“ค ์ฐพ๊ธฐ
                    if any(pattern in name for pattern in ['q_proj', 'k_proj', 'v_proj', 'o_proj']):
                        target_candidates.append((name, module_type, "Attention"))
                    elif any(pattern in name for pattern in ['gate_proj', 'up_proj', 'down_proj']):
                        target_candidates.append((name, module_type, "MLP"))
        
        # ๊ฒฐ๊ณผ ์ถœ๋ ฅ
        if target_candidates:
            print("  โœ… ๋ฐœ๊ฒฌ๋œ target modules:")
            for name, module_type, category in target_candidates:
                print(f"    - {name} ({module_type}) - {category}")
            
            # ์‹ค์ œ ์‚ฌ์šฉํ•  target modules ์ถ”์ถœ
            print("\n๐Ÿ“‹ ์‹ค์ œ ์‚ฌ์šฉํ•  target modules:")
            target_modules = []
            for name, _, _ in target_candidates:
                target_modules.append(name)
                print(f"    '{name}',")
            
            print(f"\n๐Ÿ”ข ์ด {len(target_modules)}๊ฐœ์˜ target modules ๋ฐœ๊ฒฌ")
            
        else:
            print("  โŒ language_model์—์„œ target modules๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Œ")
        
        # ๋ชจ๋ธ ํ•ด์ œ
        del model
        import gc
        gc.collect()
        
        print("\nโœ… target modules ๊ฒ€์ƒ‰ ์™„๋ฃŒ!")
        
    except Exception as e:
        print(f"โŒ target modules ๊ฒ€์ƒ‰ ์‹คํŒจ: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    find_exact_target_modules()