
## Model Details: Neural-Chat-v3-3-Slerp

This model is a merged model with a method called **SLERP**. SLERP spherically interpolates the parameters of two models, combining a base model and another model. The code for merging the models can be found in the [mergekit](https://github.com/cg123/mergekit) GitHub repository. The base model in our case was [meta-math/MetaMath-Mistral-7B](https://huggingface.co/meta-math/MetaMath-Mistral-7B) and the secondary model was [Intel/neural-chat-7b-v3-3](https://huggingface.co/Intel/neural-chat-7b-v3-3). The model was then aligned using the Direct Performance Optimization (DPO) method with [Intel/orca_dpo_pairs](https://huggingface.co/datasets/Intel/orca_dpo_pairs). 

| Model Detail | Description |
| ----------- | ----------- | 
| Model Authors | Intel. The NeuralChat team with members from DCAI/AISE/AIPT. Core team members: Kaokao Lv, Liang Lv, Chang Wang, Wenxin Zhang, Xuhui Ren, and Haihao Shen. | 
| Date | December, 2023 | 
| Version | v3-3-Slerp | 
| Type | 7B Large Language Model | 
| Paper or Other Resources | [mergekit](https://github.com/cg123/mergekit) GitHub repository | 
| License | Apache 2.0 |
| Questions or Comments | [Community Tab](https://huggingface.co/Intel/neural-chat-7b-v3-3-Slerp/discussions) and [Intel DevHub Discord](https://discord.gg/rv2Gp55UJQ)|

| Intended Use | Description |
| ----------- | ----------- | 
| Primary intended uses | You can use the fine-tuned model for several language-related tasks. Checkout the [LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard) to see how this model is doing. | 
| Primary intended users | Anyone doing inference on language-related tasks. | 
| Out-of-scope uses | This model in most cases will need to be fine-tuned for your particular task.  The model should not be used to intentionally create hostile or alienating environments for people.|

## How To Use
### Reproduce the model
The code for merging the models can be found in the [mergekit](https://github.com/cg123/mergekit) GitHub repository. As documented there, you can use a script to merge models with a YAML file:

```bash
mergekit-yaml path/to/your/config.yml ./output-model-directory [--lazy-unpickle] [--allow-crimes] [... other options]

```
For more information on the arguments accepted by mergekit-yaml run the command mergekit-yaml --help.


### Use the model

### FP32 Inference with Transformers

```python
import transformers

model_name = 'Intel/neural-chat-7b-v3-3-Slerp'
model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)

def generate_response(system_input, user_input):

    # Format the input using the provided template
    prompt = f"### System:\n{system_input}\n### User:\n{user_input}\n### Assistant:\n"

    # Tokenize and encode the prompt
    inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False)

    # Generate a response
    outputs = model.generate(inputs, max_length=1000, num_return_sequences=1)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)

    # Extract only the assistant's response
    return response.split("### Assistant:\n")[-1]

# Example usage
system_input = "You are a math expert assistant. Your mission is to help users understand and solve various math problems. You should provide step-by-step solutions, explain reasonings and give the correct answer."
user_input = "calculate 100 + 520 + 60"
response = generate_response(system_input, user_input)
print(response)

# expected response
"""
To calculate the sum of 100, 520, and 60, we will follow these steps:

1. Add the first two numbers: 100 + 520
2. Add the result from step 1 to the third number: (100 + 520) + 60

Step 1: Add 100 and 520
100 + 520 = 620

Step 2: Add the result from step 1 to the third number (60)
(620) + 60 = 680

So, the sum of 100, 520, and 60 is 680.
"""
```

### INT4 Inference with Transformers and Intel Extension for Transformers
```python
from transformers import AutoTokenizer, TextStreamer
from intel_extension_for_transformers.transformers import AutoModelForCausalLM, WeightOnlyQuantConfig
model_name = "Intel/neural-chat-7b-v3-3-Slerp"     
config = WeightOnlyQuantConfig(compute_dtype="int8", weight_dtype="int4")
prompt = "Once upon a time, there existed a little girl,"

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
inputs = tokenizer(prompt, return_tensors="pt").input_ids
streamer = TextStreamer(tokenizer)

model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=config)
outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)

```

| Factors | Description | 
| ----------- | ----------- | 
| Groups | More details about the dataset and annotations can be found at [meta-math/MetaMathQA](https://huggingface.co/datasets/meta-math/MetaMathQA), the project page https://meta-math.github.io/, and the associated paper at https://arxiv.org/abs/2309.12284. | 
| Instrumentation | The performance of the model can vary depending on the inputs to the model. In this case, the prompts provided can drastically change the prediction of the language model. |
| Environment | - |
| Card Prompts | Model deployment on varying hardware and software will change model performance. |

| Metrics | Description | 
| ----------- | ----------- | 
| Model performance measures | - |
| Decision thresholds | No decision thresholds were used. | 
| Approaches to uncertainty and variability | - | 

| Training and Evaluation Data | Description | 
| ----------- | ----------- | 
| Datasets | The training data for the base model are from [meta-math/MetaMathQA](https://huggingface.co/datasets/meta-math/MetaMathQA), which is augmented from the GSM8k and MATH training sets. There is no contamination from the GSM8k test set, as this was left out during training. |
| Motivation | - |
| Preprocessing | - | 

## Quantitative Analyses 
The detailed Open LLM Leaderboard results can be found here: [https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3-3-Slerp](https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3-3-Slerp) for this model. 

## Ethical Considerations and Limitations
Neural-chat-7b-v3-3-Slerp can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.

Therefore, before deploying any applications of the model, developers should perform safety testing.

## Caveats and Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.

Here are a couple of useful links to learn more about Intel's AI software:
* Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
* Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)

## Disclaimer

The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please cosult an attorney before using this model for commercial purposes.
{"language": ["en"], "license": "apache-2.0", "tags": ["LLMs", "mistral", "math", "Intel"], "datasets": ["meta-math/MetaMathQA", "Intel/orca_dpo_pairs"], "base_model": "meta-math/MetaMath-Mistral-7B"}
transformers pytorch mistral text-generation LLMs math Intel en dataset:meta-math/MetaMathQA dataset:Intel/orca_dpo_pairs arxiv:2309.12284 base_model:meta-math/MetaMath-Mistral-7B license:apache-2.0 autotrain_compatible endpoints_compatible has_space text-generation-inference region:us