Edit model card

Phi-3-small-128k-instruct-GGUF

Description

This repo contains GGUF format model files for Phi-3-small-128k-instruct.

About GGUF

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. Here is an incomplete list of clients and libraries that are known to support GGUF:

  • llama.cpp. This is the source project for GGUF, providing both a Command Line Interface (CLI) and a server option.
  • text-generation-webui, Known as the most widely used web UI, this project boasts numerous features and powerful extensions, and supports GPU acceleration.
  • 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​
  • KoboldCpp, A comprehensive web UI offering GPU acceleration across all platforms and architectures, particularly renowned for storytelling.
  • GPT4All, This is a free and open source GUI that runs locally, supporting Windows, Linux, and macOS with full GPU acceleration.
  • LM Studio An intuitive and powerful local GUI for Windows and macOS (Silicon), featuring GPU acceleration.
  • LoLLMS Web UI. A notable web UI with a variety of unique features, including a comprehensive model library for easy model selection.
  • Faraday.dev, An attractive, user-friendly character-based chat GUI for Windows and macOS (both Silicon and Intel), also offering GPU acceleration.
  • llama-cpp-python, A Python library equipped with GPU acceleration, LangChain support, and an OpenAI-compatible API server.
  • candle, A Rust-based ML framework focusing on performance, including GPU support, and designed for ease of use.
  • ctransformers, A Python library featuring GPU acceleration, LangChain support, and an OpenAI-compatible AI server.
  • localGPT An open-source initiative enabling private conversations with documents.

Explanation of quantisation methods

Click to see details The new methods available are:
  • 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)
  • 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.
  • 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.
  • GGML_TYPE_Q5_K - "type-1" 5-bit quantization. Same super-block structure as GGML_TYPE_Q4_K resulting in 5.5 bpw
  • 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.

How to download GGUF files

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.

The following clients/libraries will automatically download models for you, providing a list of available models to choose from:

  • LM Studio
  • LoLLMS Web UI
  • Faraday.dev

In text-generation-webui

Under Download Model, you can enter the model repo: LiteLLMs/Phi-3-small-128k-instruct-GGUF and below it, a specific filename to download, such as: Q4_0/Q4_0-00001-of-00009.gguf.

Then click Download.

On the command line, including multiple files at once

I recommend using the huggingface-hub Python library:

pip3 install huggingface-hub

Then you can download any individual model file to the current directory, at high speed, with a command like this:

huggingface-cli download LiteLLMs/Phi-3-small-128k-instruct-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks False
More advanced huggingface-cli download usage (click to read)

You can also download multiple files at once with a pattern:

huggingface-cli download LiteLLMs/Phi-3-small-128k-instruct-GGUF --local-dir . --local-dir-use-symlinks False --include='*Q4_K*gguf'

For more documentation on downloading with huggingface-cli, please see: HF -> Hub Python Library -> Download files -> Download from the CLI.

To accelerate downloads on fast connections (1Gbit/s or higher), install hf_transfer:

pip3 install huggingface_hub[hf_transfer]

And set environment variable HF_HUB_ENABLE_HF_TRANSFER to 1:

HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download LiteLLMs/Phi-3-small-128k-instruct-GGUF Q4_0/Q4_0-00001-of-00009.gguf --local-dir . --local-dir-use-symlinks False

Windows Command Line users: You can set the environment variable by running set HF_HUB_ENABLE_HF_TRANSFER=1 before the download command.

## Example `llama.cpp` command

Make sure you are using llama.cpp from commit d0cee0d or later.

./main -ngl 35 -m Q4_0/Q4_0-00001-of-00009.gguf --color -c 8192 --temp 0.7 --repeat_penalty 1.1 -n -1 -p "<PROMPT>"

Change -ngl 32 to the number of layers to offload to GPU. Remove it if you don't have GPU acceleration.

Change -c 8192 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.

If you want to have a chat-style conversation, replace the -p <PROMPT> argument with -i -ins

For other parameters and how to use them, please refer to the llama.cpp documentation

How to run in text-generation-webui

Further instructions can be found in the text-generation-webui documentation, here: text-generation-webui/docs/04 ‐ Model Tab.md.

How to run from Python code

You can use GGUF models from Python using the llama-cpp-python or 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.

