Text Generation
Transformers
Safetensors
English
qwen2
chat
conversational
text-generation-inference
Instructions to use ritaberrada/iol-bnb-test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ritaberrada/iol-bnb-test with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ritaberrada/iol-bnb-test") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ritaberrada/iol-bnb-test") model = AutoModelForCausalLM.from_pretrained("ritaberrada/iol-bnb-test", device_map="auto") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ritaberrada/iol-bnb-test with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ritaberrada/iol-bnb-test" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ritaberrada/iol-bnb-test", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ritaberrada/iol-bnb-test
- SGLang
How to use ritaberrada/iol-bnb-test 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 "ritaberrada/iol-bnb-test" \ --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": "ritaberrada/iol-bnb-test", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "ritaberrada/iol-bnb-test" \ --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": "ritaberrada/iol-bnb-test", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ritaberrada/iol-bnb-test with Docker Model Runner:
docker model run hf.co/ritaberrada/iol-bnb-test
Upload script.py with huggingface_hub
Browse files
script.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.environ["HF_HUB_OFFLINE"] = "1"
|
| 3 |
+
os.environ["TRANSFORMERS_OFFLINE"] = "1"
|
| 4 |
+
MODEL_ID = "."
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import torch
|
| 9 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 10 |
+
|
| 11 |
+
# bitsandbytes 4-bit (NF4). float16 compute dtype: the T4 is Turing, no native bfloat16.
|
| 12 |
+
bnb_config = BitsAndBytesConfig(
|
| 13 |
+
load_in_4bit=True,
|
| 14 |
+
bnb_4bit_quant_type="nf4",
|
| 15 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
tok = AutoTokenizer.from_pretrained(MODEL_ID)
|
| 19 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 20 |
+
MODEL_ID, quantization_config=bnb_config, device_map="auto"
|
| 21 |
+
).eval()
|
| 22 |
+
print("loaded model in 4-bit (bitsandbytes)", flush=True)
|
| 23 |
+
|
| 24 |
+
df = pd.read_csv("/tmp/data/test.csv", dtype=str).fillna("")
|
| 25 |
+
|
| 26 |
+
rows = []
|
| 27 |
+
for _, r in df.iterrows():
|
| 28 |
+
messages = [
|
| 29 |
+
{"role": "system", "content":
|
| 30 |
+
"You solve International Linguistics Olympiad problems. Answer every numbered "
|
| 31 |
+
"item. Put each answer on its own line, in order, with no numbering and no extra text."},
|
| 32 |
+
{"role": "user", "content": f"{r['context'].strip()}\n\n{r['query'].strip()}"},
|
| 33 |
+
]
|
| 34 |
+
ids = tok.apply_chat_template(
|
| 35 |
+
messages, add_generation_prompt=True, return_tensors="pt",
|
| 36 |
+
).to(model.device)
|
| 37 |
+
with torch.no_grad():
|
| 38 |
+
out = model.generate(ids, max_new_tokens=256, do_sample=False)
|
| 39 |
+
text = tok.decode(out[0][ids.shape[-1]:], skip_special_tokens=True).strip()
|
| 40 |
+
answers = [ln.strip() for ln in text.splitlines() if ln.strip()]
|
| 41 |
+
rows.append({"id": r["id"], "pred": json.dumps(answers, ensure_ascii=False)})
|
| 42 |
+
print(f"{len(rows)}/{len(df)} done", flush=True)
|
| 43 |
+
|
| 44 |
+
pd.DataFrame(rows).to_csv("submission.csv", index=False)
|
| 45 |
+
print("wrote submission.csv", flush=True)
|