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/data/dataset.py from AjayRangoji/AR-4B-base: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/data/dataset.py
- Command line
-
hf download hf://AjayRangoji/AR-4B-base/training_code/ar/data/dataset.py
-
curl -L -o dataset.py https://huggingface.co/AjayRangoji/AR-4B-base/resolve/main/training_code/ar/data/dataset.py
2.46 kB
| import numpy as np | |
| import torch | |
| class BinDataset: | |
| """Serves training batches from one or more memory-mapped .bin token files. | |
| Memory-mapping lets us read slices of a huge file without loading it into RAM. | |
| Each sample is a random window; input and target are the window shifted by one. | |
| Also returns segment IDs so attention can stay inside document boundaries. | |
| """ | |
| def __init__( | |
| self, | |
| bin_paths: list[str], | |
| seq_len: int, | |
| weights: list[float] | None = None, | |
| eot_token_id: int = 151643, | |
| ): | |
| self.seq_len = seq_len | |
| self.eot_token_id = eot_token_id | |
| # open each source as a read-only memory map of uint32 token ids | |
| self.data = [np.memmap(p, dtype=np.uint32, mode="r") for p in bin_paths] | |
| self.lengths = [len(d) for d in self.data] | |
| # sampling weights = the data mix (e.g. 0.65 english, 0.20 code, 0.15 math) | |
| if weights is None: | |
| weights = [n / sum(self.lengths) for n in self.lengths] | |
| self.weights = np.array(weights) / np.sum(weights) | |
| def get_batch(self, batch_size: int, device: str = "cuda"): | |
| x = np.empty((batch_size, self.seq_len), dtype=np.int64) | |
| y = np.empty((batch_size, self.seq_len), dtype=np.int64) | |
| seg = np.empty((batch_size, self.seq_len), dtype=np.int32) | |
| for i in range(batch_size): | |
| # pick a source according to the mix, then a random window inside it | |
| src = np.random.choice(len(self.data), p=self.weights) | |
| arr, n = self.data[src], self.lengths[src] | |
| start = np.random.randint(0, n - self.seq_len - 1) | |
| chunk = arr[start : start + self.seq_len + 1].astype(np.int64) | |
| x[i] = chunk[:-1] # input: tokens 0..seq_len-1 | |
| y[i] = chunk[1:] # target: same window shifted by one | |
| # segment IDs bump AFTER each EOT, so EOT stays with the doc it ends. | |
| # Example x[i]=[a,b,EOT,c,d,EOT,e] -> seg[i]=[0,0,0,1,1,1,2] | |
| is_eot = (x[i] == self.eot_token_id).astype(np.int32) | |
| seg[i] = np.cumsum(is_eot) - is_eot | |
| # pin_memory + non_blocking speeds up the CPU->GPU copy during training | |
| xt = torch.from_numpy(x).pin_memory().to(device, non_blocking=True) | |
| yt = torch.from_numpy(y).pin_memory().to(device, non_blocking=True) | |
| st = torch.from_numpy(seg).pin_memory().to(device, non_blocking=True) | |
| return xt, yt, st |