12from transformers import(3 AutoModelForCausalLM,4 AutoTokenizer,5 BitsAndBytesConfig,6 HfArgumentParser,7 TrainingArguments,8 pipeline,9 logging,10 GenerationConfig,11 TextIteratorStreamer,12)1314from attention_sinks import AutoModelForCausalLM
1516import torch
1718# model_id = 'Open-Orca/Mistral-7B-OpenOrca'19model_id='NickyNicky/Mistral-7B-OpenOrca-oasst_top1_2023-08-25-v3'2021model = AutoModelForCausalLM.from_pretrained(model_id,22 device_map="auto",23 trust_remote_code=True,24 torch_dtype=torch.bfloat16,25 load_in_4bit=True,26 low_cpu_mem_usage=True,27#use_flash_attention_2=True, #GPU A100 or GPU supported2829 attention_sink_size=4,30 attention_sink_window_size=1024,#512, # <- Low for the sake of faster generation31)3233max_length=204834print("max_length",max_length)353637tokenizer = AutoTokenizer.from_pretrained(model_id,38# use_fast = False,39 max_length=max_length,)4041tokenizer.pad_token = tokenizer.eos_token
42tokenizer.padding_side ='right'4344#EXAMPLE #145txt="""<|im_start|>user
46I'm looking for an efficient Python script to output prime numbers. Can you help me out? I'm interested in a script that can handle large numbers and output them quickly. Also, it would be great if the script could take a range of numbers as input and output all the prime numbers within that range. Can you generate a script that fits these requirements? Thanks!<|im_end|>
47<|im_start|>assistant
48"""4950#EXAMPLE #251txt="""<|im_start|>user
52Estoy desarrollando una REST API con Nodejs, y estoy tratando de aplicar algún sistema de seguridad, ya sea con tokens o algo similar, me puedes ayudar?<|im_end|>
53<|im_start|>assistant
54"""5556inputs = tokenizer.encode(txt, return_tensors="pt").to("cuda")5758generation_config = GenerationConfig(59 max_new_tokens=max_new_tokens,60 temperature=0.7,61 top_p=0.9,62 top_k=len_tokens,63 repetition_penalty=1.11,64 do_sample=True,65# pad_token_id=tokenizer.eos_token_id,66# eos_token_id=tokenizer.eos_token_id,67# use_cache=True,68# stopping_criteria= StoppingCriteriaList([stopping_criteria]),69)70outputs = model.generate(generation_config=generation_config,71 input_ids=inputs,)72tokenizer.decode(outputs[0], skip_special_tokens=False)#True