Instructions to use edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k") model = AutoModelForCausalLM.from_pretrained("edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k
- SGLang
How to use edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k with Docker Model Runner:
docker model run hf.co/edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k
LlaMa 2 7b 4-bit GPTQ Python Coder 👩💻
This model is the GPTQ Quantization of my Llama 2 7B 4-bit Python Coder. The base model link is here
The quantization parameters for the GPTQ algo are:
- 4-bit quantization
- Group size is 128
- Dataset C4
- Decreasing activation is False
Model Description
Llama 2 7B 4-bit Python Coder is a fine-tuned version of the Llama 2 7B model using QLoRa in 4-bit with PEFT library and bitsandbytes.
Quantization
A quick definition extracted from a great article in Medium by Benjamin Marie "GPTQ or bitsandbytes: Which Quantization Method to Use for LLMs — Examples with Llama 2" (Only for Medium subscribers)
"GPTQ (Frantar et al., 2023) was first applied to models ready to deploy. In other words, once the model is fully fine-tuned, GPTQ will be applied to reduce its size. GPTQ can lower the weight precision to 4-bit or 3-bit. In practice, GPTQ is mainly used for 4-bit quantization. 3-bit has been shown very unstable (Dettmers and Zettlemoyer, 2023). It quantizes without loading the entire model into memory. Instead, GPTQ loads and quantizes the LLM module by module. Quantization also requires a small sample of data for calibration which can take more than one hour on a consumer GPU."
Example of usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
instruction="Write a Python function to display the first and last elements of a list."
input=""
prompt = f"""### Instruction:
Use the Task below and the Input given to write the Response, which is a programming code that can solve the Task.
### Task:
{instruction}
### Input:
{input}
### Response:
"""
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
# with torch.inference_mode():
outputs = model.generate(input_ids=input_ids, max_new_tokens=128, do_sample=True, top_p=0.9,temperature=0.3)
print(f"Prompt:\n{prompt}\n")
print(f"Generated instruction:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
Citation
@misc {edumunozsala_2023,
author = { {Eduardo Muñoz} },
title = { llama-2-7b-int4-GPTQ-python-coder },
year = 2023,
url = { https://huggingface.co/edumunozsala/llama-2-7b-int4-GPTQ-python-code-20k },
publisher = { Hugging Face }
}
- Downloads last month
- 3