Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable special token support for exllamav2 #4314

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/exllamav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def from_pretrained(self, path_to_model):
return result, result

def encode(self, string, **kwargs):
return self.tokenizer.encode(string, add_bos=True)
return self.tokenizer.encode(string, add_bos=True, encode_special_tokens=True)

def decode(self, ids, **kwargs):
if isinstance(ids, list):
ids = torch.tensor([ids])
elif isinstance(ids, torch.Tensor) and ids.numel() == 1:
ids = ids.view(1, -1)

return self.tokenizer.decode(ids)[0]
return self.tokenizer.decode(ids, decode_special_tokens=True)[0]

def get_logits(self, token_ids, **kwargs):
self.cache.current_seq_len = 0
Expand All @@ -97,7 +97,7 @@ def generate_with_streaming(self, prompt, state):
if len(to_ban) > 0:
settings.disallow_tokens(self.tokenizer, to_ban)

ids = self.tokenizer.encode(prompt, add_bos=state['add_bos_token'])
ids = self.tokenizer.encode(prompt, add_bos=state['add_bos_token'], encode_special_tokens=True)
ids = ids[:, -get_max_prompt_length(state):]
initial_len = ids.shape[-1]

Expand All @@ -119,7 +119,7 @@ def generate_with_streaming(self, prompt, state):
if i == 0 and self.tokenizer.tokenizer.IdToPiece(int(token)).startswith('▁'):
has_leading_space = True

decoded_text = self.tokenizer.decode(ids[:, initial_len:])[0]
decoded_text = self.tokenizer.decode(ids[:, initial_len:], decode_special_tokens=not state['skip_special_tokens'])[0]
if has_leading_space:
decoded_text = ' ' + decoded_text

Expand Down
1 change: 1 addition & 0 deletions modules/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
'ban_eos_token',
'add_bos_token',
'custom_token_bans',
'skip_special_tokens',
'auto_max_new_tokens',
},
'ExLlamav2_HF': {
Expand Down