ml-explore / ml-explore/mlx-examples
T5 tokenizer decoding error with CodeT5+
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 9k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
$ python3 convert.py --model codet5p-220m
$ python3 t5.py --model codet5p-220m --prompt 'def print_hello_world():<extra_id_0>' --max-tokens 10
[INFO] Generating with T5...
Input: def print_hello_world():<extra_id_0>
<extra_id_0>ĊĠĠĠĠprintĠ"HelloĠWorld"ĊĊ
The hf_t5.py can do correct output with changes:
diff --git a/t5/hf_t5.py b/t5/hf_t5.py
index 98c6da8..23d9644 100644
--- a/t5/hf_t5.py
+++ b/t5/hf_t5.py
@@ -23,11 +23,11 @@ def embed(t5_model: str):
def generate(t5_model: str):
- prompt = "translate English to German: As much as six inches of rain could fall in the New York City region through Monday morning, and officials warned of flooding along the coast."
+ prompt = "def print_hello_world():<extra_id_0>"
tokenizer = AutoTokenizer.from_pretrained(t5_model)
torch_model = AutoModelForSeq2SeqLM.from_pretrained(t5_model)
torch_tokens = tokenizer(prompt, return_tensors="pt", padding=True).input_ids
- outputs = torch_model.generate(torch_tokens, do_sample=False, max_length=512)
+ outputs = torch_model.generate(torch_tokens, do_sample=False, max_length=10)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
$ python3 hf_t5.py --model codet5p-220m
print "Hello World"
It seems that the tokenizer does not work well with streaming decoding.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with t5.py and hf_t5.py, reproducing the CodeT5+ commands shown in the issue after running convert.py. Compare the streaming decode output with Hugging Face's tokenizer.decode result, and consider the issue done when the CodeT5+ prompt produces the expected generated text without the extra token spacing or line-break artifacts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100