halbihn commited on
Commit
baf3ab7
1 Parent(s): 6728502

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +49 -0
README.md CHANGED
@@ -95,6 +95,55 @@ sequences = pipeline(
95
  max_length=200,
96
  )
97
  print(sequences[0]['generated_text'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  ```
99
 
100
  ## Training hyperparameters
 
95
  max_length=200,
96
  )
97
  print(sequences[0]['generated_text'])
98
+
99
+
100
+ # streaming example
101
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
102
+ import torch
103
+
104
+ model_id = "halbihn/NeuralHermes-2.5-Mistral-7B"
105
+
106
+ model = AutoModelForCausalLM.from_pretrained(model_id)
107
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
108
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
109
+ model.to(device)
110
+
111
+ def stream(
112
+ user_prompt: str,
113
+ max_tokens: int = 200,
114
+ ) -> None:
115
+ """Text streaming example
116
+ """
117
+
118
+ system_prompt = 'Below is a conversation between Human and AI assistant named Mistral\n'
119
+
120
+ message = [
121
+ {"role": "system", "content": system_prompt},
122
+ {"role": "user", "content": user_prompt}
123
+ ]
124
+ prompt = tokenizer.apply_chat_template(
125
+ message,
126
+ add_generation_prompt=True,
127
+ tokenize=False,
128
+ )
129
+
130
+ inputs = tokenizer([prompt], return_tensors="pt").to(device)
131
+
132
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
133
+
134
+ _ = model.generate(**inputs, streamer=streamer, max_new_tokens=max_tokens)
135
+
136
+ stream("Tell me about the future")
137
+
138
+ >>> The future is a vast and uncertain expanse, shaped by the collective actions and innovations of humanity. It is a blend of possibilities, technological advancements, and societal changes. Some potential aspects of the future include:
139
+ >>>
140
+ >>> 1. Technological advancements: Artificial intelligence, quantum computing, and biotechnology are expected to continue evolving, leading to breakthroughs in fields like medicine, energy, and communication.
141
+ >>>
142
+ >>> 2. Space exploration: As technology progresses, space travel may become more accessible, enabling humans to establish colonies on other planets and explore the cosmos further.
143
+ >>>
144
+ >>> 3. Climate change mitigation: The future will likely see increased efforts to combat climate change through renewable energy sources, carbon capture technologies, and sustainable practices.
145
+ >>>
146
+ >>> 4. Artificial intelligence integration: AI will likely become more integrated into daily life, assisting with tasks, automating jobs, and even influencing decision-making processes in various industries.
147
  ```
148
 
149
  ## Training hyperparameters