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-llm"
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))"In the year 1834, I walked through the streets of London and witnessed a scene in which some of those who had no inclination to come in contact with him took part in his discourse. It was on this occasion that I perceived that he had been engaged in some new business connected with the house, but for some days it had not taken place, nor did he appear so desirous of pursuing any further display of interest. The result was, however, that if he came in contact witli any one else in company with him he must be regarded as an old acquaintance or companion, and when he came to the point of leaving, I had no leisure to take up his abode. The same evening, having ram ##bled about the streets, I observed that the young man who had just arrived from a neighbouring village at the time, was enjoying himself at a certain hour, and I thought that he would sleep quietly until morning, when he said in a low voice — " You are coming. Miss — I have come from the West Indies . " Then my father bade me go into the shop, and bid me put on his spectacles, which he had in his hand; but he replied no: the room was empty, and he did not want to see what had passed. When I asked him the cause of all this conversation, he answered in the affirmative, and turned away, saying that as soon as the lad could recover, the sight of him might be renewed. " Well, Mr. , " said I, " you have got a little more of your wages, do you ? " " No, sir, thank ' ee kindly, " returned the boy, " but we don ' t want to pay the poor rates . We"
1# Test with 10 automated historical prompts
2python 06_inference/test_published_models.py --model_type regular🧪 Testing Regular Model: bahree/london-historical-llm
============================================================
📂 Loading model...
✅ Model loaded in 12.5 seconds
📊 Model Info:
Type: REGULAR
Description: Regular Language Model (354M parameters)
Device: cuda
Vocabulary size: 30,000
Max length: 1024
🎯 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 regular --interactive
3
4# Single prompt test
5python 06_inference/inference_unified.py --published --model_type regular --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-llm'; t=AutoTokenizer.from_pretrained(m); model=AutoModelForCausalLM.from_pretrained(m); p='Today 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-llm' ^&^& t=AutoTokenizer.from_pretrained(m) ^&^& model=AutoModelForCausalLM.from_pretrained(m) ^&^& p='Today 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-llm")
4model = AutoModelForCausalLM.from_pretrained("bahree/london-historical-llm")
5
6if tokenizer.pad_token is None:
7 tokenizer.pad_token = tokenizer.eos_token
8
9prompt = "Today 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.7,
16 top_p=0.9,
17 top_k=30,
18 repetition_penalty=1.25,
19 no_repeat_ngram_size=4,
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.do_sample=False) and avoid complex sampling parameters. This model works best with simple generation settings due to the historical nature of the training data.1@misc{london-historical-llm,
2 title = {London Historical LLM: A Custom GPT-2 for Historical Text Generation},
3 author = {Amit Bahree},
4 year = {2025},
5 url = {https://huggingface.co/bahree/london-historical-llm}
6}1git clone https://github.com/bahree/helloLondon.git
2cd helloLondon
3python 06_inference/test_published_models.py --model_type regular