Skip to content

Commit

Permalink
remove assertation for models with unknown chat template (NVIDIA#10042)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandros Koumparoulis <[email protected]>
  • Loading branch information
akoumpa authored and XuesongYang committed Jan 18, 2025
1 parent ab44c65 commit b9d74eb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions scripts/checkpoint_converters/convert_mistral_7b_hf_to_nemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,19 @@ def save_to_nemo(args, checkpoint):
if getattr(tokenizer, 'chat_template', None) is not None:
import hashlib

assert (
hashlib.md5(tokenizer.chat_template.encode('utf-8')).hexdigest() == "0b629f783db54e02509999196956ff40"
), "Got unkown chat template"
from omegaconf import OmegaConf, open_dict

with open_dict(model.cfg):
model.cfg.tokenizer.chat_template = OmegaConf.create(
{
'prefix': "{_bos_}",
'roles': {'User': "[INST] {_content_} [/INST]", 'Assistant': "{_content_}{_eos_}"},
}
)
template_hash = hashlib.md5(tokenizer.chat_template.encode('utf-8')).hexdigest()
if template_hash != "0b629f783db54e02509999196956ff40":
logging.warning("Got unkown chat template")
else:
from omegaconf import OmegaConf, open_dict

with open_dict(model.cfg):
model.cfg.tokenizer.chat_template = OmegaConf.create(
{
'prefix': "{_bos_}",
'roles': {'User': "[INST] {_content_} [/INST]", 'Assistant': "{_content_}{_eos_}"},
}
)

model.save_to(args.output_path)
logging.info(f'NeMo model saved to: {args.output_path}')
Expand Down

0 comments on commit b9d74eb

Please sign in to comment.