liaoweiduo commited on
Commit
40fecbc
·
1 Parent(s): 473deee
Files changed (1) hide show
  1. app.py +6 -23
app.py CHANGED
@@ -32,20 +32,13 @@ else:
32
  print(f"[info] BASE_MODEL: {BASE_MODEL}; DEVICE: {DEVICE} ({DTYPE})...")
33
 
34
 
35
- _PROCESSOR = None
36
-
37
-
38
- def get_processor():
39
- """Lazy-load and cache processor for future multimodal inputs."""
40
- global _PROCESSOR
41
- if _PROCESSOR is None:
42
- _PROCESSOR = AutoProcessor.from_pretrained(BASE_MODEL)
43
- return _PROCESSOR
44
 
45
 
46
  def setup_sae_model():
47
  # 1) Load base model from HF
48
- _ = get_processor()
49
  model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
50
  BASE_MODEL,
51
  torch_dtype=DTYPE,
@@ -101,20 +94,10 @@ def setup_sae_model():
101
  print(f"[info] loaded SAE adapter repo: {sae_repo_id}")
102
  print(f"[info] target_modules : {target_modules}")
103
 
104
- return sae_model
105
-
106
-
107
- _SAE_MODEL = None
108
-
109
-
110
- def get_sae_model():
111
- """Lazy-load and cache SAE model to avoid heavy import-time initialization."""
112
- global _SAE_MODEL
113
- if _SAE_MODEL is None:
114
- _SAE_MODEL = setup_sae_model()
115
- return _SAE_MODEL
116
 
117
- _ = get_sae_model() # Trigger initial load and cache the model for future use.
 
118
 
119
 
120
  def build_demo():
 
32
  print(f"[info] BASE_MODEL: {BASE_MODEL}; DEVICE: {DEVICE} ({DTYPE})...")
33
 
34
 
35
+ global _PROCESSOR
36
+ _PROCESSOR = AutoProcessor.from_pretrained(BASE_MODEL)
37
+ print(f"[info] Processor loaded: {type(_PROCESSOR)}")
 
 
 
 
 
 
38
 
39
 
40
  def setup_sae_model():
41
  # 1) Load base model from HF
 
42
  model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
43
  BASE_MODEL,
44
  torch_dtype=DTYPE,
 
94
  print(f"[info] loaded SAE adapter repo: {sae_repo_id}")
95
  print(f"[info] target_modules : {target_modules}")
96
 
97
+ return peft_model, sae_model
 
 
 
 
 
 
 
 
 
 
 
98
 
99
+ global _PEFT_MODEL, _SAE_MODEL
100
+ _PEFT_MODEL, _SAE_MODEL = setup_sae_model()
101
 
102
 
103
  def build_demo():