Text Generation
Transformers
Safetensors
English
nsa
sparse-attention
117m
conversational
custom_code
Instructions to use seconds-0/nsa-117m-byte with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use seconds-0/nsa-117m-byte with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="seconds-0/nsa-117m-byte", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("seconds-0/nsa-117m-byte", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use seconds-0/nsa-117m-byte with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "seconds-0/nsa-117m-byte" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "seconds-0/nsa-117m-byte", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/seconds-0/nsa-117m-byte
- SGLang
How to use seconds-0/nsa-117m-byte 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 "seconds-0/nsa-117m-byte" \ --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": "seconds-0/nsa-117m-byte", "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 "seconds-0/nsa-117m-byte" \ --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": "seconds-0/nsa-117m-byte", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use seconds-0/nsa-117m-byte with Docker Model Runner:
docker model run hf.co/seconds-0/nsa-117m-byte
| # Remote code: configuration and modeling for NSA | |
| from typing import List, Optional, Dict | |
| import json | |
| from transformers import PreTrainedTokenizer | |
| class NSAByteTokenizer(PreTrainedTokenizer): | |
| """A simple byte-level tokenizer with fixed vocab size 256. | |
| - Encodes UTF-8 bytes of the input string as token ids 0..255. | |
| - No special tokens by default; EOS/PAD can be configured via special tokens map. | |
| - Decoding uses UTF-8 with replacement for invalid sequences. | |
| """ | |
| def __init__(self, **kwargs): | |
| # Build a stable 256-entry vocab mapping before base init (base may query the vocab) | |
| self._vocab: Dict[str, int] = {f"<{i}>": i for i in range(256)} | |
| self._ids_to_tokens: Dict[int, str] = {i: f"<{i}>" for i in range(256)} | |
| super().__init__(**kwargs) | |
| # Only return input_ids and attention_mask to avoid unused token_type_ids in generation | |
| self.model_input_names = ["input_ids", "attention_mask"] | |
| def vocab_size(self) -> int: # type: ignore[override] | |
| return 256 | |
| def get_vocab(self) -> Dict[str, int]: # type: ignore[override] | |
| return dict(self._vocab) | |
| def _tokenize(self, text: str) -> List[str]: # type: ignore[override] | |
| data = text.encode("utf-8", errors="replace") | |
| return [f"<{b}>" for b in data] | |
| def _convert_token_to_id(self, token: str) -> int: # type: ignore[override] | |
| if token in self._vocab: | |
| return self._vocab[token] | |
| # Fallback: try parse numeric inside <..> | |
| if token.startswith("<") and token.endswith(">"): | |
| try: | |
| v = int(token[1:-1]) | |
| if 0 <= v < 256: | |
| return v | |
| except Exception: | |
| pass | |
| return 0 | |
| def _convert_id_to_token(self, index: int) -> str: # type: ignore[override] | |
| return self._ids_to_tokens.get(int(index) % 256, "<0>") | |
| def convert_tokens_to_string(self, tokens: List[str]) -> str: # type: ignore[override] | |
| bs = [] | |
| for t in tokens: | |
| if t in self._vocab: | |
| bs.append(self._vocab[t]) | |
| else: | |
| try: | |
| if t.startswith("<") and t.endswith(">"): | |
| v = int(t[1:-1]) | |
| if 0 <= v < 256: | |
| bs.append(v) | |
| continue | |
| except Exception: | |
| pass | |
| return bytes(bs).decode("utf-8", errors="replace") | |
| def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None) -> List[int]: # type: ignore[override] | |
| if token_ids_1 is None: | |
| return token_ids_0 | |
| return token_ids_0 + token_ids_1 | |
| def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None): # type: ignore[override] | |
| # Nothing to save besides special tokens map handled by the base class. | |
| return (), () | |