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/eval_xcopa.py from eademir/TurkLM-scratch-0.5B: direct link, hf CLI and curl.
- Browser
- Download file 4.04 kB
-
https://huggingface.co/eademir/TurkLM-scratch-0.5B/resolve/main/eval/eval_xcopa.py
- Command line
-
hf download hf://eademir/TurkLM-scratch-0.5B/eval/eval_xcopa.py
-
curl -L -o eval_xcopa.py https://huggingface.co/eademir/TurkLM-scratch-0.5B/resolve/main/eval/eval_xcopa.py
4.04 kB
| """ | |
| Evaluate on XCOPA Turkish — commonsense reasoning, 2-choice. | |
| 500 test examples. Random baseline = 50%. | |
| Scoring: length-normalised conditional log-probability. | |
| No fine-tuning or instruction following needed. | |
| Usage: | |
| python eval/eval_xcopa.py --model-path ./models/ckpt_scratch_small | |
| python eval/eval_xcopa.py --model-path ./models/ckpt_qwen_1_7b | |
| """ | |
| import argparse | |
| import json | |
| import math | |
| import os | |
| import urllib.request | |
| from pathlib import Path | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from tqdm import tqdm | |
| QUESTION_MAP = { | |
| "cause": "Bunun nedeni neydi?", | |
| "effect": "Bunun ardından ne oldu?", | |
| } | |
| # Cached local path for Turkish XCOPA test data (500 examples) | |
| _DATA_DIR = Path(__file__).parent / "data" | |
| _XCOPA_TR = _DATA_DIR / "xcopa_tr_test.jsonl" | |
| _XCOPA_URL = "https://raw.githubusercontent.com/cambridgeltl/xcopa/master/data/tr/test.tr.jsonl" | |
| def load_xcopa_tr(): | |
| """Load XCOPA-TR test set (500 examples). | |
| Tries the HuggingFace `datasets` library first. If that fails (known | |
| issue: huggingface_hub >=0.29 rejects un-namespaced legacy datasets | |
| like 'xcopa'), falls back to downloading the raw JSONL from the | |
| Cambridge LTL GitHub repository and caching it under eval/data/. | |
| """ | |
| try: | |
| from datasets import load_dataset | |
| ds = load_dataset("xcopa", "tr", split="test") | |
| return list(ds) | |
| except Exception: | |
| pass | |
| if not _XCOPA_TR.exists(): | |
| _DATA_DIR.mkdir(parents=True, exist_ok=True) | |
| print(f"HuggingFace load failed — downloading XCOPA-TR from GitHub ...") | |
| urllib.request.urlretrieve(_XCOPA_URL, _XCOPA_TR) | |
| print(f"Cached to {_XCOPA_TR}") | |
| examples = [] | |
| with open(_XCOPA_TR) as f: | |
| for line in f: | |
| line = line.strip() | |
| if line: | |
| examples.append(json.loads(line)) | |
| return examples | |
| def score_continuation(model, tokenizer, context, continuation, device): | |
| ctx_ids = tokenizer.encode(context, add_special_tokens=False) | |
| cont_ids = tokenizer.encode(" " + continuation.strip(), add_special_tokens=False) | |
| if not cont_ids: | |
| return float("-inf") | |
| input_ids = torch.tensor([ctx_ids + cont_ids], device=device) | |
| labels = torch.tensor([[-100] * len(ctx_ids) + cont_ids], device=device) | |
| with torch.no_grad(): | |
| with torch.autocast("cuda", dtype=torch.bfloat16, enabled=(device.type == "cuda")): | |
| loss = model(input_ids=input_ids, labels=labels).loss | |
| return -loss.item() | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--model-path", required=True) | |
| 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"Loading model : {args.model_path}") | |
| tokenizer = AutoTokenizer.from_pretrained(args.model_path) | |
| # eager attention: the default sdpa kernel on MPS (macOS 27 / torch 2.12.1) is not | |
| # causal and corrupts the log-probabilities. Eager matches CPU fp32. | |
| model = AutoModelForCausalLM.from_pretrained( | |
| args.model_path, dtype=torch.bfloat16, attn_implementation="eager") | |
| model = model.to(device).eval() | |
| print("Loading XCOPA-TR ...") | |
| examples = load_xcopa_tr() | |
| correct = 0 | |
| for ex in tqdm(examples, desc="XCOPA-TR"): | |
| question = QUESTION_MAP.get(ex["question"], "") | |
| context = f"{ex['premise']} {question}" | |
| s0 = score_continuation(model, tokenizer, context, ex["choice1"], device) | |
| s1 = score_continuation(model, tokenizer, context, ex["choice2"], device) | |
| pred = 0 if s0 > s1 else 1 | |
| if pred == ex["label"]: | |
| correct += 1 | |
| acc = correct / len(examples) * 100 | |
| print(f"\n{'='*45}") | |
| print(f"Model : {args.model_path}") | |
| print(f"XCOPA-TR : {acc:.1f}% ({correct}/{len(examples)})") | |
| print(f"Baseline : 50.0% (random)") | |
| print(f"{'='*45}") | |
| if __name__ == "__main__": | |
| main() | |