Fixed timing
Browse files
app.py
CHANGED
|
@@ -105,7 +105,8 @@ def diffusion_chat(question, noising, max_it, pause_length):
|
|
| 105 |
)
|
| 106 |
yield render_html("Iteration 0 (initial noise)",
|
| 107 |
highlight_tokens(current_tokens[answer_start:], answer_start, just_noised_indices, color="red"))
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
last_tokens = []
|
| 111 |
prev_decoded = []
|
|
@@ -113,9 +114,10 @@ def diffusion_chat(question, noising, max_it, pause_length):
|
|
| 113 |
unmasked_mask = [False] * len(current_tokens)
|
| 114 |
|
| 115 |
for i in range(max_it):
|
| 116 |
-
|
| 117 |
generated_tokens, confidences = generate_diffusion_text(current_tokens, top_p, top_k)
|
| 118 |
current_tokens = ori_input_tokens[:answer_start] + generated_tokens[answer_start:]
|
|
|
|
| 119 |
|
| 120 |
# GREEN highlighting: compare to previous tokens
|
| 121 |
new_decoded = tokenizer.convert_ids_to_tokens(current_tokens[answer_start:])
|
|
@@ -125,6 +127,8 @@ def diffusion_chat(question, noising, max_it, pause_length):
|
|
| 125 |
}
|
| 126 |
prev_decoded = new_decoded
|
| 127 |
|
|
|
|
|
|
|
| 128 |
yield render_html(f"Iteration {i+1}/{max_it} (after generation)",
|
| 129 |
highlight_tokens(current_tokens[answer_start:], answer_start, diff_indices, color="green"))
|
| 130 |
time.sleep(pause_length)
|
|
@@ -154,6 +158,7 @@ def diffusion_chat(question, noising, max_it, pause_length):
|
|
| 154 |
|
| 155 |
yield render_html(f"Iteration {i+1}/{max_it} (before noising)",
|
| 156 |
highlight_tokens(current_tokens[answer_start:], answer_start, just_noised_indices, color="red"))
|
|
|
|
| 157 |
|
| 158 |
current_tokens = ori_input_tokens[:answer_start] + noised_answer[answer_start:]
|
| 159 |
|
|
|
|
| 105 |
)
|
| 106 |
yield render_html("Iteration 0 (initial noise)",
|
| 107 |
highlight_tokens(current_tokens[answer_start:], answer_start, just_noised_indices, color="red"))
|
| 108 |
+
|
| 109 |
+
start = time.perf_counter()
|
| 110 |
|
| 111 |
last_tokens = []
|
| 112 |
prev_decoded = []
|
|
|
|
| 114 |
unmasked_mask = [False] * len(current_tokens)
|
| 115 |
|
| 116 |
for i in range(max_it):
|
| 117 |
+
|
| 118 |
generated_tokens, confidences = generate_diffusion_text(current_tokens, top_p, top_k)
|
| 119 |
current_tokens = ori_input_tokens[:answer_start] + generated_tokens[answer_start:]
|
| 120 |
+
|
| 121 |
|
| 122 |
# GREEN highlighting: compare to previous tokens
|
| 123 |
new_decoded = tokenizer.convert_ids_to_tokens(current_tokens[answer_start:])
|
|
|
|
| 127 |
}
|
| 128 |
prev_decoded = new_decoded
|
| 129 |
|
| 130 |
+
time.sleep(max(pause_length - (time.perf_counter() - start), 0))
|
| 131 |
+
|
| 132 |
yield render_html(f"Iteration {i+1}/{max_it} (after generation)",
|
| 133 |
highlight_tokens(current_tokens[answer_start:], answer_start, diff_indices, color="green"))
|
| 134 |
time.sleep(pause_length)
|
|
|
|
| 158 |
|
| 159 |
yield render_html(f"Iteration {i+1}/{max_it} (before noising)",
|
| 160 |
highlight_tokens(current_tokens[answer_start:], answer_start, just_noised_indices, color="red"))
|
| 161 |
+
start = time.perf_counter()
|
| 162 |
|
| 163 |
current_tokens = ori_input_tokens[:answer_start] + noised_answer[answer_start:]
|
| 164 |
|