duyntnet / gemma-2-9b-it-imatrix-GGUF

huggingface.co
Total runs: 1.5K
24-hour runs: 138
7-day runs: 115
30-day runs: 417
Model's Last Updated: September 07 2024
text-generation

Introduction of gemma-2-9b-it-imatrix-GGUF

Model Details of gemma-2-9b-it-imatrix-GGUF

Quantizations of https://huggingface.co/google/gemma-2-9b-it

Update (July 7, 2024): Requantized and reuploaded using llama.cpp latest version (b3325), everything should work as expected.

Inference Clients/UIs

From original readme

Usage

Below we share some code snippets on how to get quickly started with running the model. First make sure to pip install -U transformers , then copy the snippet from the section that is relevant for your usecase.

Running the model on a single / multi GPU
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-2-9b-it",
    device_map="auto",
    torch_dtype=torch.bfloat16
)

input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))

Running the model on a GPU using different precisions

The native weights of this model were exported in bfloat16 precision. You can use float16 , which may be faster on certain hardware, indicating the torch_dtype when loading the model. For convenience, the float16 revision of the repo contains a copy of the weights already converted to that precision.

You can also use float32 if you skip the dtype, but no precision increase will occur (model weights will just be upcasted to float32 ). See examples below.

  • Using torch.float16
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-2-9b-it",
    device_map="auto",
    torch_dtype=torch.float16,
    revision="float16",
)

input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
  • Using torch.bfloat16
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-2-9b-it",
    device_map="auto",
    torch_dtype=torch.bfloat16)

input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
  • Upcasting to torch.float32
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-2-9b-it",
    device_map="auto")

input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
Quantized Versions through bitsandbytes
  • Using 8-bit precision (int8)
# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_8bit=True)

tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-2-9b-it",
    quantization_config=quantization_config)

input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
  • Using 4-bit precision
# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_4bit=True)

tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-2-9b-it",
    quantization_config=quantization_config)

input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
Other optimizations
  • Flash Attention 2

First make sure to install flash-attn in your environment pip install flash-attn

model = AutoModelForCausalLM.from_pretrained(
    model_id, 
    torch_dtype=torch.float16, 
+   attn_implementation="flash_attention_2"
).to(0)
Chat Template

The instruction-tuned models use a chat template that must be adhered to for conversational use. The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.

Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:

from transformers import AutoTokenizer, AutoModelForCausalLM
import transformers
import torch

model_id = "google/gemma-2-9b-it"
dtype = torch.bfloat16

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="cuda",
    torch_dtype=dtype,)

chat = [
    { "role": "user", "content": "Write a hello world program" },
]
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)

At this point, the prompt contains the following text:

<bos><start_of_turn>user
Write a hello world program<end_of_turn>
<start_of_turn>model

As you can see, each turn is preceded by a <start_of_turn> delimiter and then the role of the entity (either user , for content supplied by the user, or model for LLM responses). Turns finish with the <end_of_turn> token.

You can follow this format to build the prompt manually, if you need to do it without the tokenizer's chat template.

After the prompt is ready, generation can be performed like this:

inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
print(tokenizer.decode(outputs[0]))

Runs of duyntnet gemma-2-9b-it-imatrix-GGUF on huggingface.co

1.5K
Total runs
138
24-hour runs
328
3-day runs
115
7-day runs
417
30-day runs

More Information About gemma-2-9b-it-imatrix-GGUF huggingface.co Model

More gemma-2-9b-it-imatrix-GGUF license Visit here:

https://choosealicense.com/licenses/other

gemma-2-9b-it-imatrix-GGUF huggingface.co

gemma-2-9b-it-imatrix-GGUF huggingface.co is an AI model on huggingface.co that provides gemma-2-9b-it-imatrix-GGUF's model effect (), which can be used instantly with this duyntnet gemma-2-9b-it-imatrix-GGUF model. huggingface.co supports a free trial of the gemma-2-9b-it-imatrix-GGUF model, and also provides paid use of the gemma-2-9b-it-imatrix-GGUF. Support call gemma-2-9b-it-imatrix-GGUF model through api, including Node.js, Python, http.

gemma-2-9b-it-imatrix-GGUF huggingface.co Url

https://huggingface.co/duyntnet/gemma-2-9b-it-imatrix-GGUF

duyntnet gemma-2-9b-it-imatrix-GGUF online free

gemma-2-9b-it-imatrix-GGUF huggingface.co is an online trial and call api platform, which integrates gemma-2-9b-it-imatrix-GGUF's modeling effects, including api services, and provides a free online trial of gemma-2-9b-it-imatrix-GGUF, you can try gemma-2-9b-it-imatrix-GGUF online for free by clicking the link below.

duyntnet gemma-2-9b-it-imatrix-GGUF online free url in huggingface.co:

https://huggingface.co/duyntnet/gemma-2-9b-it-imatrix-GGUF

gemma-2-9b-it-imatrix-GGUF install

gemma-2-9b-it-imatrix-GGUF is an open source model from GitHub that offers a free installation service, and any user can find gemma-2-9b-it-imatrix-GGUF on GitHub to install. At the same time, huggingface.co provides the effect of gemma-2-9b-it-imatrix-GGUF install, users can directly use gemma-2-9b-it-imatrix-GGUF installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

gemma-2-9b-it-imatrix-GGUF install url in huggingface.co:

https://huggingface.co/duyntnet/gemma-2-9b-it-imatrix-GGUF

Url of gemma-2-9b-it-imatrix-GGUF

gemma-2-9b-it-imatrix-GGUF huggingface.co Url

Provider of gemma-2-9b-it-imatrix-GGUF huggingface.co

duyntnet
ORGANIZATIONS

Other API from duyntnet