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/val_loss.py from AjayRangoji/AR-4B-base: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/eval/val_loss.py
- Command line
-
hf download hf://AjayRangoji/AR-4B-base/training_code/ar/eval/val_loss.py
-
curl -L -o val_loss.py https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/eval/val_loss.py
1.96 kB
| """Validation loss on held-out data the model never trained on.""" | |
| import argparse | |
| import math | |
| import os | |
| import numpy as np | |
| import torch | |
| import torch.nn.functional as F | |
| from ar.data.tokenizer import Tokenizer | |
| from ar.eval.generate import load_model | |
| from ar.model.mask import build_doc_block_mask | |
| def val_loss(model, path, eot_id, device, seq_len=4096, max_windows=200): | |
| data = np.memmap(path, dtype=np.uint32, mode="r") | |
| n = min(max_windows, (len(data) - 1) // seq_len) | |
| total = 0.0 | |
| for i in range(n): | |
| # fixed, non-overlapping windows from the start -> same numbers every run, | |
| # so scores from different checkpoints are directly comparable | |
| chunk = data[i * seq_len : (i + 1) * seq_len + 1].astype(np.int64) | |
| chunk = torch.from_numpy(chunk).to(device) | |
| x, y = chunk[:-1][None], chunk[1:][None] | |
| # same same-document masking as training | |
| is_eot = (x == eot_id).int() | |
| seg = (torch.cumsum(is_eot, dim=1) - is_eot).int() | |
| mask = build_doc_block_mask(seg, seq_len, device=device) | |
| logits = model(x, mask) | |
| total += F.cross_entropy(logits.float().view(-1, logits.size(-1)), y.view(-1)).item() | |
| return total / n, n * seq_len | |
| if __name__ == "__main__": | |
| p = argparse.ArgumentParser() | |
| p.add_argument("--model", required=True) | |
| p.add_argument("--data", nargs="+", required=True) | |
| args = p.parse_args() | |
| device = "cuda" | |
| tok = Tokenizer() | |
| model = load_model(args.model, device) | |
| for path in args.data: | |
| if not os.path.exists(path): | |
| print(f"{os.path.basename(path)}: not found, skipping", flush=True) | |
| continue | |
| loss, ntok = val_loss(model, path, tok.eot_id, device) | |
| # perplexity = e^loss: roughly "how many tokens the model is torn between" | |
| print(f"{os.path.basename(path)}: loss {loss:.4f} | ppl {math.exp(loss):.2f} " | |
| f"| {ntok/1e6:.1f}M tokens", flush=True) |