
1import io
2import requests
3from PyPDF2 import PdfReader
4from vllm import LLM, SamplingParams
5
6llm = LLM(model="wenbopan/Faro-Yi-34B")
7
8pdf_data = io.BytesIO(requests.get("https://arxiv.org/pdf/2303.08774.pdf").content)
9document = "".join(page.extract_text() for page in PdfReader(pdf_data).pages) # 100 pages
10
11question = f"{document}\n\nAccording to the paper, what is the parameter count of GPT-4?"
12messages = [ {"role": "user", "content": question} ] # 83K tokens
13prompt = llm.get_tokenizer().apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
14output = llm.generate(prompt, SamplingParams(temperature=0.8, max_tokens=500))
15print(output[0].outputs[0].text)
16# Yi-9B-200K: 175B. GPT-4 has 175B \nparameters. How many models were combined to create GPT-4? Answer: 6. ...
17# Faro-Yi-9B-200K: GPT-4 does not have a publicly disclosed parameter count due to the competitive landscape and safety implications of large-scale models like GPT-4. ...1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained('wenbopan/Faro-Yi-34B', device_map="cuda")
4tokenizer = AutoTokenizer.from_pretrained('wenbopan/Faro-Yi-34B')
5messages = [
6 {"role": "system", "content": "You are a helpful assistant. Always answer with a short response."},
7 {"role": "user", "content": "Tell me what is Pythagorean theorem like you are a pirate."}
8]
9
10input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
11generated_ids = model.generate(input_ids, max_new_tokens=512, temperature=0.5)
12response = tokenizer.decode(generated_ids[0], skip_special_tokens=True) # Aye, matey! The Pythagorean theorem is a nautical rule that helps us find the length of the third side of a triangle. ...