Views
No views yet
Note: This model was trained from scratch - not fine-tuned from existing models.
This page includes simple virtual-env setup, install choices for CPU/CUDA/ROCm, and an auto-device inference example so anyone can get going quickly.
Virtual environments isolate project dependencies. Official Python docs:venv.
1# Linux/macOS
2python3 --version && python3 -m pip --version1# Windows (PowerShell)
2python --version; python -m pip --version1# Linux/macOS
2python3 -m venv helloLondon1# Windows (PowerShell)
2python -m venv helloLondon1:: Windows (Command Prompt)
2python -m venv helloLondonNote: You can name your virtual environment anything you like, e.g.,.venv,my_env,london_env.
1# Linux/macOS
2source helloLondon/bin/activate1# Windows (PowerShell)
2.\helloLondon\Scripts\Activate.ps11:: Windows (CMD)
2.\helloLondon\Scripts\activate.batIf PowerShell blocks activation ("running scripts is disabled"), set the policy then retry activation:
1Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
2# or just for this session:
3Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass1python -m pip install -U pip setuptools wheel
2python -m pip install "transformers" "accelerate" "safetensors"pip install torch --index-url https://download.pytorch.org/whl/cpu1# CUDA 12.6
2pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
3
4# CUDA 12.4
5pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
6
7# CUDA 11.8
8pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu1181# ROCm 6.3
2pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.3
3
4# ROCm 6.2 (incl. 6.2.x)
5pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4
6
7# ROCm 6.1
8pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.11python - <<'PY'
2import torch
3print("torch:", torch.__version__)
4print("GPU available:", torch.cuda.is_available())
5if torch.cuda.is_available():
6 print("device:", torch.cuda.get_device_name(0))
7PY1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "bahree/london-historical-slm"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(model_id)
8
9device = "cuda" if torch.cuda.is_available() else "cpu"
10model = model.to(device)
11
12prompt = "In the year 1834, I walked through the streets of London and witnessed"
13inputs = tokenizer(prompt, return_tensors="pt").to(device)
14
15outputs = model.generate(
16 inputs["input_ids"],
17 max_new_tokens=50,
18 do_sample=True,
19 temperature=0.8,
20 top_p=0.95,
21 top_k=40,
22 repetition_penalty=1.2,
23 no_repeat_ngram_size=3,
24 pad_token_id=tokenizer.eos_token_id,
25 eos_token_id=tokenizer.eos_token_id,
26 early_stopping=True,
27)
28
29print(tokenizer.decode(outputs[0], skip_special_tokens=True))1# Test with 10 automated historical prompts
2python 06_inference/test_published_models.py --model_type slm🧪 Testing SLM Model: bahree/london-historical-slm
============================================================
📂 Loading model...
✅ Model loaded in 8.91 seconds
📊 Model Info:
Type: SLM
Description: Small Language Model (117M parameters)
Device: cuda
Vocabulary size: 30,000
Max length: 512
🎯 Testing generation with 10 prompts...
[10 automated tests with historical text generation]1# Interactive mode for custom prompts
2python 06_inference/inference_unified.py --published --model_type slm --interactive
3
4# Single prompt test
5python 06_inference/inference_unified.py --published --model_type slm --prompt "In the year 1834, I walked through the streets of London and witnessed"device_map="auto" to spread layers across available devices/CPU automatically.1from transformers import AutoTokenizer, AutoModelForCausalLM
2tok = AutoTokenizer.from_pretrained(model_id)
3model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")python -c "from transformers import AutoTokenizer,AutoModelForCausalLM; m='bahree/london-historical-slm'; t=AutoTokenizer.from_pretrained(m); model=AutoModelForCausalLM.from_pretrained(m); p='In the year 1834, I walked through the streets of London and witnessed'; i=t(p,return_tensors='pt'); print(t.decode(model.generate(i['input_ids'],max_new_tokens=50,do_sample=True)[0],skip_special_tokens=True))"python -c "from transformers import AutoTokenizer, AutoModelForCausalLM ^&^& import torch ^&^& m='bahree/london-historical-slm' ^&^& t=AutoTokenizer.from_pretrained(m) ^&^& model=AutoModelForCausalLM.from_pretrained(m) ^&^& p='In the year 1834, I walked through the streets of London and witnessed' ^&^& i=t(p, return_tensors='pt') ^&^& print(t.decode(model.generate(i['input_ids'], max_new_tokens=50, do_sample=True)[0], skip_special_tokens=True))"1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3tokenizer = AutoTokenizer.from_pretrained("bahree/london-historical-slm")
4model = AutoModelForCausalLM.from_pretrained("bahree/london-historical-slm")
5
6if tokenizer.pad_token is None:
7 tokenizer.pad_token = tokenizer.eos_token
8
9prompt = "In the year 1834, I walked through the streets of London and witnessed"
10inputs = tokenizer(prompt, return_tensors="pt")
11outputs = model.generate(
12 inputs["input_ids"],
13 max_new_tokens=50,
14 do_sample=True,
15 temperature=0.8,
16 top_p=0.95,
17 top_k=40,
18 repetition_penalty=1.2,
19 no_repeat_ngram_size=3,
20 pad_token_id=tokenizer.pad_token_id,
21 eos_token_id=tokenizer.eos_token_id,
22 early_stopping=True,
23)
24print(tokenizer.decode(outputs[0], skip_special_tokens=True))ImportError: AutoModelForCausalLM requires the PyTorch library
→ Install PyTorch with the correct accelerator variant (see CPU/CUDA/ROCm above or use the official selector).pip install ... --index-url https://download.pytorch.org/whl/rocmX.Y). Verify with torch.cuda.is_available() and check the device name. ROCm wheels are Linux-only.device_map="auto" via 🤗 Accelerate to offload layers to CPU/disk.1@misc{london-historical-slm,
2 title = {London Historical LLM - Small Language Model: A Compact GPT-2 for Historical Text Generation},
3 author = {Amit Bahree},
4 year = {2025},
5 url = {https://huggingface.co/bahree/london-historical-slm}
6}1git clone https://github.com/bahree/helloLondon.git
2cd helloLondon
3python 06_inference/test_published_models.py --model_type slm