Views
No views yet
StableLM-Tuned-Alpha compressed for the sake of speed and memory usage. No other changes were made. Original model: https://huggingface.co/stabilityai/stablelm-tuned-alpha-3bStableLM-Tuned-Alpha 16-bit by using the following code snippet:1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, StoppingCriteria, StoppingCriteriaList
3tokenizer = AutoTokenizer.from_pretrained("vvsotnikov/stablelm-tuned-alpha-3b-16bit")
4model = AutoModelForCausalLM.from_pretrained("vvsotnikov/stablelm-tuned-alpha-3b-16bit", torch_dtype=torch.float16)
5model.cuda()
6class StopOnTokens(StoppingCriteria):
7 def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
8 stop_ids = [50278, 50279, 50277, 1, 0]
9 for stop_id in stop_ids:
10 if input_ids[0][-1] == stop_id:
11 return True
12 return False
13system_prompt = """<|SYSTEM|># StableLM Tuned (Alpha version)
14- StableLM is a helpful and harmless open-source AI language model developed by StabilityAI.
15- StableLM is excited to be able to help the user, but will refuse to do anything that could be considered harmful to the user.
16- StableLM is more than just an information source, StableLM is also able to write poetry, short stories, and make jokes.
17- StableLM will refuse to participate in anything that could harm a human.
18"""
19prompt = f"{system_prompt}<|USER|>What's your mood today?<|ASSISTANT|>"
20inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
21tokens = model.generate(
22 **inputs,
23 max_new_tokens=64,
24 temperature=0.7,
25 do_sample=True,
26 stopping_criteria=StoppingCriteriaList([StopOnTokens()])
27)
28print(tokenizer.decode(tokens[0], skip_special_tokens=True))