Instructions to use bartowski/gemma-2-9b-it-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bartowski/gemma-2-9b-it-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="bartowski/gemma-2-9b-it-GGUF") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("bartowski/gemma-2-9b-it-GGUF", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use bartowski/gemma-2-9b-it-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf bartowski/gemma-2-9b-it-GGUF:Q4_K_M
Use Docker
docker model run hf.co/bartowski/gemma-2-9b-it-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use bartowski/gemma-2-9b-it-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "bartowski/gemma-2-9b-it-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bartowski/gemma-2-9b-it-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/bartowski/gemma-2-9b-it-GGUF:Q4_K_M
- SGLang
How to use bartowski/gemma-2-9b-it-GGUF with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "bartowski/gemma-2-9b-it-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bartowski/gemma-2-9b-it-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "bartowski/gemma-2-9b-it-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bartowski/gemma-2-9b-it-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use bartowski/gemma-2-9b-it-GGUF with Ollama:
ollama run hf.co/bartowski/gemma-2-9b-it-GGUF:Q4_K_M
- Unsloth Studio
How to use bartowski/gemma-2-9b-it-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for bartowski/gemma-2-9b-it-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for bartowski/gemma-2-9b-it-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for bartowski/gemma-2-9b-it-GGUF to start chatting
- Atomic Chat new
- Docker Model Runner
How to use bartowski/gemma-2-9b-it-GGUF with Docker Model Runner:
docker model run hf.co/bartowski/gemma-2-9b-it-GGUF:Q4_K_M
- Lemonade
How to use bartowski/gemma-2-9b-it-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull bartowski/gemma-2-9b-it-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.gemma-2-9b-it-GGUF-Q4_K_M
List all available models
lemonade list
gemma 9b with llama cpp b3259
Using llama.cpp release b3259 for quantization
i want python code to run gemma 9b with llama cpp b3259
like
from llama_cpp import Llama
llm = Llama(
model_path="./models/7B/llama-model.gguf",
# n_gpu_layers=-1, # Uncomment to use GPU acceleration
# seed=1337, # Uncomment to set a specific seed
# n_ctx=2048, # Uncomment to increase the context window
)
output = llm(
"Q: Name the planets in the solar system? A: ", # Prompt
max_tokens=32, # Generate up to 32 tokens, set to None to generate up to the end of the context window
stop=["Q:", "\n"], # Stop generating just before the model would generate a new question
echo=True # Echo the prompt back in the output
) # Generate a completion, can also call create_completion
print(output)
import gradio as gr
from llama_cpp import Llama
from huggingface_hub import hf_hub_download
import os
Determine the number of CPU cores available
num_cores = os.cpu_count()
num_threads = num_cores - 1 # Use all but one core
print(f'number of available cores is {num_cores}')
print(f'number of used threads is {num_threads}')
Download the model file
model_file = "file name in repo"
repo_id = "repo-id"
model_path = hf_hub_download(repo_id=repo_id, filename=model_file) # you can replace this with your path if the model is in the same directory
print(f"Model downloaded to: {model_path}")
Load the GGUF model
model = Llama(
model_path=model_path,
n_ctx=2048,
n_threads=num_threads,
)
def generate_response(message, history):
prompt = f""" Very optimized prompt here concise answers to the following question:
Question: {message}
Answer:"""
try:
response = model(prompt, max_tokens=512, temperature=0.7, stream=True)
full_response = ""
for token in response:
full_response += token['choices'][0]['text']
yield full_response
except Exception as e:
yield f"An error occurred: {str(e)}"
Specify the correct paths for your images
header_image_path = "12f.jpeg" # Update this path
user_avatar_path = "profile.png" # Update this path
assistant_avatar_path = "1.jpg" # Update this path
with gr.Blocks() as demo:
gr.Image(header_image_path, show_label=False)
chatbot = gr.Chatbot(
avatar_images=(user_avatar_path, assistant_avatar_path)
)
msg = gr.Textbox(label="Type your message here...")
clear = gr.Button("Clear Chat")
def user(user_message, history):
return "", history + [[user_message, None]]
def bot(history):
bot_message = generate_response(history[-1][0], history)
for partial_message in bot_message:
history[-1][1] = partial_message
yield history
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
bot, chatbot, chatbot
)
clear.click(lambda: None, None, chatbot, queue=False)
demo.queue()
demo.launch()
this is a gradio app i made , i think you can use the model loading , response and clean_response as stand alone functions with no problems