Text Generation
Transformers
Safetensors
MLX
qwen3
oeis
integer-sequences
causal-lm
text-generation-inference
Instructions to use N8Programs/NextTerm-2-440M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use N8Programs/NextTerm-2-440M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="N8Programs/NextTerm-2-440M")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("N8Programs/NextTerm-2-440M") model = AutoModelForCausalLM.from_pretrained("N8Programs/NextTerm-2-440M", device_map="auto") - MLX
How to use N8Programs/NextTerm-2-440M with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("N8Programs/NextTerm-2-440M") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- vLLM
How to use N8Programs/NextTerm-2-440M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "N8Programs/NextTerm-2-440M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "N8Programs/NextTerm-2-440M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/N8Programs/NextTerm-2-440M
- SGLang
How to use N8Programs/NextTerm-2-440M 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 "N8Programs/NextTerm-2-440M" \ --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": "N8Programs/NextTerm-2-440M", "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 "N8Programs/NextTerm-2-440M" \ --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": "N8Programs/NextTerm-2-440M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - MLX LM
How to use N8Programs/NextTerm-2-440M with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "N8Programs/NextTerm-2-440M" --prompt "Once upon a time"
- Docker Model Runner
How to use N8Programs/NextTerm-2-440M with Docker Model Runner:
docker model run hf.co/N8Programs/NextTerm-2-440M
- Atomic Chat
Download eval_ryskina.py from N8Programs/NextTerm-2-440M: direct link, hf CLI and curl.
- Browser
- Download file 4.01 kB
-
https://huggingface.co/N8Programs/NextTerm-2-440M/resolve/main/eval_ryskina.py
- Command line
-
hf download hf://N8Programs/NextTerm-2-440M/eval_ryskina.py
-
curl -L -o eval_ryskina.py https://huggingface.co/N8Programs/NextTerm-2-440M/resolve/main/eval_ryskina.py
4.01 kB
| """Ryskina & Knight (2021) next-term eval for byte-level spark-gpt OEIS checkpoints. | |
| Each item is a short sequence. The prompt is every term but the last, written | |
| "t1,t2,...,tk," with a trailing comma. The answer is the last term. | |
| Two scores per item: | |
| exact greedy decode until the next comma or EOS; correct iff the text equals | |
| str(answer). This matches the NextTerm model-card protocol. | |
| logprob log P(answer is the next term) in nats: the sum of the log-probs of the | |
| answer's bytes, plus log(P(",") + P(EOS)) at the position after it. A | |
| continuous score, much less noisy than 57 binary outcomes. | |
| Encoding is BOS + UTF-8 bytes, exactly as spark-gpt trains. The script checks | |
| that the exported HF tokenizer agrees. | |
| Usage: python eval_ryskina.py <hf_dir> <ryskina.jsonl> <out_prefix> | |
| Writes <out_prefix>.items.jsonl and <out_prefix>.summary.json. | |
| """ | |
| import json | |
| import math | |
| import statistics | |
| import sys | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| MAX_NEW_TOKENS = 40 # longest answer is far shorter; a runaway decode just scores wrong | |
| def main(): | |
| hf_dir, data_path, out_prefix = sys.argv[1:4] | |
| tok = AutoTokenizer.from_pretrained(hf_dir) | |
| model = AutoModelForCausalLM.from_pretrained(hf_dir, dtype=torch.float32).cuda().eval() | |
| bos, eos = tok.bos_token_id, tok.eos_token_id | |
| comma = ord(",") | |
| def encode(text): | |
| ids = [bos] + list(text.encode("utf-8")) | |
| assert tok(text).input_ids == ids, f"tokenizer disagrees on {text!r}" | |
| return ids | |
| items = [json.loads(line)["seq"] for line in open(data_path)] | |
| results = [] | |
| with torch.no_grad(): | |
| for idx, seq in enumerate(items): | |
| prompt_text = ",".join(str(x) for x in seq[:-1]) + "," | |
| answer = str(seq[-1]) | |
| prompt = encode(prompt_text) | |
| # exact match: greedy until comma / EOS | |
| ids = torch.tensor([prompt], device="cuda") | |
| generated = [] | |
| for _ in range(MAX_NEW_TOKENS): | |
| nxt = int(model(ids).logits[0, -1].argmax()) | |
| if nxt in (comma, eos): | |
| break | |
| generated.append(nxt) | |
| ids = torch.cat([ids, torch.tensor([[nxt]], device="cuda")], dim=1) | |
| prediction = bytes(b for b in generated if b < 256).decode("utf-8", "replace") | |
| # log P(answer is the next term) | |
| ans_ids = list(answer.encode("utf-8")) | |
| full = torch.tensor([prompt + ans_ids], device="cuda") | |
| logp = torch.log_softmax(model(full).logits[0].float(), dim=-1) | |
| start = len(prompt) - 1 # logits at position i predict token i + 1 | |
| lp_answer = sum(float(logp[start + j, t]) for j, t in enumerate(ans_ids)) | |
| end = logp[start + len(ans_ids)] | |
| lp_stop = float(torch.logaddexp(end[comma], end[eos])) | |
| lp = lp_answer + lp_stop | |
| results.append({ | |
| "idx": idx, | |
| "prompt": prompt_text, | |
| "answer": answer, | |
| "prediction": prediction, | |
| "correct": prediction == answer, | |
| "logprob": lp, | |
| "logprob_answer_bytes": lp_answer, | |
| "logprob_stop": lp_stop, | |
| }) | |
| lps = [r["logprob"] for r in results] | |
| n_correct = sum(r["correct"] for r in results) | |
| summary = { | |
| "checkpoint": hf_dir, | |
| "items": len(results), | |
| "exact_correct": n_correct, | |
| "exact_acc": n_correct / len(results), | |
| "mean_logprob": statistics.fmean(lps), | |
| "median_logprob": statistics.median(lps), | |
| "mean_answer_prob": statistics.fmean(math.exp(x) for x in lps), | |
| } | |
| with open(out_prefix + ".items.jsonl", "w") as f: | |
| for r in results: | |
| f.write(json.dumps(r) + "\n") | |
| with open(out_prefix + ".summary.json", "w") as f: | |
| json.dump(summary, f, indent=2) | |
| print(json.dumps(summary, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |