Knowledge Base · Learning paths
Google's Gemma Open-Source LLM Takes the Throne: Runs on Laptops and Fully Commercial
Google has released Gemma, a powerful new open-source large language model available in 2B and 7B sizes. It outperforms Llama-2 and Mistral 7B on multiple benchmarks, runs locally on laptops, supports commercial use, and has claimed the top spot on the Hugging Face Open LLM Leaderboard.
Translated from Chinese by AI. Spotted an issue? Use the feedback button.
Original | The Heart of the Machine | The Heart of the Machine | 2024-02-22 00:04 | Liaoning
Original link: https://mp.weixin.qq.com/s/_iCYfqmXA3enKn3Hm-DwSA
The Heart of the Machine reports
The Heart of the Machine Editorial Team
Just now, Google has entered the open-source large language model arena.
The open-source large model space has welcomed a major new player.
Google has released a brand-new open-source model series called Gemma. Compared to Gemini, Gemma is significantly more lightweight, remains completely free to use, and comes with fully open-sourced model weights that also permit commercial use.
Gemma official page: https://ai.google.dev/gemma/
This release includes two model sizes: Gemma 2B and Gemma 7B. Each size offers both a pre-trained version and an instruction-tuned version. Users can access them via Kaggle, Google’s Colab Notebooks, or through Google Cloud.
Of course, Gemma has also been made available immediately on Hugging Face and Hugging Chat, allowing everyone to test its generation capabilities:
Despite its relatively small size, Google states that the Gemma models have “clearly outperformed significantly larger models on key benchmarks,” including Llama-2 7B and 13B, as well as the currently popular Mistral 7B.
Moreover, Gemma “can run directly on developers’ laptops or desktop computers.” In addition to the lightweight models, Google has also released tools to encourage collaboration and guidelines for the responsible use of these models.
François Chollet, the author of Keras, immediately declared: The crown of the strongest open-source large language model has now changed hands.
On Hugging Face’s LLM leaderboard, both the Gemma 2B and 7B models have taken the top spots.
The new Responsible Generative AI Toolkit provides guidance and essential tools for building safer AI applications with Gemma. Google has also delivered a complete toolchain for inference and supervised fine-tuning (SFT) through native Keras 3.0, which is compatible with all major frameworks (JAX, PyTorch, and TensorFlow).
While major tech companies and AI research institutions are racing toward hundred-billion-parameter multimodal models, many startups are focusing on building language models in the several-billion-parameter range. Meta’s Llama series, released last year, sent shockwaves through the industry and sparked intense debate about the open-source versus closed-source paths for generative AI.
Google has stated that Gemma was built using the same research and technology as the Gemini models. However, the way Gemma has been released directly into the open-source ecosystem is completely different from Gemini. Google has also broken from the “no longer open-sourcing core technology” policy it announced last year.
Although developers can build on top of Gemini, they must do so either through APIs or on Google’s Vertex AI platform, which is widely regarded as a closed approach. Compared with OpenAI, which also follows a closed-source strategy, Google had shown little competitive edge.
With the open-sourcing of Gemma, Google may now be able to attract more developers to its AI models instead of losing them to competitors like Meta and Mistral.
Google’s unannounced open-source release this time appears to be an attempt to get ahead of Meta’s Llama 3 by one day. There were earlier reports suggesting that the Llama series would see a major update this week (we look forward to the first head-to-head evaluations).
Although it has only been a few hours since release, many users on X (formerly Twitter) have already shared their experiences. One user noted that Gemma-7B is very fast with stable output, and performs better than Llama-2 13B.
As an open-source model release, Google also published a detailed technical report covering Gemma’s performance, dataset composition, and modeling methodology. In the technical report, other researchers identified several notable highlights—for example, Gemma supports a vocabulary size of 256K, which enables significantly better and faster support for languages other than English.
Below are the key details from the technical report.
Gemma Technical Details
Overall, Gemma is a lightweight, state-of-the-art (SOTA) open model family that demonstrates strong performance in language understanding, reasoning, and safety.
Technical report link: https://storage.googleapis.com/deepmind-media/gemma/gemma-report.pdf
Google released two sizes of the Gemma models: 2 billion parameters and 7 billion parameters. For each size, both pre-trained checkpoints and fine-tuned checkpoints optimized for dialogue, instruction following, helpfulness, and safety are provided. The 7B model is designed for efficient deployment and development on GPUs and TPUs, while the 2B model targets CPU and on-device applications. Different sizes cater to varying computational constraints, application scenarios, and developer needs.
Gemma outperforms similarly sized open models on 11 out of 18 text-based tasks, including question answering, commonsense reasoning, mathematics, science, coding, and more.
The chart below (Figure 1) compares the performance of Gemma (7B) against LLaMA 2 (7B), LLaMA 2 (13B), and Mistral (7B) across tasks such as question answering, reasoning, math, science, and coding. Gemma (7B) shows clear advantages across most benchmarks (except for question answering, where it trails LLaMA 2 13B).
Next, we examine Gemma’s model architecture, training infrastructure, pre-training, and fine-tuning methods.
Model Architecture
The Gemma model architecture is based on the Transformer decoder. Table 1 summarizes the core parameters of this architecture. The model is trained with a context length of 8192 tokens.
In addition, Google introduced several improvements over the original Transformer paper, including:
- Multi-Query Attention: The 7B model uses multi-head attention, while the 2B checkpoint adopts multi-query attention.
- RoPE Embeddings: Gemma applies Rotary Position Embeddings at every layer instead of absolute positional embeddings. It also shares embeddings between the input and output layers to reduce model size.
- GeGLU Activations: The standard ReLU nonlinearity is replaced with the GeGLU activation function.
- Normalizer Location: Gemma applies normalization to both the input and output of each Transformer sub-layer. This differs from the standard practice of normalizing only one or the other. RMSNorm is used as the normalization layer.
Training Infrastructure
Google used its custom-developed AI accelerator, TPUv5e, to train the Gemma models. TPUv5e pods consist of 256 chips arranged in a 16×16 two-dimensional toroidal mesh.
For the 7B model, Google trained across 16 pods (a total of 4096 TPUv5e chips). The 2B model was pre-trained on 2 pods, totaling 512 TPUv5e chips. Within a single pod, the 7B model used 16-way model sharding combined with 16-way data replication. For the 2B model, only 256-way data replication was required. Optimizer states were further sharded using a technique similar to ZeRO-3. Outside the pod, Google employed the Pathways approach to perform data replication and reduction over the data center network.
Pre-training
Gemma 2B and 7B were trained on 2 trillion and 6 trillion primarily English tokens, respectively, drawn from web documents, mathematics, and code. Unlike Gemini, these models are not multimodal and were not specifically trained to achieve state-of-the-art performance on multilingual tasks.
For compatibility, Google used a subset of Gemini’s SentencePiece tokenizer (Kudo and Richardson, 2018). It splits numbers, does not strip excess whitespace, and follows the techniques described in (Chowdhery et al., 2022) and (Gemini Team, 2023) by applying byte-level encoding to unknown tokens. The vocabulary size is 256k tokens.
Instruction Tuning
Google fine-tuned the Gemma 2B and 7B models through supervised fine-tuning (SFT) on a mixture of synthetic and human-generated prompt-response pairs in text-only, English-only data, and through Reinforcement Learning from Human Feedback (RLHF) using a reward model trained on English-only labeled preference data and a policy based on a set of high-quality prompts.
Experiments showed that both the supervised fine-tuning and RLHF stages are critical for improving performance on downstream automatic evaluations as well as human preference evaluations of model outputs.
Supervised Fine-Tuning
Google selected its mixture data for supervised fine-tuning based on LM-based side-by-side evaluation results. Given a set of held-out prompts, Google generated responses from the test model and from baseline models on the same prompts, then asked a larger, higher-performing model to express its preference between the two responses.
Google also constructed different prompt sets to highlight specific capabilities, such as instruction following, factuality, creativity, and safety. They employed various automated LM “judges” that used multiple techniques, including chain-of-thought prompting and alignment with human preferences.
Formatting
The instruction-tuned models were trained using a specific formatter that adds extra information to annotate all instruction-tuning examples during both training and inference. This serves two purposes: 1) to indicate roles in the conversation (e.g., user role), and 2) to describe conversation turns, especially in multi-turn dialogues. To achieve this, Google reserved special control tokens in the tokenizer.
Table 3 shows the relevant formatting control tokens, and Table 4 shows dialogue examples.
Reinforcement Learning from Human Feedback (RLHF)
Google further fine-tuned the supervised fine-tuning models using RLHF. In addition to collecting preference pairs from human raters, they trained a reward function under the Bradley-Terry model, similar to the approach used for Gemini. The policy was optimized using a variant of REINFORCE with a Kullback–Leibler regularization term relative to the initial tuned model.
As in the SFT stage, for hyperparameter tuning and to further mitigate reward hacking, Google relied on high-capacity models as automatic evaluators and computed comparison results against baseline models.
Evaluation
Google conducted a comprehensive evaluation of Gemma across a wide range of domains using metrics such as human preference, automatic benchmarks, and memorization.
Human Preference Evaluation
In addition to running standard academic benchmarks on the fine-tuned models, Google performed human evaluation studies on the final released candidate models to compare them with the Mistral v0.2 7B Instruct model.
Compared with Mistral v0.2 7B Instruct, Gemma 7B IT achieved a win rate of 51.7%, while Gemma 2B IT achieved a win rate of 41.6%. On approximately 400 prompts testing basic safety protocols, Gemma 7B IT achieved a win rate of 58%, and Gemma 2B IT achieved 56.5%. The corresponding numbers are reported in Table 5.
Automatic Benchmark Evaluation
Google also compared the Gemma 2B and 7B models against several external open-source LLMs on a range of academic benchmarks, as shown in Table 6.
On MMLU, Gemma 7B outperforms all open-source models of the same or smaller size, and even surpasses several larger models, including LLaMA2 13B.
However, human expert performance on this benchmark is 89.8%. Gemini Ultra was the first model to surpass this threshold, indicating that Gemma still has significant room for improvement to reach Gemini and human-level performance.
The Gemma models particularly excel on math and coding benchmarks. On mathematical tasks, Gemma outperforms other models by at least 10 points on both GSM8K and the more challenging MATH benchmark. Similarly, they outperform other open-source models by at least 6 points on HumanEval. On MBPP, Gemma even surpasses the code-tuned CodeLLaMA-7B model (CodeLLaMA scores 41.4%, while Gemma 7B scores 44.4%).
Memorization Evaluation
Google used the method proposed by Anil et al. to test Gemma’s memorization capability. Specifically, they sampled 10,000 documents from each corpus and used the first 50 tokens as the prompt for the model. In this process, Google focused primarily on exact memorization: if the subsequent 50 tokens generated by the model exactly matched the true continuation in the original text, the document was classified as memorized. Figure 2 compares the evaluation results with PaLM and PaLM 2 models of comparable scale, as shown below.
Privacy Data
The possibility that private data may be memorized by large language models is a matter of significant concern. To ensure the safety and reliability of the Gemma pre-trained models, Google applied automated methods to filter out certain private information and other sensitive data from the training set.
To identify potential privacy data, Google used the Google Cloud Data Loss Prevention (DLP) tool. This tool assigns three severity levels based on categories of private data (such as names, email addresses, etc.). Google classified the highest severity level as “sensitive” and the other two as “personal,” then measured how many generated outputs contained sensitive or personal data.
As shown in Figure 3 below, Google did not observe any memorization of sensitive data. However, the Gemma models did memorize some data classified as potentially “personal.” It is worth noting that the tool used in the study may produce many false positives (since it only matches patterns without considering context), meaning the experimental results may overestimate the actual amount of identified private data.
In terms of the volume of memorized data, as shown in Figure 4 below, Google observed approximately 50% more data being memorized, with this increase being largely consistent across all subcategories of the dataset.
Finally, Google also evaluated Gemma’s safety using standardized AI safety benchmarks. The results are shown in Table 8 below.
Reference Link:
https://www.theverge.com/2024/2/21/24078610/google-gemma-gemini-small-ai-model-open-source