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