/ Модель

Характеристики

Контекст
131 072 токена
Параметры
7,5 млрд
Размер весов
5,7 ГБ
Лицензия
Llama 3.1
Архитектура
llama · dense
Библиотека
transformers
Опубликована
24 июл 2024

Meta-Llama-3.1-8B-Instruct-GPTQ-INT4

Генерация текстаТекст → текст15 профессий

Это квантованная версия Meta-Llama-3.1-8B-Instruct, разработанной Meta AI и подготовленной сообществом Hugging Quants.

9 307скачиваний за 30 дней42лайкавеса обновлены7 авг 2024

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Тесты пользователейпока нет

Никто ещё не опубликовал тест этой модели. Соберите бенчмарк из своих задач — результат появится здесь.

  1. Добавьте модель в бенчмарк

    Вместе с другими моделями категории «Текст» — сравнение идёт внутри одной категории.

  2. Опишите свои задачи

    Напишите запросы, при необходимости приложите файлы и эталонные ответы.

  3. Запустите и опубликуйте

    Модели ответят на каждую задачу, судья оценит ответы. Опубликованный результат появится на этой странице.

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

Модель предназначена для генерации текста и ведения многоязычных диалогов, включая работу через Transformers, AutoGPTQ и Text Generation Inference. Она подходит для чат-ботов, ассистентов и других сценариев текстового взаимодействия.

Модель содержит 8 миллиардов параметров и работает только с текстом на входе и выходе. Исходная модель поддерживает английский, немецкий, французский, итальянский, португальский, хинди, испанский и тайский языки. В данном варианте веса преобразованы из FP16 в INT4 с использованием GPTQ, zero-point quantization и group size 128, что снижает требования к памяти: для загрузки контрольной точки требуется около 4 ГиБ VRAM без учёта KV-кэша и CUDA-графов.

К преимуществам относятся уменьшенное потребление видеопамяти и возможность локального запуска с поддержкой распространённых инструментов инференса. Ограничения связаны с потерями, возможными при 4-битном квантовании, отсутствием мультимодальных возможностей и необходимостью дополнительной памяти для KV-кэша и генерации. Модель распространяется по лицензии Llama 3.1; условия исходной лицензии Meta необходимо учитывать при использовании.

Для каких профессий подходит15

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Также подходит для

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

[!IMPORTANT] This repository is a community-driven quantized version of the original model meta-llama/Meta-Llama-3.1-8B-Instruct which is the FP16 half-precision official version released by Meta AI.

Model Information

The Meta Llama 3.1 collection of multilingual large language models (LLMs) is a collection of pretrained and instruction tuned generative models in 8B, 70B and 405B sizes (text in/text out). The Llama 3.1 instruction tuned text only models (8B, 70B, 405B) are optimized for multilingual dialogue use cases and outperform many of the available open source and closed chat models on common industry benchmarks.

This repository contains meta-llama/Meta-Llama-3.1-8B-Instruct quantized using AutoGPTQ from FP16 down to INT4 using the GPTQ kernels performing zero-point quantization with a group size of 128.

Model Usage

[!NOTE] In order to run the inference with Llama 3.1 8B Instruct GPTQ in INT4, around 4 GiB of VRAM are needed only for loading the model checkpoint, without including the KV cache or the CUDA graphs, meaning that there should be a bit over that VRAM available.

In order to use the current quantized model, support is offered for different solutions as transformers, autogptq, or text-generation-inference.

🤗 transformers

In order to run the inference with Llama 3.1 8B Instruct GPTQ in INT4, you need to install the following packages:

pip install -q --upgrade transformers accelerate optimum
pip install -q --no-build-isolation auto-gptq

To run the inference on top of Llama 3.1 8B Instruct GPTQ in INT4 precision, the GPTQ model can be instantiated as any other causal language modeling model via AutoModelForCausalLM and run the inference normally.

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
  model_id,
  torch_dtype=torch.float16,
  low_cpu_mem_usage=True,
  device_map="auto",
)

prompt = [
  {"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
  {"role": "user", "content": "What's Deep Learning?"},
]
inputs = tokenizer.apply_chat_template(
  prompt,
  tokenize=True,
  add_generation_prompt=True,
  return_tensors="pt",
  return_dict=True,
).to("cuda")

outputs = model.generate(**inputs, do_sample=True, max_new_tokens=256)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))

AutoGPTQ

In order to run the inference with Llama 3.1 8B Instruct GPTQ in INT4, you need to install the following packages:

pip install -q --upgrade transformers accelerate optimum
pip install -q --no-build-isolation auto-gptq

Alternatively, one may want to run that via AutoGPTQ even though it's built on top of 🤗 transformers, which is the recommended approach instead as described above.

import torch
from auto_gptq import AutoGPTQForCausalLM
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoGPTQForCausalLM.from_pretrained(
  model_id,
  torch_dtype=torch.float16,
  low_cpu_mem_usage=True,
  device_map="auto",
)

prompt = [
  {"role": "system", "content": "You are a helpful assistant, that responds as a pirate."},
  {"role": "user", "content": "What's Deep Learning?"},
]
inputs = tokenizer.apply_chat_template(
  prompt,
  tokenize=True,
  add_generation_prompt=True,
  return_tensors="pt",
  return_dict=True,
).to("cuda")

outputs = model.generate(**inputs, do_sample=True, max_new_tokens=256)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))

The AutoGPTQ script has been adapted from AutoGPTQ/examples/quantization/basic_usage.py.

🤗 Text Generation Inference (TGI)

To run the text-generation-launcher with Llama 3.1 8B Instruct GPTQ in INT4 with Marlin kernels for optimized inference speed, you will need to have Docker installed (see installation notes) and the huggingface_hub Python package as you need to login to the Hugging Face Hub.

