Text Generation
Transformers
Safetensors
Turkish
qwen3
turkish
causal-lm
from-scratch
pretraining
text-generation-inference
Instructions to use eademir/TurkLM-scratch-0.5B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use eademir/TurkLM-scratch-0.5B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="eademir/TurkLM-scratch-0.5B")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("eademir/TurkLM-scratch-0.5B") model = AutoModelForCausalLM.from_pretrained("eademir/TurkLM-scratch-0.5B", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use eademir/TurkLM-scratch-0.5B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "eademir/TurkLM-scratch-0.5B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "eademir/TurkLM-scratch-0.5B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/eademir/TurkLM-scratch-0.5B
- SGLang
How to use eademir/TurkLM-scratch-0.5B 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 "eademir/TurkLM-scratch-0.5B" \ --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": "eademir/TurkLM-scratch-0.5B", "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 "eademir/TurkLM-scratch-0.5B" \ --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": "eademir/TurkLM-scratch-0.5B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use eademir/TurkLM-scratch-0.5B with Docker Model Runner:
docker model run hf.co/eademir/TurkLM-scratch-0.5B
Download eval/bpc_two_sets.py from eademir/TurkLM-scratch-0.5B: direct link, hf CLI and curl.
- Browser
- Download file 3.39 kB
-
https://huggingface.co/eademir/TurkLM-scratch-0.5B/resolve/main/eval/bpc_two_sets.py
- Command line
-
hf download hf://eademir/TurkLM-scratch-0.5B/eval/bpc_two_sets.py
-
curl -L -o bpc_two_sets.py https://huggingface.co/eademir/TurkLM-scratch-0.5B/resolve/main/eval/bpc_two_sets.py
3.39 kB
| """ | |
| Bits-per-character (BPC) of a causal LM on two sets of Turkish Wikipedia articles. | |
| overlap : Wikipedia articles #5,001-5,200 of the 20231101 dump (data/bpc_docs.json, cached). | |
| WARNING: this slice lies inside the TurkLM training stream - it is NOT held out. It is kept only because the | |
| first published numbers used it; it rewards models that saw it. Do not use it to compare TurkLM with other models. | |
| fresh : articles created AFTER the training cutoff (data/fresh_wiki.json, built by fetch_fresh_wiki.py). Use this one. | |
| BPC = total negative log-likelihood (bits) / number of characters. It is comparable across tokenizers (perplexity is not). | |
| Method: each document is cut into windows of 1,024 tokens; a window needs >= 2 tokens; loss is the mean token NLL of the window. | |
| IMPORTANT (macOS / Apple GPU): the default sdpa attention on MPS (macOS 27, torch 2.12.1) is not causal and gives wrong, | |
| far too low BPC. This script always uses attn_implementation="eager", which matches CPU fp32 and CUDA. | |
| usage: python bpc_two_sets.py --model-path MODEL_DIR_OR_HF_ID [--json out.json] [--device cpu|cuda|mps] | |
| """ | |
| import argparse, json, math | |
| from pathlib import Path | |
| import torch | |
| from tqdm import tqdm | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| HERE = Path(__file__).parent | |
| MAX_SEQ_LEN = 1024 | |
| def doc_nats_chars(model, tok, text, device): | |
| text = text.strip() | |
| ids = tok.encode(text, add_special_tokens=False) | |
| nats = 0.0 | |
| for i in range(0, len(ids), MAX_SEQ_LEN): | |
| chunk = ids[i:i + MAX_SEQ_LEN] | |
| if len(chunk) < 2: | |
| continue | |
| x = torch.tensor([chunk], device=device) | |
| nats += model(input_ids=x, labels=x).loss.item() * (len(chunk) - 1) | |
| return nats, len(text) | |
| def bpc(model, tok, texts, device, desc): | |
| per_doc = [doc_nats_chars(model, tok, t, device) for t in tqdm(texts, desc=desc)] | |
| return sum(n for n, _ in per_doc) / (math.log(2) * sum(c for _, c in per_doc)), per_doc | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--model-path", required=True) | |
| ap.add_argument("--json", default="") | |
| ap.add_argument("--device", default="") | |
| ap.add_argument("--sets", default="overlap,fresh") | |
| a = ap.parse_args() | |
| device = torch.device(a.device or ("cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu")) | |
| tok = AutoTokenizer.from_pretrained(a.model_path) | |
| model = AutoModelForCausalLM.from_pretrained(a.model_path, dtype=torch.bfloat16, attn_implementation="eager").to(device).eval() | |
| out = {"model": a.model_path} | |
| if "overlap" in a.sets: | |
| texts = json.loads((HERE / "data" / "bpc_docs.json").read_text()) | |
| out["overlap"], per = bpc(model, tok, texts, device, "overlap set") | |
| out["overlap_n"] = len(texts) | |
| print(f"BPC overlap set ({len(texts)} articles, inside the training stream): {out['overlap']:.4f}") | |
| if "fresh" in a.sets: | |
| docs = json.loads((HERE / "data" / "fresh_wiki.json").read_text()) | |
| out["fresh"], per = bpc(model, tok, [d["text"] for d in docs], device, "fresh set") | |
| out["fresh_n"] = len(docs) | |
| print(f"BPC fresh set ({len(docs)} articles created after the cutoff): {out['fresh']:.4f}") | |
| if a.json: | |
| Path(a.json).write_text(json.dumps(out, indent=1)) | |
| if __name__ == "__main__": | |
| main() | |