Text Generation
Transformers
Safetensors
Portuguese
nanothink
thinking
reasoning
reason
think
lowparams
5m_params
thinkset-ptbr
gpt2
Instructions to use AxionLab-Co/NanoThink-5M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AxionLab-Co/NanoThink-5M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AxionLab-Co/NanoThink-5M")# Load model directly from transformers import NanoThink model = NanoThink.from_pretrained("AxionLab-Co/NanoThink-5M", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use AxionLab-Co/NanoThink-5M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AxionLab-Co/NanoThink-5M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AxionLab-Co/NanoThink-5M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AxionLab-Co/NanoThink-5M
- SGLang
How to use AxionLab-Co/NanoThink-5M 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 "AxionLab-Co/NanoThink-5M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AxionLab-Co/NanoThink-5M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "AxionLab-Co/NanoThink-5M" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AxionLab-Co/NanoThink-5M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AxionLab-Co/NanoThink-5M with Docker Model Runner:
docker model run hf.co/AxionLab-Co/NanoThink-5M
File size: 1,643 Bytes
93ca81b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import torch
import torch.nn as nn
from transformers import PreTrainedModel, PretrainedConfig
class NanoThinkConfig(PretrainedConfig):
model_type = "nanothink"
def __init__(
self,
vocab_size=1229,
dim=128,
n_layers=4,
n_heads=4,
max_len=256,
**kwargs
):
super().__init__(**kwargs)
self.vocab_size = vocab_size
self.dim = dim
self.n_layers = n_layers
self.n_heads = n_heads
self.max_len = max_len
class NanoThinkModel(PreTrainedModel):
config_class = NanoThinkConfig
def __init__(self, config):
super().__init__(config)
self.token_emb = nn.Embedding(config.vocab_size, config.dim)
self.pos_emb = nn.Embedding(config.max_len, config.dim)
encoder_layer = nn.TransformerEncoderLayer(
d_model=config.dim,
nhead=config.n_heads,
batch_first=True
)
self.transformer = nn.TransformerEncoder(
encoder_layer,
num_layers=config.n_layers
)
self.ln = nn.LayerNorm(config.dim)
self.head = nn.Linear(config.dim, config.vocab_size)
self.post_init()
def forward(self, input_ids):
B, T = input_ids.shape
pos = torch.arange(T, device=input_ids.device).unsqueeze(0)
x = self.token_emb(input_ids) + self.pos_emb(pos)
mask = torch.triu(
torch.ones(T, T, device=input_ids.device),
diagonal=1
).bool()
x = self.transformer(x, mask=mask)
x = self.ln(x)
logits = self.head(x)
return logits |