---
title: Gemma2-9B-IT-Simpo-Infinity-Preference
canonical_url: "https://www.modelscope.cn/models/BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference"
md_url: "https://www.modelscope.cn/models/BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference.md"
repository: BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference
last_updated: 2024-09-13
model_type:
  - gemma2
architectures:
  - Gemma2ForCausalLM
base_model:
  - google/gemma-2-9b-it
base_model_relation: finetune
parameters: 9.2B
tensor_type:
  - BF16
library_name:
  - pytorch
  - transformer
  - safetensors
frameworks:
  - pytorch
language:
  - en
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 2231
stars: 0
---

# Gemma2-9B-IT-Simpo-Infinity-Preference

> Gemma2-9B-IT-Simpo-Infinity-Preference - BAAI 在 ModelScope 开源的模型。Overview Gemma2-9B-IT-Simpo-Infinity-Preference is based on gemma-2-9b-it and finetuned on Infinity-Preference with Simpo. It achieves 73.4% LC win-rate on AlpacaEval 2.0 and 58.1% win-rate on…

BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference 是 ModelScope 魔搭社区上的 9.2B 参数机器学习模型，基于 google/gemma-2-9b-it 构建，可用 deploy_task text/emb、lmdeploy 0.9.1、sglang 0.5.2 部署。

- **Repository**: BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference
- **Parameters**: 9.2B
- **Base model**: google/gemma-2-9b-it
- **Inference backends**: deploy_task text/emb, lmdeploy 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Downloads**: 2231
- **Stars**: 0
- **Last updated**: 2024-09-13

Source: https://www.modelscope.cn/models/BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference

---

## Overview
Gemma2-9B-IT-Simpo-Infinity-Preference is based on [gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it) and finetuned on [Infinity-Preference](https://huggingface.co/datasets/BAAI/Infinity-Preference) with [Simpo](https://github.com/princeton-nlp/SimPO). It achieves 73.4% LC win-rate on AlpacaEval 2.0 and 58.1% win-rate on Arena-Hard against GPT-4.

## Training hyperparameters

```yaml
beta: 10
gamma_beta_ratio: 1
learning_rate: 8.0e-7
log_level: info
logging_steps: 5
max_length: 2048
max_prompt_length: 1800
num_train_epochs: 1
batch_size: 128
```

## How to Use

Gemma2-9B-IT-Simpo-Infinity-Preference adopt the same chat template of [gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it):

```bash
<bos><start_of_turn>user
How are you?<end_of_turn>
<start_of_turn>model
Hi!<end_of_turn>
```

To apply this model and template in conversation scenarios, you can refer to the following code:

```python
from transformers import AutoModelForCausalLM, AutoTokenizer, LogitsProcessorList
import torch
device = "cuda" # the device to load the model onto

model = AutoModelForCausalLM.from_pretrained("BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference",
    torch_dtype=torch.bfloat16,
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("BAAI/Gemma2-9B-IT-Simpo-Infinity-Preference")

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "user", "content": prompt}
]

text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

logits_processor = LogitsProcessorList(
            [
                MinLengthLogitsProcessor(1, eos_token_id=tokenizer.eos_token_id),
                TemperatureLogitsWarper(0.8),
            ]
 )
 
generated_ids = model.generate(
    model_inputs.input_ids,
    logits_processor=logits_processor,
    max_new_tokens=512
)

generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
```

## Disclaimer

The resources, including code, data, and model weights, associated with this project are restricted for academic research purposes only and cannot be used for commercial purposes. The content produced by any version of Infinity-Preference is influenced by uncontrollable variables such as randomness, and therefore, the accuracy of the output cannot be guaranteed by this project. This project does not accept any legal liability for the content of the model output, nor does it assume responsibility for any losses incurred due to the use of associated resources and output results.
