Views
No views yet
sliding_windows argument.pip install git+https://github.com/kyleliang919/transformerssliding_windows argument is a list where each element specifies the window size for the corresponding layer.
You can load the Sliding Llama model using the following code snippet:
For instance, in the example below there is one full attention in every four layers and have a total interpolated context of 32K (originally llama3 8b has 8K context length)1from transformers import AutoConfig, AutoTokenizer
2from modeling_sliding_llama import LlamaForCausalLM
3# Load the tokenizer and model
4config = AutoConfig.from_pretrained("kz919/sliding_llama3_8b_no_finetune", trust_remote_code=True)
5config.sliding_windows = [512, 512, 512, 0, 512, 512, 512, 0, 512, 512, 512, 0, 512, 512, 512, 0, 512, 512, 512, 0, 512, 512, 512, 0, 512, 512, 512, 0, 512, 512, 512, 0]
6config.rope_scaling = {
7 "factor": 4.0,
8 "high_freq_factor": 4.0,
9 "low_freq_factor": 1.0,
10 "original_max_position_embeddings": 8192,
11 "rope_type": "llama3"
12 }
13tokenizer = AutoTokenizer.from_pretrained("kz919/sliding_llama3_8b_no_finetune")
14model = LlamaForCausalLM.from_pretrained("kz919/sliding_llama3_8b_no_finetune",
15 config = config,
16 device_map="auto",
17 trust_remote_code=True)
18prompt = "Your prompt here"
19inputs = tokenizer(prompt, return_tensors = "pt")
20outputs = model.generate(**inputs, use_cache = True)
21print(tokenizer.decode(outputs[0]))from peft import PeftModel
model = PeftModel.from_pretrained(model, "path_to_your_adepter")
model = model.merge_and_unload()@inproceedings{slidingllama2024,
title={Sliding Llama},
author={Kaizhao Liang},
year={2024}
}