importtorchfromtransformersimportAutoModelForCausalLM,AutoTokenizertokenizer=AutoTokenizer.from_pretrained("ragraph-ai/stable-cypher-instruct-3b",trust_remote_code=True)model=AutoModelForCausalLM.from_pretrained("ragraph-ai/stable-cypher-instruct-3b",torch_dtype=torch.bfloat16,trust_remote_code=True)messages=[{"role":"user","content":"Show me the people who have Python and Cloud skills and have been in the company for at least 3 years."}]prompt=tokenizer.apply_chat_template(messages,add_generation_prompt=True,tokenize=False)inputs=tokenizer([prompt],return_tensors="pt").to(model.device)tokens=model.generate(**inputs,max_new_tokens=128,do_sample=True,top_p=0.9,temperature=0.2,pad_token_id=tokenizer.eos_token_id,)outputs=tokenizer.batch_decode(tokens[:,inputs.input_ids.shape[-1]:],skip_special_tokens=False)[0]
GGUF
fromllama_cppimportLlama# Load the GGUF modelprint("Loading model...")model=Llama(model_path=r"C:\Users\John\stable-cypher-instruct-3b.Q4_K_M.gguf",n_ctx=512,n_batch=512,n_gpu_layers=-1,# Use all available GPU layersmax_tokens=128,top_p=0.9,temperature=0.2,verbose=False)# Define your questionquestion="Show me the people who have Python and Cloud skills and have been in the company for at least 3 years."# Create the full prompt (simulating the apply_chat_template function)full_prompt=f"<|im_start|>system\nCreate a Cypher statement to answer the following question:<|im_end|>\n<|im_start|>user\n{question}<|im_end|>\n<|im_start|>assistant\n"# Generate responseprint("Generating response...")response=model(full_prompt,max_tokens=128,stop=["<|im_end|>","<|im_start|>"],echo=False)# Extract and print the generated responseanswer=response['choices'][0]['text'].strip()print("\nQuestion:",question)print("\nGenerated Cypher statement:")print(answer)
I used llama.cpp to merge the LoRa and generate the quants.
The progress achieved from the base model is significant but you will still need to finetune on your company's syntax and entities.
I've been tickering with the training parameters for a few batches of training but there is room for improvements.
I'm open to the idea of making a full tutorial if there is enough interest in this project.