This llama model was trained 2x faster with
Unsloth and Huggingface's TRL library.
Install dependencies. Check
Unsloth documentation for specific installation for other environments.
1%%capture
2# Installs Unsloth, Xformers (Flash Attention) and all other packages!
3!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
4!pip install --no-deps "xformers<0.0.26" trl peft accelerate bitsandbytes
1from unsloth.chat_templates import get_chat_template
2
3tokenizer = get_chat_template(
4 tokenizer,
5 chat_template = "llama-3",
6 map_eos_token = True,
7)
8
9FastLanguageModel.for_inference(model) # Enable native 2x faster inference
10
11schema = """Node properties: - **Question** - `favorites`: INTEGER Example: "0" - `answered`: BOOLEAN - `text`: STRING Example: "### This is: Bug ### Specifications OS: Win10" - `link`: STRING Example: "https://stackoverflow.com/questions/62224586/playg" - `createdAt`: DATE_TIME Min: 2020-06-05T16:57:19Z, Max: 2020-06-05T21:49:16Z - `title`: STRING Example: "Playground is not loading with apollo-server-lambd" - `id`: INTEGER Min: 62220505, Max: 62224586 - `upVotes`: INTEGER Example: "0" - `score`: INTEGER Example: "-1" - `downVotes`: INTEGER Example: "1" - **Tag** - `name`: STRING Example: "aws-lambda" - **User** - `image`: STRING Example: "https://lh3.googleusercontent.com/-NcFYSuXU0nk/AAA" - `link`: STRING Example: "https://stackoverflow.com/users/10251021/alexandre" - `id`: INTEGER Min: 751, Max: 13681006 - `reputation`: INTEGER Min: 1, Max: 420137 - `display_name`: STRING Example: "Alexandre Le" Relationship properties: The relationships: (:Question)-[:TAGGED]->(:Tag) (:User)-[:ASKED]->(:Question)"""
12question = "Identify the top 5 questions with the most downVotes."
13
14messages = [
15 {"role": "system", "content": "Given an input question, convert it to a Cypher query. No pre-amble."},
16 {"role": "user", "content": f"""Based on the Neo4j graph schema below, write a Cypher query that would answer the user's question:
17{schema}
18
19Question: {question}
20Cypher query:"""}
21]
22inputs = tokenizer.apply_chat_template(
23 messages,
24 tokenize = True,
25 add_generation_prompt = True, # Must add for generation
26 return_tensors = "pt",
27).to("cuda")
28
29outputs = model.generate(input_ids = inputs, max_new_tokens = 128, use_cache = True)
30tokenizer.batch_decode(outputs)