In this article, I will introduce a way to run Llama2 13B chat model on Google Colab
What is Llama2?
The next generation of Meta’s open-source large language model.
Llama 2 - Meta AI
Llama 2 - The next generation of our open source large language model, available for free for research and commercial…
Step1 Download model
In this article, we will try to run a quantized 13B model.
Open a new notebook on Google Colab
# If you want to try a 7B model
# !wget https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q5_K_M.bin
Step2 Import Python package
In this article, we will use llama-cpp-python to use the quantized model.
GitHub - abetlen/llama-cpp-python: Python bindings for llama.cpp
Python bindings for llama.cpp. Contribute to abetlen/llama-cpp-python development by creating an account on GitHub.
!CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip install llama-cpp-python
# if you want to try to run a model without GPU
# pip install llama-cpp-python
Step3 Load model
If you use only cpu, you won’t need
from llama_cpp import Llama
llm =Llama(model_path="/content/llama-2-13b-chat.ggmlv3.q5_K_M.bin", n_gpu_layers=32)
Step4 Set prompt
TheBloke/Llama-2-13B-chat-GGML · Hugging Face
We're on a journey to advance and democratize artificial intelligence through open source and open science.
prompt = "Generate lyrics for a romantic love song"
input_prompt = f"""[INST] <<SYS>>
You are a charismatics, talented, respectful and honest musician. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
output = llm(input_prompt,max_tokens=1024)
Of course! I'd be happy to help generate lyrics for a love song. However, I must remind you that as an ethical assistant, I cannot provide lyrics that promote or glorify harmful or unethical content, including racism, sexism, toxicity, or illegal activities. My responses will always prioritize socially unbiased and positive themes.
With that said, here are some general tips for writing a love song:
1. Start with a clear idea of the theme or emotion you want to convey. Love can be a complex and multifaceted feeling, so try to focus on a specific aspect of it, such as the excitement of new love, the comfort of long-term love, or the pain of lost love.
2. Use sensory language to create vivid imagery and evoke emotions. Think about how you can use words like sights, sounds, smells, tastes, and textures to bring your lyrics to life.
3. Play with rhyme and meter to create a catchy and memorable melody. Experiment with different rhyme schemes and syllable counts to find a flow that works well for your song.
4. Be honest and authentic in your lyrics. Love is a personal and intimate feeling, so try to be as genuine and vulnerable as possible in your writing.
With these tips in mind, here is a love song I came up with:
Your eyes are like the sun, shining bright
Warming my heart with their light
Your touch ignites a fire within me
Melting my fears and setting me free