Text Generation
Transformers
Safetensors
Arabic
llama
arabic
reasoning
chain-of-thought
math
gsm8k
small-language-model
slm
sft
conversational
text-generation-inference
Instructions to use oddadmix/Nawah-Math-Reasoning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use oddadmix/Nawah-Math-Reasoning with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="oddadmix/Nawah-Math-Reasoning") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("oddadmix/Nawah-Math-Reasoning") model = AutoModelForCausalLM.from_pretrained("oddadmix/Nawah-Math-Reasoning", 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 oddadmix/Nawah-Math-Reasoning with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "oddadmix/Nawah-Math-Reasoning" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "oddadmix/Nawah-Math-Reasoning", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/oddadmix/Nawah-Math-Reasoning
- SGLang
How to use oddadmix/Nawah-Math-Reasoning 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 "oddadmix/Nawah-Math-Reasoning" \ --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": "oddadmix/Nawah-Math-Reasoning", "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 "oddadmix/Nawah-Math-Reasoning" \ --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": "oddadmix/Nawah-Math-Reasoning", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use oddadmix/Nawah-Math-Reasoning with Docker Model Runner:
docker model run hf.co/oddadmix/Nawah-Math-Reasoning
| """ | |
| Second pass over segments whose greedy translation failed validation. | |
| Two recovery strategies, tried in order, keeping the first candidate that validates: | |
| 1. beam search (beam_width=4) — what the Seed-X authors recommend | |
| 2. sampled best-of-8 — a different part of the distribution when beam search repeats the error | |
| Recovered translations are appended to the cache, overriding the greedy result. | |
| """ | |
| import json | |
| import os | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, ".") | |
| from build_dataset import check | |
| from gsm_common import SRC_PROMPT | |
| OUT = Path("out_gsm") | |
| CACHE = OUT / "translations.jsonl" | |
| MODEL = "./models/Seed-X-PPO-7B" | |
| def load(): | |
| trans = {} | |
| with open(CACHE, encoding="utf-8") as fh: | |
| for line in fh: | |
| try: | |
| r = json.loads(line) | |
| except json.JSONDecodeError: | |
| continue | |
| trans[r["src"]] = r["tgt"] | |
| rows = [json.loads(l) for l in open(OUT / "selected_rows.jsonl", encoding="utf-8")] | |
| kind = {} | |
| for r in rows: | |
| kind.setdefault(r["question"], "question") | |
| kind.setdefault(r["thinking"], "thinking") | |
| return trans, kind | |
| def main(): | |
| trans, kind = load() | |
| failed = [ | |
| s for s, t in trans.items() | |
| if check(s, t, strict=(kind.get(s) == "thinking")) is not None | |
| ] | |
| print(f"[*] {len(failed)}/{len(trans)} segments failed validation ({len(failed)/len(trans):.2%})") | |
| if not failed: | |
| return | |
| from vllm import LLM, SamplingParams | |
| from vllm.sampling_params import BeamSearchParams | |
| llm = LLM(model=MODEL, max_num_seqs=256, gpu_memory_utilization=0.92, max_model_len=1024) | |
| prompts = [SRC_PROMPT.format(text=s) for s in failed] | |
| recovered = {} | |
| # Beam search is disabled by default: vLLM 0.8.5 runs it as a Python-level loop and it took | |
| # >50 min on ~4.8k segments without finishing, versus ~2 min for the batched sampling path | |
| # below. Set RETRY_BEAM=1 to use it anyway. | |
| if os.environ.get("RETRY_BEAM") == "1": | |
| print("[*] pass 1: beam search") | |
| outs = llm.beam_search([{"prompt": p} for p in prompts], BeamSearchParams(beam_width=4, max_tokens=256)) | |
| still = [] | |
| for src, o in zip(failed, outs): | |
| strict = kind.get(src) == "thinking" | |
| for seq in o.sequences: | |
| cand = seq.text.strip() | |
| if check(src, cand, strict=strict) is None: | |
| recovered[src] = cand | |
| break | |
| else: | |
| still.append(src) | |
| print(f" recovered {len(recovered)}, still failing {len(still)}") | |
| else: | |
| print("[*] pass 1: skipped (beam search disabled)") | |
| still = list(failed) | |
| if still: | |
| print("[*] pass 2: sampled best-of-8") | |
| params = SamplingParams(n=8, temperature=0.8, top_p=0.95, max_tokens=256, skip_special_tokens=True) | |
| outs = llm.generate([SRC_PROMPT.format(text=s) for s in still], params) | |
| final = [] | |
| for src, o in zip(still, outs): | |
| strict = kind.get(src) == "thinking" | |
| for cand in o.outputs: | |
| text = cand.text.strip() | |
| if check(src, text, strict=strict) is None: | |
| recovered[src] = text | |
| break | |
| else: | |
| final.append(src) | |
| print(f" recovered {len(recovered)} total, unrecoverable {len(final)}") | |
| with open(CACHE, "a", encoding="utf-8") as fh: | |
| for src, tgt in recovered.items(): | |
| fh.write(json.dumps({"src": src, "tgt": tgt}, ensure_ascii=False) + "\n") | |
| print(f"[+] appended {len(recovered)} recovered translations to {CACHE}") | |
| if __name__ == "__main__": | |
| main() | |