andrijdavid commited on
Commit
e88ffbb
1 Parent(s): e102dcc

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,20 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Q2_K/Q2_K-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
37
+ Q3_K/Q3_K-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
38
+ Q3_K_L/Q3_K_L-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
39
+ Q3_K_M/Q3_K_M-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
40
+ Q3_K_S/Q3_K_S-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
41
+ Q4_0/Q4_0-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
42
+ Q4_1/Q4_1-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
43
+ Q4_K/Q4_K-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
44
+ Q4_K_M/Q4_K_M-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
45
+ Q4_K_S/Q4_K_S-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
46
+ Q5_0/Q5_0-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
47
+ Q5_1/Q5_1-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
48
+ Q5_K/Q5_K-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
49
+ Q5_K_M/Q5_K_M-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
50
+ Q5_K_S/Q5_K_S-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
51
+ Q6_K/Q6_K-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
52
+ Q8_0/Q8_0-00001-of-00001.gguf filter=lfs diff=lfs merge=lfs -text
Q2_K/Q2_K-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:77ea21a7ae125c64290621b226a33563b6785312349e738f8abe40ebfacfa1ae
3
+ size 3481447040
Q3_K/Q3_K-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6704bdfda09b421603c7551a2f7bb8df634c884cbf23859fc53c09ed86467057
3
+ size 4369328768
Q3_K_L/Q3_K_L-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc23e4cf2a3a345b8457cdbc1fa77b1e956658268ad8311e8254b640840963d0
3
+ size 4709067392
Q3_K_M/Q3_K_M-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6704bdfda09b421603c7551a2f7bb8df634c884cbf23859fc53c09ed86467057
3
+ size 4369328768
Q3_K_S/Q3_K_S-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c1143003992b194479084b77dda731e1222ccca18e84d31c98424f71cfb2dfa
3
+ size 3982404224
Q4_0/Q4_0-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:34276975a9582b6c14f822d08e77ab50fc3831812ebc2e722a0b82254561ed29
3
+ size 5011843712
Q4_1/Q4_1-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52d97cf1200ae8d30a2218527e472a005a879cc3d27119b1a99c316ca27fa002
3
+ size 5496285824
Q4_K/Q4_K-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b19c604915587dc73988cc63b09414c5e4f4f231112db6b4d2e83c63eb7c1c04
3
+ size 5329758848
Q4_K_M/Q4_K_M-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b19c604915587dc73988cc63b09414c5e4f4f231112db6b4d2e83c63eb7c1c04
3
+ size 5329758848
Q4_K_S/Q4_K_S-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b85fe83d9c77eeac18e628a009056b9775fae82614dba4479ada3a851bef3974
3
+ size 5046446720
Q5_0/Q5_0-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:daafb65d0de82a69ce861d5fb03637c8056c6d20a0537fe584fdce2ebeb37ceb
3
+ size 5980727936
Q5_1/Q5_1-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de84f949df85ba8ba95b586482f010258f57b69c240c7a0c097ae473c850a2c1
3
+ size 6465170048
Q5_K/Q5_K-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6f2cb0ae25f8808aef41987eb4a20f2033036cdaa027ba11a4f88800ff009dc
3
+ size 6144502400
Q5_K_M/Q5_K_M-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6f2cb0ae25f8808aef41987eb4a20f2033036cdaa027ba11a4f88800ff009dc
3
+ size 6144502400
Q5_K_S/Q5_K_S-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a4073c845ff11649d8d17f862b3feaacb5c77cfbd3f1373327f7ef2aeda47fc
3
+ size 5980727936
Q6_K/Q6_K-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:650c6f6d21e017c70eb4e4e6d12bc3c32509495be692c676261877b5c0d5fff7
3
+ size 7010167424
Q8_0/Q8_0-00001-of-00001.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8df09dc26df63468c961c58066bfc9a3733487931782e22ac58f18e542844c05
3
+ size 9077844608
README.md ADDED
@@ -0,0 +1,451 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: gemma
4
+ license_link: https://ai.google.dev/gemma/terms
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - GGUF
8
+ extra_gated_heading: Access CodeGemma on Hugging Face
9
+ extra_gated_prompt: To access CodeGemma on Hugging Face, you’re required to review
10
+ and agree to Google’s usage license. To do this, please ensure you’re logged-in
11
+ to Hugging Face and click below. Requests are processed immediately.
12
+ extra_gated_button_content: Acknowledge license
13
+ widget:
14
+ - text: '<start_of_turn>user Write a Python function to calculate the nth fibonacci
15
+ number.<end_of_turn> <start_of_turn>model
16
+
17
+ '
18
+ inference:
19
+ parameters:
20
+ max_new_tokens: 200
21
+ quantized_by: andrijdavid
22
+ ---
23
+ # codegemma-7b-it-GGUF
24
+ - Original model: [codegemma-7b-it](https://huggingface.co/google/codegemma-7b-it)
25
+
26
+ <!-- description start -->
27
+ ## Description
28
+
29
+ This repo contains GGUF format model files for [codegemma-7b-it](https://huggingface.co/google/codegemma-7b-it).
30
+
31
+ <!-- description end -->
32
+ <!-- README_GGUF.md-about-gguf start -->
33
+ ### About GGUF
34
+ GGUF 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.
35
+ Here is an incomplete list of clients and libraries that are known to support GGUF:
36
+ * [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.
37
+ * [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.
38
+ * [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 applications​
39
+ * [KoboldCpp](https://github.com/LostRuins/koboldcpp), A comprehensive web UI offering GPU acceleration across all platforms and architectures, particularly renowned for storytelling.
40
+ * [GPT4All](https://gpt4all.io), This is a free and open source GUI that runs locally, supporting Windows, Linux, and macOS with full GPU acceleration.
41
+ * [LM Studio](https://lmstudio.ai/) An intuitive and powerful local GUI for Windows and macOS (Silicon), featuring GPU acceleration.
42
+ * [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.
43
+ * [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.
44
+ * [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.
45
+ * [candle](https://github.com/huggingface/candle), A Rust-based ML framework focusing on performance, including GPU support, and designed for ease of use.
46
+ * [ctransformers](https://github.com/marella/ctransformers), A Python library featuring GPU acceleration, LangChain support, and an OpenAI-compatible AI server.
47
+ * [localGPT](https://github.com/PromtEngineer/localGPT) An open-source initiative enabling private conversations with documents.
48
+ <!-- README_GGUF.md-about-gguf end -->
49
+
50
+ <!-- compatibility_gguf start -->
51
+ ## Explanation of quantisation methods
52
+ <details>
53
+ <summary>Click to see details</summary>
54
+ The new methods available are:
55
+
56
+ * 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)
57
+ * 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.
58
+ * 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.
59
+ * GGML_TYPE_Q5_K - "type-1" 5-bit quantization. Same super-block structure as GGML_TYPE_Q4_K resulting in 5.5 bpw
60
+ * 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.
61
+ </details>
62
+ <!-- compatibility_gguf end -->
63
+
64
+ <!-- README_GGUF.md-how-to-download start -->
65
+ ## How to download GGUF files
66
+
67
+ **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.
68
+
69
+ The following clients/libraries will automatically download models for you, providing a list of available models to choose from:
70
+
71
+ * LM Studio
72
+ * LoLLMS Web UI
73
+ * Faraday.dev
74
+
75
+ ### In `text-generation-webui`
76
+
77
+ Under Download Model, you can enter the model repo: LiteLLMs/codegemma-7b-it-GGUF and below it, a specific filename to download, such as: Q4_0/Q4_0-00001-of-00001.gguf.
78
+
79
+ Then click Download.
80
+
81
+ ### On the command line, including multiple files at once
82
+
83
+ I recommend using the `huggingface-hub` Python library:
84
+
85
+ ```shell
86
+ pip3 install huggingface-hub
87
+ ```
88
+
89
+ Then you can download any individual model file to the current directory, at high speed, with a command like this:
90
+
91
+ ```shell
92
+ huggingface-cli download LiteLLMs/codegemma-7b-it-GGUF Q4_0/Q4_0-00001-of-00001.gguf --local-dir . --local-dir-use-symlinks False
93
+ ```
94
+
95
+ <details>
96
+ <summary>More advanced huggingface-cli download usage (click to read)</summary>
97
+
98
+ You can also download multiple files at once with a pattern:
99
+
100
+ ```shell
101
+ huggingface-cli download LiteLLMs/codegemma-7b-it-GGUF --local-dir . --local-dir-use-symlinks False --include='*Q4_K*gguf'
102
+ ```
103
+
104
+ For 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).
105
+
106
+ To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:
107
+
108
+ ```shell
109
+ pip3 install huggingface_hub[hf_transfer]
110
+ ```
111
+
112
+ And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:
113
+
114
+ ```shell
115
+ HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download LiteLLMs/codegemma-7b-it-GGUF Q4_0/Q4_0-00001-of-00001.gguf --local-dir . --local-dir-use-symlinks False
116
+ ```
117
+
118
+ Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.
119
+ </details>
120
+ <!-- README_GGUF.md-how-to-download end -->
121
+ <!-- README_GGUF.md-how-to-run start -->
122
+ ## Example `llama.cpp` command
123
+
124
+ Make sure you are using `llama.cpp` from commit [d0cee0d](https://github.com/ggerganov/llama.cpp/commit/d0cee0d36d5be95a0d9088b674dbb27354107221) or later.
125
+
126
+ ```shell
127
+ ./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>"
128
+ ```
129
+
130
+ Change `-ngl 32` to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.
131
+
132
+ Change `-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.
133
+
134
+ If you want to have a chat-style conversation, replace the `-p <PROMPT>` argument with `-i -ins`
135
+
136
+ For 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)
137
+
138
+ ## How to run in `text-generation-webui`
139
+
140
+ Further 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).
141
+
142
+ ## How to run from Python code
143
+
144
+ You 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.
145
+
146
+ ### How to load this model in Python code, using llama-cpp-python
147
+
148
+ For full documentation, please see: [llama-cpp-python docs](https://abetlen.github.io/llama-cpp-python/).
149
+
150
+ #### First install the package
151
+
152
+ Run one of the following commands, according to your system:
153
+
154
+ ```shell
155
+ # Base ctransformers with no GPU acceleration
156
+ pip install llama-cpp-python
157
+ # With NVidia CUDA acceleration
158
+ CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python
159
+ # Or with OpenBLAS acceleration
160
+ CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
161
+ # Or with CLBLast acceleration
162
+ CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
163
+ # Or with AMD ROCm GPU acceleration (Linux only)
164
+ CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
165
+ # Or with Metal GPU acceleration for macOS systems only
166
+ CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
167
+ # In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
168
+ $env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on"
169
+ pip install llama-cpp-python
170
+ ```
171
+
172
+ #### Simple llama-cpp-python example code
173
+
174
+ ```python
175
+ from llama_cpp import Llama
176
+ # Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
177
+ llm = Llama(
178
+ model_path="./Q4_0/Q4_0-00001-of-00001.gguf", # Download the model file first
179
+ n_ctx=32768, # The max sequence length to use - note that longer sequence lengths require much more resources
180
+ n_threads=8, # The number of CPU threads to use, tailor to your system and the resulting performance
181
+ n_gpu_layers=35 # The number of layers to offload to GPU, if you have GPU acceleration available
182
+ )
183
+ # Simple inference example
184
+ output = llm(
185
+ "<PROMPT>", # Prompt
186
+ max_tokens=512, # Generate up to 512 tokens
187
+ stop=["</s>"], # Example stop token - not necessarily correct for this specific model! Please check before using.
188
+ echo=True # Whether to echo the prompt
189
+ )
190
+ # Chat Completion API
191
+ llm = Llama(model_path="./Q4_0/Q4_0-00001-of-00001.gguf", chat_format="llama-2") # Set chat_format according to the model you are using
192
+ llm.create_chat_completion(
193
+ messages = [
194
+ {"role": "system", "content": "You are a story writing assistant."},
195
+ {
196
+ "role": "user",
197
+ "content": "Write a story about llamas."
198
+ }
199
+ ]
200
+ )
201
+ ```
202
+
203
+ ## How to use with LangChain
204
+
205
+ Here are guides on using llama-cpp-python and ctransformers with LangChain:
206
+
207
+ * [LangChain + llama-cpp-python](https://python.langchain.com/docs/integrations/llms/llamacpp)
208
+ * [LangChain + ctransformers](https://python.langchain.com/docs/integrations/providers/ctransformers)
209
+
210
+ <!-- README_GGUF.md-how-to-run end -->
211
+
212
+ <!-- footer end -->
213
+
214
+ <!-- original-model-card start -->
215
+ # Original model card: codegemma-7b-it
216
+
217
+
218
+ # CodeGemma
219
+
220
+ Model Page
221
+ : [CodeGemma](https://ai.google.dev/gemma/docs/codegemma)
222
+
223
+ Resources and Technical Documentation
224
+ : [Technical Report](https://goo.gle/codegemma)
225
+ : [Responsible Generative AI Toolkit](https://ai.google.dev/responsible)
226
+
227
+ Terms of Use
228
+ : [Terms](https://www.kaggle.com/models/google/codegemma/license/consent/verify/huggingface?returnModelRepoId=google/codegemma-7b-it)
229
+
230
+ Authors
231
+ : Google
232
+
233
+ ## Model Information
234
+
235
+ Summary description and brief definition of inputs and outputs.
236
+
237
+ ### Description
238
+
239
+ CodeGemma 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.
240
+
241
+ | | [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) |
242
+ | -- | :--: | :--: | :: |
243
+ | Code Completion | ✅ | ✅ | |
244
+ | Generation from natural language | | ✅ | ✅ |
245
+ | Chat | | | ✅ |
246
+ | Instruction Following | | | ✅ |
247
+
248
+ ### Sample Usage
249
+
250
+ This model is intended to answer questions about code fragments, to generate code from natural language, or to engage in a conversation with the user about programming or technical problems. If you need to use code completion (for example, integrated in an IDE), we recommend you use one of the pre-trained models instead: [CodeGemma 7B](https://huggingface.co/google/codegemma-7b), or [CodeGemma 2B](https://huggingface.co/google/codegemma-2b).
251
+
252
+ #### For Code Generation
253
+
254
+ ```python
255
+ from transformers import GemmaTokenizer, AutoModelForCausalLM
256
+
257
+ tokenizer = GemmaTokenizer.from_pretrained("google/codegemma-7b-it")
258
+ model = AutoModelForCausalLM.from_pretrained("google/codegemma-7b-it")
259
+
260
+ input_text = "Write me a Python function to calculate the nth fibonacci number."
261
+ input_ids = tokenizer(input_text, return_tensors="pt")
262
+
263
+ outputs = model.generate(**input_ids)
264
+ print(tokenizer.decode(outputs[0]))
265
+ ```
266
+
267
+ #### Chat Template
268
+
269
+ The instruction-tuned models use a chat template that must be adhered to for conversational use.
270
+ The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
271
+
272
+ Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
273
+
274
+ ```py
275
+ from transformers import AutoTokenizer, AutoModelForCausalLM
276
+ import transformers
277
+ import torch
278
+
279
+ model_id = "google/codegemma-7b-it"
280
+ dtype = torch.bfloat16
281
+
282
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
283
+ model = AutoModelForCausalLM.from_pretrained(
284
+ model_id,
285
+ device_map="cuda",
286
+ torch_dtype=dtype,
287
+ )
288
+
289
+ chat = [
290
+ { "role": "user", "content": "Write a hello world program" },
291
+ ]
292
+
293
+ prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
294
+ ```
295
+
296
+ At this point, the prompt contains the following text:
297
+
298
+ ```
299
+ <bos><start_of_turn>user
300
+ Write a hello world program<end_of_turn>
301
+ <start_of_turn>model
302
+ ```
303
+
304
+ As you can see, each turn is preceded by a `<start_of_turn>` delimiter and then the role of the entity
305
+ (either `user`, for content supplied by the user, or `model` for LLM responses). Turns finish with
306
+ the `<end_of_turn>` token.
307
+
308
+ You can follow this format to build the prompt manually, if you need to do it without the tokenizer's
309
+ chat template.
310
+
311
+ After the prompt is ready, generation can be performed like this:
312
+
313
+ ```py
314
+ inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
315
+ outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
316
+ ```
317
+
318
+ ### Inputs and Outputs
319
+
320
+ Inputs
321
+ : For pretrained model variants: code prefix and/or suffix for code completion and generation scenarios, or natural language text or prompt
322
+ : For instruction tuned model variant: natural language text or prompt
323
+
324
+ Outputs
325
+ : For pretrained model variants: fill-in-the-middle code completion, code and natural language
326
+ : For instruction tuned model variant: code and natural language
327
+
328
+ ## Model Data
329
+
330
+ Data used for model training and how the data was processed.
331
+
332
+ ### Training Dataset
333
+
334
+ Using 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.
335
+
336
+ ### Training Data Processing
337
+
338
+ The following data pre-processing techniques were applied:
339
+
340
+ * 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.
341
+ * 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 packing
342
+ * 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.
343
+ * 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).
344
+
345
+ ## Implementation Information
346
+
347
+ Information about the hardware and software used to train the models.
348
+
349
+ ### Hardware
350
+
351
+ CodeGemma was trained using the latest generation of [Tensor Processing Unit (TPU)](https://cloud.google.com/tpu/docs/intro-to-tpu) hardware (TPUv5e).
352
+
353
+ ### Software
354
+
355
+ Training was done using [JAX](https://github.com/google/jax) and [ML Pathways](https://blog.google/technology/ai/introducing-pathways-next-generation-ai-architecture/).
356
+
357
+ ## Evaluation Information
358
+
359
+ Model evaluation metrics and results.
360
+
361
+ ### Evaluation Approach
362
+
363
+ We evaluate CodeGemma on a variety of academic benchmarks across several domains:
364
+
365
+ * Code completion benchmarks: HumanEval Single Line and Multiple Line Infilling
366
+ * Code generation benchmarks: HumanEval, MBPP, BabelCode (C++, C#, Go, Java, JavaScript, Kotlin, Python, Rust)
367
+ * Q&A: BoolQ, PIQA, TriviaQA
368
+ * Natural Language: ARC-Challenge, HellaSwag, MMLU, WinoGrande
369
+ * Math Reasoning: GSM8K, MATH
370
+
371
+ ### Evaluation Results
372
+
373
+ #### Coding Benchmarks
374
+
375
+ | Benchmark | 2B | 7B | 7B-IT |
376
+ | -- | -- |
377
+ | HumanEval | 31.1 | 44.5 | 56.1 |
378
+ | MBPP | 43.6 | 56.2 | 54.2 |
379
+ | HumanEval Single Line | 78.41 | 76.09 | 68.25 |
380
+ | HumanEval Multi Line | 51.44 | 58.44 | 20.05 |
381
+ | BC HE C++ | 24.2 | 32.9 | 42.2 |
382
+ | BC HE C# | 10.6 | 22.4 | 26.7 |
383
+ | BC HE Go | 20.5 | 21.7 | 28.6 |
384
+ | BC HE Java | 29.2 | 41.0 | 48.4 |
385
+ | BC HE JavaScript | 21.7 | 39.8 | 46.0 |
386
+ | BC HE Kotlin | 28.0 | 39.8 | 51.6 |
387
+ | BC HE Python | 21.7 | 42.2 | 48.4 |
388
+ | BC HE Rust | 26.7 | 34.1 | 36.0 |
389
+ | BC MBPP C++ | 47.1 | 53.8 | 56.7 |
390
+ | BC MBPP C# | 28.7 | 32.5 | 41.2 |
391
+ | BC MBPP Go | 45.6 | 43.3 | 46.2 |
392
+ | BC MBPP Java | 41.8 | 50.3 | 57.3 |
393
+ | BC MBPP JavaScript | 45.3 | 58.2 | 61.4 |
394
+ | BC MBPP Kotlin | 46.8 | 54.7 | 59.9 |
395
+ | BC MBPP Python | 38.6 | 59.1 | 62.0 |
396
+ | BC MBPP Rust | 45.3 | 52.9 | 53.5 |
397
+
398
+ #### Natural Language Benchmarks
399
+
400
+ ![CodeGemma Natural Language Benchmarks](./codegemma_nl_benchmarks.png)
401
+
402
+ ## Ethics and Safety
403
+
404
+ Ethics and safety evaluation approach and results.
405
+
406
+ ### Evaluation Approach
407
+
408
+ Our 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:
409
+
410
+ * 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.
411
+ * Specific testing of cyber-offence capabilities, focusing on testing autonomous hacking capabilities and ensuring potential harms are limited.
412
+
413
+ ### Evaluation Results
414
+
415
+ The 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.
416
+
417
+ ## Model Usage & Limitations
418
+
419
+ These models have certain limitations that users should be aware of.
420
+
421
+ ### Intended Usage
422
+
423
+ Code 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.
424
+
425
+ Code Completion
426
+ : PT models can be used to complete code with an IDE extension
427
+
428
+ Code Generation
429
+ : IT model can be used to generate code with or without an IDE extension
430
+
431
+ Code Conversation
432
+ : IT model can power conversation interfaces which discuss code.
433
+
434
+ Code Education
435
+ : IT model supports interactive code learning experiences, aids in syntax correction or provides coding practice.
436
+
437
+ ### Known Limitations
438
+
439
+ Large 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.
440
+
441
+ ### Ethical Considerations & Risks
442
+
443
+ The 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.
444
+
445
+ ### Benefits
446
+
447
+ At 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.
448
+
449
+ Using the coding benchmark evaluation metrics described in this document, these models have shown to provide superior performance to other, comparably-sized open model alternatives.
450
+
451
+ <!-- original-model-card end -->