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/model/rope.py from AjayRangoji/AR-4B-base: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/model/rope.py
- Command line
-
hf download hf://AjayRangoji/AR-4B-base/training_code/ar/model/rope.py
-
curl -L -o rope.py https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/model/rope.py
1.56 kB
| import torch | |
| import torch.nn as nn | |
| def build_rope_cache(head_dim: int, max_seq_len: int, theta: float = 1_000_000.0): | |
| """Precompute the cos/sin rotation tables used by RoPE. | |
| Returns two tensors of shape (max_seq_len, head_dim), ready to index by position. | |
| """ | |
| # each of the head_dim/2 pairs gets its own rotation speed (fast -> slow) | |
| idx = torch.arange(0, head_dim, 2, dtype=torch.float32) | |
| inv_freq = 1.0 / (theta ** (idx / head_dim)) | |
| # outer product: rotation angle for every (position, pair) combination | |
| pos = torch.arange(max_seq_len, dtype=torch.float32) | |
| angles = torch.outer(pos, inv_freq) # (max_seq_len, head_dim/2) | |
| # duplicate each angle so it lines up with both halves of the vector | |
| angles = torch.cat([angles, angles], dim=-1) # (max_seq_len, head_dim) | |
| return angles.cos(), angles.sin() | |
| def _rotate_half(x: torch.Tensor) -> torch.Tensor: | |
| # turns [x1, x2] into [-x2, x1] — the 90-degree partner needed for rotation | |
| half = x.shape[-1] // 2 | |
| x1, x2 = x[..., :half], x[..., half:] | |
| return torch.cat([-x2, x1], dim=-1) | |
| def apply_rope(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor: | |
| """Rotate query or key vectors by their positions. | |
| x: (batch, heads, seq_len, head_dim); cos/sin: (seq_len, head_dim). | |
| """ | |
| # broadcast cos/sin over batch and head dims | |
| cos = cos[None, None, :, :] | |
| sin = sin[None, None, :, :] | |
| # the rotation identity: x*cos + rotate_half(x)*sin | |
| return x * cos + _rotate_half(x) * sin |