eddddyy commited on
Commit
63e33f3
·
verified ·
1 Parent(s): 8fee865

Update model_loader.py

Browse files
Files changed (1) hide show
  1. model_loader.py +8 -6
model_loader.py CHANGED
@@ -5,10 +5,10 @@ from config import HF_TOKEN, MODEL_ID
5
  def load_model():
6
  try:
7
  print(f"🔄 Loading tokenizer and model: {MODEL_ID}")
8
-
9
  tokenizer = AutoTokenizer.from_pretrained(
10
  MODEL_ID,
11
- token=HF_TOKEN or None, # Handles public and private
12
  trust_remote_code=True
13
  )
14
 
@@ -16,19 +16,21 @@ def load_model():
16
  MODEL_ID,
17
  token=HF_TOKEN or None,
18
  trust_remote_code=True,
19
- device_map="auto" if torch.cuda.is_available() else None,
20
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
21
  low_cpu_mem_usage=True
22
  )
23
 
24
- device = "cuda" if torch.cuda.is_available() else "cpu"
25
- print(f"✅ Model loaded successfully.\nDevice set to: {device}")
26
 
27
  return pipeline(
28
  "text-generation",
29
  model=model,
30
  tokenizer=tokenizer,
31
- device=0 if device == "cuda" else -1
 
 
 
32
  )
33
 
34
  except Exception as e:
 
5
  def load_model():
6
  try:
7
  print(f"🔄 Loading tokenizer and model: {MODEL_ID}")
8
+
9
  tokenizer = AutoTokenizer.from_pretrained(
10
  MODEL_ID,
11
+ token=HF_TOKEN or None,
12
  trust_remote_code=True
13
  )
14
 
 
16
  MODEL_ID,
17
  token=HF_TOKEN or None,
18
  trust_remote_code=True,
19
+ device_map="auto" if torch.cuda.is_available() else "cpu",
20
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
21
  low_cpu_mem_usage=True
22
  )
23
 
24
+ print("✅ Model loaded successfully.")
 
25
 
26
  return pipeline(
27
  "text-generation",
28
  model=model,
29
  tokenizer=tokenizer,
30
+ max_new_tokens=2048,
31
+ do_sample=True,
32
+ temperature=0.7,
33
+ top_p=0.9
34
  )
35
 
36
  except Exception as e: