MathObsession commited on
Commit
784cb0e
·
verified ·
1 Parent(s): 199bd2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -2,8 +2,7 @@ import os
2
  import torch
3
  import gradio as gr
4
  import spaces
5
- # Use AutoModel to let trust_remote_code resolve the custom vector architecture cleanly
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 using custom remote code loaders
28
  config = AutoConfig.from_pretrained(LOCAL_PATH, trust_remote_code=True)
29
  tokenizer = AutoTokenizer.from_pretrained(LOCAL_PATH, trust_remote_code=True)
30
 
31
- # Setting this manually patch-fixes the missing attribute crash
32
- if not hasattr(config, "pad_token_id"):
33
- config.pad_token_id = tokenizer.eos_token_id if tokenizer.eos_token_id is not None else 151643
34
-
35
- model = AutoModel.from_pretrained(
36
  LOCAL_PATH,
37
  config=config,
38
- dtype=torch.bfloat16,
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)