Commit bbede19
committed
feat(llama): enhance chat template initialization with full special tokens
Update Llama.__init__ to register additional tokenizer special tokens
and improve stop token handling for chat templates.
- Expose extra special tokens (EOT, SEP, NL, PAD, MASK) via
`special_tokens_map` to Jinja2ChatFormatter.
- Keep BOS and EOS tokens as explicit parameters, no longer redundantly
put them in `special_tokens_map`.
- Build `stop_token_ids` once, including EOS and EOT tokens, skipping
invalid (-1) ids.
- Update try-block comment: now `{% generation %}` blocks are supported,
guard only against malformed or model-specific templates.
- This ensures better compatibility with HuggingFace-style chat templates
while maintaining llama-cpp-python prompt-rendering behavior.
Signed-off-by: JamePeng <jame_peng@sina.com>1 parent a7db23a commit bbede19
1 file changed
Lines changed: 35 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
692 | 692 | | |
693 | 693 | | |
694 | 694 | | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | 695 | | |
699 | 696 | | |
700 | 697 | | |
| |||
720 | 717 | | |
721 | 718 | | |
722 | 719 | | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
723 | 743 | | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
730 | 752 | | |
731 | 753 | | |
732 | 754 | | |
| |||
750 | 772 | | |
751 | 773 | | |
752 | 774 | | |
753 | | - | |
754 | | - | |
755 | | - | |
| 775 | + | |
| 776 | + | |
756 | 777 | | |
757 | 778 | | |
758 | 779 | | |
759 | 780 | | |
760 | | - | |
| 781 | + | |
| 782 | + | |
761 | 783 | | |
762 | 784 | | |
763 | 785 | | |
| |||
0 commit comments