Views
No views yet
TinyLlama-1.1B-Chat-v1.0. By loading this residual adapter, you can instantly equip standard causal LLMs with biological continuous-time dynamics, maintaining 100% precision on Long-Context Retrieval (Needle-in-a-Haystack) up to 4K tokens at extremely high efficiency.1git clone https://github.com/everest-an/O1.git
2cd O1
3pip install -r requirements.txt1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
3from mt_lnn.llama_adapter import (
4 attach_adapters_from_checkpoint,
5 load_adapter_state,
6 maybe_apply_lora_for_checkpoint
7)
8from huggingface_hub import hf_hub_download
9
10device = "cuda" if torch.cuda.is_available() else "cpu"
11model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
12
13# 1. Download the adapter weights from Hugging Face
14adapter_path = hf_hub_download(repo_id="EverestAn/MT-LNN", filename="llama_mt_adapter_000500.pt")
15
16# 2. Load Base Model
17tokenizer = AutoTokenizer.from_pretrained(model_id)
18if tokenizer.pad_token is None:
19 tokenizer.pad_token = tokenizer.eos_token
20
21# (Optional) Apply RoPE scaling for 4K+ long context
22config = AutoConfig.from_pretrained(model_id)
23if not hasattr(config, "rope_theta") or config.rope_theta is None: config.rope_theta = 10000.0
24config.rope_scaling = {"type": "linear", "rope_type": "linear", "factor": 4.0}
25
26model = AutoModelForCausalLM.from_pretrained(model_id, config=config, torch_dtype=torch.bfloat16)
27
28# 3. Inject the Microtubule (MT) Adapter
29checkpoint = torch.load(adapter_path, map_location="cpu")
30attach_adapters_from_checkpoint(model, checkpoint)
31model = maybe_apply_lora_for_checkpoint(model, checkpoint)
32load_adapter_state(model, adapter_path, strict=False)
33
34model.to(device).eval()
35
36# 4. Generate
37inputs = tokenizer("What is the biological function of computational microtubules?", return_tensors="pt").to(device)
38outputs = model.generate(**inputs, max_new_tokens=100)
39print(tokenizer.decode(outputs[0], skip_special_tokens=True))| Variant | Context | Depth | Exact | Contains | Tok/s |
|---|---|---|---|---|---|
| Base | 1024-2048 | All | 1.000 | 1.000 | ~800 |
| MT-Adapter | 1024-2048 | All | 1.000 | 1.000 | ~670 (-13%) |
| Base | 4096 (RoPE) | All | 1.000 | 1.000 | ~580 |
| MT-Adapter | 4096 (RoPE) | All | 1.000 | 1.000 | ~545 |