Instructions to use teddyoas/mathcode-llm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use teddyoas/mathcode-llm with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="teddyoas/mathcode-llm")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("teddyoas/mathcode-llm", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use teddyoas/mathcode-llm with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "teddyoas/mathcode-llm" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "teddyoas/mathcode-llm", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/teddyoas/mathcode-llm
- SGLang
How to use teddyoas/mathcode-llm 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 "teddyoas/mathcode-llm" \ --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": "teddyoas/mathcode-llm", "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 "teddyoas/mathcode-llm" \ --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": "teddyoas/mathcode-llm", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use teddyoas/mathcode-llm with Docker Model Runner:
docker model run hf.co/teddyoas/mathcode-llm
checkpoint at step 100
Browse files- README.md +61 -0
- checkpoint/latest.pt +3 -0
- config.json +14 -0
- model.safetensors +3 -0
- model_config.json +14 -0
- tokenizer.json +0 -0
- tokenizer_config.json +7 -0
README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mathcode-llm
|
| 2 |
+
|
| 3 |
+
A decoder-only transformer language model **built from scratch** -- no
|
| 4 |
+
pretrained weights, no `transformers` model classes. Every layer (RMSNorm,
|
| 5 |
+
RoPE, grouped-query attention, SwiGLU, KV-cached decoding) is hand-written
|
| 6 |
+
PyTorch in `model/transformer.py`, and the BPE tokenizer was trained from
|
| 7 |
+
scratch on our own corpus.
|
| 8 |
+
|
| 9 |
+
## Training data
|
| 10 |
+
|
| 11 |
+
| Source | Share |
|
| 12 |
+
|---|---|
|
| 13 |
+
| `open-web-math` (arXiv papers, Math StackExchange) | 50.2% |
|
| 14 |
+
| `codeparrot-clean` (Python from GitHub) | 37.7% |
|
| 15 |
+
| `code-search-net` (Python / JS / Go / Java functions) | 5.8% |
|
| 16 |
+
| `verifiable-coding-problems-python` | 4.8% |
|
| 17 |
+
| **The Nature of Code** (Daniel Shiffman, full 13 chapters) | 1.4% |
|
| 18 |
+
|
| 19 |
+
600 M training tokens, interleaved at 4096-token granularity so the domain
|
| 20 |
+
mixture stays stable throughout training.
|
| 21 |
+
|
| 22 |
+
## Architecture
|
| 23 |
+
|
| 24 |
+
| | |
|
| 25 |
+
|---|---|
|
| 26 |
+
| Parameters | ~110 M (85 M non-embedding) |
|
| 27 |
+
| Layers / heads / width | 12 / 12 / 768 |
|
| 28 |
+
| Context length | 1024 tokens |
|
| 29 |
+
| Vocabulary | 32,768 (byte-level BPE, trained from scratch) |
|
| 30 |
+
| Normalisation | RMSNorm (pre-norm) |
|
| 31 |
+
| Position | RoPE |
|
| 32 |
+
| FFN | SwiGLU |
|
| 33 |
+
| Attention | multi-head, KV cache for fast sampling |
|
| 34 |
+
| Embeddings | tied |
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 40 |
+
|
| 41 |
+
tok = AutoTokenizer.from_pretrained("teddyoas/mathcode-llm")
|
| 42 |
+
model = AutoModelForCausalLM.from_pretrained("teddyoas/mathcode-llm")
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
The tokenizer is a `PreTrainedTokenizerFast` built with the `tokenizers`
|
| 46 |
+
library, so `AutoTokenizer` loads it directly.
|
| 47 |
+
|
| 48 |
+
## Resuming training
|
| 49 |
+
|
| 50 |
+
`checkpoint/latest.pt` holds the model, the optimiser state, the AMP scaler,
|
| 51 |
+
the step counter and the token counter:
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
python train.py --config configs/mathcode.yaml \
|
| 55 |
+
--resume checkpoint/latest.pt
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
## Status
|
| 59 |
+
|
| 60 |
+
Training checkpoint: **step 100 / ?**
|
| 61 |
+
(13,107,200 tokens seen, val loss inf)
|
checkpoint/latest.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:11f3d39acb9a1f6203cae3fb1d18266a96faf681cb1c83ae3edf37209d37c486
|
| 3 |
+
size 1321524875
|
config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"vocab_size": 32768,
|
| 3 |
+
"n_layer": 12,
|
| 4 |
+
"n_head": 12,
|
| 5 |
+
"n_embd": 768,
|
| 6 |
+
"n_kv_head": 12,
|
| 7 |
+
"block_size": 1024,
|
| 8 |
+
"dropout": 0.0,
|
| 9 |
+
"rope_theta": 10000.0,
|
| 10 |
+
"tie_weights": true,
|
| 11 |
+
"use_swiglu": true,
|
| 12 |
+
"norm_eps": 1e-05,
|
| 13 |
+
"init_std": 0.02
|
| 14 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:390e71cd986fec558d058865da32464ab743bcd2a6731033c66df8eba23d83ca
|
| 3 |
+
size 440485848
|
model_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"vocab_size": 32768,
|
| 3 |
+
"n_layer": 12,
|
| 4 |
+
"n_head": 12,
|
| 5 |
+
"n_embd": 768,
|
| 6 |
+
"n_kv_head": 12,
|
| 7 |
+
"block_size": 1024,
|
| 8 |
+
"dropout": 0.0,
|
| 9 |
+
"rope_theta": 10000.0,
|
| 10 |
+
"tie_weights": true,
|
| 11 |
+
"use_swiglu": true,
|
| 12 |
+
"norm_eps": 1e-05,
|
| 13 |
+
"init_std": 0.02
|
| 14 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 3 |
+
"eos_token": "",
|
| 4 |
+
"bos_token": "",
|
| 5 |
+
"unk_token": null,
|
| 6 |
+
"model_max_length": 1024
|
| 7 |
+
}
|