How to load this model in Python code, using llama-cpp-python

For full documentation, please see: llama-cpp-python docs.

First install the package

Run one of the following commands, according to your system:

# Base ctransformers with no GPU acceleration
pip install llama-cpp-python
# With NVidia CUDA acceleration
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python
# Or with OpenBLAS acceleration
CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS" pip install llama-cpp-python
# Or with CLBLast acceleration
CMAKE_ARGS="-DLLAMA_CLBLAST=on" pip install llama-cpp-python
# Or with AMD ROCm GPU acceleration (Linux only)
CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
# Or with Metal GPU acceleration for macOS systems only
CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
# In windows, to set the variables CMAKE_ARGS in PowerShell, follow this format; eg for NVidia CUDA:
$env:CMAKE_ARGS = "-DLLAMA_OPENBLAS=on"
pip install llama-cpp-python

Simple llama-cpp-python example code

from llama_cpp import Llama
# Set gpu_layers to the number of layers to offload to GPU. Set to 0 if no GPU acceleration is available on your system.
llm = Llama(
  model_path="./Q4_0/Q4_0-00001-of-00009.gguf",  # Download the model file first
  n_ctx=32768,  # The max sequence length to use - note that longer sequence lengths require much more resources
  n_threads=8,            # The number of CPU threads to use, tailor to your system and the resulting performance
  n_gpu_layers=35         # The number of layers to offload to GPU, if you have GPU acceleration available
)
# Simple inference example
output = llm(
  "<PROMPT>", # Prompt
  max_tokens=512,  # Generate up to 512 tokens
  stop=["</s>"],   # Example stop token - not necessarily correct for this specific model! Please check before using.
  echo=True        # Whether to echo the prompt
)
# Chat Completion API
llm = Llama(model_path="./Q4_0/Q4_0-00001-of-00009.gguf", chat_format="llama-2")  # Set chat_format according to the model you are using
llm.create_chat_completion(
    messages = [
        {"role": "system", "content": "You are a story writing assistant."},
        {
            "role": "user",
            "content": "Write a story about llamas."
        }
    ]
)

How to use with LangChain

Here are guides on using llama-cpp-python and ctransformers with LangChain:

Original model card: Phi-3-small-128k-instruct

Model Summary

The Phi-3-Small-128K-Instruct is a 7B parameters, lightweight, state-of-the-art open model trained with the Phi-3 datasets that includes both synthetic data and the filtered publicly available websites data with a focus on high-quality and reasoning dense properties. The model belongs to the Phi-3 family with the Small version in two variants 8K and 128K which is the context length (in tokens) that it can support.

The model has underwent a post-training process that incorporates both supervised fine-tuning and direct preference optimization for the instruction following and safety measures. When assessed against benchmarks testing common sense, language understanding, math, code, long context and logical reasoning, Phi-3-Small-128K-Instruct showcased a robust and state-of-the-art performance among models of the same-size and next-size-up.

Resources and Technical Documentation:

