TurkishCodeMan commited on
Commit
7104a49
·
verified ·
1 Parent(s): 4db9aa3

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. models/model_loader.py +8 -25
models/model_loader.py CHANGED
@@ -9,23 +9,18 @@ def load_embed_model(model_path: str = "nvidia/llama-nemotron-embed-vl-1b-v2"):
9
 
10
  print(f"🔄 Loading embedding model on {device}...")
11
 
12
- # ✅ FIX: Load CONFIG from hub but CODE from local patched file
13
  config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
 
 
 
14
 
15
- # Import local patched model class
16
- import sys
17
- import os
18
- sys.path.append(os.path.join(os.path.dirname(__file__), "local_nemotron"))
19
- from local_nemotron.modeling_llama_nemotron_vl import LlamaNemotronVLModel
20
-
21
- # Initialize model using local class
22
- model = LlamaNemotronVLModel.from_pretrained(
23
  model_path,
24
  config=config,
25
  torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
26
- trust_remote_code=False, # We are using local code now
27
- low_cpu_mem_usage=True,
28
- # attn_implementation="eager", # Explicitly set in __init__ patch now
29
  ).to(device).eval()
30
 
31
  print(f"✅ Embedding model loaded on {device}")
@@ -40,20 +35,8 @@ def load_rerank_model(model_path: str = "nvidia/llama-nemotron-rerank-vl-1b-v2")
40
  print(f"🔄 Loading reranking model on {device}...")
41
 
42
  # ✅ FIX: Use manual device instead of device_map="auto"
43
- # FIX: Load CONFIG from hub but CODE from local patched file
44
- config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
45
-
46
- # Import local patched model class
47
- import sys
48
- import os
49
- sys.path.append(os.path.join(os.path.dirname(__file__), "local_nemotron_rerank"))
50
- # Rerank model usually uses ForSequenceClassification variant, checking imports
51
- from local_nemotron_rerank.modeling_llama_nemotron_vl import LlamaNemotronVLForSequenceClassification
52
-
53
- # Initialize model using local class
54
- model = LlamaNemotronVLForSequenceClassification.from_pretrained(
55
  model_path,
56
- config=config,
57
  torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
58
  trust_remote_code=False,
59
  attn_implementation="eager",
 
9
 
10
  print(f"🔄 Loading embedding model on {device}...")
11
 
 
12
  config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
13
+ config._attn_implementation = "sdpa"
14
+ if hasattr(config, 'llm_config'):
15
+ config.llm_config._attn_implementation = "sdpa"
16
 
17
+ # FIX: Use manual device instead of device_map="auto"
18
+ model = AutoModel.from_pretrained(
 
 
 
 
 
 
19
  model_path,
20
  config=config,
21
  torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
22
+ trust_remote_code=False,
23
+ low_cpu_mem_usage=True, # ✅ CPU optimization
 
24
  ).to(device).eval()
25
 
26
  print(f"✅ Embedding model loaded on {device}")
 
35
  print(f"🔄 Loading reranking model on {device}...")
36
 
37
  # ✅ FIX: Use manual device instead of device_map="auto"
38
+ model = AutoModelForSequenceClassification.from_pretrained(
 
 
 
 
 
 
 
 
 
 
 
39
  model_path,
 
40
  torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
41
  trust_remote_code=False,
42
  attn_implementation="eager",