Text Generation
Transformers
PyTorch
English
llama
english
sql
text2text-generation
text-generation-inference
Instructions to use MRNH/llama-2-7b-coder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MRNH/llama-2-7b-coder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="MRNH/llama-2-7b-coder")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("MRNH/llama-2-7b-coder") model = AutoModelForCausalLM.from_pretrained("MRNH/llama-2-7b-coder") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use MRNH/llama-2-7b-coder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "MRNH/llama-2-7b-coder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MRNH/llama-2-7b-coder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/MRNH/llama-2-7b-coder
- SGLang
How to use MRNH/llama-2-7b-coder 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 "MRNH/llama-2-7b-coder" \ --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": "MRNH/llama-2-7b-coder", "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 "MRNH/llama-2-7b-coder" \ --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": "MRNH/llama-2-7b-coder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use MRNH/llama-2-7b-coder with Docker Model Runner:
docker model run hf.co/MRNH/llama-2-7b-coder
Update README.md
Browse files
README.md
CHANGED
|
@@ -14,27 +14,45 @@ This is a fine-tuned version of LLAMA2 trained (7b) on spider, sql-create-contex
|
|
| 14 |
|
| 15 |
To initialize the model:
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
Use the tokenizer:
|
| 23 |
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
To generate text using the model:
|
| 31 |
-
|
| 32 |
-
#output = model.generate(input["input_ids"],attention_mask=input["attention_mask"],
|
| 33 |
-
# forced_bos_token_id=tokenizer_it.lang_code_to_id["en_XX"])
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
#h.logits, h.loss = model(input_ids=input["input_ids"],
|
| 39 |
-
# attention_mask=input["attention_mask"],
|
| 40 |
-
# labels=input["labels"])
|
|
|
|
| 14 |
|
| 15 |
To initialize the model:
|
| 16 |
|
| 17 |
+
bnb_config = BitsAndBytesConfig(
|
| 18 |
+
load_in_4bit=use_4bit,
|
| 19 |
+
bnb_4bit_quant_type=bnb_4bit_quant_type,
|
| 20 |
+
bnb_4bit_compute_dtype=compute_dtype,
|
| 21 |
+
bnb_4bit_use_double_quant=use_nested_quant,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 25 |
+
model_name,
|
| 26 |
+
quantization_config=bnb_config,
|
| 27 |
+
device_map=device_map,
|
| 28 |
+
trust_remote_code=True
|
| 29 |
+
)
|
| 30 |
|
| 31 |
|
| 32 |
Use the tokenizer:
|
| 33 |
|
| 34 |
|
| 35 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 36 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 37 |
+
tokenizer.padding_side = "right"
|
| 38 |
+
|
| 39 |
+
To get the prompt:
|
| 40 |
+
dataset = dataset.map(
|
| 41 |
+
lambda example: {
|
| 42 |
+
"input": "### Instruction: \nYou are a powerful text-to-SQL model. \
|
| 43 |
+
Your job is to answer questions about a database. You are given \
|
| 44 |
+
a question and context regarding one or more tables. \n\nYou must \
|
| 45 |
+
output the SQL query that answers the question. \
|
| 46 |
+
\n\n \
|
| 47 |
+
### Dialect:\n\nsqlite\n\n \
|
| 48 |
+
### question:\n\n"+ example["question"]+" \
|
| 49 |
+
\n\n### Context:\n\n"+example["context"],
|
| 50 |
+
"answer": example["answer"]
|
| 51 |
+
}
|
| 52 |
+
)
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
To generate text using the model:
|
| 56 |
|
| 57 |
+
output = model.generate(input["input_ids"])
|
| 58 |
|
|
|
|
|
|
|
|
|