| | Short Context | Long Context | | | -- | -- | - | - | | AGI Eval
5-shot | 43.9 | 42.1 | 45.2 | 42.0 | 48.4 | 49.0 | 59.6 | | MMLU
5-shot | 75.5 | 63.6 | 70.5 | 66.5 | 71.4 | 66.7 | 84.0 | | BigBench Hard
3-shot | 77.6 | 59.6 | 69.7 | 51.5 | 68.3 | 75.6 | 87.7 | | ANLI
7-shot | 55.8 | 48.7 | 55.2 | 57.3 | 58.1 | 64.2 | 71.7 | | HellaSwag
5-shot | 79.6 | 49.8 | 70.4 | 71.1 | 78.8 | 76.2 | 88.3 | | ARC Challenge
10-shot | 90.8 | 78.3 | 87.3 | 82.8 | 87.4 | 88.3 | 95.6 | | ARC Easy
10-shot | 97.3 | 91.4 | 95.6 | 93.4 | 96.3 | 96.1 | 98.8 | | BoolQ
2-shot | 83.7 | 66.0 | 76.6 | 80.9 | 79.1 | 86.4 | 91.3 | | CommonsenseQA
10-shot | 80.8 | 76.2 | 78.1 | 79.0 | 79.6 | 81.8 | 86.7 | | MedQA
2-shot | 46.3 | 49.6 | 62.2 | 60.5 | 63.4 | 58.2 | 83.7 | | OpenBookQA
10-shot | 87.8 | 78.6 | 85.8 | 82.6 | 86.0 | 86.4 | 93.4 | | PIQA
5-shot | 88.1 | 78.1 | 86.0 | 75.7 | 86.6 | 86.2 | 90.1 | | Social IQA
5-shot | 78.7 | 65.5 | 75.9 | 73.9 | 68.3 | 75.4 | 81.7 | | TruthfulQA (MC2)
10-shot | 69.6 | 52.1 | 60.1 | 63.2 | 67.7 | 72.6 | 85.2 | | WinoGrande
5-shot | 80.1 | 55.6 | 62.0 | 65.0 | 68.8 | 72.2 | 86.7 | | TriviaQA
5-shot | 66.0 | 72.3 | 82.2 | 67.7 | 85.8 | 80.2 | 73.3 | | GSM8K Chain of Thought
8-shot | 87.3 | 59.8 | 64.7 | 77.4 | 78.1 | 80.4 | 94.2 | | HumanEval
0-shot | 59.1 | 34.1 | 37.8 | 60.4 | 62.2 | 64.4 | 79.9 | | MBPP
3-shot | 70.3 | 51.5 | 60.2 | 67.7 | 77.8 | 73.2 | 86.7 | | Average | 74.6 | 61.8 | 69.8 | 69.4 | 74.3 | 75.4 | 85.2 |

We take a closer look at different categories across 80 public benchmark datasets at the table below:

| Benchmark | Phi-3-Small-128K-Instruct
7b | Gemma
7B | Mixtral
8x7B | Llama-3-Instruct
8b | GPT-3.5-Turbo
version 1106 | Gemini
Pro | GPT-4-Turbo
version 1106 (Chat) | | -- | - | - | | Popular aggregated benchmark | 70.6 | 59.4 | 66.2 | 59.9 | 67.0 | 67.5 | 80.5 | | Reasoning | 80.3 | 69.1 | 77.0 | 75.7 | 78.3 | 80.4 | 89.3 | | Language understanding | 67.4 | 58.4 | 64.9 | 65.4 | 70.4 | 75.3 | 81.6 | | Code generation | 60.0 | 45.6 | 52.7 | 56.4 | 70.4 | 66.7 | 76.1 | | Math | 48.1 | 35.8 | 40.3 | 41.1 | 52.8 | 50.9 | 67.1 | | Factual knowledge | 41.7 | 46.7 | 58.6 | 43.1 | 63.4 | 54.6 | 45.9 | | Multilingual | 62.6 | 63.2 | 63.4 | 65.0 | 69.1 | 76.5 | 82.0 | | Robustness | 68.7 | 38.4 | 51.0 | 64.5 | 69.3 | 69.7 | 84.6 |

Software

Hardware

Note that by default, the Phi-3-Small model uses flash attention, which requires certain types of GPU hardware to run. We have tested on the following GPU types:

  • NVIDIA A100
  • NVIDIA A6000
  • NVIDIA H100

If you want to run the model on:

  • Optimized inference on GPU, CPU, and Mobile: use the ONNX models 128K

Cross Platform Support

ONNX runtime ecosystem now supports Phi3 small models across platforms and hardware. Optimized phi-3 models are also published here in ONNX format, to run with ONNX Runtime on CPU and GPU across devices, including server platforms, Windows, Linux and Mac desktops, and mobile CPUs, with the precision best suited to each of these targets. DirectML GPU acceleration is supported for Windows desktops GPUs (AMD, Intel, and NVIDIA).
Along with DML, ONNX Runtime provides cross platform support for Phi3 Small across a range of devices CPU, GPU, and mobile. Here are some of the optimized configurations we have added:

  1. ONNX models for int4 DML: Quantized to int4 via AWQ
  2. ONNX model for fp16 CUDA
  3. ONNX model for int4 CUDA: Quantized to int4 via RTN
  4. ONNX model for int4 CPU and Mobile: Quantized to int4 via RTN

License

The model is licensed under the MIT license.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft’s Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.

Downloads last month

-

Downloads are not tracked for this model. How to track
Unable to determine this model's library. Check the docs .