@@ -633,15 +633,26 @@ public sealed class Vocabulary
633
633
internal unsafe LLamaVocabNative * VocabNative => llama_model_get_vocab ( _model ) ;
634
634
635
635
/// <summary>
636
- /// Cache of all the tokens in the vocabulary, and their string representation
636
+ /// Map of each token in this vocabulary to its string representation
637
637
/// </summary>
638
638
public readonly IReadOnlyDictionary < LLamaToken , string > TokenToString ;
639
639
640
+ /// <summary>
641
+ /// Contains unique tokens that are supposed to end the generation (e.g.: EOS, EOT, etc)
642
+ /// </summary>
643
+ public readonly HashSet < LLamaToken > EOGTokens ;
644
+
645
+ /// <summary>
646
+ /// Contains unique tokens that exist for inference control rather than text output
647
+ /// </summary>
648
+ public readonly HashSet < LLamaToken > ControlTokens ;
649
+
640
650
internal Vocabulary ( SafeLlamaModelHandle model )
641
651
{
642
652
_model = model ;
643
653
TokenToString = GetVocabCache ( ) ;
644
654
655
+ // Cache the various properties that llama.cpp API exposes about the vocab
645
656
unsafe
646
657
{
647
658
var vocabNative = llama_model_get_vocab ( _model ) ;
@@ -662,6 +673,9 @@ internal Vocabulary(SafeLlamaModelHandle model)
662
673
DecoderStartToken = Normalize ( llama_model_decoder_start_token ( _model ) ) ;
663
674
ShouldAddBOS = LLamaVocabNative . llama_vocab_get_add_bos ( vocabNative ) ;
664
675
ShouldAddEOS = LLamaVocabNative . llama_vocab_get_add_eos ( vocabNative ) ;
676
+
677
+ EOGTokens = new HashSet < LLamaToken > ( TokenToString . Keys . Where ( token => LLamaVocabNative . llama_vocab_is_eog ( vocabNative , token ) ) ) ;
678
+ ControlTokens = new HashSet < LLamaToken > ( TokenToString . Keys . Where ( token => LLamaVocabNative . llama_vocab_is_control ( vocabNative , token ) ) ) ;
665
679
}
666
680
}
667
681
0 commit comments