import tensorflow as tf from transformers import pipeline, AutoTokenizer,…
- User
import tensorflow as tf from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
Initialize the context manager once
strategy = tf.distribute.MirroredStrategy( devices=["/gpu:0"], cross_device_ops=tf.distribute.HierarchicalCopyAllReduce() )
with strategy.scope():
code#model_name = "HuggingFaceH4/zephyr-7b-beta" model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0" # Or a better model if you find one tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left") model = AutoModelForCausalLM.from_pretrained(model_name)Create the pipeline for text generation
def generate_response(messages): prompts = [tokenizer.apply_chat_template(messages + [prompt], tokenize=False, add_generation_prompt=True) for prompt in batch_prompts]
codewith strategy.scope(): input_ids = tokenizer.batch_encode_plus(prompts, return_tensors='pt', padding=True) eos_token_id = tokenizer.eos_token_id attention_mask = input_ids['input_ids'].ne(tokenizer.eos_token_id).int() with strategy.scope(): outputs = model.generate(input_ids=input_ids['input_ids'], attention_mask=attention_mask, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95) return [tokenizer.decode(output, skip_special_tokens=True) for output in outputs]Initial messages
messages = [ { "role": "system", "content": "You are an emotionally intelligent and brilliant experienced expert futures stock, forex and cryptocurrency day trader who knows his stuff and does'nt make excuses. I (the prompter) am your boss and I count on your advice to make big profits in the markets, you are handsomely rewarded and thereby love this arrangement. As my employee your job is to offer me expert opinions and predictions.", "content": "examine the crypto currency data and decide whether we should enter long position, short position or wait for better signals", }, {"role": "user", "content": ""}, ]
Main interaction loop
- Assistant
- User
complete code for amd gpus
- Assistant