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():
#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]
with 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
batch_prompts = [] while True: with strategy.scope(): while True: # Inner loop for collecting a batch new_prompt = input("Enter your new prompt (or type 'go' to process): ") if new_prompt.lower() == 'go': break # Exit the inner batch collection loop
batch_prompts.append({"role": "user", "content": new_prompt}) # Process the batch responses = generate_response(messages) for response in responses: print("Trader Response:", response) batch_prompts = [] # Clear the batch_prompts for the next set of questions i need to make this work for directml tensorflow plugin - Assistant
- User
why you did not keep exact format
- Assistant
- User
you did not use TinyLlama/TinyLlama-1.1B-Chat-v1.0
- Assistant
- User
Traceback (most recent call last): File "C:\Users\Administrator\Desktop\TRADER\tensor-test.py", line 11, in model = TFAutoModelForCausalLM.from_pretrained(model_name) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python3105\lib\site-packages\transformers\models\auto\auto_factory.py", line 569, in from_pretrained raise ValueError( ValueError: Unrecognized configuration class <class 'transformers.models.llama.configuration_llama.LlamaConfig'> for this kind of AutoModel: TFAutoModelForCausalLM. Model type should be one of BertConfig, CamembertConfig, CTRLConfig, GPT2Config, GPT2Config, GPTJConfig, OpenAIGPTConfig, OPTConfig, RemBertConfig, RobertaConfig, RobertaPreLayerNormConfig, RoFormerConfig, TransfoXLConfig, XGLMConfig, XLMConfig, XLMRobertaConfig, XLNetConfig.
- Assistant
- User
example wih pytorch for amd gpus
- Assistant