Text Generation
Transformers
Safetensors
Turkish
qwen3
turkish
causal-lm
from-scratch
pretraining
text-generation-inference
Instructions to use eademir/TurkLM-scratch-0.3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use eademir/TurkLM-scratch-0.3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="eademir/TurkLM-scratch-0.3B")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("eademir/TurkLM-scratch-0.3B") model = AutoModelForCausalLM.from_pretrained("eademir/TurkLM-scratch-0.3B", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use eademir/TurkLM-scratch-0.3B 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.3B" # 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.3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/eademir/TurkLM-scratch-0.3B
- SGLang
How to use eademir/TurkLM-scratch-0.3B 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.3B" \ --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.3B", "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.3B" \ --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.3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use eademir/TurkLM-scratch-0.3B with Docker Model Runner:
docker model run hf.co/eademir/TurkLM-scratch-0.3B
Download eval/eval_efficiency.py from eademir/TurkLM-scratch-0.3B: direct link, hf CLI and curl.
- Browser
- Download file 6.19 kB
-
https://huggingface.co/eademir/TurkLM-scratch-0.3B/resolve/main/eval/eval_efficiency.py
- Command line
-
hf download hf://eademir/TurkLM-scratch-0.3B/eval/eval_efficiency.py
-
curl -L -o eval_efficiency.py https://huggingface.co/eademir/TurkLM-scratch-0.3B/resolve/main/eval/eval_efficiency.py
6.19 kB
| """ | |
| Measure two efficiency metrics for the paper's efficiency analysis section: | |
| 1. Tokenizer fertility β avg tokens per word on Turkish text (lower = better compression) | |
| 2. Inference speed β tokens/second for autoregressive generation | |
| Usage: | |
| python eval/eval_efficiency.py --model-path ./ckpt_scratch_small | |
| python eval/eval_efficiency.py --model-path Qwen/Qwen3-1.7B | |
| python eval/eval_efficiency.py --model-path TURKCELL/Turkcell-LLM-7b-v1 | |
| """ | |
| import argparse | |
| import time | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from datasets import load_dataset | |
| # Fixed Turkish prompt for all models β kept short so it fits every tokenizer | |
| PROMPT = ( | |
| "TΓΌrkiye, Avrupa ile Asya arasΔ±nda kΓΆprΓΌ gΓΆrevi gΓΆren eΕsiz bir coΔrafi konuma sahiptir. " | |
| "Δ°stanbul, dΓΌnyanΔ±n iki kΔ±taya yayΔ±lan tek bΓΌyΓΌkΕehridir." | |
| ) | |
| N_GENERATE = 100 # tokens to generate for speed test | |
| N_WARMUP = 1 # warmup forward pass (discarded) | |
| N_DOCS = 100 # Wikipedia docs for fertility measurement | |
| SKIP_DOCS = 5_000 | |
| # ββ Tokenizer fertility ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def measure_fertility(tokenizer, texts): | |
| total_tokens = 0 | |
| total_words = 0 | |
| for text in texts: | |
| text = text.strip() | |
| if not text: | |
| continue | |
| words = text.split() | |
| tokens = tokenizer.encode(text, add_special_tokens=False) | |
| total_words += len(words) | |
| total_tokens += len(tokens) | |
| return total_tokens / total_words if total_words else 0.0 | |
| # ββ Inference speed ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def measure_speed(model, tokenizer, prompt, device, n_generate=N_GENERATE, n_warmup=N_WARMUP): | |
| input_ids = tokenizer.encode(prompt, return_tensors="pt").to(device) | |
| generate_kwargs = dict( | |
| input_ids=input_ids, | |
| max_new_tokens=n_generate, | |
| do_sample=False, # greedy β deterministic, fair comparison | |
| pad_token_id=tokenizer.eos_token_id, | |
| ) | |
| # warmup | |
| for _ in range(n_warmup): | |
| with torch.no_grad(): | |
| model.generate(**generate_kwargs) | |
| if device.type == "mps": | |
| torch.mps.synchronize() | |
| elif device.type == "cuda": | |
| torch.cuda.synchronize() | |
| start = time.perf_counter() | |
| with torch.no_grad(): | |
| out = model.generate(**generate_kwargs) | |
| if device.type == "mps": | |
| torch.mps.synchronize() | |
| elif device.type == "cuda": | |
| torch.cuda.synchronize() | |
| elapsed = time.perf_counter() - start | |
| generated_tokens = out.shape[1] - input_ids.shape[1] | |
| tokens_per_sec = generated_tokens / elapsed | |
| ms_per_token = elapsed / generated_tokens * 1000 | |
| return tokens_per_sec, ms_per_token, generated_tokens | |
| # ββ Main βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--model-path", required=True) | |
| parser.add_argument("--n-docs", type=int, default=N_DOCS) | |
| parser.add_argument("--skip-docs", type=int, default=SKIP_DOCS) | |
| parser.add_argument("--n-generate",type=int, default=N_GENERATE) | |
| args = parser.parse_args() | |
| device = torch.device( | |
| "cuda" if torch.cuda.is_available() else | |
| "mps" if torch.backends.mps.is_available() else | |
| "cpu" | |
| ) | |
| print(f"Device : {device}") | |
| print(f"Loading model : {args.model_path}") | |
| tokenizer = AutoTokenizer.from_pretrained(args.model_path) | |
| model = AutoModelForCausalLM.from_pretrained(args.model_path, torch_dtype=torch.bfloat16) | |
| model = model.to(device).eval() | |
| n_params = sum(p.numel() for p in model.parameters()) | |
| print(f"Parameters : {n_params / 1e6:.0f}M") | |
| # ββ Fertility ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| print(f"\nLoading Turkish Wikipedia docs (skip={args.skip_docs}, n={args.n_docs}) ...") | |
| ds = load_dataset("wikimedia/wikipedia", "20231101.tr", split="train", streaming=True) | |
| texts = [] | |
| for i, ex in enumerate(ds): | |
| if i < args.skip_docs: | |
| continue | |
| texts.append(ex["text"]) | |
| if len(texts) == args.n_docs: | |
| break | |
| fertility = measure_fertility(tokenizer, texts) | |
| # ββ Speed ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| print(f"Measuring inference speed ({args.n_generate} tokens) ...") | |
| tok_per_sec, ms_per_tok, n_gen = measure_speed( | |
| model, tokenizer, PROMPT, device, n_generate=args.n_generate | |
| ) | |
| # ββ Report βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| print(f"\n{'='*50}") | |
| print(f"Model : {args.model_path}") | |
| print(f"Parameters : {n_params / 1e6:.0f}M") | |
| print(f"Vocab size : {len(tokenizer):,}") | |
| print(f"β"*50) | |
| print(f"Fertility : {fertility:.2f} tokens/word (lower = better)") | |
| print(f"β"*50) | |
| print(f"Inference speed : {tok_per_sec:.1f} tok/s") | |
| print(f"Latency : {ms_per_tok:.1f} ms/token") | |
| print(f"Tokens generated : {n_gen}") | |
| print(f"{'='*50}") | |
| if __name__ == "__main__": | |
| main() | |
| # The abandoned streaming dataset leaves pyarrow threads that deadlock at | |
| # interpreter shutdown, which hangs run_all.sh. Results are already printed. | |
| import os, sys | |
| sys.stdout.flush() | |
| sys.stderr.flush() | |
| os._exit(0) | |