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