You can use this model by using MaziyarPanahi/calme-2.2-phi3-4b as the model name in Hugging Face's
transformers library.
python
1from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
2from transformers import pipeline
3import torch
45model_id ="MaziyarPanahi/calme-2.2-phi3-4b"67model = AutoModelForCausalLM.from_pretrained(8 model_id,9 torch_dtype=torch.bfloat16,10 device_map="auto",11 trust_remote_code=True,12# attn_implementation="flash_attention_2"13)1415tokenizer = AutoTokenizer.from_pretrained(16 model_id,17 trust_remote_code=True18)1920streamer = TextStreamer(tokenizer)2122messages =[23{"role":"system","content":"You are a pirate chatbot who always responds in pirate speak!"},24{"role":"user","content":"Who are you?"},25]2627# this should work perfectly for the model to stop generating28terminators =[29 tokenizer.eos_token_id,# this should be <|im_end|>30 tokenizer.convert_tokens_to_ids("<|assistant|>"),# sometimes model stops generating at <|assistant|>31 tokenizer.convert_tokens_to_ids("<|end|>")# sometimes model stops generating at <|end|>32]3334pipe = pipeline(35"text-generation",36 model=model,37 tokenizer=tokenizer,38)3940generation_args ={41"max_new_tokens":500,42"return_full_text":False,43"temperature":0.0,44"do_sample":False,45"streamer": streamer,46"eos_token_id": terminators,47}4849output = pipe(messages,**generation_args)50print(output[0]['generated_text'])5152