Update app.py
Browse files
app.py
CHANGED
|
@@ -464,7 +464,7 @@ def generate_modeling_phoenix_code():
|
|
| 464 |
Hub에서 로드 시 자동으로 Retention 변환
|
| 465 |
"""
|
| 466 |
|
| 467 |
-
modeling_code =
|
| 468 |
PHOENIX Retention Model - Custom Implementation
|
| 469 |
Auto-loaded by HuggingFace transformers with trust_remote_code=True
|
| 470 |
|
|
@@ -812,23 +812,26 @@ class PhoenixModelForCausalLM(PhoenixPreTrainedModel):
|
|
| 812 |
|
| 813 |
print(f"🔥 Loading PHOENIX model from {pretrained_model_name_or_path}")
|
| 814 |
|
| 815 |
-
# 1. Load base model
|
| 816 |
config = AutoConfig.from_pretrained(pretrained_model_name_or_path, trust_remote_code=True)
|
| 817 |
|
| 818 |
# Original architecture 추출
|
| 819 |
original_arch = config.architectures[0] if hasattr(config, 'architectures') else 'AutoModelForCausalLM'
|
| 820 |
|
| 821 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 823 |
pretrained_model_name_or_path,
|
| 824 |
*model_args,
|
| 825 |
-
**
|
| 826 |
-
trust_remote_code=False # 원본 모델은 trust 불필요
|
| 827 |
)
|
| 828 |
|
| 829 |
print(f" ✅ Base model loaded: {original_arch}")
|
| 830 |
|
| 831 |
-
#
|
| 832 |
use_hierarchical = config.use_hierarchical if hasattr(config, 'use_hierarchical') else True
|
| 833 |
|
| 834 |
print(f"🔄 Converting to PHOENIX Retention...")
|
|
@@ -836,7 +839,7 @@ class PhoenixModelForCausalLM(PhoenixPreTrainedModel):
|
|
| 836 |
|
| 837 |
print(f"✅ Converted {converted}/{total} layers to Retention")
|
| 838 |
|
| 839 |
-
#
|
| 840 |
phoenix_instance = cls(config)
|
| 841 |
phoenix_instance._original_model = base_model
|
| 842 |
phoenix_instance._initialized = True
|
|
@@ -868,7 +871,6 @@ class PhoenixModelForCausalLM(PhoenixPreTrainedModel):
|
|
| 868 |
|
| 869 |
# Auto-registration
|
| 870 |
AutoConfig.register("phoenix", PhoenixConfig)
|
| 871 |
-
'''
|
| 872 |
|
| 873 |
return modeling_code
|
| 874 |
|
|
|
|
| 464 |
Hub에서 로드 시 자동으로 Retention 변환
|
| 465 |
"""
|
| 466 |
|
| 467 |
+
modeling_code = """
|
| 468 |
PHOENIX Retention Model - Custom Implementation
|
| 469 |
Auto-loaded by HuggingFace transformers with trust_remote_code=True
|
| 470 |
|
|
|
|
| 812 |
|
| 813 |
print(f"🔥 Loading PHOENIX model from {pretrained_model_name_or_path}")
|
| 814 |
|
| 815 |
+
# 1. Load base model config
|
| 816 |
config = AutoConfig.from_pretrained(pretrained_model_name_or_path, trust_remote_code=True)
|
| 817 |
|
| 818 |
# Original architecture 추출
|
| 819 |
original_arch = config.architectures[0] if hasattr(config, 'architectures') else 'AutoModelForCausalLM'
|
| 820 |
|
| 821 |
+
# 2. kwargs 복사 및 trust_remote_code 제거
|
| 822 |
+
base_kwargs = kwargs.copy()
|
| 823 |
+
base_kwargs.pop('trust_remote_code', None) # 중복 방지
|
| 824 |
+
|
| 825 |
+
# 3. Load with original architecture
|
| 826 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 827 |
pretrained_model_name_or_path,
|
| 828 |
*model_args,
|
| 829 |
+
**base_kwargs
|
|
|
|
| 830 |
)
|
| 831 |
|
| 832 |
print(f" ✅ Base model loaded: {original_arch}")
|
| 833 |
|
| 834 |
+
# 4. Retention 변환
|
| 835 |
use_hierarchical = config.use_hierarchical if hasattr(config, 'use_hierarchical') else True
|
| 836 |
|
| 837 |
print(f"🔄 Converting to PHOENIX Retention...")
|
|
|
|
| 839 |
|
| 840 |
print(f"✅ Converted {converted}/{total} layers to Retention")
|
| 841 |
|
| 842 |
+
# 5. Create PHOENIX wrapper
|
| 843 |
phoenix_instance = cls(config)
|
| 844 |
phoenix_instance._original_model = base_model
|
| 845 |
phoenix_instance._initialized = True
|
|
|
|
| 871 |
|
| 872 |
# Auto-registration
|
| 873 |
AutoConfig.register("phoenix", PhoenixConfig)
|
|
|
|
| 874 |
|
| 875 |
return modeling_code
|
| 876 |
|