Nada commited on
Commit
872c7e8
·
1 Parent(s): cddf446
Files changed (1) hide show
  1. chatbot.py +25 -12
chatbot.py CHANGED
@@ -46,9 +46,7 @@ warnings.filterwarnings('ignore', category=UserWarning)
46
  os.environ.update({
47
  'TRANSFORMERS_VERBOSITY': 'error',
48
  'TOKENIZERS_PARALLELISM': 'false',
49
- 'BITSANDBYTES_NOWELCOME': '1',
50
- 'TRANSFORMERS_CACHE': '/tmp/huggingface', # Set cache directory to /tmp
51
- 'HF_HOME': '/tmp/huggingface' # Set Hugging Face home directory to /tmp
52
  })
53
 
54
  # Define base directory and paths
@@ -290,16 +288,20 @@ Response:"""
290
  "text-classification",
291
  model="SamLowe/roberta-base-go_emotions",
292
  top_k=None,
293
- device_map="auto" if self.device == "cuda" else None
 
 
294
  )
295
  except Exception as e:
296
  logger.error(f"Error loading emotion model: {e}")
297
- # Fallback
298
  return pipeline(
299
  "text-classification",
300
  model="j-hartmann/emotion-english-distilroberta-base",
301
  return_all_scores=True,
302
- device_map="auto" if self.device == "cuda" else None
 
 
303
  )
304
 
305
  def _initialize_llm(self, model_name: str, use_4bit: bool):
@@ -315,23 +317,34 @@ Response:"""
315
  else:
316
  quantization_config = None
317
 
318
- # Load base model
319
  logger.info(f"Loading base model: {model_name}")
320
  base_model = AutoModelForCausalLM.from_pretrained(
321
  model_name,
322
  quantization_config=quantization_config,
323
  device_map="auto" if self.device == "cuda" else None,
324
- trust_remote_code=True
 
 
325
  )
326
 
327
- # Load tokenizer
328
  logger.info("Loading tokenizer")
329
- tokenizer = AutoTokenizer.from_pretrained(model_name)
 
 
 
 
330
  tokenizer.pad_token = tokenizer.eos_token
331
 
332
- # Load PEFT model from Hugging Face
333
  logger.info(f"Loading PEFT model from {self.peft_model_path}")
334
- model = PeftModel.from_pretrained(base_model, self.peft_model_path)
 
 
 
 
 
335
  logger.info("Successfully loaded PEFT model")
336
 
337
  # Create text generation pipeline
 
46
  os.environ.update({
47
  'TRANSFORMERS_VERBOSITY': 'error',
48
  'TOKENIZERS_PARALLELISM': 'false',
49
+ 'BITSANDBYTES_NOWELCOME': '1'
 
 
50
  })
51
 
52
  # Define base directory and paths
 
288
  "text-classification",
289
  model="SamLowe/roberta-base-go_emotions",
290
  top_k=None,
291
+ device_map="auto" if self.device == "cuda" else None,
292
+ local_files_only=False, # Force download from Hugging Face Hub
293
+ use_auth_token=False # No authentication needed for public models
294
  )
295
  except Exception as e:
296
  logger.error(f"Error loading emotion model: {e}")
297
+ # Fallback to a simpler model
298
  return pipeline(
299
  "text-classification",
300
  model="j-hartmann/emotion-english-distilroberta-base",
301
  return_all_scores=True,
302
+ device_map="auto" if self.device == "cuda" else None,
303
+ local_files_only=False,
304
+ use_auth_token=False
305
  )
306
 
307
  def _initialize_llm(self, model_name: str, use_4bit: bool):
 
317
  else:
318
  quantization_config = None
319
 
320
+ # Load base model directly from Hugging Face Hub
321
  logger.info(f"Loading base model: {model_name}")
322
  base_model = AutoModelForCausalLM.from_pretrained(
323
  model_name,
324
  quantization_config=quantization_config,
325
  device_map="auto" if self.device == "cuda" else None,
326
+ trust_remote_code=True,
327
+ local_files_only=False,
328
+ use_auth_token=False
329
  )
330
 
331
+ # Load tokenizer directly from Hugging Face Hub
332
  logger.info("Loading tokenizer")
333
+ tokenizer = AutoTokenizer.from_pretrained(
334
+ model_name,
335
+ local_files_only=False,
336
+ use_auth_token=False
337
+ )
338
  tokenizer.pad_token = tokenizer.eos_token
339
 
340
+ # Load PEFT model directly from Hugging Face Hub
341
  logger.info(f"Loading PEFT model from {self.peft_model_path}")
342
+ model = PeftModel.from_pretrained(
343
+ base_model,
344
+ self.peft_model_path,
345
+ local_files_only=False,
346
+ use_auth_token=False
347
+ )
348
  logger.info("Successfully loaded PEFT model")
349
 
350
  # Create text generation pipeline