Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,7 @@ import os
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
| 5 |
-
|
| 6 |
-
from transformers import AutoConfig, AutoModel, AutoTokenizer
|
| 7 |
from huggingface_hub import snapshot_download
|
| 8 |
|
| 9 |
# 1. Configuration Settings
|
|
@@ -22,21 +21,19 @@ if not os.path.exists(LOCAL_PATH) or not os.listdir(LOCAL_PATH):
|
|
| 22 |
else:
|
| 23 |
print(f"Found existing local weights at {LOCAL_PATH}. Loading directly...")
|
| 24 |
|
| 25 |
-
print("Loading architecture layers from local storage...")
|
| 26 |
|
| 27 |
-
# 3. Load
|
| 28 |
config = AutoConfig.from_pretrained(LOCAL_PATH, trust_remote_code=True)
|
| 29 |
tokenizer = AutoTokenizer.from_pretrained(LOCAL_PATH, trust_remote_code=True)
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
model = AutoModel.from_pretrained(
|
| 36 |
LOCAL_PATH,
|
| 37 |
config=config,
|
| 38 |
-
|
| 39 |
-
trust_remote_code=True
|
| 40 |
)
|
| 41 |
|
| 42 |
@spaces.GPU(duration=60)
|
|
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
import spaces
|
| 5 |
+
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 6 |
from huggingface_hub import snapshot_download
|
| 7 |
|
| 8 |
# 1. Configuration Settings
|
|
|
|
| 21 |
else:
|
| 22 |
print(f"Found existing local weights at {LOCAL_PATH}. Loading directly...")
|
| 23 |
|
| 24 |
+
print("Loading architecture layers from local storage using custom remote scripts...")
|
| 25 |
|
| 26 |
+
# 3. Load configuration and enforce remote script execution
|
| 27 |
config = AutoConfig.from_pretrained(LOCAL_PATH, trust_remote_code=True)
|
| 28 |
tokenizer = AutoTokenizer.from_pretrained(LOCAL_PATH, trust_remote_code=True)
|
| 29 |
|
| 30 |
+
# Enforcing trust_remote_code=True on AutoModelForCausalLM forces Hugging Face
|
| 31 |
+
# to use the custom modeling_qwen2_5_vl.py script inside the weight directory.
|
| 32 |
+
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
| 33 |
LOCAL_PATH,
|
| 34 |
config=config,
|
| 35 |
+
torch_dtype=torch.bfloat16,
|
| 36 |
+
trust_remote_code=True # <-- CRITICAL: Tells the factory to load custom keys mapping
|
| 37 |
)
|
| 38 |
|
| 39 |
@spaces.GPU(duration=60)
|