Landmark Attention: Random-Access Infinite Context Length for Transformers
Paper • 2305.16300 • Published
How to use emozilla/landmark-llama-7b with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="emozilla/landmark-llama-7b", trust_remote_code=True) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("emozilla/landmark-llama-7b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("emozilla/landmark-llama-7b", trust_remote_code=True)How to use emozilla/landmark-llama-7b with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "emozilla/landmark-llama-7b"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "emozilla/landmark-llama-7b",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/emozilla/landmark-llama-7b
How to use emozilla/landmark-llama-7b with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "emozilla/landmark-llama-7b" \
--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": "emozilla/landmark-llama-7b",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "emozilla/landmark-llama-7b" \
--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": "emozilla/landmark-llama-7b",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use emozilla/landmark-llama-7b with Docker Model Runner:
docker model run hf.co/emozilla/landmark-llama-7b
This model is an out-of-the-box ready version of the LLaMA-7B variant of Landmark Attention. The original code is modified from the Landmark GitHub and the weights from here.
As a LLaMA variant, this model may be subject to the LLaMA license.
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import torch
tokenizer = AutoTokenizer.from_pretrained("emozilla/landmark-llama-7b", use_fast=False)
model = AutoModelForCausalLM.from_pretrained("emozilla/landmark-llama-7b", \
torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto")
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
print(pipe("Somebody once told me the world is gonna roll me", \
max_new_tokens=256, temperature=0.8, do_sample=True))
You can configure the Landmark parameters by editing mem_freq, mem_top_k, mem_max_seq_len, and mem_max_cache_size.
config = AutoConfig.from_pretrained("emozilla/landmark-llama-7b", trust_remote_code=True)
config.mem_top_k = 6
model = AutoModelForCausalLM.from_pretrained("emozilla/landmark-llama-7b", \
torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto", config=config)