Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/axolotl/contribs/lgpl/unsloth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@

@torch.inference_mode()
def fix_untrained_tokens( # pylint: disable=too-many-return-statements
model, tokenizer, train_dataset, ignored_tokenizer_names=None, eps=1e-16
model, tokenizer, train_dataset, ignored_tokenizer_names=None, eps=1e-16, token_ids_to_fix=None,
):
"""
Llama-3 for eg has untrained vectors in the base model.
These include <|eot_id|>, <|start_header_id|>, <|end_header_id|>
We reset them to the mean of the rest of the tokens
"""
# Code licensed under LGPL
if not token_ids_to_fix:
token_ids_to_fix = []
embedding_matrix = model.get_input_embeddings().weight
lm_head_matrix = model.get_output_embeddings().weight
chat_template = getattr(tokenizer, "chat_template", None)
Expand Down Expand Up @@ -91,6 +93,7 @@ def fix_untrained_tokens( # pylint: disable=too-many-return-statements

# Get set and actual tokens
where_untrained = where_untrained.tolist()
where_untrained = list(set(token_ids_to_fix + where_untrained))
if len(where_untrained) == 0:
return

Expand Down