Text Generation
Transformers
Safetensors
English
qwen2
chat
conversational
text-generation-inference
4-bit precision
awq
Instructions to use lindazeng979/iol-baseline with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lindazeng979/iol-baseline with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lindazeng979/iol-baseline") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("lindazeng979/iol-baseline") model = AutoModelForCausalLM.from_pretrained("lindazeng979/iol-baseline", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lindazeng979/iol-baseline with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lindazeng979/iol-baseline" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lindazeng979/iol-baseline", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/lindazeng979/iol-baseline
- SGLang
How to use lindazeng979/iol-baseline 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 "lindazeng979/iol-baseline" \ --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": "lindazeng979/iol-baseline", "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 "lindazeng979/iol-baseline" \ --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": "lindazeng979/iol-baseline", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use lindazeng979/iol-baseline with Docker Model Runner:
docker model run hf.co/lindazeng979/iol-baseline
Download script.py from lindazeng979/iol-baseline: direct link, hf CLI and curl.
- Browser
- Download file 3.53 kB
-
https://huggingface.co/lindazeng979/iol-baseline/resolve/main/script.py
- Command line
-
hf download hf://lindazeng979/iol-baseline/script.py
-
curl -L -o script.py https://huggingface.co/lindazeng979/iol-baseline/resolve/main/script.py
3.53 kB
| #import subprocess, sys | |
| #subprocess.run([sys.executable, "-m", "pip", "install", "-q", | |
| # "transformers>=4.43", "accelerate>=0.30", "torch>=2.2", "pandas"], check=True) | |
| import os | |
| # The repo is the working directory at run time, and the sandbox has no network. | |
| os.environ["HF_HUB_OFFLINE"] = "1" | |
| os.environ["TRANSFORMERS_OFFLINE"] = "1" | |
| MODEL_ID = "." # "." "./model" # your model's weights are shipped in this repo | |
| import re | |
| import json | |
| import pandas as pd | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| tok = AutoTokenizer.from_pretrained(MODEL_ID) | |
| if tok.pad_token_id is None: | |
| tok.pad_token = tok.eos_token | |
| model = AutoModelForCausalLM.from_pretrained( | |
| MODEL_ID, | |
| torch_dtype=torch.float16, | |
| device_map="auto", | |
| ).eval() | |
| df = pd.read_csv("/tmp/data/test.csv", dtype=str).fillna("") | |
| rows = [] | |
| # ===== CHANGE HERE — your prompt (the main lever: how you ask the model) ===== | |
| SYSTEM = ( | |
| "You solve International Linguistics Olympiad problems by reasoning from the " | |
| "data you are given. You may meet a task type you have never seen: read the " | |
| "instruction and the examples, and answer in the same form they use. " | |
| "Common task types and what to give -- " | |
| "translation: the translated form only, in the language the task asks for; " | |
| "fill_blanks: only the missing form for each blank; " | |
| "match_letters: only the option letter (for example A, B, C); " | |
| "text_to_num: the number in digits; " | |
| "num_to_text: the number written out in words, in the language asked; " | |
| "any other type: give exactly what the instruction asks, nothing else. " | |
| "Reason step by step first. Then write a line that says exactly FINAL ANSWERS: " | |
| "and, below it, one answer per line in the order the items are asked -- the " | |
| "bare answer only, no numbering, no quotes, no extra text." | |
| ) | |
| # ===== CHANGE HERE — how you read the answers back (must match the format your prompt asks for) ===== | |
| def parse_answers(text): | |
| """Keep only the lines after the last 'FINAL ANSWERS:' marker, one answer per line.""" | |
| marker = list(re.finditer(r"(?im)^\s*final answers?\s*:?\s*$", text)) | |
| if marker: | |
| text = text[marker[-1].end():] | |
| answers = [] | |
| for line in text.splitlines(): | |
| line = re.sub(r"^\s*\d+[.)]\s*", "", line).strip() # drop "1. " / "2) " if the model adds it | |
| if line: | |
| answers.append(line) | |
| return answers | |
| for _, r in df.iterrows(): | |
| messages = [ | |
| { | |
| "role": "system", | |
| "content": SYSTEM | |
| }, | |
| { | |
| "role": "user", | |
| "content": f"{r['context'].strip()}\n\n{r['query'].strip()}", | |
| }, | |
| ] | |
| inputs = tok.apply_chat_template( | |
| messages, | |
| add_generation_prompt=True, | |
| return_tensors="pt", | |
| return_dict=True, | |
| ).to(model.device) | |
| input_length = inputs["input_ids"].shape[-1] | |
| with torch.no_grad(): | |
| out = model.generate( | |
| **inputs, | |
| max_new_tokens=512, | |
| do_sample=False, | |
| pad_token_id=tok.pad_token_id, | |
| ) | |
| text = tok.decode( | |
| out[0][input_length:], | |
| skip_special_tokens=True, | |
| ).strip() | |
| answers = parse_answers(text) | |
| #answers = [ | |
| # line.strip() | |
| # for line in text.splitlines() | |
| # if line.strip() | |
| #] | |
| rows.append({ | |
| "id": r["id"], | |
| "pred": json.dumps(answers, ensure_ascii=False), | |
| }) | |
| pd.DataFrame(rows).to_csv("submission.csv", index=False) |