dvilares/head_qa
Updated • 1.4k • 21
How to use iblai/ibl-multiple-choice-7B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="iblai/ibl-multiple-choice-7B")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("iblai/ibl-multiple-choice-7B")
model = AutoModelForCausalLM.from_pretrained("iblai/ibl-multiple-choice-7B")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use iblai/ibl-multiple-choice-7B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "iblai/ibl-multiple-choice-7B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "iblai/ibl-multiple-choice-7B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/iblai/ibl-multiple-choice-7B
How to use iblai/ibl-multiple-choice-7B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "iblai/ibl-multiple-choice-7B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "iblai/ibl-multiple-choice-7B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "iblai/ibl-multiple-choice-7B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "iblai/ibl-multiple-choice-7B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use iblai/ibl-multiple-choice-7B with Docker Model Runner:
docker model run hf.co/iblai/ibl-multiple-choice-7B
ibleducation/ibl-multiple-choice-7B is a model finetuned on top of mistralai/Mistral-7B-Instruct-v0.1
The model is finetuned to generate a multiple choice questions. The output of the model is a json object with the following entries
aid (answer id) and atext (answer text.) {
"category": "Photosynthesis",
"qtext": "The chlorophyll fluorescence measurement technique is based on the emission of fluorescence by the chlorophylls present in the photosynthetic pigmentation:",
"ra": 4,
"answers": [
{"aid": 1, "atext": "It is used to determine the light absorption characteristics of the pigments."},
{"aid": 2, "atext": "It is used to determine the light emission characteristics of the pigments."},
{"aid": 3, "atext": "It is used to determine the kinetics of light absorption by the pigments."},
{"aid": 4, "atext": "It is used to determine the kinetics of light emission by the pigments."},
{"aid": 5, "atext": "It is used to determine the energy that the pigments emit when they absorb light."}
]
}
Requires: transformers > 4.35.0
pip install transformers
pip install accelerate
from transformers import AutoModelForCausalLM, AutoTokenizer
import transformers
import torch
model_id = "ibleducation/ibl-multiple-choice-7B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
)
pipeline = transformers.pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
)
prompt = "<s>[INST] Algebra [/INST] "
response = pipeline(prompt)
print(response['generated_text'])
Important - Use the prompt template below:
<s>[INST] {prompt} [/INST]