Spaces:
Sleeping
Sleeping
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()
|