Instructions to use AjayRangoji/AR-4B-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AjayRangoji/AR-4B-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AjayRangoji/AR-4B-base", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("AjayRangoji/AR-4B-base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AjayRangoji/AR-4B-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AjayRangoji/AR-4B-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AjayRangoji/AR-4B-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/AjayRangoji/AR-4B-base
- SGLang
How to use AjayRangoji/AR-4B-base 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 "AjayRangoji/AR-4B-base" \ --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": "AjayRangoji/AR-4B-base", "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 "AjayRangoji/AR-4B-base" \ --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": "AjayRangoji/AR-4B-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use AjayRangoji/AR-4B-base with Docker Model Runner:
docker model run hf.co/AjayRangoji/AR-4B-base
Download training_code/ar/eval/gsm8k.py from AjayRangoji/AR-4B-base: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/eval/gsm8k.py
- Command line
-
hf download hf://AjayRangoji/AR-4B-base/training_code/ar/eval/gsm8k.py
-
curl -L -o gsm8k.py https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/eval/gsm8k.py
2.55 kB
| """GSM8K (grade-school math): 8-shot, step-by-step, greedy, exact-match accuracy.""" | |
| import argparse | |
| import re | |
| from datasets import load_dataset | |
| from ar.data.tokenizer import Tokenizer | |
| from ar.eval.batch_gen import generate_batch | |
| from ar.eval.generate import load_model | |
| def clean_answer(ans): | |
| # train answers look like "... <<3*4=12>>12 ... #### 12"; turn them into | |
| # plain worked solutions that end with "The answer is 12." | |
| ans = re.sub(r"<<.*?>>", "", ans) | |
| body, final = ans.split("####") | |
| return body.strip() + f"\nThe answer is {final.strip()}." | |
| def extract_number(text): | |
| # prefer "The answer is X"; otherwise fall back to the last number written | |
| m = re.search(r"The answer is\s*\$?(-?[\d,]*\.?\d+)", text) | |
| nums = [m.group(1)] if m else re.findall(r"-?[\d,]*\.?\d+", text) | |
| if not nums: | |
| return None | |
| try: | |
| return float(nums[-1].replace(",", "")) | |
| except ValueError: | |
| return None | |
| if __name__ == "__main__": | |
| p = argparse.ArgumentParser() | |
| p.add_argument("--model", required=True) | |
| p.add_argument("--n", type=int, default=250) # fixed subset -> comparable runs | |
| p.add_argument("--batch", type=int, default=8) | |
| args = p.parse_args() | |
| device = "cuda" | |
| tok = Tokenizer() | |
| model = load_model(args.model, device) | |
| train = load_dataset("openai/gsm8k", "main", split="train") | |
| test = load_dataset("openai/gsm8k", "main", split="test").select(range(args.n)) | |
| shots = "".join(f"Question: {ex['question']}\nAnswer: {clean_answer(ex['answer'])}\n\n" | |
| for ex in train.select(range(8))) | |
| correct = 0 | |
| for i in range(0, len(test), args.batch): | |
| chunk = test.select(range(i, min(i + args.batch, len(test)))) | |
| prompts = [shots + f"Question: {ex['question']}\nAnswer:" for ex in chunk] | |
| outs = generate_batch(model, tok, prompts, seq_len=2048, max_new=256, | |
| stop=["Question:"], device=device) | |
| for ex, out in zip(chunk, outs): | |
| gold = float(ex["answer"].split("####")[-1].strip().replace(",", "")) | |
| pred = extract_number(out) | |
| correct += pred is not None and abs(pred - gold) < 1e-6 | |
| done = min(i + args.batch, len(test)) | |
| print(f"[{done}/{len(test)}] accuracy so far: {100 * correct / done:.1f}%", flush=True) | |
| if i == 0: | |
| print("--- example output ---\n" + outs[0].strip() + "\n----------------------", flush=True) | |
| print(f"GSM8K ({len(test)} questions, 8-shot): {100 * correct / len(test):.1f}%") |