Fix: decode with skip_special_tokens=False to preserve <think> tags for stripping
Browse files- training/rollout.py +8 -2
training/rollout.py
CHANGED
|
@@ -121,8 +121,14 @@ def rollout_episode(
|
|
| 121 |
pad_token_id=tokenizer.pad_token_id or tokenizer.eos_token_id,
|
| 122 |
)
|
| 123 |
completion_ids = gen[0, prompt_ids.shape[0]:]
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
del gen
|
| 127 |
if torch.cuda.is_available():
|
| 128 |
torch.cuda.empty_cache()
|
|
|
|
| 121 |
pad_token_id=tokenizer.pad_token_id or tokenizer.eos_token_id,
|
| 122 |
)
|
| 123 |
completion_ids = gen[0, prompt_ids.shape[0]:]
|
| 124 |
+
# Decode WITHOUT skipping special tokens so <think>...</think> tags
|
| 125 |
+
# are preserved for our regex. Then strip think blocks, then remove
|
| 126 |
+
# remaining special tokens (EOS, chat markers, etc.).
|
| 127 |
+
raw_text = tokenizer.decode(completion_ids, skip_special_tokens=False)
|
| 128 |
+
cleaned = strip_think_blocks(raw_text)
|
| 129 |
+
for tok in tokenizer.all_special_tokens:
|
| 130 |
+
cleaned = cleaned.replace(tok, "")
|
| 131 |
+
completion_text = cleaned.strip()
|
| 132 |
del gen
|
| 133 |
if torch.cuda.is_available():
|
| 134 |
torch.cuda.empty_cache()
|