pip install -q --upgrade huggingface_hub
huggingface-cli login

Then you just need to run the TGI v2.2.0 (or higher) Docker container as follows:

docker run --gpus all --shm-size 1g -ti -p 8080:80 \
  -v hf_cache:/data \
  -e MODEL_ID=hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4 \
  -e QUANTIZE=gptq \
  -e HF_TOKEN=$(cat ~/.cache/huggingface/token) \
  -e MAX_INPUT_LENGTH=4000 \
  -e MAX_TOTAL_TOKENS=4096 \
  ghcr.io/huggingface/text-generation-inference:2.2.0

[!NOTE] TGI will expose different endpoints, to see all the endpoints available check TGI OpenAPI Specification.

To send request to the deployed TGI endpoint compatible with OpenAI OpenAPI specification i.e. /v1/chat/completions:

curl 0.0.0.0:8080/v1/chat/completions \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "tgi",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "What is Deep Learning?"
      }
    ],
    "max_tokens": 128
  }'

Or programatically via the huggingface_hub Python client as follows:

import os
from huggingface_hub import InferenceClient

client = InferenceClient(base_url="http://0.0.0.0:8080", api_key=os.getenv("HF_TOKEN", "-"))

chat_completion = client.chat.completions.create(
  model="hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is Deep Learning?"},
  ],
  max_tokens=128,
)

Alternatively, the OpenAI Python client can also be used (see installation notes) as follows:

import os
from openai import OpenAI

client = OpenAI(base_url="http://0.0.0.0:8080/v1", api_key=os.getenv("OPENAI_API_KEY", "-"))

chat_completion = client.chat.completions.create(
  model="tgi",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is Deep Learning?"},
  ],
  max_tokens=128,
)

vLLM

To run vLLM with Llama 3.1 8B Instruct GPTQ in INT4, you will need to have Docker installed (see installation notes) and run the latest vLLM Docker container as follows:

docker run --runtime nvidia --gpus all --ipc=host -p 8000:8000 \
  -v hf_cache:/root/.cache/huggingface \
  vllm/vllm-openai:latest \
  --model hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4 \
  --quantization gptq_marlin \
  --max-model-len 4096

To send request to the deployed vLLM endpoint compatible with OpenAI OpenAPI specification i.e. /v1/chat/completions:

curl 0.0.0.0:8000/v1/chat/completions \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "What is Deep Learning?"
      }
    ],
    "max_tokens": 128
  }'

Or programatically via the openai Python client (see installation notes) as follows:

import os
from openai import OpenAI

client = OpenAI(base_url="http://0.0.0.0:8000/v1", api_key=os.getenv("VLLM_API_KEY", "-"))

chat_completion = client.chat.completions.create(
  model="hugging-quants/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is Deep Learning?"},
  ],
  max_tokens=128,
)

Quantization Reproduction

[!NOTE] In order to quantize Llama 3.1 8B Instruct using AutoGPTQ, you will need to use an instance with at least enough CPU RAM to fit the whole model i.e. ~8GiB, and an NVIDIA GPU with 16GiB of VRAM to quantize it.

In order to quantize Llama 3.1 8B Instruct with GPTQ in INT4, you need to install the following packages:

pip install -q --upgrade transformers accelerate optimum
pip install -q --no-build-isolation auto-gptq

Then run the following script, adapted from AutoGPTQ/examples/quantization/basic_usage.py.

import random

import numpy as np
import torch

from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
from datasets import load_dataset
from transformers import AutoTokenizer

pretrained_model_dir = "meta-llama/Meta-Llama-3.1-8B-Instruct"
quantized_model_dir = "meta-llama/Meta-Llama-3.1-8B-Instruct-GPTQ-INT4"

print("Loading tokenizer, dataset, and tokenizing the dataset...")
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_dir, use_fast=True)
dataset = load_dataset("Salesforce/wikitext", "wikitext-2-raw-v1", split="train")
encodings = tokenizer("\n\n".join(dataset["text"]), return_tensors="pt")

print("Setting random seeds...")
random.seed(0)
np.random.seed(0)
torch.random.manual_seed(0)

print("Setting calibration samples...")
nsamples = 128
seqlen = 2048
calibration_samples = []
for _ in range(nsamples):
    i = random.randint(0, encodings.input_ids.shape[1] - seqlen - 1)
    j = i + seqlen
    input_ids = encodings.input_ids[:, i:j]
    attention_mask = torch.ones_like(input_ids)
    calibration_samples.append({"input_ids": input_ids, "attention_mask": attention_mask})

quantize_config = BaseQuantizeConfig(
    bits=4,  # quantize model to 4-bit
    group_size=128,  # it is recommended to set the value to 128
    desc_act=True,  # set to False can significantly speed up inference but the perplexity may slightly bad
    sym=True,  # using symmetric quantization so that the range is symmetric allowing the value 0 to be precisely represented (can provide speedups)
    damp_percent=0.1,  # see https://github.com/AutoGPTQ/AutoGPTQ/issues/196
)

# load un-quantized model, by default, the model will always be loaded into CPU memory
print("Load unquantized model...")
model = AutoGPTQForCausalLM.from_pretrained(pretrained_model_dir, quantize_config)

# quantize model, the examples should be list of dict whose keys can only be "input_ids" and "attention_mask"
print("Quantize model with calibration samples...")
model.quantize(calibration_samples)

# save quantized model using safetensors
model.save_quantized(quantized_model_dir, use_safetensors=True)

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

vLLM

Можно запустить

Подбираем GPU…

Класс архитектуры
LlamaForCausalLM
Ревизия весов
f184d2b

0 моделей