LiteLLMs/codegemma-2b-GGUF
1273
1---2library_name: transformers3license: gemma4license_link: https://ai.google.dev/gemma/terms5tags:6- GGUF7extra_gated_heading: Access CodeGemma on Hugging Face8extra_gated_prompt: To access CodeGemma on Hugging Face, you’re required to review9 and agree to Google’s usage license. To do this, please ensure you’re logged-in10 to Hugging Face and click below. Requests are processed immediately.11extra_gated_button_content: Acknowledge license12quantized_by: andrijdavid13---14# codegemma-2b-GGUF15- Original model: [codegemma-2b](https://huggingface.co/google/codegemma-2b)16 17<!-- description start -->18## Description19 20This repo contains GGUF format model files for [codegemma-2b](https://huggingface.co/google/codegemma-2b).21 22<!-- description end -->23<!-- README_GGUF.md-about-gguf start -->24### About GGUF25GGUF is a new format introduced by the llama.cpp team on August 21st 2023. It is a replacement for GGML, which is no longer supported by llama.cpp.26Here is an incomplete list of clients and libraries that are known to support GGUF:27* [llama.cpp](https://github.com/ggerganov/llama.cpp). This is the source project for GGUF, providing both a Command Line Interface (CLI) and a server option.28* [text-generation-webui](https://github.com/oobabooga/text-generation-webui), Known as the most widely used web UI, this project boasts numerous features and powerful extensions, and supports GPU acceleration.29* [Ollama](https://github.com/jmorganca/ollama) Ollama is a lightweight and extensible framework designed for building and running language models locally. It features a simple API for creating, managing, and executing models, along with a library of pre-built models for use in various applications30* [KoboldCpp](https://github.com/LostRuins/koboldcpp), A comprehensive web UI offering GPU acceleration across all platforms and architectures, particularly renowned for storytelling.31* [GPT4All](https://gpt4all.io), This is a free and open source GUI that runs locally, supporting Windows, Linux, and macOS with full GPU acceleration.32* [LM Studio](https://lmstudio.ai/) An intuitive and powerful local GUI for Windows and macOS (Silicon), featuring GPU acceleration.33* [LoLLMS Web UI](https://github.com/ParisNeo/lollms-webui). A notable web UI with a variety of unique features, including a comprehensive model library for easy model selection.34* [Faraday.dev](https://faraday.dev/), An attractive, user-friendly character-based chat GUI for Windows and macOS (both Silicon and Intel), also offering GPU acceleration.35* [llama-cpp-python](https://github.com/abetlen/llama-cpp-python), A Python library equipped with GPU acceleration, LangChain support, and an OpenAI-compatible API server.36* [candle](https://github.com/huggingface/candle), A Rust-based ML framework focusing on performance, including GPU support, and designed for ease of use.37* [ctransformers](https://github.com/marella/ctransformers), A Python library featuring GPU acceleration, LangChain support, and an OpenAI-compatible AI server.38* [localGPT](https://github.com/PromtEngineer/localGPT) An open-source initiative enabling private conversations with documents. 39<!-- README_GGUF.md-about-gguf end -->40 41<!-- compatibility_gguf start -->42## Explanation of quantisation methods43<details>44 <summary>Click to see details</summary>45The new methods available are:46 47* GGML_TYPE_Q2_K - "type-1" 2-bit quantization in super-blocks containing 16 blocks, each block having 16 weight. Block scales and mins are quantized with 4 bits. This ends up effectively using 2.5625 bits per weight (bpw)48* GGML_TYPE_Q3_K - "type-0" 3-bit quantization in super-blocks containing 16 blocks, each block having 16 weights. Scales are quantized with 6 bits. This end up using 3.4375 bpw.49* GGML_TYPE_Q4_K - "type-1" 4-bit quantization in super-blocks containing 8 blocks, each block having 32 weights. Scales and mins are quantized with 6 bits. This ends up using 4.5 bpw.50* GGML_TYPE_Q5_K - "type-1" 5-bit quantization. Same super-block structure as GGML_TYPE_Q4_K resulting in 5.5 bpw51* GGML_TYPE_Q6_K - "type-0" 6-bit quantization. Super-blocks with 16 blocks, each block having 16 weights. Scales are quantized with 8 bits. This ends up using 6.5625 bpw.52</details>53<!-- compatibility_gguf end -->54 55<!-- README_GGUF.md-how-to-download start -->56## How to download GGUF files57 58**Note for manual downloaders:** You almost never want to clone the entire repo! Multiple different quantisation formats are provided, and most users only want to pick and download a single folder.59 60The following clients/libraries will automatically download models for you, providing a list of available models to choose from:61 62* LM Studio63* LoLLMS Web UI64* Faraday.dev65 66### In `text-generation-webui`67 68Under Download Model, you can enter the model repo: LiteLLMs/codegemma-2b-GGUF and below it, a specific filename to download, such as: Q4_0/Q4_0-00001-of-00001.gguf.69 70Then click Download.71 72### On the command line, including multiple files at once73 74I recommend using the `huggingface-hub` Python library:75 76```shell77pip3 install huggingface-hub78```79 80Then you can download any individual model file to the current directory, at high speed, with a command like this:81 82```shell83huggingface-cli download LiteLLMs/codegemma-2b-GGUF Q4_0/Q4_0-00001-of-00001.gguf --local-dir . --local-dir-use-symlinks False84```85 86<details>87 <summary>More advanced huggingface-cli download usage (click to read)</summary>88 89You can also download multiple files at once with a pattern:90 91```shell92huggingface-cli download LiteLLMs/codegemma-2b-GGUF --local-dir . --local-dir-use-symlinks False --include='*Q4_K*gguf'93```94 95For more documentation on downloading with `huggingface-cli`, please see: [HF -> Hub Python Library -> Download files -> Download from the CLI](https://huggingface.co/docs/huggingface_hub/guides/download#download-from-the-cli).96 97To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:98 99```shell100pip3 install huggingface_hub[hf_transfer]101```102 103And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:104 105```shell106HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download LiteLLMs/codegemma-2b-GGUF Q4_0/Q4_0-00001-of-00001.gguf --local-dir . --local-dir-use-symlinks False107```108 109Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.110</details>111<!-- README_GGUF.md-how-to-download end -->112<!-- README_GGUF.md-how-to-run start -->113## Example `llama.cpp` command114 115Make sure you are using `llama.cpp` from commit [d0cee0d](https://github.com/ggerganov/llama.cpp/commit/d0cee0d36d5be95a0d9088b674dbb27354107221) or later.116 117```shell118./main -ngl 35 -m Q4_0/Q4_0-00001-of-00001.gguf --color -c --temp 0.7 --repeat_penalty 1.1 -n -1 -p "<PROMPT>"119```120 121Change `-ngl 32` to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.122 123Change `-c ` to the desired sequence length. For extended sequence models - eg 8K, 16K, 32K - the necessary RoPE scaling parameters are read from the GGUF file and set by llama.cpp automatically. Note that longer sequence lengths require much more resources, so you may need to reduce this value.124 125If you want to have a chat-style conversation, replace the `-p <PROMPT>` argument with `-i -ins`126 127For other parameters and how to use them, please refer to [the llama.cpp documentation](https://github.com/ggerganov/llama.cpp/blob/master/examples/main/README.md)128 129## How to run in `text-generation-webui`130 131Further instructions can be found in the text-generation-webui documentation, here: [text-generation-webui/docs/04 ‐ Model Tab.md](https://github.com/oobabooga/text-generation-webui/blob/main/docs/04%20%E2%80%90%20Model%20Tab.md#llamacpp).132 133## How to run from Python code134 135You can use GGUF models from Python using the [llama-cpp-python](https://github.com/abetlen/llama-cpp-python) or [ctransformers](https://github.com/marella/ctransformers) libraries. Note that at the time of writing (Nov 27th 2023), ctransformers has not been updated for some time and is not compatible with some recent models. Therefore I recommend you use llama-cpp-python.136 137### How to load this model in Python code, using llama-cpp-python138 139For full documentation, please see: [llama-cpp-python docs](https://abetlen.github.io/llama-cpp-python/).140 141#### First install the package142 143Run one of the following commands, according to your system:144 145```shell146# Base ctransformers with no GPU acceleration147pip install llama-cpp-python148# With NVidia CUDA acceleration149CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python150# Or with OpenBLAS acceleration151CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python152# Or with CLBLast acceleration153CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python154# Or with AMD ROCm GPU acceleration (Linux only)155CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python156# Or with Metal GPU acceleration for macOS systems only157CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python158# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:159$env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on"160pip install llama-cpp-python161```162 163#### Simple llama-cpp-python example code164 165```python166from llama_cpp import Llama167# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.168llm = Llama(169 model_path="./Q4_0/Q4_0-00001-of-00001.gguf", # Download the model file first170 n_ctx=32768, # The max sequence length to use - note that longer sequence lengths require much more resources171 n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance172 n_gpu_layers=35 # The number of layers to offload to GPU, if you have GPU acceleration available173)174# Simple inference example175output = llm(176 "<PROMPT>", # Prompt177 max_tokens=512, # Generate up to 512 tokens178 stop=["</s>"], # Example stop token - not necessarily correct for this specific model! Please check before using.179 echo=True # Whether to echo the prompt180)181# Chat Completion API182llm = Llama(model_path="./Q4_0/Q4_0-00001-of-00001.gguf", chat_format="llama-2") # Set chat_format according to the model you are using183llm.create_chat_completion(184 messages = [185 {"role": "system", "content": "You are a story writing assistant."},186 {187 "role": "user",188 "content": "Write a story about llamas."189 }190 ]191)192```193 194## How to use with LangChain195 196Here are guides on using llama-cpp-python and ctransformers with LangChain:197 198* [LangChain + llama-cpp-python](https://python.langchain.com/docs/integrations/llms/llamacpp)199* [LangChain + ctransformers](https://python.langchain.com/docs/integrations/providers/ctransformers)200 201<!-- README_GGUF.md-how-to-run end -->202 203<!-- footer end -->204 205<!-- original-model-card start -->206# Original model card: codegemma-2b207 208 209# CodeGemma210 211Model Page212: [CodeGemma](https://ai.google.dev/gemma/docs/codegemma)213 214Resources and Technical Documentation215: [Technical Report](https://goo.gle/codegemma)216: [Responsible Generative AI Toolkit](https://ai.google.dev/responsible)217 218Terms of Use219: [Terms](https://www.kaggle.com/models/google/codegemma/license/consent/verify/huggingface?returnModelRepoId=google/codegemma-2b)220 221Authors222: Google223 224## Model Information225 226Summary description and brief definition of inputs and outputs.227 228### Description229 230CodeGemma is a collection of lightweight open code models built on top of Gemma. CodeGemma models are text-to-text and text-to-code decoder-only models and are available as a 7 billion pretrained variant that specializes in code completion and code generation tasks, a 7 billion parameter instruction-tuned variant for code chat and instruction following and a 2 billion parameter pretrained variant for fast code completion.231 232| | [ **codegemma-2b** ](https://huggingface.co/google/codegemma-2b) | [codegemma-7b](https://huggingface.co/google/codegemma-7b) | [codegemma-7b-it](https://huggingface.co/google/codegemma-7b-it) |233| -- | :--: | :--: | :--: |234| Code Completion | ✅ | ✅ | |235| Generation from natural language | | ✅ | ✅ |236| Chat | | | ✅ |237| Instruction Following | | | ✅ |238 239### Sample Usage240 241#### For Code Completion242 243Code completion can be used for infilling inside code editors. CodeGemma was trained for this task using the fill-in-the-middle (FIM) objective, where you provide a prefix and a suffix as context for the completion. The following tokens are used to separate the different parts of the input:244 245- `<|fim_prefix|>` precedes the context before the completion we want to run.246- `<|fim_suffix|>` precedes the suffix. You must put this token exactly where the cursor would be positioned in an editor, as this is the location that will be completed by the model.247- `<|fim_middle|>` is the prompt that invites the model to run the generation.248 249In addition to these, there's also `<|file_separator|>`, which is used to provide multi-file contexts.250 251Please, make sure to not provide any extra spaces or newlines around the tokens, other than those that would naturally occur in the code fragment you want to complete. Here's an example:252 253```python254from transformers import GemmaTokenizer, AutoModelForCausalLM255 256model_id = "google/codegemma-2b"257tokenizer = GemmaTokenizer.from_pretrained(model_id)258model = AutoModelForCausalLM.from_pretrained(model_id)259 260prompt = '''\261<|fim_prefix|>import datetime262def calculate_age(birth_year):263 """Calculates a person's age based on their birth year."""264 current_year = datetime.date.today().year265 <|fim_suffix|>266 return age<|fim_middle|>\267'''268 269inputs = tokenizer(prompt, return_tensors="pt").to(model.device)270prompt_len = inputs["input_ids"].shape[-1]271outputs = model.generate(**inputs, max_new_tokens=100)272print(tokenizer.decode(outputs[0][prompt_len:]))273```274 275This may return something like the following:276 277```278age = current_year - birth_year<|file_separator|>test_calculate_age.py279<|fim_suffix|>280 assert calculate_age(1990) == 33281 assert calculate_age(1980) == 43282 assert calculate_age(1970) == 53283 assert calculate_age(1960) == 63284 assert calculate_age(1950) == 73285```286 287Note the extra content after the correct completion. The model returns the completion, followed by one of the FIM tokens or the EOS token. You should ignore everything that comes after any of these tokens. A good way to achieve this is by providing a list of terminators to the `generate` function, like this:288 289```python290FIM_PREFIX = '<|fim_prefix|>'291FIM_SUFFIX = '<|fim_suffix|>'292FIM_MIDDLE = '<|fim_middle|>'293FIM_FILE_SEPARATOR = '<|file_separator|>'294 295terminators = tokenizer.convert_tokens_to_ids([FIM_PREFIX, FIM_MIDDLE, FIM_SUFFIX, FIM_FILE_SEPARATOR])296terminators += [tokenizer.eos_token_id]297 298outputs = model.generate(299 **inputs,300 max_new_tokens=100,301 eos_token_id=terminators,302)303```304 305In this case, generation stops as soon as the first delimiter is found in the response:306 307```308age = current_year - birth_year<|file_separator|>309```310 311 312#### For Code Generation313 314```python315from transformers import GemmaTokenizer, AutoModelForCausalLM316 317tokenizer = GemmaTokenizer.from_pretrained("google/codegemma-2b")318model = AutoModelForCausalLM.from_pretrained("google/codegemma-2b")319 320input_text = "Write me a Python function to calculate the nth fibonacci number."321input_ids = tokenizer(input_text, return_tensors="pt")322 323outputs = model.generate(**input_ids)324print(tokenizer.decode(outputs[0]))325```326 327### Inputs and Outputs328 329Inputs330: For pretrained model variants: code prefix and/or suffix for code completion and generation scenarios, or natural language text or prompt331: For instruction tuned model variant: natural language text or prompt332 333Outputs334: For pretrained model variants: fill-in-the-middle code completion, code and natural language335: For instruction tuned model variant: code and natural language336 337## Model Data338 339Data used for model training and how the data was processed.340 341### Training Dataset342 343Using Gemma as the base model, CodeGemma 2B and 7B pretrained variants are further trained on an additional 500 billion tokens of primarily English language data from publicly available code repositories, open source mathematics datasets and synthetically generated code.344 345### Training Data Processing346 347The following data pre-processing techniques were applied:348 349 * FIM Pretrained CodeGemma models focus on fill-in-the-middle (FIM) tasks. The models are trained to work with both PSM and SPM modes. Our FIM settings are 80% FIM rate with 50-50 PSM/SPM.350 * Dependency Graph-based Packing and Unit Test-based Lexical Packing techniques: To improve model alignment with real-world applications, we structured training examples at the project/repository level to co-locate the most relevant source files within each repository. Specifically, we employed two heuristic techniques: dependency graph-based packing and unit test-based lexical packing351 * We developed a novel technique for splitting the documents into prefix, middle, and suffix to make the suffix start in a more syntactically natural point rather than purely random distribution.352 * Safety: Similarly to Gemma, we deployed rigorous safety filtering including filtering personal data, CSAM filtering and other filtering based on content quality and safety in line with [our policies](https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11).353 354## Implementation Information355 356Information about the hardware and software used to train the models.357 358### Hardware359 360CodeGemma was trained using the latest generation of [Tensor Processing Unit (TPU)](https://cloud.google.com/tpu/docs/intro-to-tpu) hardware (TPUv5e).361 362### Software363 364Training was done using [JAX](https://github.com/google/jax) and [ML Pathways](https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/).365 366## Evaluation Information367 368Model evaluation metrics and results.369 370### Evaluation Approach371 372We evaluate CodeGemma on a variety of academic benchmarks across several domains:373 374 * Code completion benchmarks: HumanEval Single Line and Multiple Line Infilling375 * Code generation benchmarks: HumanEval, MBPP, BabelCode (C++, C#, Go, Java, JavaScript, Kotlin, Python, Rust)376 * Q&A: BoolQ, PIQA, TriviaQA377 * Natural Language: ARC-Challenge, HellaSwag, MMLU, WinoGrande378 * Math Reasoning: GSM8K, MATH379 380### Evaluation Results381 382#### Coding Benchmarks383 384| Benchmark | 2B | 7B | 7B-IT |385| -- | -- |386| HumanEval | 31.1 | 44.5 | 56.1 |387| MBPP | 43.6 | 56.2 | 54.2 |388| HumanEval Single Line | 78.41 | 76.09 | 68.25 |389| HumanEval Multi Line | 51.44 | 58.44 | 20.05 |390| BC HE C++ | 24.2 | 32.9 | 42.2 |391| BC HE C# | 10.6 | 22.4 | 26.7 |392| BC HE Go | 20.5 | 21.7 | 28.6 |393| BC HE Java | 29.2 | 41.0 | 48.4 |394| BC HE JavaScript | 21.7 | 39.8 | 46.0 |395| BC HE Kotlin | 28.0 | 39.8 | 51.6 |396| BC HE Python | 21.7 | 42.2 | 48.4 |397| BC HE Rust | 26.7 | 34.1 | 36.0 |398| BC MBPP C++ | 47.1 | 53.8 | 56.7 |399| BC MBPP C# | 28.7 | 32.5 | 41.2 |400| BC MBPP Go | 45.6 | 43.3 | 46.2 |401| BC MBPP Java | 41.8 | 50.3 | 57.3 |402| BC MBPP JavaScript | 45.3 | 58.2 | 61.4 |403| BC MBPP Kotlin | 46.8 | 54.7 | 59.9 |404| BC MBPP Python | 38.6 | 59.1 | 62.0 |405| BC MBPP Rust | 45.3 | 52.9 | 53.5 |406 407#### Natural Language Benchmarks408 409410 411## Ethics and Safety412 413Ethics and safety evaluation approach and results.414 415### Evaluation Approach416 417Our evaluation methods include structured evaluations and internal red-teaming testing of relevant content policies. Red-teaming was conducted by a number of different teams, each with different goals and human evaluation metrics. These models were evaluated against a number of different categories relevant to ethics and safety, including:418 419 * Human evaluation on prompts covering content safety and representational harms. See the [Gemma model card](https://ai.google.dev/gemma/docs/model_card#evaluation_approach) for more details on evaluation approach.420 * Specific testing of cyber-offence capabilities, focusing on testing autonomous hacking capabilities and ensuring potential harms are limited.421 422### Evaluation Results423 424The results of ethics and safety evaluations are within acceptable thresholds for meeting [internal policies](https://storage.googleapis.com/gweb-uniblog-publish-prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page=11) for categories such as child safety, content safety, representational harms, memorization, large-scale harms. See the [Gemma model card](https://ai.google.dev/gemma/docs/model_card#evaluation_results) for more details.425 426## Model Usage & Limitations427 428These models have certain limitations that users should be aware of.429 430### Intended Usage431 432Code Gemma models have a wide range of applications, which vary between IT and PT models. The following list of potential uses is not comprehensive. The purpose of this list is to provide contextual information about the possible use-cases that the model creators considered as part of model training and development.433 434Code Completion435: PT models can be used to complete code with an IDE extension436 437Code Generation438: IT model can be used to generate code with or without an IDE extension439 440Code Conversation441: IT model can power conversation interfaces which discuss code.442 443Code Education444: IT model supports interactive code learning experiences, aids in syntax correction or provides coding practice.445 446### Known Limitations447 448Large Language Models (LLMs) have limitations based on their training data and the inherent limitations of the technology. See the [Gemma model card](https://ai.google.dev/gemma/docs/model_card#evaluation_results) for more details on the limitations of LLMs.449 450### Ethical Considerations & Risks451 452The development of large language models (LLMs) raises several ethical concerns. We have carefully considered multiple aspects in the development of these models. Please refer to [the same discussion](https://ai.google.dev/gemma/docs/model_card#ethical_considerations_and_risks) in the Gemma model card for model details.453 454### Benefits455 456At the time of release, this family of models provides high-performance open code-focused large language model implementations designed from the ground up for Responsible AI development compared to similarly sized models.457 458Using the coding benchmark evaluation metrics described in this document, these models have shown to provide superior performance to other, comparably-sized open model alternatives.459 460<!-- original-model-card end -->