Views
No views yet
meta-llama/Meta-Llama-3-8B-Instruct is preserved. However, the standard LlamaAttention modules have been dynamically replaced with a custom version that utilizes the l_mul_attention function for its core computations. This function is defined in the lmul.py file included in this repository.trust_remote_code=True flag when loading it. This is required to execute the custom lmul.py file that defines the new attention mechanism.transformers library. Since this model is stored in a subdirectory of a collective repository, you first need to download the specific files.1from transformers import AutoTokenizer, AutoModelForCausalLM
2from huggingface_hub import snapshot_download
3import torch
4
5# Define the repository and the specific model subfolder
6repo_id = "Peacemann/LMUL-Optimized-Models"
7model_name = "meta-llama_Meta-Llama-3-8B-Instruct"
8
9# Download the specific model snapshot
10# Note: On Windows, you might need to set local_dir_use_symlinks=False
11local_model_path = snapshot_download(
12 repo_id=repo_id,
13 allow_patterns=f"{model_name}/*",
14)
15# Construct the full path to the model files within the snapshot
16local_model_path = f"{local_model_path}/{model_name}"
17
18
19# Load the tokenizer and model, trusting the remote code to load lmul.py
20tokenizer = AutoTokenizer.from_pretrained(local_model_path)
21model = AutoModelForCausalLM.from_pretrained(
22 local_model_path,
23 trust_remote_code=True,
24 torch_dtype=torch.bfloat16,
25 device_map="auto",
26)
27
28# Example usage
29prompt = "The L-Mul algorithm is an experimental method for..."
30inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
31outputs = model.generate(**inputs, max_new_tokens=50)
32
33print(tokenizer.decode(outputs[0], skip_special_tokens=True))vLLM:1from vllm import LLM
2
3# The local_model_path is the same as downloaded above
4llm = LLM(model=local_model_path, trust_remote_code=True)Llama-3-8B-Instruct model, and its behavior may be altered in unpredictable ways.