edouardlgp commited on
Commit
f666a76
Β·
verified Β·
1 Parent(s): ab8a52c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -41,27 +41,27 @@ try:
41
  rag = RAGWithCitations(model_path_or_name=MODEL_CACHE_DIR)
42
 
43
  # Fix the warnings by properly configuring generation parameters
44
- if hasattr(rag, "model"):
45
  # Configure tokenizer
46
- if hasattr(rag, "tokenizer"):
47
- if rag.tokenizer.pad_token is None:
48
- rag.tokenizer.pad_token = rag.tokenizer.eos_token
49
- rag.tokenizer.padding_side = "left" # For batch generation
50
 
51
  # Configure model generation settings
52
- rag.model.config.pad_token_id = rag.tokenizer.pad_token_id
53
- rag.model.generation_config.pad_token_id = rag.tokenizer.pad_token_id
54
 
55
  # Fix the do_sample/top_p warning
56
- rag.model.generation_config.do_sample = True
57
- rag.model.generation_config.top_p = 0.95 # Explicitly set to match warning
58
 
59
  # Configure attention mask handling
60
- rag.model.config.use_cache = True
61
 
62
- log_debug("βœ… Model loaded successfully with configuration:")
63
- log_debug(f" - Pad token: {rag.tokenizer.pad_token} (ID: {rag.tokenizer.pad_token_id})")
64
- log_debug(f" - Generation config: {rag.model.generation_config}")
65
 
66
  except Exception as e:
67
  log_debug(f"❌ Model initialization failed: {str(e)}")
@@ -89,7 +89,13 @@ log_debug("πŸ“„ Test Sources loaded successfully.")
89
  # Generate a response
90
  try:
91
  log_debug("🧠 Test rag model on simple example...")
92
- response = rag.generate(query, sources)
 
 
 
 
 
 
93
  log_debug("βœ… Test Answer generated successfully.")
94
  log_debug(response["processed"]["clean_answer"])
95
  except Exception as e:
 
41
  rag = RAGWithCitations(model_path_or_name=MODEL_CACHE_DIR)
42
 
43
  # Fix the warnings by properly configuring generation parameters
44
+ # if hasattr(rag, "model"):
45
  # Configure tokenizer
46
+ # if hasattr(rag, "tokenizer"):
47
+ # if rag.tokenizer.pad_token is None:
48
+ # rag.tokenizer.pad_token = rag.tokenizer.eos_token
49
+ # rag.tokenizer.padding_side = "left" # For batch generation
50
 
51
  # Configure model generation settings
52
+ # rag.model.config.pad_token_id = rag.tokenizer.pad_token_id
53
+ # rag.model.generation_config.pad_token_id = rag.tokenizer.pad_token_id
54
 
55
  # Fix the do_sample/top_p warning
56
+ # rag.model.generation_config.do_sample = True
57
+ # rag.model.generation_config.top_p = 0.95 # Explicitly set to match warning
58
 
59
  # Configure attention mask handling
60
+ # rag.model.config.use_cache = True
61
 
62
+ # log_debug("βœ… Model loaded successfully with configuration:")
63
+ # log_debug(f" - Pad token: {rag.tokenizer.pad_token} (ID: {rag.tokenizer.pad_token_id})")
64
+ # log_debug(f" - Generation config: {rag.model.generation_config}")
65
 
66
  except Exception as e:
67
  log_debug(f"❌ Model initialization failed: {str(e)}")
 
89
  # Generate a response
90
  try:
91
  log_debug("🧠 Test rag model on simple example...")
92
+ response = rag.generate(query,
93
+ sources,
94
+ do_sample=True, # Enable sampling
95
+ top_p=0.95, # Set top_p for nucleus sampling
96
+ pad_token_id=rag.tokenizer.eos_token_id, # Set pad_token_id to eos_token_id
97
+ attention_mask=None # Ensure attention_mask is passed if needed
98
+ )
99
  log_debug("βœ… Test Answer generated successfully.")
100
  log_debug(response["processed"]["clean_answer"])
101
  except Exception as e: