Instructions to use TNSA/NGen2-170M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TNSA/NGen2-170M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TNSA/NGen2-170M")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("TNSA/NGen2-170M", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TNSA/NGen2-170M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TNSA/NGen2-170M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TNSA/NGen2-170M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/TNSA/NGen2-170M
- SGLang
How to use TNSA/NGen2-170M 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 "TNSA/NGen2-170M" \ --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": "TNSA/NGen2-170M", "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 "TNSA/NGen2-170M" \ --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": "TNSA/NGen2-170M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use TNSA/NGen2-170M with Docker Model Runner:
docker model run hf.co/TNSA/NGen2-170M
Upload 2 files
Browse files
books.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# train a miniature character-level shakespeare model
|
| 2 |
+
# good for debugging and playing on macbooks and such
|
| 3 |
+
|
| 4 |
+
out_dir = 'out-books2'
|
| 5 |
+
eval_interval = 250 # keep frequent because we'll overfit
|
| 6 |
+
eval_iters = 200
|
| 7 |
+
log_interval = 10 # don't print too too often
|
| 8 |
+
|
| 9 |
+
# we expect to overfit on this small dataset, so only save when val improves
|
| 10 |
+
always_save_checkpoint = False
|
| 11 |
+
|
| 12 |
+
wandb_log = False # override via command line if you like
|
| 13 |
+
wandb_project = 'shakespeare'
|
| 14 |
+
wandb_run_name = 'mini-gpt'
|
| 15 |
+
|
| 16 |
+
dataset = 'books2'
|
| 17 |
+
gradient_accumulation_steps = 1
|
| 18 |
+
batch_size = 128
|
| 19 |
+
block_size = 256 # context of up to 256 previous characters
|
| 20 |
+
|
| 21 |
+
# baby GPT model :)
|
| 22 |
+
n_layer = 8
|
| 23 |
+
n_head = 8
|
| 24 |
+
n_embd = 512
|
| 25 |
+
dropout = 0.2
|
| 26 |
+
|
| 27 |
+
learning_rate = 1e-3 # with baby networks can afford to go a bit higher
|
| 28 |
+
max_iters = 5000
|
| 29 |
+
lr_decay_iters = 5000 # make equal to max_iters usually
|
| 30 |
+
min_lr = 1e-4 # learning_rate / 10 usually
|
| 31 |
+
beta2 = 0.99 # make a bit bigger because number of tokens per iter is small
|
| 32 |
+
|
| 33 |
+
warmup_iters = 100 # not super necessary potentially
|
| 34 |
+
|
| 35 |
+
# on macbook also add
|
| 36 |
+
device = 'cuda' # run on cpu only
|
| 37 |
+
compile = False # do not torch compile the model
|
| 38 |
+
|
| 39 |
+
# Evaluation settings
|
| 40 |
+
generate_samples = 100 # number of samples to generate for BLEU score
|
| 41 |
+
max_sample_length = 100 # maximum length of generated samples
|
| 42 |
+
|
| 43 |
+
# Add BLEU score settings
|
| 44 |
+
bleu_ngrams = 4 # maximum n-gram size for BLEU calculation
|
| 45 |
+
calculate_metrics = True # flag to enable/disable PPL and BLEU calculation
|
ckpt.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ef50ef7a2312551fe8783ad19cc95d127920eb4e1aadb4dd20b9b4eab9d5545f
|
| 3 |
+
size 1445446661
|