Text Generation
Transformers
Safetensors
English
moeloop
looptitan
mixture-of-experts
Mixture of Experts
looped-moe
looped-transformer
looped-language-model
recurrent-depth
weight-sharing
custom_code
adamw
conversational
Eval Results (legacy)
Instructions to use NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW", 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("NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW
- SGLang
How to use NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW 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 "NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW" \ --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": "NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW", "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 "NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW" \ --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": "NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW with Docker Model Runner:
docker model run hf.co/NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW
Download cache.py from NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW: direct link, hf CLI and curl.
- Browser
- Download file 4.04 kB
-
https://huggingface.co/NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW/resolve/main/cache.py
- Command line
-
hf download hf://NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW/cache.py
-
curl -L -o cache.py https://huggingface.co/NaturalScale/LoopTitan-Looped-1.3B-A0.2B-AdamW/resolve/main/cache.py
4.04 kB
| """Exact, inference-only KV storage indexed by logical attention calls.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass, field | |
| import torch | |
| from torch import Tensor | |
| CacheSlot = tuple[str, int, int] | |
| class DecodeCache: | |
| """Fixed-depth KV cache. Shared attention weights still have separate slots. | |
| ``length`` counts stored columns (including padding), while ``valid_mask`` | |
| and ``positions`` retain each row's valid-token and RoPE metadata. Use | |
| :meth:`reorder` for beam/batch reordering; never reorder slots individually. | |
| During a forward every attention call appends to its slot; ``advance`` then | |
| records the forward's columns. A forward that raises midway leaves some | |
| slots longer than ``length``, and the next forward on this cache fails, so | |
| ``clear`` it or start a new cache. | |
| """ | |
| num_visits: int | |
| length: int = field(default=0, init=False) | |
| slots: dict[CacheSlot, tuple[Tensor, Tensor]] = field(default_factory=dict, init=False) | |
| positions: Tensor | None = field(default=None, init=False) | |
| valid_mask: Tensor | None = field(default=None, init=False) | |
| def next_positions(self, valid_mask: Tensor) -> Tensor: | |
| """Standard padding-aware positions for the new query columns.""" | |
| offset = valid_mask.new_zeros((valid_mask.size(0), 1), dtype=torch.long) | |
| if self.valid_mask is not None: | |
| if self.valid_mask.size(0) != valid_mask.size(0): | |
| raise ValueError("cache batch size changed without reorder") | |
| columns = torch.arange(self.length, device=self.valid_mask.device) | |
| last = torch.where(self.valid_mask, columns, -1).amax(-1, keepdim=True) | |
| offset = self.positions.gather(1, last.clamp_min(0)) + 1 | |
| offset = torch.where(last >= 0, offset, 0) | |
| positions = offset + valid_mask.long().cumsum(-1) - 1 | |
| return positions.clamp_min(0) | |
| def append(self, slot: CacheSlot, key: Tensor, value: Tensor) -> tuple[Tensor, Tensor]: | |
| """Append this forward's [batch, kv_heads, tokens, head_dim] K/V; return the slot's whole K/V.""" | |
| if slot in self.slots: | |
| old_key, old_value = self.slots[slot] | |
| key, value = torch.cat((old_key, key), dim=-2), torch.cat((old_value, value), dim=-2) | |
| self.slots[slot] = (key, value) | |
| return key, value | |
| def advance(self, positions: Tensor, valid_mask: Tensor, expected_slots: tuple[CacheSlot, ...]) -> None: | |
| """Record a finished forward's columns; every expected slot must hold all of them.""" | |
| if self.positions is not None: | |
| positions = torch.cat((self.positions, positions), dim=1) | |
| valid_mask = torch.cat((self.valid_mask, valid_mask), dim=1) | |
| length = positions.size(1) | |
| if set(self.slots) != set(expected_slots) or any(key.size(-2) != length for key, _ in self.slots.values()): | |
| raise ValueError("forward did not update every logical cache slot; " | |
| "clear() the cache after a failed forward") | |
| self.positions, self.valid_mask, self.length = positions, valid_mask, length | |
| def reorder(self, indices: Tensor) -> "DecodeCache": | |
| if indices.ndim != 1 or indices.dtype not in (torch.int32, torch.int64): | |
| raise ValueError("cache reorder indices must be integer [new_batch]") | |
| self.slots = { | |
| slot: (key.index_select(0, indices.to(key.device, dtype=torch.long)), | |
| value.index_select(0, indices.to(value.device, dtype=torch.long))) | |
| for slot, (key, value) in self.slots.items() | |
| } | |
| if self.positions is not None: | |
| self.positions = self.positions.index_select(0, indices.to(self.positions.device, dtype=torch.long)) | |
| self.valid_mask = self.valid_mask.index_select(0, indices.to(self.valid_mask.device, dtype=torch.long)) | |
| return self | |
| def clear(self) -> None: | |
| self.slots.clear() | |
| self.length = 0 | |
| self.positions = self.valid_mask = None | |