alexkueck commited on
Commit
43c5b06
1 Parent(s): dd9fcd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -42,10 +42,14 @@ def predict(text,
42
  else:
43
  prompt,inputs=inputs
44
  begin_length = len(prompt)
 
45
  input_ids = inputs["input_ids"][:,-max_context_length_tokens:].to(device)
46
  torch.cuda.empty_cache()
47
 
 
 
48
  with torch.no_grad():
 
49
  for x in greedy_search(input_ids,model,tokenizer,stop_words=["[|Human|]", "[|AI|]"],max_length=max_length_tokens,temperature=temperature,top_p=top_p):
50
  if is_stop_word_or_prefix(x,["[|Human|]", "[|AI|]"]) is False:
51
  if "[|Human|]" in x:
@@ -65,9 +69,7 @@ def predict(text,
65
  del input_ids
66
  gc.collect()
67
  torch.cuda.empty_cache()
68
- #print(text)
69
- #print(x)
70
- #print("="*80)
71
  try:
72
  yield a,b,"Generate: Success"
73
  except:
@@ -75,8 +77,8 @@ def predict(text,
75
 
76
 
77
  def reset_chat():
78
- id_new = chatbot.new_conversation()
79
- chatbot.change_conversation(id_new)
80
  reset_textbox()
81
 
82
 
 
42
  else:
43
  prompt,inputs=inputs
44
  begin_length = len(prompt)
45
+
46
  input_ids = inputs["input_ids"][:,-max_context_length_tokens:].to(device)
47
  torch.cuda.empty_cache()
48
 
49
+ #torch.no_grad() bedeutet, dass für die betreffenden tensoren keine Ableitungen berechnet werden bei der backpropagation
50
+ #hier soll das NN ja auch nicht geändert werden 8backprop ist nicht nötig), da es um interference-prompts geht!
51
  with torch.no_grad():
52
+ #die vergangenen prompts werden alle als Tupel in history abgelegt sortiert nach 'Human' und 'AI'- dass sind daher auch die stop-words, die den jeweils nächsten Eintrag kennzeichnen
53
  for x in greedy_search(input_ids,model,tokenizer,stop_words=["[|Human|]", "[|AI|]"],max_length=max_length_tokens,temperature=temperature,top_p=top_p):
54
  if is_stop_word_or_prefix(x,["[|Human|]", "[|AI|]"]) is False:
55
  if "[|Human|]" in x:
 
69
  del input_ids
70
  gc.collect()
71
  torch.cuda.empty_cache()
72
+
 
 
73
  try:
74
  yield a,b,"Generate: Success"
75
  except:
 
77
 
78
 
79
  def reset_chat():
80
+ #id_new = chatbot.new_conversation()
81
+ #chatbot.change_conversation(id_new)
82
  reset_textbox()
83
 
84