Downloads · 30 days
7
1% of all-time downloads
benchang1110/Taiwan-tinyllama-v1.0-chat
Taiwan-tinyllama-v1.0-chat is a text generation model from benchang1110. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
This model is the instruction finetuning version of benchang1110/Taiwan-tinyllama-v1.0-base.
Downloads · 30 days
7
1% of all-time downloads
All-time downloads
1.1K
Public
Parameters
1.1B
4.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors2.2 GB · 100%
From the Hugging Face model README
This model is the instruction finetuning version of benchang1110/Taiwan-tinyllama-v1.0-base.
import torch, transformers
def generate_response():
model = transformers.AutoModelForCausalLM.from_pretrained("benchang1110/Taiwan-tinyllama-v1.0-chat", torch_dtype=torch.bfloat16, device_map=device,attn_implementation="flash_attention_2")
tokenizer = transformers.AutoTokenizer.from_pretrained("benchang1110/Taiwan-tinyllama-v1.0-chat")
streamer = transformers.TextStreamer(tokenizer,skip_prompt=True)
while(1):
prompt = input('USER:')
if prompt == "exit":
break
print("Assistant: ")
message = [
{'content': prompt, 'role': 'user'},
]
untokenized_chat = tokenizer.apply_chat_template(message,tokenize=False,add_generation_prompt=False)
inputs = tokenizer.encode_plus(untokenized_chat, add_special_tokens=True, return_tensors="pt",return_attention_mask=True).to(device)
outputs = model.generate(inputs["input_ids"],attention_mask=inputs['attention_mask'],streamer=streamer,use_cache=True,max_new_tokens=512,do_sample=True,temperature=0.1,repetition_penalty=1.2)
if __name__ == '__main__':
device = 'cuda' if torch.cuda.is_available() else 'cpu'
generate_response()